fixed kilo in metals
This commit is contained in:
@@ -16,6 +16,7 @@ use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
use Rooyesh\Wallet\models\Transaction;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
use App\Models\Setting;
|
||||
use App\Services\BalanceReportService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
@@ -133,19 +134,27 @@ class CustomerController extends SuperController
|
||||
return response()->json(true);
|
||||
}
|
||||
public function tableWallets(Request $request){
|
||||
$query_table = Customer::with(['wallet','referral'])->where("is_archive",false)/*->where('type',1)*/;
|
||||
$query_table = Customer::with(['wallet.product:id,metal_id', 'referral'])->where("is_archive",false)/*->where('type',1)*/;
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select(['*',Customer::$SELECT_TYPE_STR])
|
||||
->export($query_table);
|
||||
|
||||
$balanceService = app(WalletBalanceService::class);
|
||||
$mainWalletProductIds = app(ConfigService::class)->mainWalletProductIds();
|
||||
$balanceReport = app(BalanceReportService::class);
|
||||
$catalogMetalIds = $balanceService->catalogMetalIds();
|
||||
$query_table['catalogMetals'] = $balanceReport->catalogMetalsMeta();
|
||||
|
||||
if (isset($query_table['rows'])) {
|
||||
$query_table['rows'] = collect($query_table['rows'])->map(function ($row) use ($balanceService, $mainWalletProductIds) {
|
||||
$query_table['rows'] = collect($query_table['rows'])->map(function ($row) use ($balanceService, $catalogMetalIds) {
|
||||
$wallets = collect($row['wallet'] ?? []);
|
||||
$row['wallet_cash'] = $balanceService->mainWalletCash($wallets);
|
||||
$row['wallet_gold'] = $balanceService->totalGoldWeight($wallets, $mainWalletProductIds);
|
||||
$metalMap = $balanceService->buildCustomerWalletMetalDisplayMap($wallets, $catalogMetalIds);
|
||||
$row['wallet_metal_gold'] = $metalMap;
|
||||
foreach ($catalogMetalIds as $metalId) {
|
||||
$row['wallet_metal_gold_' . $metalId] = $metalMap[(string) $metalId] ?? 0.0;
|
||||
}
|
||||
$row['wallet_gold'] = array_sum($metalMap);
|
||||
|
||||
return $row;
|
||||
})->values();
|
||||
|
||||
Reference in New Issue
Block a user