Recommit von r1168 von skoehler: Kundennummer laesst sich nur einmal vergegen, nicht...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 22 Nov 2006 16:39:18 +0000 (16:39 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 22 Nov 2006 16:39:18 +0000 (16:39 +0000)
SL/CT.pm
bin/mozilla/ct.pl
locale/de/all
locale/de/ct

index c61f5a4..7ce7510 100644 (file)
--- 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}',
index e96e718..dddd734 100644 (file)
@@ -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();
index 302f599..b3bece7 100644 (file)
@@ -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',
index ed6f3c2..d742fac 100644 (file)
@@ -116,6 +116,7 @@ $self{texts} = {
   'Year'                        => 'Jahr',
   'Zipcode'                     => 'PLZ',
   'button'                      => '?',
+  'customernumber not unique!'  => 'Die Kundennummer ist schon vergeben',
   'days'                        => 'Tage',
   's'                           => 's',
 };