From 5dd059ffbe9317acf466ad70610513ded8ad1c6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20K=C3=B6hler?= Date: Mon, 17 Jul 2006 15:17:38 +0000 Subject: [PATCH] Kundennummer laesst sich nur einmal vergegen, nicht ueber Datenbankschema unique bwz. primary key --- SL/CT.pm | 44 +++++++++++++++++++++++++++++++++----------- bin/mozilla/ct.pl | 9 +++++---- locale/de/all | 1 + locale/de/ct | 1 + 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/SL/CT.pm b/SL/CT.pm index ab5d70ef4..3616a4eee 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -248,9 +248,21 @@ sub save_customer { $form->{salesman_id} *= 1; $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit}); - my ($query, $sth); + my ($query, $sth, $f_id); if ($form->{id}) { + + $query = qq|SELECT id FROM customer + WHERE customernumber = '$form->{customernumber}'|; + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + (${f_id}) = $sth->fetchrow_array; + $sth->finish; + if ((${f_id} ne $form->{id}) and (${f_id} ne "")) { + + $main::lxdebug->leave_sub(); + return 3; + } $query = qq|DELETE FROM customertax WHERE customer_id = $form->{id}|; $dbh->do($query) || $form->dberror($query); @@ -259,11 +271,31 @@ sub save_customer { WHERE trans_id = $form->{id}|; $dbh->do($query) || $form->dberror($query); } else { + my $uid = rand() . time; $uid .= $form->{login}; $uid = substr($uid, 2, 75); + if (!$form->{customernumber} && $form->{business}) { + $form->{customernumber} = + $form->update_business($myconfig, $form->{business}); + } + if (!$form->{customernumber}) { + $form->{customernumber} = + $form->update_defaults($myconfig, "customernumber"); + } + + $query = qq|SELECT c.id FROM customer c + WHERE c.customernumber = '$form->{customernumber}'|; + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + (${f_id}) = $sth->fetchrow_array; + $sth->finish; + if (${f_id} ne "") { + $main::lxdebug->leave_sub(); + return 3; + } $query = qq|INSERT INTO customer (name) VALUES ('$uid')|; @@ -276,17 +308,7 @@ sub save_customer { ($form->{id}) = $sth->fetchrow_array; $sth->finish; - if (!$form->{customernumber} && $form->{business}) { - $form->{customernumber} = - $form->update_business($myconfig, $form->{business}); - } - if (!$form->{customernumber}) { - $form->{customernumber} = - $form->update_defaults($myconfig, "customernumber"); - } - } - $query = qq|UPDATE customer SET customernumber = '$form->{customernumber}', name = '$form->{name}', diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index d074a2787..782f183e4 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -463,8 +463,7 @@ sub form_header { $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0); - $form->{discount} = - $form->format_amount(\%myconfig, $form->{discount}); + $form->{discount} = $form->format_amount(\%myconfig, $form->{discount}); if ($myconfig{role} eq 'admin') { $bcc = qq| @@ -977,8 +976,10 @@ sub save { if ($vertreter && $form->{db} eq "customer") { $form->isblank("salesman_id", $locale->text("Salesman missing!")); } - &{"CT::save_$form->{db}"}("", \%myconfig, \%$form); - + $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form); + if ($rc == 3) { + $form->error($locale->text('customernumber not unique!')); + } $form->redirect($locale->text($msg)); $lxdebug->leave_sub(); diff --git a/locale/de/all b/locale/de/all index 0f97330b3..5d2de10d3 100644 --- a/locale/de/all +++ b/locale/de/all @@ -848,6 +848,7 @@ $self{texts} = { 'choice part' => 'Artikel auswählen', 'config' => 'Konfiguration', 'continue' => 'weiter', + 'customernumber not unique!' => 'Die Kundennummer ist schon vergeben', 'days' => 'Tage', 'debug' => 'Debug', 'deliverydate' => 'Lieferdatum', diff --git a/locale/de/ct b/locale/de/ct index a564050a4..f0b4d116e 100644 --- a/locale/de/ct +++ b/locale/de/ct @@ -87,6 +87,7 @@ $self{texts} = { 'Vendor saved!' => 'Lieferant gespeichert!', 'Vendors' => 'Lieferanten', 'Zipcode' => 'PLZ', + 'customernumber not unique!' => 'Die Kundennummer ist schon vergeben', 'days' => 'Tage', 's' => 's', }; -- 2.20.1