fix wallet
This commit is contained in:
@@ -299,35 +299,29 @@ class WalletController extends Controller
|
||||
|
||||
public function indexWallet(Request $request)
|
||||
{
|
||||
// محاسبهی مجموع gold و cash به ازای هر owner
|
||||
$lastPrice = (float) (Price::latest()->first()?->price ?? 0);
|
||||
|
||||
// همان فیلتر/جستجوی جدول — بدون صفحهبندی — برای مجموع ردیفهای قابل مشاهده
|
||||
$sumQuery = Wallet::query();
|
||||
TableEngine::create($sumQuery, $request->all())
|
||||
->initSearch(['customer.name']);
|
||||
|
||||
$totalGold = (float) (clone $sumQuery)->sum('gold');
|
||||
$totalCash = (float) (clone $sumQuery)->sum('cash');
|
||||
|
||||
$sums = [
|
||||
'gold' => round($totalGold, 2),
|
||||
'goldToCash' => round($totalGold * $lastPrice, 2),
|
||||
'cash' => round($totalCash, 2),
|
||||
'cashToGold' => $lastPrice > 0 ? round($totalCash / $lastPrice, 2) : 0,
|
||||
];
|
||||
|
||||
$records = Wallet::with('customer');
|
||||
|
||||
|
||||
// ایجاد جدول با استفاده از TableEngine
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select(['*'])
|
||||
->export($records);
|
||||
|
||||
// محاسبهی قیمت آخرین قیمت و مجموع کلی مقادیر gold و cash
|
||||
$lastPrice = Price::latest()->first()->price;
|
||||
$walletQuery = Wallet::where('owner', '!=', 4)->where('product_id', null);
|
||||
$sums = [
|
||||
"gold" => round($walletQuery->sum('gold'), 2),
|
||||
"goldToCash" => round($walletQuery->sum('gold') * $lastPrice, 2),
|
||||
"cash" => round($walletQuery->sum('cash'), 2),
|
||||
"cashToGold" => round($walletQuery->sum('cash') / $lastPrice, 2),
|
||||
];
|
||||
|
||||
// $sums = [
|
||||
// "gold" => round(Wallet::whereNot('owner', 4)->sum('gold'), 2),
|
||||
// "goldToCash" => round(Wallet::sum('gold') * $lastPrice, 2),
|
||||
// "cash" => round(Wallet::sum('cash'), 2),
|
||||
// "cashToGold" => round(Wallet::sum('cash') / $lastPrice, 2),
|
||||
// "on" => $lastPrice,
|
||||
// ];
|
||||
|
||||
// افزودن sums به records
|
||||
$records['sums'] = $sums;
|
||||
|
||||
return response()->json($records);
|
||||
|
||||
Reference in New Issue
Block a user