X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FGL.pm;h=8d68624224c2f7918c5db7c366f43d2fce86c469;hb=777e883798f57271d29f089bb5520bd4d56ad373;hp=3d65eac46cda0d2a410af523242db54b28f911fa;hpb=e2e06cbb81c60cd462133b97024886766e4c167d;p=kivitendo-erp.git diff --git a/SL/GL.pm b/SL/GL.pm index 3d65eac46..8d6862422 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -277,7 +277,7 @@ sub all_transactions { (SELECT id FROM chart c2 WHERE c2.category = ?))|; $apwhere .= qq| AND ap.id in (SELECT trans_id FROM acc_trans ac2 WHERE ac2.chart_id IN - (SELECT id FROM chart c2 WHERE c2.category = ?))"|; + (SELECT id FROM chart c2 WHERE c2.category = ?))|; push(@glvalues, $form->{category}); push(@arvalues, $form->{category}); push(@apvalues, $form->{category}); @@ -573,7 +573,7 @@ sub transaction { # retrieve individual rows $query = - qq|SELECT c.accno, t.taxkey AS accnotaxkey, a.amount, a.memo, + qq|SELECT c.accno, t.taxkey AS accnotaxkey, a.amount, a.memo, a.source, a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate AS taxrate, t.id, (SELECT c1.accno @@ -638,4 +638,48 @@ 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)); + + $query = qq|UPDATE gl SET storno = 't' WHERE id = ?|; + do_query($form, $dbh, $query, $id); + + # 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;