From e13cce568df1ca601a4e85e1a8a2a15cc5c6000a Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 9 Jun 2026 20:43:01 +0330 Subject: [PATCH] added seprated method for withdraw and deposit --- .../Controllers/Admin/WalletController.php | 26 ++++ app/Models/Withdraw.php | 89 ++++++++++++- .../views/admin/withdrawReport.blade.php | 122 ++++++++++++++++++ routes/admin.php | 1 + 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 resources/views/admin/withdrawReport.blade.php diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index 5358307..1ff160f 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use App\Http\Controllers\Admin\TahesabController; use App\Models\Setting; use App\Models\User; +use Hekmatinasser\Verta\Verta; class WalletController extends Controller @@ -330,6 +331,7 @@ class WalletController extends Controller public function indexWithdraw(Request $request) { $records = Withdraw::with(['customer', 'bank_account', 'Address', "Transaction"]); + Withdraw::applyFlowFilter($records, $request->input('flow_type', 'all')); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ @@ -338,6 +340,30 @@ class WalletController extends Controller return response()->json($records); } + public function exportWithdrawReport(Request $request) + { + $flowType = $request->input('flow_type', 'all'); + $query = Withdraw::with(['customer', 'bank_account']); + Withdraw::applyFlowFilter($query, $flowType); + TableEngine::create($query, $request->all()) + ->initSearch(['customer.name']); + + $rows = $query->orderBy('id', 'desc')->get(); + + $titles = [ + 'all' => 'گزارش برداشت و واریز', + 'withdraw' => 'گزارش برداشت', + 'deposit' => 'گزارش واریز', + ]; + + return response()->view('admin.withdrawReport', [ + 'rows' => $rows, + 'title' => $titles[$flowType] ?? $titles['all'], + 'flowType' => $flowType, + 'generatedAt' => Verta::now()->format('Y/n/j H:i:s'), + ])->header('Content-Type', 'text/html; charset=UTF-8'); + } + public function updateWithdraw(Request $request, $id) { // پیدا کردن رکورد Withdraw با استفاده از شناسه diff --git a/app/Models/Withdraw.php b/app/Models/Withdraw.php index fbc12c7..6fce8e1 100644 --- a/app/Models/Withdraw.php +++ b/app/Models/Withdraw.php @@ -1 +1,88 @@ - 'در انتظار واریز', 2 => 'واریز شد', 4 => 'واریز توسط ادمین', 5 => 'پاداش معرفی', 9 => 'سود زیر مجموعه', 3 => 'واریز ناموفق', 50 => 'در انتظار ارسال', 51 => 'ارسال شده', 52 => 'لغو شده', ]; public function customer() { return $this->belongsTo('App\Models\Customer')->select(['id','name',"mobile"]); } public function Address() { return $this->belongsTo('App\Models\Address'); } public function Transaction() { return $this->hasMany(Transaction::class, 'withdraw_id', 'id'); } public function bank_account() { return $this->hasOne('App\Models\BankAccount','id','bank_account_id'); } } \ No newline at end of file + 'در انتظار واریز', + 2 => 'واریز شد', + 4 => 'واریز توسط ادمین', + 5 => 'پاداش معرفی', + 9 => 'سود زیر مجموعه', + 3 => 'واریز ناموفق', + 50 => 'در انتظار ارسال', + 51 => 'ارسال شده', + 52 => 'لغو شده', + ]; + + public function customer() + { + return $this->belongsTo('App\Models\Customer')->select(['id', 'name', 'mobile']); + } + + public function Address() + { + return $this->belongsTo('App\Models\Address'); + } + + public function Transaction() + { + return $this->hasMany(Transaction::class, 'withdraw_id', 'id'); + } + + public function bank_account() + { + return $this->hasOne('App\Models\BankAccount', 'id', 'bank_account_id'); + } + + public static function applyFlowFilter($query, ?string $flowType = 'all') + { + if (!$flowType || $flowType === 'all') { + return $query; + } + + if ($flowType === 'withdraw') { + return $query->where(function ($q) { + $q->where('note', 'like', '%برداشت%') + ->orWhere('type', 2) + ->orWhereBetween('sts', [50, 52]); + }); + } + + if ($flowType === 'deposit') { + return $query->where(function ($q) { + $q->where('note', 'like', '%واریز%') + ->orWhere('type', 1) + ->orWhere(function ($admin) { + $admin->where('sts', 4) + ->where(function ($note) { + $note->whereNull('note') + ->orWhere('note', 'not like', '%برداشت%'); + }); + }); + }); + } + + return $query; + } +} diff --git a/resources/views/admin/withdrawReport.blade.php b/resources/views/admin/withdrawReport.blade.php new file mode 100644 index 0000000..a72996a --- /dev/null +++ b/resources/views/admin/withdrawReport.blade.php @@ -0,0 +1,122 @@ + + + + + + {{ $title }} + + + +

{{ $title }}

+
+ تاریخ تهیه: {{ $generatedAt }} | + تعداد ردیف: {{ $rows->count() }} +
+ + + + + + + + + + + + + + + + + + + @forelse($rows as $index => $row) + + + + + + + + + + + + + + @empty + + + + @endforelse + +
ردیفنام مشتریکد کاربرعلت تراکنشمقدار (ریال)طلاشماره کارتشماره شباشماره پیگیریوضعیتتاریخ ثبت
{{ $index + 1 }}{{ $row->customer->name ?? '-' }}{{ $row->customer_id ?? '-' }}{{ $row->note ?? '-' }}{{ number_format((float) ($row->cash ?? 0)) }}{{ $row->gold ?? '-' }}{{ $row->bank_account->cart_number ?? '-' }}{{ $row->bank_account->shaba_number ?? '-' }}{{ $row->tracked_number ?? '-' }}{{ $row->sts_str ?? '-' }} + @if($row->created_at) + {{ \Hekmatinasser\Verta\Verta::instance($row->created_at)->format('Y/n/j H:i:s') }} + @else + - + @endif +
موردی یافت نشد
+ +
+ +
+ + + + diff --git a/routes/admin.php b/routes/admin.php index 449925a..03b61a7 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -97,6 +97,7 @@ Route::middleware('auth:user')->group(function (){ Route::post('/wallet/transaction/table',[WalletController::class,'index']); Route::post('/wallet/transaction/update',[WalletController::class,'updateTransaction']); Route::post('/wallet/withdraw/table',[WalletController::class,'indexWithdraw']); + Route::post('/wallet/withdraw/report',[WalletController::class,'exportWithdrawReport']); Route::put('/wallet/withdraw/{id}',[WalletController::class,'updateWithdraw']); Route::get('/wallet/withdraw/{id}',[WalletController::class,'getWithdraw']); Route::post('/wallet/withdraw/complete',[WalletController::class,'completeWithdraw']);