X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAP.pm;h=95b0d5208fa5d5d5bf2b70a3b5c3656c219672c2;hb=691a12938bb3c3d1f6be31f93764d02fc3be6b71;hp=7db5649f6856c90af12e1f4e3c154f0f01a83114;hpb=8c1d5d7530f3a1c923ee470b7ff31616800a8574;p=kivitendo-erp.git diff --git a/SL/AP.pm b/SL/AP.pm index 7db5649f6..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; @@ -318,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', ?, | . @@ -453,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 @@ -469,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 | . @@ -493,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}) { @@ -506,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; @@ -718,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 { @@ -832,8 +869,6 @@ sub storno { map { IO->set_datepaid(table => 'ap', id => $_, dbh => $dbh) } ($id, $new_id); - $form->new_lastmtime('ap') if $storno_id == $form->{id}; - $dbh->commit; $main::lxdebug->leave_sub();