X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAR.pm;h=81be410e819f7d490d57c233be811c26a37aa2e0;hb=0b8b24545c98eb4cf22bda155d0e7efbf2bdcdb7;hp=95aba2680e906805620991afa94d773f2a172586;hpb=ea14cfa54fc510f47a4ec9a85939deacf780adde;p=kivitendo-erp.git diff --git a/SL/AR.pm b/SL/AR.pm index 95aba2680..81be410e8 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -69,40 +69,11 @@ sub post_transaction { $form->{AR_amounts}{receivables} = $form->{ARselected}; $form->{AR}{receivables} = $form->{ARselected}; - # parsing - for $i (1 .. $form->{rowcount}) { - $form->{"amount_$i"} = $form->round_amount($form->parse_amount($myconfig, $form->{"amount_$i"}) * $form->{exchangerate}, 2); - $form->{amount} += $form->{"amount_$i"}; - $form->{"tax_$i"} = $form->parse_amount($myconfig, $form->{"tax_$i"}); - } - - # this is for ar - $form->{tax} = 0; - $form->{netamount} = 0; - $form->{total_tax} = 0; - - # taxincluded doesn't make sense if there is no amount - $form->{taxincluded} = 0 unless $form->{amount}; + $form->{tax} = 0; # is this still needed? - for $i (1 .. $form->{rowcount}) { - ($form->{"tax_id_$i"}) = split /--/, $form->{"taxchart_$i"}; - - $query = qq|SELECT c.accno, t.taxkey, t.rate FROM tax t LEFT JOIN chart c ON (c.id = t.chart_id) WHERE t.id = ? ORDER BY c.accno|; - ($form->{AR_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = selectrow_query($form, $dbh, $query, $form->{"tax_id_$i"}); - - if ($form->{taxincluded} *= 1) { - $tax = $form->{"korrektur_$i"} - ? $form->{"tax_$i"} - : $form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1)); # should be same as taxrate * amount / (taxrate + 1) - $form->{"amount_$i"} = $form->round_amount($form->{"amount_$i"} - $tax, 2); - $form->{"tax_$i"} = $form->round_amount($tax, 2); - } else { - $form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"} unless $form->{"korrektur_$i"}; - $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2); - } - $form->{netamount} += $form->{"amount_$i"}; - $form->{total_tax} += $form->{"tax_$i"}; - } + # main calculation of rowcount loop inside Form method, amount_$i and tax_$i get formatted + $form->{taxincluded} = 0 unless $form->{taxincluded}; + ($form->{netamount},$form->{total_tax},$form->{amount}) = $form->calculate_arap('sell', $form->{taxincluded}, $form->{exchangerate}); # adjust paidaccounts if there is no date in the last row # this does not apply to stornos, where the paid field is set manually @@ -117,7 +88,6 @@ sub post_transaction { $form->{datepaid} = $form->{"datepaid_$i"}; } - $form->{amount} = $form->{netamount} + $form->{total_tax}; } $form->{paid} = $form->round_amount($form->{paid} * ($form->{exchangerate} || 1), 2); @@ -332,8 +302,6 @@ sub post_transaction { exporttype => DATEV_ET_BUCHUNGEN, format => DATEV_FORMAT_KNE, dbh => $dbh, - from => $transdate, - to => $transdate, trans_id => $form->{id}, ); @@ -510,6 +478,7 @@ sub ar_transactions { ) AS charts } . qq|FROM ar a | . qq|JOIN customer c ON (a.customer_id = c.id) | . + qq|LEFT JOIN contacts cp ON (a.cp_id = cp.cp_id) | . qq|LEFT JOIN employee e ON (a.employee_id = e.id) | . qq|LEFT JOIN employee e2 ON (a.salesman_id = e2.id) | . qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id)| . @@ -535,6 +504,10 @@ sub ar_transactions { $where .= " AND c.name ILIKE ?"; push(@values, $form->like($form->{customer})); } + if ($form->{"cp_name"}) { + $where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; + push(@values, ('%' . $form->{"cp_name"} . '%')x2); + } if ($form->{business_id}) { my $business_id = $form->{business_id}; $where .= " AND c.business_id = ?"; @@ -586,7 +559,7 @@ sub ar_transactions { if (!$main::auth->assert('sales_all_edit', 1)) { # only show own invoices $where .= " AND a.employee_id = (select id from employee where login= ?)"; - push (@values, $form->{login}); + push (@values, $::myconfig{login}); } else { if ($form->{employee_id}) { $where .= " AND a.employee_id = ?"; @@ -598,6 +571,15 @@ sub ar_transactions { } }; + my ($cvar_where, @cvar_values) = CVar->build_filter_query('module' => 'CT', + 'trans_id_field' => 'c.id', + 'filter' => $form, + ); + if ($cvar_where) { + $where .= qq| AND ($cvar_where)|; + push @values, @cvar_values; + } + my @a = qw(transdate invnumber name); push @a, "employee" if $form->{l_employee}; my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';