From d450bd216c0505ef90a144f72052a9c8146ab2aa Mon Sep 17 00:00:00 2001 From: adonis Date: Sat, 11 Jul 2026 22:31:16 +0330 Subject: [PATCH] added charge for all products 2 --- .../Controllers/Admin/DashboardController.php | 54 ++++++++++++++++--- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 9bd43ff..28cedf1 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -371,18 +371,58 @@ class DashboardController extends Controller $daily[$dateKey]['order_count']++; } - // مرتب‌سازی نزولی بر اساس تاریخ و گرد کردن گرم‌ها - krsort($daily); - $response['daily'] = array_map(function ($row) { - $row['profit_gold'] = round($row['profit_gold'], 4); - return $row; - }, array_values($daily)); - $response['profitGoldGrams'] = round($response['profitGoldGrams'], 4); + + // سندهای تبدیل سود ریالی به طلا: از سود ریالی کم و به سود طلایی (گرم) اضافه می‌شود. + $conversions = ProfitConversion::whereBetween('converted_at', [$startDate, $endDate])->get(); + $convertedRial = 0.0; + $convertedGram = 0.0; + + foreach ($conversions as $conversion) { + $rialAmount = (float) $conversion->rial_amount; + $gramAmount = (float) $conversion->gram_amount; + $convertedRial += $rialAmount; + $convertedGram += $gramAmount; + + $dateKey = $conversion->converted_at + ? Carbon::parse($conversion->converted_at)->toDateString() + : null; + if (!$dateKey) { + continue; + } + + if (!isset($daily[$dateKey])) { + $daily[$dateKey] = [ + 'date' => $dateKey, + 'profit_gold' => 0.0, + 'profit_rial' => 0.0, + 'spread_rial' => 0.0, + 'order_count' => 0, + ]; + } + + $daily[$dateKey]['profit_rial'] -= $rialAmount; + $daily[$dateKey]['profit_gold'] += $gramAmount; + } + + $response['profitRialGross'] = $response['profitRial']; + $response['profitGoldGramsGross'] = $response['profitGoldGrams']; + $response['profitRialConverted'] = round($convertedRial, 0); + $response['profitGoldConvertedGram'] = round($convertedGram, 4); + + $response['profitRial'] = round($response['profitRial'] - $convertedRial, 0); + $response['profitGoldGrams'] = round($response['profitGoldGrams'] + $convertedGram, 4); $response['profitGoldValueRial'] = $lastGoldPrice > 0 ? (int) floor($response['profitGoldGrams'] * $lastGoldPrice) : 0; + krsort($daily); + $response['daily'] = array_map(function ($row) { + $row['profit_gold'] = round($row['profit_gold'], 4); + $row['profit_rial'] = round($row['profit_rial'], 0); + return $row; + }, array_values($daily)); + $response['totalTradingProfit'] = $response['fullPriceSood'] + $response['fullPriceKarmozd']; $response['sumAll'] = $response['fullPriceM1'] - $response['GiftsPrise']; return $response;