From dc7f3c9afe98b033d29c645cd9d9ced238663fbc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 7 May 2007 09:29:18 +0000 Subject: [PATCH] =?utf8?q?Stornieren=20beim=20Dialogbuchen:=201.=20In=20de?= =?utf8?q?r=20Datenbank=20wird=20tats=C3=A4chlich=20gespeichert,=20ob=20ei?= =?utf8?q?ne=20Buchung=20storniert=20wurde=20bzw.=20eine=20Stornobuchung?= =?utf8?q?=20ist.=202.=20Der=20"Storno"-Button=20wird=20nur=20angezeigt,?= =?utf8?q?=20wenn=20die=20Buchung=20noch=20nicht=20storniert=20wurde.=203.?= =?utf8?q?=20Es=20wird=20verhindert,=20dass=20eine=20bereits=20stornierte?= =?utf8?q?=20Buchung=20erneut=20storniert=20wird=20(Fix=20f=C3=BCr=20Bug?= =?utf8?q?=20646).=204.=20Vor=20dem=20Stornieren=20wird=20die=20urspr?= =?utf8?q?=C3=BCngliche=20Buchung=20erneut=20aus=20der=20Datenbank=20gelad?= =?utf8?q?en,=20damit=20die=20Stornierung=20nicht=20vom=20Benutzer=20ver?= =?utf8?q?=C3=A4ndert=20werden=20kann.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/GL.pm | 17 ++++--- bin/mozilla/gl.pl | 90 +++++++++++++++++++++++++---------- locale/de/all | 2 + locale/de/gl | 2 + sql/Pg-upgrade2/gl_storno.sql | 42 ++++++++++++++++ 5 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 sql/Pg-upgrade2/gl_storno.sql 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-%'); -- 2.20.1