X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDN.pm;h=1804959f955b3f87122688d98345122064f48418;hb=2134f89abb07c18b07b3121e80d243af03ede0e0;hp=976a238855d6684241e8f8d022206ca2a55f7fcf;hpb=718f7a1b58963922cb3a4512692e15e2b4267ee7;p=kivitendo-erp.git diff --git a/SL/DN.pm b/SL/DN.pm index 976a23885..1804959f9 100644 --- a/SL/DN.pm +++ b/SL/DN.pm @@ -45,6 +45,7 @@ use SL::Template; use SL::DB::Printer; use SL::DB::Language; use SL::TransNumber; +use SL::Util qw(trim); use strict; @@ -211,7 +212,7 @@ sub create_invoice_for_fees { $query = qq|INSERT INTO ar (id, invnumber, transdate, gldate, customer_id, taxincluded, amount, netamount, paid, duedate, - invoice, currency_id, notes, + invoice, currency_id, taxzone_id, notes, employee_id) VALUES ( ?, -- id @@ -232,6 +233,14 @@ sub create_invoice_for_fees { (SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1), 'f', -- invoice (SELECT id FROM currencies WHERE name = ?), -- curr + --taxzone_id: + (SELECT taxzone_id FROM customer WHERE id = + (SELECT ar.customer_id + FROM dunning dn + LEFT JOIN ar ON (dn.trans_id = ar.id) + WHERE dn.dunning_id = ? + LIMIT 1) + ), ?, -- notes -- employee_id: (SELECT id FROM employee WHERE login = ?) @@ -243,8 +252,9 @@ sub create_invoice_for_fees { $amount, $dunning_id, # duedate $curr, # default currency + $dunning_id, # taxzone_id sprintf($main::locale->text('Automatically created invoice for fee and interest for dunning %s'), $dunning_id), # notes - $form->{login}); # employee_id + $::myconfig{login}); # employee_id do_query($form, $dbh, $query, @values); $query = @@ -482,7 +492,7 @@ sub get_invoices { } elsif ($form->{customer}) { $where .= qq| AND (ct.name ILIKE ?)|; - push(@values, '%' . $form->{customer} . '%'); + push(@values, like($form->{customer})); } my %columns = ( @@ -494,7 +504,7 @@ sub get_invoices { foreach my $key (keys(%columns)) { next unless ($form->{$key}); $where .= qq| AND $columns{$key} ILIKE ?|; - push(@values, '%' . $form->{$key} . '%'); + push(@values, like($form->{$key})); } if ($form->{dunning_level}) { @@ -505,7 +515,7 @@ sub get_invoices { $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount}); if ($form->{minamount}) { $where .= qq| AND ((a.amount - a.paid) > ?) |; - push(@values, $form->{minamount}); + push(@values, trim($form->{minamount})); } my $query = @@ -514,11 +524,16 @@ sub get_invoices { WHERE dunning_level = (SELECT MAX(dunning_level) FROM dunning_config)|; my ($id_for_max_dunning_level) = selectrow_query($form, $dbh, $query); + if (!$form->{l_include_direct_debit}) { + $where .= qq| AND NOT COALESCE(a.direct_debit, FALSE) |; + } + $query = qq|SELECT - a.id, a.ordnumber, a.transdate, a.invnumber, a.amount, a.language_id, + a.id, a.invoice, a.ordnumber, a.transdate, a.invnumber, a.amount, a.language_id, ct.name AS customername, a.customer_id, a.duedate, a.amount - a.paid AS open_amount, + a.direct_debit, cfg.dunning_description, cfg.dunning_level, @@ -604,7 +619,7 @@ sub get_dunning { } elsif ($form->{customer}) { $where .= qq| AND (ct.name ILIKE ?)|; - push(@values, '%' . $form->{customer} . '%'); + push(@values, like($form->{customer})); } my %columns = ( @@ -615,7 +630,7 @@ sub get_dunning { foreach my $key (keys(%columns)) { next unless ($form->{$key}); $where .= qq| AND $columns{$key} ILIKE ?|; - push(@values, '%' . $form->{$key} . '%'); + push(@values, like($form->{$key})); } if ($form->{dunning_level}) { @@ -873,7 +888,7 @@ sub print_dunning { push @{ $form->{DUNNING_PDFS} }, $filename; push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'filename' => "${spool}/$filename", - 'name' => "dunning_${dunning_id}.pdf" }; + 'name' => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" }; $form->parse_template($myconfig); @@ -926,7 +941,7 @@ sub print_invoice_for_fees { map { $form->{$_} = $ref->{$_} } keys %{ $ref }; $query = qq|SELECT * FROM employee WHERE login = ?|; - $ref = selectfirst_hashref_query($form, $dbh, $query, $form->{login}); + $ref = selectfirst_hashref_query($form, $dbh, $query, $::myconfig{login}); map { $form->{"employee_${_}"} = $ref->{$_} } keys %{ $ref }; $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY acc_trans_id ASC|;