From: Moritz Bunkus Date: Mon, 7 May 2007 09:29:18 +0000 (+0000) Subject: Stornieren beim Dialogbuchen: X-Git-Tag: release-2.4.3^2~370 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;ds=sidebyside;h=dc7f3c9afe98b033d29c645cd9d9ced238663fbc;hp=3740b5032e01a83f12912887e66d0824c47aebcc;p=kivitendo-erp.git Stornieren beim Dialogbuchen: 1. In der Datenbank wird tatsächlich gespeichert, ob eine Buchung storniert wurde bzw. eine Stornobuchung ist. 2. Der "Storno"-Button wird nur angezeigt, wenn die Buchung noch nicht storniert wurde. 3. Es wird verhindert, dass eine bereits stornierte Buchung erneut storniert wird (Fix für Bug 646). 4. Vor dem Stornieren wird die ursprüngliche Buchung erneut aus der Datenbank geladen, damit die Stornierung nicht vom Benutzer verändert werden kann. --- diff --git a/SL/GL.pm b/SL/GL.pm index eda712813..1b4a59e8c 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -70,13 +70,6 @@ sub post_transaction { my $i; - # check if debit and credit balances - - if ($form->{storno}) { - $form->{reference} = "Storno-" . $form->{reference}; - $form->{description} = "Storno-" . $form->{description}; - } - # connect to database, turn off AutoCommit my $dbh = $form->dbconnect_noauto($myconfig); @@ -119,11 +112,13 @@ sub post_transaction { $query = qq|UPDATE gl SET reference = ?, description = ?, notes = ?, - transdate = ?, department_id = ?, taxincluded = ? + transdate = ?, department_id = ?, taxincluded = ?, + storno = ?, storno_id = ? WHERE id = ?|; @values = ($form->{reference}, $form->{description}, $form->{notes}, conv_date($form->{transdate}), $department_id, $form->{taxincluded}, + $form->{storno} ? 't' : 'f', conv_i($form->{storno_id}), conv_i($form->{id})); do_query($form, $dbh, $query, @values); @@ -180,6 +175,10 @@ sub post_transaction { } } + if ($form->{storno} && $form->{storno_id}) { + do_query($form, $dbh, qq|UPDATE gl SET storno = 't' WHERE id = ?|, conv_i($form->{storno_id})); + } + # commit and redirect my $rc = $dbh->commit; $dbh->disconnect; @@ -558,7 +557,7 @@ sub transaction { if ($form->{id}) { $query = - qq|SELECT g.reference, g.description, g.notes, g.transdate, + qq|SELECT g.reference, g.description, g.notes, g.transdate, g.storno, g.storno_id, d.description AS department, e.name AS employee, g.taxincluded, g.gldate FROM gl g LEFT JOIN department d ON (d.id = g.department_id) diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index faaad5828..43f5447cc 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -32,6 +32,7 @@ #====================================================================== use SL::GL; +use SL::IS; use SL::PE; require "bin/mozilla/arap.pl"; @@ -109,7 +110,7 @@ sub add { } -sub edit { +sub prepare_transaction { $lxdebug->enter_sub(); GL->transaction(\%myconfig, \%$form); @@ -178,15 +179,24 @@ sub edit { ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + $lxdebug->leave_sub(); +} + +sub edit { + $lxdebug->enter_sub(); + + prepare_transaction(); + $form->{title} = "Edit"; - &form_header; - &display_rows; - &form_footer; - $lxdebug->leave_sub(); + form_header(); + display_rows(); + form_footer(); + $lxdebug->leave_sub(); } + sub search { $lxdebug->enter_sub(); @@ -1317,11 +1327,11 @@ sub form_header {
{script}> +|; -{id}> + $form->hide_form(qw(id closedto locked storno storno_id)); -{closedto}> -{locked}> + print qq| @@ -1466,8 +1476,10 @@ sub form_footer { if ($form->{id}) { - print qq||; + if (!$form->{storno}) { + print qq||; + } # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich @@ -1575,19 +1587,6 @@ sub post { my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart); - if ($form->{storno}) { - for my $i (1 .. $form->{rowcount}) { - unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) { - if ($form->{"debit_$i"} ne "") { - $form->{"credit_$i"} = $form->{"debit_$i"}; - $form->{"debit_$i"} = ""; - } elsif ($form->{"credit_$i"} ne "") { - $form->{"debit_$i"} = $form->{"credit_$i"}; - $form->{"credit_$i"} = ""; - } - } - } - } for my $i (1 .. $form->{rowcount}) { @@ -1758,8 +1757,47 @@ sub post_as_new { sub storno { $lxdebug->enter_sub(); - $form->{id} = 0; - $form->{storno} = 1; + if (IS->has_storno(\%myconfig, $form, 'gl')) { + $form->{title} = $locale->text("Cancel General Ledger 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(); + # saving the history if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; @@ -1767,7 +1805,7 @@ sub storno { $form->save_history($form->dbconnect(\%myconfig)); } # /saving the history - &post; + $lxdebug->leave_sub(); } diff --git a/locale/de/all b/locale/de/all index e6b4b9c59..e0bbf49e0 100644 --- a/locale/de/all +++ b/locale/de/all @@ -206,6 +206,7 @@ aktualisieren wollen?', 'C' => 'G', 'CANCELED' => 'Storniert', 'Calculate' => 'Berechnen', + 'Cancel General Ledger Transaction' => 'Buchung stornieren', 'Cannot create Lock!' => 'System kann nicht gesperrt werden!', 'Cannot delete account!' => 'Konto kann nicht gelöscht werden!', 'Cannot delete customer!' => 'Kunde kann nicht gelöscht werden!', @@ -1083,6 +1084,7 @@ gestartet', 'Transaction Date missing!' => 'Buchungsdatum fehlt!', 'Transaction deleted!' => 'Buchung gelöscht!', 'Transaction description' => 'Vorgangsbezeichnung', + 'Transaction has already been cancelled!' => 'Diese Buchung wurde bereits storniert.', 'Transaction posted!' => 'Buchung verbucht!', 'Transaction reversal enforced for all dates' => 'Fehleintragungen müssen für jeden Zeitraum mit einer Kontraeintragung ausgebessert werden', 'Transaction reversal enforced up to' => 'Fehleintragungen können bis zu dem angegebenen Zeitraum nur mit einer Kontraeintragung ausgebessert werden!', diff --git a/locale/de/gl b/locale/de/gl index 9da6fe5df..5db946e9b 100644 --- a/locale/de/gl +++ b/locale/de/gl @@ -22,6 +22,7 @@ $self->{texts} = { 'Buchungsjournal' => 'Buchungsjournal', 'Buchungsnummer' => 'Buchungsnummer', 'CANCELED' => 'Storniert', + 'Cancel General Ledger Transaction' => 'Buchung stornieren', 'Cannot delete transaction!' => 'Buchung kann nicht gelöscht werden!', 'Cannot have a value in both Debit and Credit!' => 'Es kann nicht gleichzeitig Soll und Haben gebucht werden!', 'Cannot post a transaction without a value!' => 'Eine Buchung ohne Betrag kann nicht vorgenommen werden!', @@ -149,6 +150,7 @@ $self->{texts} = { 'To (time)' => 'Bis', 'Transaction Date missing!' => 'Buchungsdatum fehlt!', 'Transaction deleted!' => 'Buchung gelöscht!', + 'Transaction has already been cancelled!' => 'Diese Buchung wurde bereits storniert.', 'Trying to call a sub without a name' => 'Es wurde versucht, eine Unterfunktion ohne Namen aufzurufen.', 'Unbalanced Ledger' => 'Bilanzfehler', 'Unit' => 'Einheit', diff --git a/sql/Pg-upgrade2/gl_storno.sql b/sql/Pg-upgrade2/gl_storno.sql new file mode 100644 index 000000000..89e54c6d5 --- /dev/null +++ b/sql/Pg-upgrade2/gl_storno.sql @@ -0,0 +1,42 @@ +-- @tag: gl_storno +-- @description: Spalten für Dialogbuchen zum Speichern, ob diese Buchung storniert wurde bzw. für welche andere Buchung diese eine Stornobuchung ist +-- @depends: release_2_4_2 +ALTER TABLE gl ADD COLUMN storno boolean; +ALTER TABLE gl ALTER COLUMN storno SET DEFAULT 'f'; + +ALTER TABLE gl ADD COLUMN storno_id integer; +ALTER TABLE gl ADD FOREIGN KEY (storno_id) REFERENCES gl (id); + +UPDATE gl SET storno = 'f'; + +UPDATE gl SET storno = 't' + WHERE (reference LIKE 'Storno-%') + AND (description LIKE 'Storno-%') + AND EXISTS + (SELECT gl2.id + FROM gl gl2 + WHERE ('Storno-' || gl2.reference = gl.reference) + AND ('Storno-' || gl2.description = gl.description) + AND (gl2.id < gl.id)); + +UPDATE gl SET storno = 't' + WHERE (reference NOT LIKE 'Storno-%') + AND (description NOT LIKE 'Storno-%') + AND EXISTS + (SELECT gl2.id + FROM gl gl2 + WHERE ('Storno-' || gl.reference = gl2.reference) + AND ('Storno-' || gl.description = gl2.description) + AND (gl2.id > gl.id)); + +UPDATE gl SET storno_id = + (SELECT id + FROM gl gl2 + WHERE ('Storno-' || gl2.reference = gl.reference) + AND ('Storno-' || gl2.description = gl.description) + AND (gl2.id < gl.id) + ORDER BY itime + LIMIT 1) + WHERE storno + AND (reference LIKE 'Storno-%') + AND (description LIKE 'Storno-%');