added seprated method for withdraw and deposit

This commit is contained in:
2026-06-09 20:43:01 +03:30
parent e75edfb791
commit e13cce568d
4 changed files with 237 additions and 1 deletions
@@ -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 با استفاده از شناسه
+88 -1
View File
@@ -1 +1,88 @@
<?php␍␍namespace App\Models;␍␍use Illuminate\Database\Eloquent\Factories\HasFactory;␍use Illuminate\Database\Eloquent\Model;␍use Rooyesh\Wallet\models\Transaction;␍␍␍class Withdraw extends Model␍{␍ use HasFactory,Selector;␍ protected $fillable = [␍ 'customer_id',␍ 'user_id',␍ 'cash',␍ 'gold',␍ 'note',␍ 'tracked_number',␍ 'bank_account_id',␍ 'date_at',//تاریخ و ساعت واریز␍ 'sts',␍ 'type',␍ ];␍ static $STS = [␍ 1 => 'در انتظار واریز',␍ 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');␍ }␍}␍
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Rooyesh\Wallet\models\Transaction;
class Withdraw extends Model
{
use HasFactory, Selector;
protected $fillable = [
'customer_id',
'user_id',
'cash',
'gold',
'note',
'tracked_number',
'bank_account_id',
'date_at',
'sts',
'type',
];
static $STS = [
1 => 'در انتظار واریز',
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;
}
}
@@ -0,0 +1,122 @@
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $title }}</title>
<style>
* { box-sizing: border-box; }
body {
font-family: Tahoma, Arial, sans-serif;
margin: 24px;
color: #111827;
background: #fff;
}
h1 {
margin: 0 0 8px;
font-size: 20px;
}
.meta {
margin-bottom: 20px;
color: #6b7280;
font-size: 12px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th, td {
border: 1px solid #d1d5db;
padding: 6px 8px;
text-align: center;
vertical-align: middle;
}
th {
background: #f3f4f6;
font-weight: 700;
}
tr:nth-child(even) td {
background: #fafafa;
}
.actions {
margin-top: 20px;
}
.actions button {
background: #2563eb;
color: #fff;
border: none;
border-radius: 8px;
padding: 8px 16px;
cursor: pointer;
font-family: inherit;
}
@media print {
.actions { display: none !important; }
body { margin: 12px; }
}
</style>
</head>
<body>
<h1>{{ $title }}</h1>
<div class="meta">
تاریخ تهیه: {{ $generatedAt }} |
تعداد ردیف: {{ $rows->count() }}
</div>
<table>
<thead>
<tr>
<th>ردیف</th>
<th>نام مشتری</th>
<th>کد کاربر</th>
<th>علت تراکنش</th>
<th>مقدار (ریال)</th>
<th>طلا</th>
<th>شماره کارت</th>
<th>شماره شبا</th>
<th>شماره پیگیری</th>
<th>وضعیت</th>
<th>تاریخ ثبت</th>
</tr>
</thead>
<tbody>
@forelse($rows as $index => $row)
<tr>
<td>{{ $index + 1 }}</td>
<td>{{ $row->customer->name ?? '-' }}</td>
<td>{{ $row->customer_id ?? '-' }}</td>
<td>{{ $row->note ?? '-' }}</td>
<td>{{ number_format((float) ($row->cash ?? 0)) }}</td>
<td>{{ $row->gold ?? '-' }}</td>
<td>{{ $row->bank_account->cart_number ?? '-' }}</td>
<td>{{ $row->bank_account->shaba_number ?? '-' }}</td>
<td>{{ $row->tracked_number ?? '-' }}</td>
<td>{{ $row->sts_str ?? '-' }}</td>
<td>
@if($row->created_at)
{{ \Hekmatinasser\Verta\Verta::instance($row->created_at)->format('Y/n/j H:i:s') }}
@else
-
@endif
</td>
</tr>
@empty
<tr>
<td colspan="11">موردی یافت نشد</td>
</tr>
@endforelse
</tbody>
</table>
<div class="actions">
<button type="button" onclick="window.print()">چاپ / ذخیره PDF</button>
</div>
<script>
window.addEventListener('load', function () {
setTimeout(function () { window.print(); }, 400);
});
</script>
</body>
</html>
+1
View File
@@ -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']);