X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAR.pm;h=2841743965fc432c39f08ec9a3b558ca9fa775ca;hb=d56c9b0850c73bceeeadc534836c8164928cff71;hp=ca3f61a26ef38f08edf57cc1f6b9e6875514afd9;hpb=727d806576b6eed75107dbf52736c3dd08093004;p=kivitendo-erp.git diff --git a/SL/AR.pm b/SL/AR.pm index ca3f61a26..284174396 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -40,6 +40,7 @@ use SL::DBUtils; use SL::IO; use SL::MoreCommon; use SL::DB::Default; +use SL::TransNumber; use strict; @@ -68,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}; - - for $i (1 .. $form->{rowcount}) { - ($form->{"tax_id_$i"}) = split /--/, $form->{"taxchart_$i"}; + $form->{tax} = 0; # is this still needed? - $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 @@ -116,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); @@ -134,9 +105,12 @@ sub post_transaction { } else { $query = qq|SELECT nextval('glid')|; ($form->{id}) = selectrow_query($form, $dbh, $query); - $query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?))|; - do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency}); - $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber}; + $query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id, taxzone_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?), (SELECT taxzone_id FROM customer WHERE id = ?))|; + do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency}, $form->{customer_id}); + if (!$form->{invnumber}) { + my $trans_number = SL::TransNumber->new(type => 'invoice', dbh => $dbh, number => $form->{partnumber}, id => $form->{id}); + $form->{invnumber} = $trans_number->create_unique; + } } } @@ -328,8 +302,6 @@ sub post_transaction { exporttype => DATEV_ET_BUCHUNGEN, format => DATEV_FORMAT_KNE, dbh => $dbh, - from => $transdate, - to => $transdate, trans_id => $form->{id}, ); @@ -484,17 +456,18 @@ sub ar_transactions { my @values; my $query = - qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.transdate, | . + qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.cusordnumber, a.transdate, | . qq| a.duedate, a.netamount, a.amount, a.paid, | . - qq| a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | . + qq| a.invoice, a.datepaid, a.notes, a.shipvia, | . qq| a.shippingpoint, a.storno, a.storno_id, a.globalproject_id, | . qq| a.marge_total, a.marge_percent, | . - qq| a.transaction_description, | . + qq| a.transaction_description, a.direct_debit, | . qq| pr.projectnumber AS globalprojectnumber, | . qq| c.name, c.customernumber, c.country, c.ustid, b.description as customertype, | . qq| c.id as customer_id, | . qq| e.name AS employee, | . qq| e2.name AS salesman, | . + qq| dc.dunning_description, | . qq| tz.description AS taxzone, | . qq| pt.description AS payment_terms, | . qq{ ( SELECT ch.accno || ' -- ' || ch.description @@ -506,17 +479,19 @@ 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 dunning_config dc ON (a.dunning_config_id = dc.id) | . qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id)| . - qq|LEFT JOIN tax_zones tz ON (tz.id = c.taxzone_id)| . - qq|LEFT JOIN payment_terms pt ON (pt.id = c.payment_id)| . + qq|LEFT JOIN tax_zones tz ON (tz.id = a.taxzone_id)| . + qq|LEFT JOIN payment_terms pt ON (pt.id = a.payment_id)| . qq|LEFT JOIN business b ON (b.id = c.business_id)| . qq|LEFT JOIN department d ON (d.id = a.department_id)|; my $where = "1 = 1"; - unless ( $::auth->assert('show_ar_transactions', 1) ) { + unless ( $::auth->assert('show_ar_transactions', 1) ) { $where .= " AND NOT invoice = 'f' "; # remove ar transactions from Sales -> Reports -> Invoices }; @@ -531,6 +506,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 = ?"; @@ -546,7 +525,7 @@ sub ar_transactions { $where .= " AND d.description ILIKE ?"; push(@values, $department); } - foreach my $column (qw(invnumber ordnumber notes transaction_description)) { + foreach my $column (qw(invnumber ordnumber cusordnumber notes transaction_description)) { if ($form->{$column}) { $where .= " AND a.$column ILIKE ?"; push(@values, $form->like($form->{$column})); @@ -572,6 +551,14 @@ sub ar_transactions { $where .= " AND a.transdate <= ?"; push(@values, $form->{transdateto}); } + if ($form->{duedatefrom}) { + $where .= " AND a.duedate >= ?"; + push(@values, $form->{duedatefrom}); + } + if ($form->{duedateto}) { + $where .= " AND a.duedate <= ?"; + push(@values, $form->{duedateto}); + } if ($form->{open} || $form->{closed}) { unless ($form->{open} && $form->{closed}) { $where .= " AND a.amount <> a.paid" if ($form->{open}); @@ -582,7 +569,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 = ?"; @@ -594,12 +581,21 @@ 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'; my $sortorder = join(', ', map { "$_ $sortdir" } @a); - if (grep({ $_ eq $form->{sort} } qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description))) { + if (grep({ $_ eq $form->{sort} } qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description))) { $sortorder = $form->{sort} . " $sortdir"; } @@ -638,7 +634,7 @@ sub setup_form { my ($self, $form, $for_post_payments) = @_; my ($exchangerate, $akey, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate, - $totalamount, $taxincluded, $tax); + $totalamount, $tax); # forex $form->{forex} = $form->{exchangerate}; @@ -722,7 +718,6 @@ sub setup_form { } } - $form->{taxincluded} = $taxincluded if ($form->{id}); $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; if ($form->{taxincluded} && $form->{taxrate} && $totalamount) { @@ -801,4 +796,3 @@ sub storno { 1; -