added percent in product price

This commit is contained in:
2026-07-04 18:00:57 +03:30
parent 4dea2fb212
commit 4ef0dfb2c0
7 changed files with 161 additions and 6 deletions
+43
View File
@@ -6,6 +6,49 @@ use App\Models\Product;
class ProductPriceService
{
/** 5 => 5% ، 0.05 => 5% (اعشاری) */
public static function feePercentRatio(float $percentValue): float
{
if ($percentValue == 0.0) {
return 0.0;
}
if (abs($percentValue) > 0 && abs($percentValue) < 1) {
return $percentValue;
}
return $percentValue / 100;
}
public static function resolveCashFeeRial(Product $product, int $direction, float $basePriceRial): float
{
$isBuy = $direction === 1;
$rawFee = (float) ($isBuy ? ($product->cash_fee_buy ?? 0) : ($product->cash_fee_sell ?? 0));
if ($rawFee == 0.0) {
return 0.0;
}
$isPercent = $isBuy
? (bool) ($product->cash_fee_buy_is_percent ?? false)
: (bool) ($product->cash_fee_sell_is_percent ?? false);
if (! $isPercent || ! Product::hasCashFeePercentModeColumns()) {
return $rawFee;
}
if ($basePriceRial <= 0) {
return 0.0;
}
return round(abs($basePriceRial * self::feePercentRatio($rawFee)));
}
public static function productBasePriceRial(Product $product): float
{
return (float) (($product->price ?? 0) + ($product->price_profit ?? 0));
}
public static function referenceTotal(int $basePrice, int $baseProfit = 0): int
{
return $basePrice + $baseProfit;