X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FIR.pm;h=2c46e8f613bc1e4c0a4ce4aef07cc33ade94f4fb;hb=6ff1674fc7d8e48723efa5a8152ac468c5d4ea58;hp=909a3b07dcb8ccd6867d9e5f255f6a5c50752393;hpb=5074cc502811728e2bbaf42cfd5ea39974ba6e2a;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index 909a3b07d..2c46e8f61 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -499,6 +499,12 @@ sub post_invoice { # record payments and offsetting AP for my $i (1 .. $form->{paidaccounts}) { + if ($form->{"acc_trans_id_$i"} + && $payments_only + && ($::lx_office_conf{features}->{payments_changeable} == 0)) { + next; + } + next if $form->{"paid_$i"} == 0; my ($accno) = split /--/, $form->{"AP_paid_$i"}; @@ -518,11 +524,14 @@ sub post_invoice { } # record payment - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, taxkey, project_id) - VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, + my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); + + $query = + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id) + VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; @values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, - $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); + $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); do_query($form, $dbh, $query, @values); $exchangerate = 0; @@ -844,6 +853,9 @@ sub retrieve_invoice { $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id})); map { $form->{$_} = $ref->{$_} } keys %$ref; + # remove any trailing whitespace + $form->{currency} =~ s/\s*$//; + $form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell"); # get shipto @@ -1394,10 +1406,12 @@ sub post_payment { $old_form = save_form(); # Delete all entries in acc_trans from prior payments. - $self->_delete_payments($form, $dbh); + if ($::lx_office_conf{features}->{payments_changeable} != 0) { + $self->_delete_payments($form, $dbh); + } # Save the new payments the user made before cleaning up $form. - map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AP_paid_\d+$|^paidaccounts$/, keys %{ $form }; + map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^gldate_\d+$|^acc_trans_id_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AP_paid_\d+$|^paidaccounts$/, keys %{ $form }; # Clean up $form so that old content won't tamper the results. %keep_vars = map { $_, 1 } qw(login password id); @@ -1450,38 +1464,26 @@ sub post_payment { } sub get_duedate { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; - my $self = shift; - my %params = @_; + my ($self, %params) = @_; if (!$params{vendor_id} || !$params{invdate}) { - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; return $params{default}; } - my $myconfig = \%main::myconfig; - my $form = $main::form; - - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - + my $dbh = $::form->get_standard_dbh; my $query = qq|SELECT ?::date + pt.terms_netto FROM vendor v LEFT JOIN payment_terms pt ON (pt.id = v.payment_id) WHERE v.id = ?|; - my ($sth, $duedate); - - if (($sth = $dbh->prepare($query)) && $sth->execute($params{invdate}, conv_i($params{vendor_id}))) { - ($duedate) = $sth->fetchrow_array(); - $sth->finish(); - } else { - $dbh->rollback(); - } + my ($duedate) = selectfirst_array_query($::form, $dbh, $query, $params{invdate}, $params{vendor_id}); $duedate ||= $params{default}; - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; return $duedate; }