From 2b3f8b3a8e518497566e3281dae387db2d98500a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 13 Jun 2007 18:24:24 +0000 Subject: [PATCH] =?utf8?q?und=20das=20ganze=20nochmal=20f=C3=BCr=20Kredito?= =?utf8?q?renbuchungen=20und=20deren=20Stornos?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AP.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ bin/mozilla/ap.pl | 23 +++-------------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index 3bd658cb5..edd42c033 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -745,5 +745,50 @@ 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 * FROM acc_trans WHERE trans_id = ?|; + for my $row (@{ selectall_hashref_query($form, $dbh, $query, $id) }) { + delete @$row{qw(itime mtime)}; + $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; diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 1b2f65206..2110042c6 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -1497,26 +1497,7 @@ sub storno { $form->error($locale->text("Transaction has already been cancelled!")); } - # negate amount/taxes - for my $i (1 .. $form->{rowcount}) { - $form->{"amount_$i"} *= -1; - $form->{"tax_$i"} *= -1; - } - - # format things - for my $i (1 .. $form->{rowcount}) { - for (qw(amount tax)) { - $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"}; - } - } - - $form->{storno} = 1; - $form->{storno_id} = $form->{id}; - $form->{id} = 0; - - $form->{invnumber} = "Storno-" . $form->{invnumber}; - - post(); + AP->storno($form, \%myconfig, $form->{id}); # saving the history if(!exists $form->{addition} && $form->{id} ne "") { @@ -1526,5 +1507,7 @@ sub storno { } # /saving the history + $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); + $lxdebug->leave_sub(); } -- 2.20.1