fix count bug

This commit is contained in:
2026-07-20 19:11:04 +03:30
parent a809a843b8
commit 5d98a6f041
@@ -518,7 +518,7 @@ class PargarInboundController extends Controller
$product = $sync->resolveOrderProduct($order, $payload);
$number = (float) ($payload['number'] ?? 0);
$amount = (float) ($order->amount ?? 0);
$amount = abs((float) ($order->amount ?? 0));
$totalPrice = (float) ($order->total_price ?? $order->payment_amount ?? 0);
$unitPrice = (float) ($order->price ?? 0);
@@ -526,13 +526,13 @@ class PargarInboundController extends Controller
? self::isCountBasedProduct(self::productUnitPayload($product))
: false;
$count = 1;
// پرگار: Count>0 → سند تعدادی (وزن را نادیده می‌گیرد)
// آبشده/وزنی مثل آذین: Count=0 و Weight=گرم
$count = 0;
$weight = $amount;
if ($isCountBased && $number > 0) {
$count = max(1, (int) round($number));
if ($isCountBased) {
$count = $number > 0 ? max(1, (int) round($number)) : 1;
$weight = $amount;
} elseif ($number > 0 && abs($number - $amount) > 0.0001) {
$count = max(1, (int) round($number));
}
$itemId = $sync->pargarItemIdGold();
@@ -543,25 +543,29 @@ class PargarInboundController extends Controller
$tradedProductId = (int) ($payload['product_id'] ?? $order->product_id ?? 0);
$tradesMainGold = $tradedProductId <= 0
|| app(ConfigService::class)->isMainWalletProduct($tradedProductId);
|| app(ConfigService::class)->isMainWalletProduct($tradedProductId)
|| ($product && self::isMeltedTradeGroup($product->group_type ?? null));
// اثر مانده از روش پرداخت؛ وزن طلا فقط وقتی کالای معامله یا پرداخت به کیف اصلی مربوط است
if ($paymentKind === PargarSyncService::PAYMENT_CASH) {
if ($tradesMainGold) {
// خرید/فروش آبشده کیف‌اصلی با نقدی: وزن + مبلغ
// خرید/فروش آبشده کیف‌اصلی با نقدی: وزن + مبلغ — حتماً تعدادی نباشد
$itemId = $sync->pargarItemIdGold();
$count = 0;
$weight = $amount;
} else {
// محصول غیر اصلی با پرداخت نقدی: فقط ریال
$rialItemId = $sync->pargarItemIdRial();
$itemId = $rialItemId > 0 ? $rialItemId : $sync->pargarItemIdGold();
$weight = 0;
$count = 1;
$count = 0;
}
} elseif ($paymentKind === PargarSyncService::PAYMENT_MAIN_GOLD) {
$itemId = $sync->pargarItemIdGold();
$itemName = $sync->mainWalletGoldItemName();
$paymentGold = (float) ($payload['payment_gold'] ?? $amount);
$weight = abs($paymentGold);
$paymentGold = abs((float) ($payload['payment_gold'] ?? $amount));
$weight = $paymentGold;
$count = 0;
$totalPrice = 0;
}
@@ -624,7 +628,7 @@ class PargarInboundController extends Controller
'ItemName' => $sync->mainWalletGoldItemName(),
'OrderDate' => Jalalian::fromDateTime($log->date ?? $log->created_at)->format('Y/m/d-H:i:s'),
'Fee' => 0,
'Count' => 1,
'Count' => 0,
'Weight' => abs($signed),
'Price' => 0,
'Carat' => 750,
@@ -643,7 +647,7 @@ class PargarInboundController extends Controller
'ItemName' => $isDeposit ? 'واریز ریالی' : 'برداشت ریالی',
'OrderDate' => Jalalian::fromDateTime($log->date ?? $log->created_at)->format('Y/m/d-H:i:s'),
'Fee' => 0,
'Count' => 1,
'Count' => 0,
'Weight' => 0,
'Price' => abs($signed),
'Carat' => 750,