added pargar 4

This commit is contained in:
2026-07-05 21:48:11 +03:30
parent af6c751ede
commit 2f48b88cf6
4 changed files with 166 additions and 43 deletions
@@ -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;