fixed bugs

This commit is contained in:
2026-07-18 17:49:36 +03:30
parent 285a159762
commit 518334da11
@@ -1367,20 +1367,22 @@ class SingleOrderController extends Controller
foreach ($spreadLines as $line) {
$perUnit = (float) ($line['per_unit'] ?? 0);
$total = $perUnit * $amount;
$total = (int) round($perUnit * $amount);
$spreadTotal += $total;
$amountLabel = rtrim(rtrim(number_format($amount, 4, '.', ''), '0'), '.');
$receiptLines[] = array_merge($line, [
'amount_units' => $amount,
'total' => $total,
'line_text' => ($line['detail'] ?? number_format($perUnit) . ' ریال / گرم')
. ($amount > 0
? (' × ' . rtrim(rtrim(number_format($amount, 4, '.', ''), '0'), '.') . ' گرم = ' . number_format($total) . ' ریال')
? (' × ' . $amountLabel . ' گرم = ' . number_format($total) . ' ریال')
: ''),
]);
}
// اگر اقلام ذخیره نشده بود، حداقل یک خط از اختلاف واقعی بساز
if ($receiptLines === [] && $data['fee'] > 0) {
$feeTotal = (int) round((float) $data['total_fee']);
$receiptLines[] = [
'kind' => 'spread',
'key' => $data['fee_source_key'] ?? 'fee',
@@ -1388,17 +1390,17 @@ class SingleOrderController extends Controller
'is_percent' => false,
'per_unit' => $data['fee'],
'amount_units' => $amount,
'total' => $data['total_fee'],
'total' => $feeTotal,
'detail' => number_format($data['fee']) . ' ریال / گرم',
'line_text' => number_format($data['fee']) . ' ریال / گرم × '
. rtrim(rtrim(number_format($amount, 4, '.', ''), '0'), '.')
. ' گرم = ' . number_format($data['total_fee']) . ' ریال',
. ' گرم = ' . number_format($feeTotal) . ' ریال',
];
$spreadTotal = (float) $data['total_fee'];
$spreadTotal = $feeTotal;
}
$scGold = (float) ($data['service_charge'] ?? 0);
$scRial = (float) ($data['service_charge_price'] ?? 0);
$scRial = (int) round((float) ($data['service_charge_price'] ?? 0));
$scPct = (float) ($data['service_charge_percentage'] ?? 0);
if ($scGold > 0 || $scRial > 0) {
@@ -1433,12 +1435,18 @@ class SingleOrderController extends Controller
];
}
$baseTotal = (int) round($amount * $priceOriginal);
$customerTotal = (int) round((float) ($data['total_price'] ?? ($amount * $price)));
$spreadTotal = (int) round($spreadTotal);
$grandTotal = $spreadTotal + $scRial;
$data['fee_breakdown'] = [
'uses_app_price' => (bool) ($data['_fee_uses_app_price'] ?? false),
'amount_units' => $amount,
'price_original' => $priceOriginal,
'price_customer' => $price,
'base_total' => $baseTotal,
'customer_total' => $customerTotal,
'spread_per_unit' => (float) $data['fee'],
'spread_total' => $spreadTotal,
'service_charge_gold' => $scGold,