89 |
89 |
|
90 |
90 |
my $vc = $form->{vc} eq "customer" ? "customer" : "vendor";
|
91 |
91 |
|
|
92 |
if ($form->{type} !~ /_quotation/) {
|
|
93 |
$form->{hide_amounts} = !( ($vc eq 'customer' && $::auth->assert('sales_order_reports_amounts', 1))
|
|
94 |
|| ($vc eq 'vendor' && $::auth->assert('purchase_order_reports_amounts', 1)) );
|
|
95 |
$form->{hide_links} = $form->{hide_amounts};
|
|
96 |
}
|
|
97 |
|
|
98 |
if ($form->{hide_amounts}) {
|
|
99 |
$form->{"l_$_"} = '' for qw(remaining_amount remaining_netamount amount netamount marge_total marge_percent expected_netamount tax);
|
|
100 |
}
|
|
101 |
|
92 |
102 |
my %billed_amount;
|
93 |
103 |
my %billed_netamount;
|
94 |
|
if ($form->{l_remaining_amount} || $form->{l_remaining_netamount}) {
|
|
104 |
if (!$form->{hide_amounts} && ($form->{l_remaining_amount} || $form->{l_remaining_netamount})) {
|
95 |
105 |
my $arap = $form->{vc} eq "customer" ? "ar" : "ap";
|
96 |
106 |
|
97 |
107 |
$query = <<"SQL";
|
... | ... | |
127 |
137 |
$phone_notes_join = qq| JOIN notes phone_notes ON (o.id = phone_notes.trans_id AND phone_notes.trans_module LIKE 'oe') |;
|
128 |
138 |
}
|
129 |
139 |
|
|
140 |
my $amount_columns = $form->{hide_amounts}
|
|
141 |
? ''
|
|
142 |
: qq| , o.amount, o.netamount, o.marge_total, o.marge_percent, (o.netamount * o.order_probability / 100) AS expected_netamount |;
|
|
143 |
|
130 |
144 |
$query =
|
131 |
|
qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate, | .
|
132 |
|
qq| o.amount, ct.${vc}number, ct.name, o.netamount, o.${vc}_id, o.globalproject_id, | .
|
|
145 |
qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate | .
|
|
146 |
$amount_columns .
|
|
147 |
qq| , ct.${vc}number, ct.name, o.${vc}_id, o.globalproject_id, | .
|
133 |
148 |
qq| o.closed, o.delivered, o.quonumber, o.cusordnumber, o.shippingpoint, o.shipvia, | .
|
134 |
149 |
qq| o.transaction_description, | .
|
135 |
|
qq| o.marge_total, o.marge_percent, | .
|
136 |
150 |
qq| o.exchangerate, | .
|
137 |
151 |
qq| o.itime::DATE AS insertdate, | .
|
138 |
152 |
qq| o.intnotes,| .
|
... | ... | |
149 |
163 |
qq| order_statuses.name AS order_status | .
|
150 |
164 |
$periodic_invoices_columns .
|
151 |
165 |
$phone_notes_columns .
|
152 |
|
qq| , o.order_probability, o.expected_billing_date, (o.netamount * o.order_probability / 100) AS expected_netamount | .
|
|
166 |
qq| , o.order_probability, o.expected_billing_date | .
|
153 |
167 |
qq|FROM oe o | .
|
154 |
168 |
qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | .
|
155 |
169 |
qq|LEFT JOIN contacts cp ON (o.cp_id = cp.cp_id) | .
|
... | ... | |
497 |
511 |
my %id = ();
|
498 |
512 |
$form->{OE} = [];
|
499 |
513 |
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
|
500 |
|
$ref->{billed_amount} = $billed_amount{$ref->{id}};
|
501 |
|
$ref->{billed_netamount} = $billed_netamount{$ref->{id}};
|
502 |
|
if ($ref->{billed_amount} < 0) { # case: credit note(s) higher than invoices
|
503 |
|
$ref->{remaining_amount} = $ref->{amount} + $ref->{billed_amount};
|
504 |
|
$ref->{remaining_netamount} = $ref->{netamount} + $ref->{billed_netamount};
|
505 |
|
} else {
|
506 |
|
$ref->{remaining_amount} = $ref->{amount} - $ref->{billed_amount};
|
507 |
|
$ref->{remaining_netamount} = $ref->{netamount} - $ref->{billed_netamount};
|
|
514 |
if (!$form->{hide_amounts}) {
|
|
515 |
$ref->{billed_amount} = $billed_amount{$ref->{id}};
|
|
516 |
$ref->{billed_netamount} = $billed_netamount{$ref->{id}};
|
|
517 |
if ($ref->{billed_amount} < 0) { # case: credit note(s) higher than invoices
|
|
518 |
$ref->{remaining_amount} = $ref->{amount} + $ref->{billed_amount};
|
|
519 |
$ref->{remaining_netamount} = $ref->{netamount} + $ref->{billed_netamount};
|
|
520 |
} else {
|
|
521 |
$ref->{remaining_amount} = $ref->{amount} - $ref->{billed_amount};
|
|
522 |
$ref->{remaining_netamount} = $ref->{netamount} - $ref->{billed_netamount};
|
|
523 |
}
|
508 |
524 |
}
|
|
525 |
|
509 |
526 |
$ref->{exchangerate} ||= $ref->{daily_exchangerate};
|
510 |
527 |
$ref->{exchangerate} ||= 1;
|
|
528 |
|
511 |
529 |
push @{ $form->{OE} }, $ref if $ref->{id} != $id{ $ref->{id} };
|
512 |
530 |
$id{ $ref->{id} } = $ref->{id};
|
513 |
531 |
}
|
Auftragsbericht ohne Beträge u. Links, wenn kein Recht