fixed kilo in metals
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 App\Services\WalletBalanceService;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
|
||||
|
||||
@@ -301,28 +302,42 @@ class WalletController extends Controller
|
||||
public function indexWallet(Request $request)
|
||||
{
|
||||
$lastPrice = (float) (Price::latest()->first()?->price ?? 0);
|
||||
$balanceService = app(WalletBalanceService::class);
|
||||
$catalogMetalIds = $balanceService->catalogMetalIds();
|
||||
$mainWalletMetalId = $balanceService->resolveMainWalletMetalId();
|
||||
|
||||
// همان فیلتر/جستجوی جدول — بدون صفحهبندی — برای مجموع ردیفهای قابل مشاهده
|
||||
$sumQuery = Wallet::query();
|
||||
TableEngine::create($sumQuery, $request->all())
|
||||
->initSearch(['customer.name']);
|
||||
|
||||
$totalGold = (float) (clone $sumQuery)->sum('gold');
|
||||
$sumRows = (clone $sumQuery)->with('product:id,metal_id')->get();
|
||||
$metalBalances = $balanceService->buildWalletMetalSums($sumRows, $catalogMetalIds);
|
||||
$totalGold = array_sum(array_column($metalBalances, 'gold'));
|
||||
$totalGoldToCash = array_sum(array_column($metalBalances, 'goldToCash'));
|
||||
$totalCash = (float) (clone $sumQuery)->sum('cash');
|
||||
|
||||
$sums = [
|
||||
'gold' => round($totalGold, 2),
|
||||
'goldToCash' => round($totalGold * $lastPrice, 2),
|
||||
'goldToCash' => round($totalGoldToCash, 2),
|
||||
'cash' => round($totalCash, 2),
|
||||
'cashToGold' => $lastPrice > 0 ? round($totalCash / $lastPrice, 2) : 0,
|
||||
'metalBalances' => $metalBalances,
|
||||
];
|
||||
|
||||
$records = Wallet::with('customer');
|
||||
$records = Wallet::with(['customer', 'product:id,metal_id']);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select(['*'])
|
||||
->export($records);
|
||||
|
||||
if (isset($records['rows'])) {
|
||||
foreach ($records['rows'] as &$row) {
|
||||
$balanceService->enrichWalletTableRow($row, $catalogMetalIds, $mainWalletMetalId);
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
$records['sums'] = $sums;
|
||||
|
||||
return response()->json($records);
|
||||
|
||||
Reference in New Issue
Block a user