X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAP.pm;h=2da4eca6ca8dfcdbd78895b460817a8de1c072f5;hb=f0ce00ebc34b16381f25c9ce75d36521bd046e1f;hp=0f2e8ee0736b5ce46e301af8141c380e8e09407a;hpb=1118dab96d2c42e872c9782b4374709d52b20653;p=kivitendo-erp.git diff --git a/SL/AP.pm b/SL/AP.pm index 0f2e8ee07..2da4eca6c 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -48,6 +48,8 @@ sub post_transaction { my ($null, $taxrate, $amount); my $exchangerate = 0; + $form->{defaultcurrency} = $form->get_default_currency($myconfig); + ($null, $form->{department_id}) = split(/--/, $form->{department}); $form->{department_id} *= 1; @@ -743,5 +745,57 @@ sub setup_form { $main::lxdebug->leave_sub(); } +sub storno { + $main::lxdebug->enter_sub(); + + my ($self, $form, $myconfig, $id) = @_; + + my ($query, $new_id, $storno_row, $acc_trans_rows); + my $dbh = $form->get_standard_dbh($myconfig); + + $query = qq|SELECT nextval('glid')|; + ($new_id) = selectrow_query($form, $dbh, $query); + + $query = qq|SELECT * FROM ap WHERE id = ?|; + $storno_row = selectfirst_hashref_query($form, $dbh, $query, $id); + + $storno_row->{id} = $new_id; + $storno_row->{storno_id} = $id; + $storno_row->{storno} = 't'; + $storno_row->{invnumber} = 'Storno-' . $storno_row->{invnumber}; + $storno_row->{amount} *= -1; + $storno_row->{netamount} *= -1; + $storno_row->{paid} = $storno_amount->{amount}; + + delete @$storno_row{qw(itime mtime)}; + + $query = sprintf 'INSERT INTO ap (%s) VALUES (%s)', join(', ', keys %$storno_row), join(', ', map '?', values %$storno_row); + do_query($form, $dbh, $query, (values %$storno_row)); + + $query = qq|UPDATE ap SET paid = amount + paid, storno = 't' WHERE id = ?|; + do_query($form, $dbh, $query, $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 = ?|; + my $rowref = selectall_hashref_query($form, $dbh, $query, $id); + + # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/ + while ($rowref->[-1]{link} =~ /paid/) { + splice(@$rowref, -2); + } + + for my $row (@$rowref) { + delete @$row{qw(itime mtime link)}; + $query = sprintf 'INSERT INTO acc_trans (%s) VALUES (%s)', join(', ', keys %$row), join(', ', map '?', values %$row); + $row->{trans_id} = $new_id; + $row->{amount} *= -1; + do_query($form, $dbh, $query, (values %$row)); + } + + $dbh->commit; + + $main::lxdebug->leave_sub(); +} + 1;