added pargar 4
This commit is contained in:
@@ -127,8 +127,7 @@ class PargarController extends Controller
|
||||
$errors = [];
|
||||
|
||||
foreach ($validated['customers'] as $item) {
|
||||
$tel = trim((string) ($item['tel'] ?? ''));
|
||||
$mobile = $tel !== '' ? '0' . ltrim($tel, '0') : '';
|
||||
$mobile = Customer::normalizeMobile($item['tel'] ?? '') ?? '';
|
||||
$fullName = trim($item['name']);
|
||||
$accountId = (string) $item['code'];
|
||||
|
||||
@@ -142,8 +141,19 @@ class PargarController extends Controller
|
||||
}
|
||||
|
||||
if ($mobile !== '') {
|
||||
$byMobile = Customer::whereNull('deleted_at')->where('mobile', $mobile)->first();
|
||||
$byMobile = Customer::findActiveByMobile($mobile);
|
||||
if ($byMobile) {
|
||||
$currentAccount = (string) ($byMobile->pargar_account_id ?? '');
|
||||
if ($currentAccount !== '' && $currentAccount !== $accountId) {
|
||||
$failed++;
|
||||
$errors[] = [
|
||||
'name' => $item['name'],
|
||||
'code' => $item['code'],
|
||||
'error' => 'شماره موبایل تکراری است',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$byMobile->pargar_account_id = $accountId;
|
||||
if ($fullName !== '') {
|
||||
$byMobile->fname = $fullName;
|
||||
@@ -155,6 +165,19 @@ class PargarController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$byAccount = Customer::whereNull('deleted_at')
|
||||
->where('pargar_account_id', $accountId)
|
||||
->first();
|
||||
if ($byAccount) {
|
||||
$failed++;
|
||||
$errors[] = [
|
||||
'name' => $item['name'],
|
||||
'code' => $item['code'],
|
||||
'error' => 'کد حساب پرگار قبلاً ثبت شده است',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$customer = new Customer();
|
||||
$customer->fname = $fullName;
|
||||
|
||||
Reference in New Issue
Block a user