Skip to content

Commit dbee0de

Browse files
committed
Issue #3706: Checked customer company name for uniqueness in frontend module.
1 parent 3711c74 commit dbee0de

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

Kernel/Modules/AdminCustomerCompany.pm

+51-8
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,31 @@ sub Run {
161161
);
162162

163163
# check duplicate field
164-
if ( %List && $List{ $GetParam{CustomerID} } ) {
165-
$Errors{Duplicate} = 'ServerError';
164+
if (%List) {
165+
SEARCHRESULT:
166+
for my $SearchResultID ( keys %List ) {
167+
my %CustomerCompany = $CustomerCompanyObject->CustomerCompanyGet(
168+
CustomerID => $SearchResultID,
169+
);
170+
171+
# check CustomerID and Name as both are unique
172+
if ( $CustomerCompany{CustomerID} eq $GetParam{CustomerID} ) {
173+
$Errors{Duplicate} = 'ServerError';
174+
$Errors{DuplicateMessage} = $LayoutObject->{LanguageObject}->Translate(
175+
'Customer Company %s already exists!',
176+
$GetParam{CustomerID},
177+
);
178+
last SEARCHRESULT;
179+
}
180+
elsif ( $CustomerCompany{CustomerCompanyName} eq $GetParam{CustomerCompanyName} ) {
181+
$Errors{Duplicate} = 'ServerError';
182+
$Errors{DuplicateMessage} = $LayoutObject->{LanguageObject}->Translate(
183+
'Customer Company name %s already exists!',
184+
$GetParam{CustomerCompanyName},
185+
);
186+
last SEARCHRESULT;
187+
}
188+
}
166189
}
167190
}
168191

@@ -394,8 +417,31 @@ sub Run {
394417
);
395418

396419
# check duplicate field
397-
if ( %List && $List{$CustomerCompanyID} ) {
398-
$Errors{Duplicate} = 'ServerError';
420+
if (%List) {
421+
SEARCHRESULT:
422+
for my $SearchResultID ( keys %List ) {
423+
my %CustomerCompany = $CustomerCompanyObject->CustomerCompanyGet(
424+
CustomerID => $SearchResultID,
425+
);
426+
427+
# check CustomerID and Name as both are unique
428+
if ( $CustomerCompany{CustomerID} eq $CustomerCompanyID ) {
429+
$Errors{Duplicate} = 'ServerError';
430+
$Errors{DuplicateMessage} = $LayoutObject->{LanguageObject}->Translate(
431+
'Customer Company %s already exists!',
432+
$CustomerCompanyID,
433+
);
434+
last SEARCHRESULT;
435+
}
436+
elsif ( $CustomerCompany{CustomerCompanyName} eq $GetParam{CustomerCompanyName} ) {
437+
$Errors{Duplicate} = 'ServerError';
438+
$Errors{DuplicateMessage} = $LayoutObject->{LanguageObject}->Translate(
439+
'Customer Company name %s already exists!',
440+
$GetParam{CustomerCompanyName},
441+
);
442+
last SEARCHRESULT;
443+
}
444+
}
399445
}
400446

401447
# if no errors occurred
@@ -482,10 +528,7 @@ sub Run {
482528
if ( $Errors{Duplicate} ) {
483529
$Output .= $LayoutObject->Notify(
484530
Priority => 'Error',
485-
Info => $LayoutObject->{LanguageObject}->Translate(
486-
'Customer Company %s already exists!',
487-
$CustomerCompanyID,
488-
),
531+
Info => $Errors{DuplicateMessage},
489532
);
490533
}
491534

0 commit comments

Comments
 (0)