X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAP.pm;h=95b0d5208fa5d5d5bf2b70a3b5c3656c219672c2;hb=daaac66a83e3dbdcc910731a1695e7e59b9cbbc6;hp=8de1c3ca7a17f48274ab5e449b8c8f5d5e020f4d;hpb=1b15807093421ca00493a447048b960f2f512152;p=kivitendo-erp.git diff --git a/SL/AP.pm b/SL/AP.pm index 8de1c3ca7..95b0d5208 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -39,6 +39,7 @@ use SL::DBUtils; use SL::IO; use SL::MoreCommon; use SL::DB::Default; +use SL::Util qw(trim); use Data::Dumper; use strict; @@ -148,6 +149,8 @@ sub post_transaction { $form->{id}); do_query($form, $dbh, $query, @values); + $form->new_lastmtime('ap'); + # add individual transactions for my $i (1 .. $form->{rowcount}) { if ($form->{"amount_$i"} != 0) { @@ -316,6 +319,15 @@ sub post_transaction { $form->{"exchangerate_$i"}), 2); if ($amount != 0) { + # fetch fxgain and fxloss chart info from defaults if charts aren't already filled in form + if ( !$form->{fxgain_accno} && $::instance_conf->get_fxgain_accno_id ) { + $form->{fxgain_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxgain_accno_id)->accno; + }; + if ( !$form->{fxloss_accno} && $::instance_conf->get_fxloss_accno_id ) { + $form->{fxloss_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxloss_accno_id)->accno; + }; + die "fxloss_accno missing" if $amount < 0 and not $form->{fxloss_accno}; + die "fxgain_accno missing" if $amount > 0 and not $form->{fxgain_accno}; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . @@ -349,6 +361,7 @@ sub post_transaction { if ($payments_only) { $query = qq|UPDATE ap SET paid = ?, datepaid = ? WHERE id = ?|; do_query($form, $dbh, $query, $form->{invpaid}, $form->{invpaid} ? conv_date($form->{datepaid}) : undef, conv_i($form->{id})); + $form->new_lastmtime('ap'); } IO->set_datepaid(table => 'ap', id => $form->{id}, dbh => $dbh); @@ -362,8 +375,6 @@ sub post_transaction { exporttype => DATEV_ET_BUCHUNGEN, format => DATEV_FORMAT_KNE, dbh => $dbh, - from => $transdate, - to => $transdate, trans_id => $form->{id}, ); @@ -418,7 +429,7 @@ sub ap_transactions { my $query = qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, a.amount, a.paid, | . qq| a.ordnumber, v.name, a.invoice, a.netamount, a.datepaid, a.notes, | . - qq| a.globalproject_id, a.storno, a.storno_id, | . + qq| a.globalproject_id, a.storno, a.storno_id, a.direct_debit, | . qq| pr.projectnumber AS globalprojectnumber, | . qq| e.name AS employee, | . qq| v.vendornumber, v.country, v.ustid, | . @@ -452,11 +463,11 @@ sub ap_transactions { push(@values, $form->{vendor_id}); } elsif ($form->{vendor}) { $where .= " AND v.name ILIKE ?"; - push(@values, $form->like($form->{vendor})); + push(@values, like($form->{vendor})); } if ($form->{"cp_name"}) { $where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push(@values, ('%' . $form->{"cp_name"} . '%')x2); + push(@values, (like($form->{"cp_name"}))x2); } if ($form->{department}) { # ähnlich wie commit 0bbfb33b6aa8e38bb6c81d1684ab7d08e5b5c5af abteilung @@ -468,19 +479,19 @@ sub ap_transactions { } if ($form->{invnumber}) { $where .= " AND a.invnumber ILIKE ?"; - push(@values, $form->like($form->{invnumber})); + push(@values, like($form->{invnumber})); } if ($form->{ordnumber}) { $where .= " AND a.ordnumber ILIKE ?"; - push(@values, $form->like($form->{ordnumber})); + push(@values, like($form->{ordnumber})); } if ($form->{notes}) { $where .= " AND lower(a.notes) LIKE ?"; - push(@values, $form->like($form->{notes})); + push(@values, like($form->{notes})); } if ($form->{project_id}) { $where .= - qq|AND ((a.globalproject_id = ?) OR EXISTS | . + qq| AND ((a.globalproject_id = ?) OR EXISTS | . qq| (SELECT * FROM invoice i | . qq| WHERE i.project_id = ? AND i.trans_id = a.id) | . qq| OR EXISTS | . @@ -492,11 +503,11 @@ sub ap_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->{open} || $form->{closed}) { unless ($form->{open} && $form->{closed}) { @@ -505,6 +516,33 @@ sub ap_transactions { } } + if ($form->{parts_partnumber}) { + $where .= <{parts_partnumber}); + } + + if ($form->{parts_description}) { + $where .= <{parts_description}); + } + if ($where) { substr($where, 0, 4, " WHERE "); $query .= $where; @@ -515,7 +553,7 @@ sub ap_transactions { my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC'; my $sortorder = join(', ', map { "$_ $sortdir" } @a); - if (grep({ $_ eq $form->{sort} } qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee transaction_description))) { + if (grep({ $_ eq $form->{sort} } qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee transaction_description direct_debit))) { $sortorder = $form->{sort} . " $sortdir"; } @@ -717,7 +755,7 @@ sub setup_form { } $index = $form->{acc_trans}{$key}->[$i - 1]->{index}; - $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; + $form->{"tax_$index"} = $form->round_amount($form->{acc_trans}{$key}->[$i - 1]->{amount} * -1 / $exchangerate, 2); $totaltax += $form->{"tax_$index"}; } else { @@ -810,6 +848,8 @@ sub storno { $query = qq|UPDATE ap SET paid = amount + paid, storno = 't' WHERE id = ?|; do_query($form, $dbh, $query, $id); + $form->new_lastmtime('ap') 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);