From: Moritz Bunkus Date: Wed, 22 Nov 2006 16:39:18 +0000 (+0000) Subject: Recommit von r1168 von skoehler: Kundennummer laesst sich nur einmal vergegen, nicht... X-Git-Tag: release-2.4.0^2~203 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=992a539da1a37c94c13a2f015fb470636d219331;p=kivitendo-erp.git Recommit von r1168 von skoehler: Kundennummer laesst sich nur einmal vergegen, nicht ueber Datenbankschema unique bwz. primary key --- diff --git a/SL/CT.pm b/SL/CT.pm index c61f5a450..7ce751050 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -378,9 +378,21 @@ sub save_customer { $form->{taxzone_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); @@ -389,11 +401,31 @@ sub save_customer { # WHERE trans_id = $form->{id} AND module = 'CT'|; # $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')|; @@ -406,17 +438,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 e96e71884..dddd7346e 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -806,8 +806,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| @@ -1573,8 +1572,10 @@ sub save_and_close { 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 302f5994d..b3bece7f4 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1067,6 +1067,7 @@ gestartet', '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 ed6f3c228..d742fac9b 100644 --- a/locale/de/ct +++ b/locale/de/ct @@ -116,6 +116,7 @@ $self{texts} = { 'Year' => 'Jahr', 'Zipcode' => 'PLZ', 'button' => '?', + 'customernumber not unique!' => 'Die Kundennummer ist schon vergeben', 'days' => 'Tage', 's' => 's', };