fix wallet ui

This commit is contained in:
2026-06-26 22:19:51 +03:30
parent 1247a5ca07
commit 14d417d9ec
3 changed files with 20 additions and 3 deletions
@@ -16,6 +16,7 @@ use Rooyesh\Wallet\interfaces\WalletInterface;
use Rooyesh\Wallet\models\Transaction; use Rooyesh\Wallet\models\Transaction;
use Rooyesh\Wallet\models\Wallet; use Rooyesh\Wallet\models\Wallet;
use App\Models\Setting; use App\Models\Setting;
use App\Services\AssetSummaryService;
use App\Services\BalanceReportService; use App\Services\BalanceReportService;
use App\Services\ConfigService; use App\Services\ConfigService;
use App\Services\WalletBalanceService; use App\Services\WalletBalanceService;
@@ -23,6 +24,11 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class CustomerController extends SuperController class CustomerController extends SuperController
{ {
/** فیلدهای محصول لازم برای محاسبهٔ صحیح وزن موجودی */
private const WALLET_PRODUCT_COLUMNS = [
'id', 'metal_id', 'unit', 'amount', 'group_type', 'trade_by_quantity', 'direct_price', 'title',
];
public function __construct() public function __construct()
{ {
$this->with = []; $this->with = [];
@@ -134,7 +140,8 @@ class CustomerController extends SuperController
return response()->json(true); return response()->json(true);
} }
public function tableWallets(Request $request){ public function tableWallets(Request $request){
$query_table = Customer::with(['wallet.product:id,metal_id', 'referral'])->where("is_archive",false)/*->where('type',1)*/; $productSelect = 'product:'.implode(',', self::WALLET_PRODUCT_COLUMNS);
$query_table = Customer::with(['wallet.'.$productSelect, 'referral'])->where('is_archive', false);
TableEngine::create($query_table, $request) TableEngine::create($query_table, $request)
->initSearch($this->search) ->initSearch($this->search)
->select(['*',Customer::$SELECT_TYPE_STR]) ->select(['*',Customer::$SELECT_TYPE_STR])
@@ -163,6 +170,15 @@ class CustomerController extends SuperController
return response()->json($query_table); return response()->json($query_table);
} }
public function assetsSummary($customerId, AssetSummaryService $assetSummaryService)
{
$customer = Customer::findOrFail($customerId);
return response()->json(
$assetSummaryService->buildForCustomer((int) $customer->id, (int) $customer->type)
);
}
public function archiveTable(Request $request) public function archiveTable(Request $request)
{ {
$query_table = Customer::with($this->with)->where("is_archive",true)/*->where('type',1)*/; $query_table = Customer::with($this->with)->where("is_archive",true)/*->where('type',1)*/;
@@ -490,7 +490,7 @@ class WalletController extends Controller
TableEngine::create($sumQuery, $request->all()) TableEngine::create($sumQuery, $request->all())
->initSearch(['customer.name']); ->initSearch(['customer.name']);
$sumRows = (clone $sumQuery)->with('product:id,metal_id')->get(); $sumRows = (clone $sumQuery)->with('product:id,metal_id,unit,amount,group_type,trade_by_quantity,direct_price,title')->get();
$metalBalances = $balanceService->buildWalletMetalSums($sumRows, $catalogMetalIds); $metalBalances = $balanceService->buildWalletMetalSums($sumRows, $catalogMetalIds);
$totalGold = array_sum(array_column($metalBalances, 'gold')); $totalGold = array_sum(array_column($metalBalances, 'gold'));
$totalGoldToCash = array_sum(array_column($metalBalances, 'goldToCash')); $totalGoldToCash = array_sum(array_column($metalBalances, 'goldToCash'));
@@ -504,7 +504,7 @@ class WalletController extends Controller
'metalBalances' => $metalBalances, 'metalBalances' => $metalBalances,
]; ];
$records = Wallet::with(['customer', 'product:id,metal_id']); $records = Wallet::with(['customer', 'product:id,metal_id,unit,amount,group_type,trade_by_quantity,direct_price,title']);
TableEngine::create($records, $request->all()) TableEngine::create($records, $request->all())
->initSearch(['customer.name']) ->initSearch(['customer.name'])
->select(['*']) ->select(['*'])
+1
View File
@@ -78,6 +78,7 @@ Route::middleware('auth:user')->group(function (){
//--------customer //--------customer
Route::post('/customer/table',[CustomerController::class,'tableWallets']); Route::post('/customer/table',[CustomerController::class,'tableWallets']);
Route::get('/customer/{id}/assets',[CustomerController::class,'assetsSummary']);
Route::get('/customer/active/{id}',[CustomerController::class,'active']); Route::get('/customer/active/{id}',[CustomerController::class,'active']);
Route::get('/customer/archive/{id}',[CustomerController::class,'archive']); Route::get('/customer/archive/{id}',[CustomerController::class,'archive']);
Route::get('/customer/trade/{id}',[CustomerController::class,'changeTradeActive']); Route::get('/customer/trade/{id}',[CustomerController::class,'changeTradeActive']);