$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);
# 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')|;
($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}',
$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|
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();