From 7b2d052be1e819476c2e0c5b8bc971f42471d018 Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 28 Jun 2026 21:28:44 +0330 Subject: [PATCH] added some feature for accounting and price 9 --- .../Controllers/Admin/TahesabController.php | 98 +++++++++---------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/Admin/TahesabController.php b/app/Http/Controllers/Admin/TahesabController.php index ed39249..c213b79 100644 --- a/app/Http/Controllers/Admin/TahesabController.php +++ b/app/Http/Controllers/Admin/TahesabController.php @@ -80,42 +80,7 @@ class TahesabController extends Controller // مشتریان پنل $panelTotal = Customer::whereNull('deleted_at')->count(); $panelRegistered = Customer::whereNull('deleted_at')->whereNotNull('moshtari_code')->count(); - $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(); + $panelOnly = $panelTotal - $panelRegistered; $panelOnlyQuery = Customer::whereNull('deleted_at')->whereNull('moshtari_code') ->select('id', 'name', 'mobile', 'created_at'); @@ -128,24 +93,53 @@ class TahesabController extends Controller } $panelOnlyList = $panelOnlyQuery->orderBy('id')->paginate(20); - // پیجینیشن برای تب ته‌حساب → پنل - $tahesabOnlyPage = (int) $request->input('tahesab_page', 1); - $perPage = 20; - $tahesabOnlyPaged = array_slice($tahesabOnlyList, ($tahesabOnlyPage - 1) * $perPage, $perPage); + // مشتریان ته‌حساب — فقط وقتی include_tahesab=true ارسال شده (چون کند است) + $tahesabTotal = null; + $tahesabOnlyCount = null; + $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([ - 'panel_total' => $panelTotal, - 'panel_registered' => $panelRegistered, - 'panel_only' => $panelOnly, - 'tahesab_total' => $tahesabTotal, - 'tahesab_only_count'=> $tahesabOnlyCount, - 'panel_only_list' => $panelOnlyList, - 'tahesab_only_list' => [ - 'data' => $tahesabOnlyPaged, - 'total' => $tahesabOnlyCount, - 'current_page' => $tahesabOnlyPage, - 'last_page' => max(1, (int) ceil($tahesabOnlyCount / $perPage)), - ], + 'panel_total' => $panelTotal, + 'panel_registered' => $panelRegistered, + 'panel_only' => $panelOnly, + 'tahesab_total' => $tahesabTotal, + 'tahesab_only_count' => $tahesabOnlyCount, + 'panel_only_list' => $panelOnlyList, + 'tahesab_only_list' => $tahesabOnlyResult, ]); }