added seprated method for withdraw and deposit
This commit is contained in:
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user