added some feature for accounting and price 9
This commit is contained in:
@@ -80,42 +80,7 @@ class TahesabController extends Controller
|
|||||||
// مشتریان پنل
|
// مشتریان پنل
|
||||||
$panelTotal = Customer::whereNull('deleted_at')->count();
|
$panelTotal = Customer::whereNull('deleted_at')->count();
|
||||||
$panelRegistered = Customer::whereNull('deleted_at')->whereNotNull('moshtari_code')->count();
|
$panelRegistered = Customer::whereNull('deleted_at')->whereNotNull('moshtari_code')->count();
|
||||||
$panelOnly = $panelTotal - $panelRegistered; // در پنل هستند ولی در تهحساب نیستند
|
$panelOnly = $panelTotal - $panelRegistered;
|
||||||
|
|
||||||
// مشتریان تهحساب
|
|
||||||
$tahesabCustomers = $this->fetchAllTahesabCustomers();
|
|
||||||
$tahesabTotal = count($tahesabCustomers);
|
|
||||||
|
|
||||||
// موبایلهای پنل (بدون صفر ابتدایی چون تهحساب بدون صفر ذخیره میکند)
|
|
||||||
$panelMobiles = Customer::whereNull('deleted_at')
|
|
||||||
->whereNotNull('mobile')
|
|
||||||
->pluck('mobile')
|
|
||||||
->map(fn ($m) => ltrim((string) $m, '0'))
|
|
||||||
->flip()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
// مشتریان تهحساب که در پنل نیستند
|
|
||||||
$tahesabOnlyList = [];
|
|
||||||
foreach ($tahesabCustomers as $item) {
|
|
||||||
if (! is_array($item)) continue;
|
|
||||||
$tel = ltrim((string) ($item['Tel'] ?? ''), '0');
|
|
||||||
if ($tel && isset($panelMobiles[$tel])) continue; // موجود در پنل
|
|
||||||
$tahesabOnlyList[] = [
|
|
||||||
'code' => $item['Code'] ?? null,
|
|
||||||
'name' => $item['Name'] ?? '',
|
|
||||||
'tel' => $item['Tel'] ?? '',
|
|
||||||
'gid' => $item['GID'] ?? null,
|
|
||||||
'group'=> $item['GoroupName'] ?? '',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$tahesabOnlyCount = count($tahesabOnlyList);
|
|
||||||
|
|
||||||
// مشتریان پنل که در تهحساب نیستند
|
|
||||||
$tahesabCodes = Customer::whereNull('deleted_at')
|
|
||||||
->whereNotNull('moshtari_code')
|
|
||||||
->pluck('moshtari_code')
|
|
||||||
->flip()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$panelOnlyQuery = Customer::whereNull('deleted_at')->whereNull('moshtari_code')
|
$panelOnlyQuery = Customer::whereNull('deleted_at')->whereNull('moshtari_code')
|
||||||
->select('id', 'name', 'mobile', 'created_at');
|
->select('id', 'name', 'mobile', 'created_at');
|
||||||
@@ -128,24 +93,53 @@ class TahesabController extends Controller
|
|||||||
}
|
}
|
||||||
$panelOnlyList = $panelOnlyQuery->orderBy('id')->paginate(20);
|
$panelOnlyList = $panelOnlyQuery->orderBy('id')->paginate(20);
|
||||||
|
|
||||||
// پیجینیشن برای تب تهحساب → پنل
|
// مشتریان تهحساب — فقط وقتی include_tahesab=true ارسال شده (چون کند است)
|
||||||
$tahesabOnlyPage = (int) $request->input('tahesab_page', 1);
|
$tahesabTotal = null;
|
||||||
$perPage = 20;
|
$tahesabOnlyCount = null;
|
||||||
$tahesabOnlyPaged = array_slice($tahesabOnlyList, ($tahesabOnlyPage - 1) * $perPage, $perPage);
|
$tahesabOnlyResult = ['data' => [], 'total' => 0, 'current_page' => 1, 'last_page' => 1];
|
||||||
|
|
||||||
|
if ($request->boolean('include_tahesab')) {
|
||||||
|
$tahesabCustomers = $this->fetchAllTahesabCustomers();
|
||||||
|
$tahesabTotal = count($tahesabCustomers);
|
||||||
|
|
||||||
|
// موبایلهای پنل بدون صفر ابتدایی
|
||||||
|
$panelMobiles = Customer::whereNull('deleted_at')
|
||||||
|
->whereNotNull('mobile')
|
||||||
|
->pluck('mobile')
|
||||||
|
->mapWithKeys(fn ($m) => [ltrim((string) $m, '0') => true])
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$tahesabOnlyList = [];
|
||||||
|
foreach ($tahesabCustomers as $item) {
|
||||||
|
if (! is_array($item)) continue;
|
||||||
|
$tel = ltrim((string) ($item['Tel'] ?? ''), '0');
|
||||||
|
if ($tel && isset($panelMobiles[$tel])) continue;
|
||||||
|
$tahesabOnlyList[] = [
|
||||||
|
'code' => $item['Code'] ?? null,
|
||||||
|
'name' => $item['Name'] ?? '',
|
||||||
|
'tel' => $item['Tel'] ?? '',
|
||||||
|
'gid' => $item['GID'] ?? null,
|
||||||
|
'group' => $item['GoroupName'] ?? '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$tahesabOnlyCount = count($tahesabOnlyList);
|
||||||
|
// همه رو برمیگردونیم — frontend خودش paginate میکنه
|
||||||
|
$tahesabOnlyResult = [
|
||||||
|
'data' => array_values($tahesabOnlyList),
|
||||||
|
'total' => $tahesabOnlyCount,
|
||||||
|
'current_page' => 1,
|
||||||
|
'last_page' => 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'panel_total' => $panelTotal,
|
'panel_total' => $panelTotal,
|
||||||
'panel_registered' => $panelRegistered,
|
'panel_registered' => $panelRegistered,
|
||||||
'panel_only' => $panelOnly,
|
'panel_only' => $panelOnly,
|
||||||
'tahesab_total' => $tahesabTotal,
|
'tahesab_total' => $tahesabTotal,
|
||||||
'tahesab_only_count'=> $tahesabOnlyCount,
|
'tahesab_only_count' => $tahesabOnlyCount,
|
||||||
'panel_only_list' => $panelOnlyList,
|
'panel_only_list' => $panelOnlyList,
|
||||||
'tahesab_only_list' => [
|
'tahesab_only_list' => $tahesabOnlyResult,
|
||||||
'data' => $tahesabOnlyPaged,
|
|
||||||
'total' => $tahesabOnlyCount,
|
|
||||||
'current_page' => $tahesabOnlyPage,
|
|
||||||
'last_page' => max(1, (int) ceil($tahesabOnlyCount / $perPage)),
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user