From 7712480e4a082f84a2229f5b1a90d79a6c01255b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 1 Mar 2007 14:19:20 +0000 Subject: [PATCH] =?utf8?q?Rechnungs-=20und=20Gutschriftsnummern=20werden?= =?utf8?q?=20nun=20direkt=20innerhalb=20der=20Backend-Routinen=20innerhalb?= =?utf8?q?=20der=20gleichen=20Transaktion=20vergeben,=20in=20der=20auch=20?= =?utf8?q?die=20eigentliche=20Rechnung=20etc=20gespeichert=20wird.=20Damit?= =?utf8?q?=20soll=20besser=20verhindert=20werden,=20dass=20sich=20L=C3=B6c?= =?utf8?q?her=20in=20den=20Nummernkreisen=20ergeben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AR.pm | 4 ++++ SL/Form.pm | 15 +++++++++++---- SL/IS.pm | 6 ++++++ bin/mozilla/ar.pl | 3 --- bin/mozilla/io.pl | 2 +- bin/mozilla/is.pl | 7 ++++--- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/SL/AR.pm b/SL/AR.pm index 17dbd6499..96e66ef4b 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -170,6 +170,10 @@ sub post_transaction { $query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|; do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}); + + if (!$form->{invnumber}) { + $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh); + } } # update department diff --git a/SL/Form.pm b/SL/Form.pm index 157bb61b0..edf5de978 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -2448,9 +2448,14 @@ sub save_status { sub update_defaults { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $fld) = @_; + my ($self, $myconfig, $fld, $provided_dbh) = @_; - my $dbh = $self->dbconnect_noauto($myconfig); + my $dbh; + if ($provided_dbh) { + $dbh = $provided_dbh; + } else { + $dbh = $self->dbconnect_noauto($myconfig); + } my $query = qq|SELECT $fld FROM defaults FOR UPDATE|; my $sth = $dbh->prepare($query); @@ -2464,8 +2469,10 @@ sub update_defaults { SET $fld = '$var'|; $dbh->do($query) || $self->dberror($query); - $dbh->commit; - $dbh->disconnect; + if (!$provided_dbh) { + $dbh->commit; + $dbh->disconnect; + } $main::lxdebug->leave_sub(); diff --git a/SL/IS.pm b/SL/IS.pm index a7b09917c..6b69bb249 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -550,6 +550,12 @@ sub post_invoice { ($form->{id}) = $sth->fetchrow_array; $sth->finish; + + if (!$form->{invnumber}) { + $form->{invnumber} = + $form->update_defaults($myconfig, $form->{type} eq "credit_note" ? + "cnnumber" : "invnumber", $dbh); + } } map { $form->{$_} =~ s/\'/\'\'/g } diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index da4315b2e..5b3e3b2a1 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -1050,9 +1050,6 @@ sub post { $form->{AR}{receivables} = $form->{ARselected}; - $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") - unless $form->{invnumber}; - $form->{id} = 0 if $form->{postasnew}; if (AR->post_transaction(\%myconfig, \%$form)) { # saving the history diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index f38ffe20a..6fa6718a7 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1864,7 +1864,7 @@ sub print_form { # assign number $form->{what_done} = $form->{formname}; - if (!$form->{"${inv}number"} && !$form->{preview}) { + if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) { $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld); if ($form->{media} ne 'email') { diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 9b6da27c6..33a049f17 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -1441,13 +1441,14 @@ sub post { $form->{id} = 0 if $form->{postasnew}; # get new invnumber in sequence if no invnumber is given or if posasnew was requested - if (!$form->{invnumber} || $form->{postasnew}) { + if ($form->{postasnew}) { if ($form->{type} eq "credit_note") { - $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber"); + undef($form->{cnnumber}); } else { - $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber"); + undef($form->{invnumber}); } } + relink_accounts(); if ($print_post) { if (!(IS->post_invoice(\%myconfig, \%$form))) { -- 2.20.1