|
1 |
package SL::DB::Helper::FlattenToForm;
|
|
2 |
|
|
3 |
use strict;
|
|
4 |
|
|
5 |
use parent qw(Exporter);
|
|
6 |
our @EXPORT = qw(flatten_to_form);
|
|
7 |
|
|
8 |
use List::MoreUtils qw(any);
|
|
9 |
|
|
10 |
use SL::CVar;
|
|
11 |
|
|
12 |
sub flatten_to_form {
|
|
13 |
my ($self, $form, $format_amounts) = @_;
|
|
14 |
|
|
15 |
my $vc = $self->can('customer_id') && $self->customer_id ? 'customer' : 'vendor';
|
|
16 |
|
|
17 |
_copy($self, $form, '', '', 0, qw(id type taxzone_id ordnumber quonumber invnumber donumber cusordnumber taxincluded shippingpoint shipvia notes intnotes curr cp_id
|
|
18 |
employee_id salesman_id closed department_id language_id payment_id delivery_customer_id delivery_vendor_id shipto_id proforma
|
|
19 |
globalproject_id delivered transaction_description container_type accepted_by_customer orddate quodate reqdate gldate duedate deliverydate
|
|
20 |
datepaid invoice terms storno storno_id dunning_config_id));
|
|
21 |
|
|
22 |
if (_has($self, 'transdate')) {
|
|
23 |
my $transdate_idx = ref($self) eq 'SL::DB::Order' ? ($self->quotation ? 'quodate' : 'orddate')
|
|
24 |
: ref($self) eq 'SL::DB::Invoice' ? 'invdate'
|
|
25 |
: 'transdate';
|
|
26 |
$form->{$transdate_idx} = $self->transdate->to_lxoffice;
|
|
27 |
}
|
|
28 |
|
|
29 |
_copy($self, $form, '', '', 1, qw(amount netamount marge_total marge_percent container_remaining_weight container_remaining_volume
|
|
30 |
paid));
|
|
31 |
_copy($self->$vc, $form, "${vc}_", '', 0, map { $_->name } ref($self->$vc)->meta->columns);
|
|
32 |
_copy($self->contact, $form, '', '', 0, grep { /^cp_/ } map { $_->name } SL::DB::Contact->meta->columns) if _has($self, 'cp_id');
|
|
33 |
_copy($self->shipto, $form, '', '', 0, grep { /^shipto/ } map { $_->name } SL::DB::Shipto->meta->columns) if _has($self, 'shipto_id');
|
|
34 |
_copy($self->globalproject, $form, 'globalproject', '', 0, qw(number description)) if _has($self, 'globalproject_id');
|
|
35 |
_copy($self->employee, $form, 'employee', '', 0, map { $_->name } SL::DB::Employee->meta->columns) if _has($self, 'employee_id');
|
|
36 |
_copy($self->salesman, $form, 'salesman', '', 0, map { $_->name } SL::DB::Employee->meta->columns) if _has($self, 'salesman_id');
|
|
37 |
_copy($self->acceptance_confirmed_by, $form, 'acceptance_confirmed_by_', '', 0, map { $_->name } SL::DB::Employee->meta->columns) if _has($self, 'acceptance_confirmed_by_id');
|
|
38 |
|
|
39 |
$form->{language} = $self->language_code if _has($self, 'language_id');
|
|
40 |
$form->{department} = $self->department->description if _has($self, 'department_id');
|
|
41 |
$form->{rowcount} = scalar(@{ $self->items });
|
|
42 |
|
|
43 |
my $idx = 0;
|
|
44 |
foreach my $item (@{ $self->items }) {
|
|
45 |
next if _has($item, 'assemblyitem');
|
|
46 |
|
|
47 |
$idx++;
|
|
48 |
|
|
49 |
$form->{"id_${idx}"} = $item->parts_id;
|
|
50 |
$form->{"number_${idx}"} = $item->part->partnumber;
|
|
51 |
_copy($item, $form, '', "_${idx}", 0, qw(description project_id ship serialnumber pricegroup_id ordnumber cusordnumber unit
|
|
52 |
subtotal longdescription price_factor_id marge_price_factor approved_sellprice reqdate transdate));
|
|
53 |
_copy($item, $form, '', "_${idx}", $format_amounts, qw(qty sellprice discount marge_total marge_percent lastcost));
|
|
54 |
_copy($item->project, $form, 'project', "_${idx}", 0, qw(number description)) if _has($item, 'project_id');
|
|
55 |
|
|
56 |
_copy_custom_variables($item, $form, 'ic_cvar_', "_${idx}");
|
|
57 |
}
|
|
58 |
|
|
59 |
_copy_custom_variables($self, $form, 'vc_cvar_', '');
|
|
60 |
# TODO: CustomVariables
|
|
61 |
|
|
62 |
return $self;
|
|
63 |
}
|
|
64 |
|
|
65 |
sub _has {
|
|
66 |
my ($obj, $column) = @_;
|
|
67 |
return $obj->can($column) && $obj->$column;
|
|
68 |
}
|
|
69 |
|
|
70 |
sub _copy {
|
|
71 |
my ($src, $form, $prefix, $postfix, $format_amounts, @columns) = @_;
|
|
72 |
|
|
73 |
map { $form->{"${prefix}${_}${postfix}"} = ref($src->$_) eq 'DateTime' ? $src->$_->to_lxoffice : $src->$_ if $src->can($_) } @columns if !$format_amounts;
|
|
74 |
map { $form->{"${prefix}${_}${postfix}"} = $::form->format_amount(\%::myconfig, $src->$_ * 1, 2) if $src->can($_) } @columns if $format_amounts;
|
|
75 |
|
|
76 |
return $src;
|
|
77 |
}
|
|
78 |
|
|
79 |
sub _copy_custom_variables {
|
|
80 |
my ($src, $form, $prefix, $postfix) = @_;
|
|
81 |
|
|
82 |
my ($module, $sub_module, $trans_id) = ref($src) eq 'SL::DB::OrderItem' ? ('IC', 'orderitems', $src->id)
|
|
83 |
: ref($src) eq 'SL::DB::DeliveryOrderItem' ? ('IC', 'delivery_order_items', $src->id)
|
|
84 |
: ref($src) eq 'SL::DB::InvoiceItem' ? ('IC', 'invoice', $src->id)
|
|
85 |
: ('CT', undef, _has($src, 'customer_id') ? $src->customer_id : $src->vendor_id);
|
|
86 |
|
|
87 |
return unless $trans_id;
|
|
88 |
|
|
89 |
my $cvars = CVar->get_custom_variables(dbh => $src->db->dbh,
|
|
90 |
module => $module,
|
|
91 |
sub_module => $sub_module,
|
|
92 |
trans_id => $trans_id,
|
|
93 |
);
|
|
94 |
map { $form->{ $prefix . $_->{name} . $postfix } = $_->{value} } @{ $cvars };
|
|
95 |
|
|
96 |
return $src;
|
|
97 |
}
|
|
98 |
|
|
99 |
1;
|
Mechanismus zur Konvertierung von RDBO-Objekten nach $form für $form->parse_template
Noch leicht unvollständig
Conflicts: