added charge for all products 2

This commit is contained in:
2026-07-11 22:31:16 +03:30
parent 0d78bcb750
commit d450bd216c
@@ -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;