fix amount 5

This commit is contained in:
2026-06-09 12:43:41 +03:30
parent a8dd0071e2
commit e83afb89d5
4 changed files with 122 additions and 45 deletions
@@ -50,72 +50,71 @@ class CustomerController extends Controller
->where('owner_type', $user->type)
->whereNull('fund_id')
->first() ?? new Wallet();
$wallet->gold_ab = round(Wallet::where('owner', $user->id)->where('product_id', null)->sum('gold'), 2);
$treasureGrams = 0;
$wallet->wp = Wallet::with('product')->where('owner', $user->id)->get();
foreach ($wallet->wp as $row){
if ($row->product_id != null){
$wallet->treasure +=$row->product->amount*$row->gold;
foreach ($wallet->wp as $row) {
if ($row->product_id != null) {
$treasureGrams += self::productLineWeightToGrams($row->product, $row->gold);
}
$wallet->treasure_sum =$user->gold+$wallet->treasure;
}
$wallet->gold_sum = $wallet->treasure_sum+$wallet->gold_ab;
$goldAbGrams = self::weightToGrams((float) Wallet::where('owner', $user->id)->where('product_id', null)->sum('gold'));
$userGoldGrams = self::weightToGrams((float) $user->gold);
$wallet->treasure = round(self::gramsToTradeUnit($treasureGrams), 3);
$wallet->treasure_sum = round(self::gramsToTradeUnit($userGoldGrams + $treasureGrams), 3);
$wallet->gold_ab = round(self::gramsToTradeUnit($goldAbGrams), 2);
$wallet->gold_sum = round($wallet->treasure_sum + $wallet->gold_ab, 2);
$user->wallets = Wallet::with(['product'])->where('owner', $user->id)->get() ?? new Wallet();
$count_gold =0;
$count_silver = 0; // وزن نقره
$count_copper = 0; // وزن مس
$count_cash_from_gold = 0; // مبلغ حاصل از طلا
$count_cash_from_silver = 0; // مبلغ حاصل از نقره
$count_cash_from_copper = 0; // مبلغ حاصل از مس
$count_cash_pure = 0; // نقدینگی خالص بدون ارزش محصولات
$count_gold = 0;
$count_silver = 0;
$count_copper = 0;
$count_cash_from_gold = 0;
$count_cash_from_silver = 0;
$count_cash_from_copper = 0;
$count_cash_pure = 0;
$count_product =0;
$count_product = 0;
foreach ($user->wallets as $walletSingle) {
if ($walletSingle->product_id) {
// محاسبه برای طلا (metal_id = 1)
if ($walletSingle->product->metal_id == 1) {
if (!($walletSingle->product->group_type == "سکه")){
(float)$count_gold += $walletSingle->product->amount*$walletSingle->gold;
}
if (!($walletSingle->product->group_type == "سکه")) {
$count_gold += self::productLineWeightToGrams($walletSingle->product, $walletSingle->gold);
}
$count_cash_from_gold += $walletSingle->product->price * $walletSingle->gold;
$count_product += $walletSingle->gold;
}
// محاسبه برای نقره (metal_id = 2)
elseif ($walletSingle->product->metal_id == 2) {
if (!($walletSingle->product->group_type == "سکه")){
(float)$count_silver += $walletSingle->product->amount * $walletSingle->gold;
} elseif ($walletSingle->product->metal_id == 2) {
if (!($walletSingle->product->group_type == "سکه")) {
$count_silver += self::productLineWeightToGrams($walletSingle->product, $walletSingle->gold);
}
$count_cash_from_silver += ($walletSingle->product->price * $walletSingle->product->amount) * $walletSingle->gold;
$count_product += $walletSingle->gold;
}
// محاسبه برای مس (metal_id = 3)
elseif ($walletSingle->product->metal_id == 3) {
if (!($walletSingle->product->group_type == "سکه")){
(float)$count_copper += $walletSingle->product->amount * $walletSingle->gold;
} elseif ($walletSingle->product->metal_id == 3) {
if (!($walletSingle->product->group_type == "سکه")) {
$count_copper += self::productLineWeightToGrams($walletSingle->product, $walletSingle->gold);
}
$count_cash_from_copper += ($walletSingle->product->price * $walletSingle->product->amount) * $walletSingle->gold;
$count_product += $walletSingle->gold;
}
} else {
(float)$count_gold += $walletSingle->gold;
(float)$count_cash_pure += $walletSingle->cash;
$wallet->count_cash_wallet = $walletSingle->cash;
$wallet->count_gold_wallet = $walletSingle->gold;
$count_gold += self::weightToGrams((float) $walletSingle->gold);
$count_cash_pure += $walletSingle->cash;
$wallet->count_cash_wallet = $walletSingle->cash;
$wallet->count_gold_wallet = round(self::gramsToTradeUnit(self::weightToGrams((float) $walletSingle->gold)), 3);
}
}
// محاسبه مجموع کل ارزش دارایی
$count_cash_total = $count_cash_from_gold + $count_cash_from_silver + $count_cash_from_copper + $count_cash_pure;
$wallet->count_cash_wallets = $count_cash_total - $wallet->count_cash_wallet;
$wallet->count_gold_wallets = $count_gold - $wallet->count_gold_wallet;
$wallet->count_gold = $count_gold;
$wallet->count_silver = $count_silver;
$wallet->count_copper = $count_copper;
$wallet->count_gold = round(self::gramsToTradeUnit($count_gold), 3);
$wallet->count_gold_wallets = round($wallet->count_gold - $wallet->count_gold_wallet, 3);
$wallet->count_silver = round(self::gramsToTradeUnit($count_silver), 3);
$wallet->count_copper = round(self::gramsToTradeUnit($count_copper), 3);
$wallet->count_cash = $count_cash_pure;
$wallet->count_product = $count_product;
$wallet->cash_from_gold = $count_cash_from_gold;