Kundennummer laesst sich nur einmal vergegen,
authorStephan Köhler <s.koehler@linet-services.de>
Mon, 17 Jul 2006 15:17:38 +0000 (15:17 +0000)
committerStephan Köhler <s.koehler@linet-services.de>
Mon, 17 Jul 2006 15:17:38 +0000 (15:17 +0000)
nicht ueber Datenbankschema unique bwz. primary key

SL/CT.pm
bin/mozilla/ct.pl
locale/de/all
locale/de/ct

index ab5d70e..3616a4e 100644 (file)
--- 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}',
index d074a27..782f183 100644 (file)
@@ -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();
index 0f97330..5d2de10 100644 (file)
@@ -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',
index a564050..f0b4d11 100644 (file)
@@ -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',
 };