NASER seperate gold, cooper and silver
This commit is contained in:
@@ -49,28 +49,67 @@ class CustomerController extends Controller
|
|||||||
$user->wallets = Wallet::with(['product'])->where('owner', $user->id)->get() ?? new Wallet();
|
$user->wallets = Wallet::with(['product'])->where('owner', $user->id)->get() ?? new Wallet();
|
||||||
|
|
||||||
$count_gold =0;
|
$count_gold =0;
|
||||||
$count_cash =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) {
|
foreach ($user->wallets as $walletSingle) {
|
||||||
if ($walletSingle->product_id) {
|
if ($walletSingle->product_id) {
|
||||||
|
|
||||||
|
// محاسبه برای طلا (metal_id = 1)
|
||||||
|
if ($walletSingle->product->metal_id == 1) {
|
||||||
|
|
||||||
if (!($walletSingle->product->group_type == "سکه")){
|
if (!($walletSingle->product->group_type == "سکه")){
|
||||||
(float)$count_gold += $walletSingle->product->amount*$walletSingle->gold;
|
(float)$count_gold += $walletSingle->product->amount*$walletSingle->gold;
|
||||||
}
|
}
|
||||||
$count_cash += $walletSingle->product->price*$walletSingle->gold;
|
$count_cash_from_gold += $walletSingle->product->price * $walletSingle->gold;
|
||||||
$count_product += $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;
|
||||||
|
}
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$count_cash_from_copper += ($walletSingle->product->price * $walletSingle->product->amount) * $walletSingle->gold;
|
||||||
|
$count_product += $walletSingle->gold;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
(float)$count_gold += $walletSingle->gold;
|
(float)$count_gold += $walletSingle->gold;
|
||||||
(float)$count_cash += $walletSingle->cash;
|
(float)$count_cash_pure += $walletSingle->cash;
|
||||||
$wallet->count_cash_wallet = $walletSingle->cash;
|
$wallet->count_cash_wallet = $walletSingle->cash;
|
||||||
$wallet->count_gold_wallet = $walletSingle->gold;
|
$wallet->count_gold_wallet = $walletSingle->gold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$wallet->count_cash_wallets = $count_cash-$wallet->count_cash_wallet;
|
|
||||||
$wallet->count_gold_wallets = $count_gold-$wallet->count_gold_wallet;
|
// محاسبه مجموع کل ارزش دارایی
|
||||||
|
$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_gold = $count_gold;
|
||||||
$wallet->count_cash = $count_cash;
|
$wallet->count_silver = $count_silver;
|
||||||
|
$wallet->count_copper = $count_copper;
|
||||||
|
$wallet->count_cash = $count_cash_pure;
|
||||||
$wallet->count_product = $count_product;
|
$wallet->count_product = $count_product;
|
||||||
|
$wallet->cash_from_gold = $count_cash_from_gold;
|
||||||
|
$wallet->cash_from_silver = $count_cash_from_silver;
|
||||||
|
$wallet->cash_from_copper = $count_cash_from_copper;
|
||||||
|
$wallet->count_cash_total = $count_cash_total;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$user->wallet = $wallet;
|
$user->wallet = $wallet;
|
||||||
$user->pwallet = Wallet::with("product")->where('owner', $user->id)
|
$user->pwallet = Wallet::with("product")->where('owner', $user->id)
|
||||||
|
|||||||
Reference in New Issue
Block a user