From 090de47c1a3aaf08f0d825b83926695616fc7ace Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 14 Jun 2007 15:54:19 +0000 Subject: [PATCH] Stornomechanismus mal auf Dialogbuchen ausgeweitet --- SL/GL.pm | 41 +++++++++++++++++++++++++++++++++++++++++ bin/mozilla/gl.pl | 46 ++++++---------------------------------------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/SL/GL.pm b/SL/GL.pm index 2da6e7e7d..6cdcee978 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -638,4 +638,45 @@ sub transaction { $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 gl 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->{reference} = 'Storno-' . $storno_row->{reference}; + + delete @$storno_row{qw(itime mtime)}; + + $query = sprintf 'INSERT INTO gl (%s) VALUES (%s)', join(', ', keys %$storno_row), join(', ', map '?', values %$storno_row); + do_query($form, $dbh, $query, (values %$storno_row)); + + # now copy acc_trans entries + $query = qq|SELECT * FROM acc_trans WHERE trans_id = ?|; + my $rowref = selectall_hashref_query($form, $dbh, $query, $id); + + for my $row (@$rowref) { + 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/gl.pl b/bin/mozilla/gl.pl index 18e3fa580..461800b84 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -1783,58 +1783,24 @@ sub post_as_new { sub storno { $lxdebug->enter_sub(); + # don't cancel cancelled transactions if (IS->has_storno(\%myconfig, $form, 'gl')) { - $form->{title} = $locale->text("Cancel General Ledger Transaction"); + $form->{title} = $locale->text("Cancel Accounts Receivables Transaction"); $form->error($locale->text("Transaction has already been cancelled!")); } - my %keep_keys = map { $_, 1 } qw(login password id stylesheet); - map { delete $form->{$_} unless $keep_keys{$_} } keys %{ $form }; - - prepare_transaction(); - - for my $i (1 .. $form->{rowcount}) { - for (qw(debit credit tax)) { - $form->{"${_}_$i"} = - ($form->{"${_}_$i"}) - ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) - : ""; - } - } - - $form->{storno} = 1; - $form->{storno_id} = $form->{id}; - $form->{id} = 0; - - $form->{reference} = "Storno-" . $form->{reference}; - $form->{description} = "Storno-" . $form->{description}; - - for my $i (1 .. $form->{rowcount}) { - next if (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")); - - if ($form->{"debit_$i"} ne "") { - $form->{"credit_$i"} = $form->{"debit_$i"}; - $form->{"debit_$i"} = ""; - - } else { - $form->{"debit_$i"} = $form->{"credit_$i"}; - $form->{"credit_$i"} = ""; - } - } - - post_transaction(); + GL->storno($form, \%myconfig, $form->{id}); # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; - $form->{addition} = "STORNO"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{snumbers} = "ordnumber_$form->{ordnumber}"; + $form->{addition} = "STORNO"; + $form->save_history($form->dbconnect(\%myconfig)); } # /saving the history $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); $lxdebug->leave_sub(); - } -- 2.20.1