X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAR.pm;h=a2cad1196afadf59b8931a8efb5d973f40bcf3d6;hb=da6a187ab3fc3cbb97e094559dc964a9809f347b;hp=692967fae01a3024dad8c82fb3cacdef5b79bb3f;hpb=b98b8e3f73a399d2d4df7be4962b56bd4ad8c82b;p=kivitendo-erp.git diff --git a/SL/AR.pm b/SL/AR.pm index 692967fae..a2cad1196 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -41,6 +41,7 @@ use SL::IO; use SL::MoreCommon; use SL::DB::Default; use SL::TransNumber; +use SL::Util qw(trim); use strict; @@ -183,6 +184,8 @@ sub post_transaction { do_query($form, $dbh, $query, $form->{paid}, $form->{paid} ? conv_date($form->{datepaid}) : undef, conv_i($form->{id})); } + $form->new_lastmtime('ar'); + # add paid transactions for my $i (1 .. $form->{paidaccounts}) { @@ -302,8 +305,6 @@ sub post_transaction { exporttype => DATEV_ET_BUCHUNGEN, format => DATEV_FORMAT_KNE, dbh => $dbh, - from => $transdate, - to => $transdate, trans_id => $form->{id}, ); @@ -460,15 +461,16 @@ sub ar_transactions { my $query = 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 @@ -483,6 +485,7 @@ sub ar_transactions { 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 = a.taxzone_id)| . qq|LEFT JOIN payment_terms pt ON (pt.id = a.payment_id)| . @@ -497,7 +500,7 @@ sub ar_transactions { if ($form->{customernumber}) { $where .= " AND c.customernumber = ?"; - push(@values, $form->{customernumber}); + push(@values, trim($form->{customernumber})); } if ($form->{customer_id}) { $where .= " AND a.customer_id = ?"; @@ -508,7 +511,7 @@ sub ar_transactions { } if ($form->{"cp_name"}) { $where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push(@values, ('%' . $form->{"cp_name"} . '%')x2); + push(@values, ('%' . trim($form->{"cp_name"}) . '%')x2); } if ($form->{business_id}) { my $business_id = $form->{business_id}; @@ -521,7 +524,7 @@ sub ar_transactions { push(@values, $department_id); } if ($form->{department}) { - my $department = "%" . $form->{department} . "%"; + my $department = "%" . trim($form->{department}) . "%"; $where .= " AND d.description ILIKE ?"; push(@values, $department); } @@ -545,11 +548,19 @@ sub ar_transactions { if ($form->{transdatefrom}) { $where .= " AND a.transdate >= ?"; - push(@values, $form->{transdatefrom}); + push(@values, trim($form->{transdatefrom})); } if ($form->{transdateto}) { $where .= " AND a.transdate <= ?"; - push(@values, $form->{transdateto}); + push(@values, trim($form->{transdateto})); + } + if ($form->{duedatefrom}) { + $where .= " AND a.duedate >= ?"; + push(@values, trim($form->{duedatefrom})); + } + if ($form->{duedateto}) { + $where .= " AND a.duedate <= ?"; + push(@values, trim($form->{duedateto})); } if ($form->{open} || $form->{closed}) { unless ($form->{open} && $form->{closed}) { @@ -561,7 +572,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 = ?"; @@ -573,6 +584,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'; @@ -753,6 +773,8 @@ sub storno { $query = qq|UPDATE ar SET paid = amount + paid, storno = 't' WHERE id = ?|; do_query($form, $dbh, $query, $id); + $form->new_lastmtime('ar') if $id == $form->{id}; + # now copy acc_trans entries $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.acc_trans_id|; my $rowref = selectall_hashref_query($form, $dbh, $query, $id);