$basePrice) { $fixedPriceDiscount = $basePrice; } } // حساب السعر بعد تطبيق الخصومات وقبل الضريبة $priceAfterDiscounts = calculatePriceAfterDiscounts($basePrice, $percentageDiscount, $discountAmount, $pointsDiscount + $fixedPriceDiscount); // التأكد من أن السعر بعد الخصم لا يكون سالب if ($priceAfterDiscounts < 0) { $priceAfterDiscounts = 0; } // حساب مبلغ الضريبة على السعر بعد الخصم $taxAmount = calculateTaxAmount($priceAfterDiscounts, $taxRate); // حساب السعر النهائي بعد الخصم والضريبة $finalPrice = $priceAfterDiscounts + $taxAmount; // التقريب لأقرب رقمين بعد الفاصلة العشرية $basePrice = round($basePrice, 2); $percentageDiscount = round($percentageDiscount, 2); $pointsDiscount = round($pointsDiscount, 2); $fixedPriceDiscount = round($fixedPriceDiscount, 2); $priceAfterDiscounts = round($priceAfterDiscounts, 2); $taxAmount = round($taxAmount, 2); $finalPrice = round($finalPrice, 2); return [ 'base_price' => $basePrice, 'percentage_discount' => $percentageDiscount, 'points_discount' => $pointsDiscount, 'fixed_price_discount' => $fixedPriceDiscount, 'price_after_discounts' => $priceAfterDiscounts, 'tax_amount' => $taxAmount, 'final_price' => $finalPrice ]; } // مثال للاستخدام $totalPrice = 172.5; $discountRate = 0; // نسبة الخصم 0% $discountAmount = 0; // إذا كان الخصم نسبة، يتم تجاهل مبلغ الخصم $points = 0; // عدد النقاط المتاحة $discountPerPoint = 0; // قيمة الخصم لكل نقطة $useFixedPrice = true; // تفعيل نظام تثبيت السعر $fixedTotalPrice = 115.00; // السعر الثابت المراد تطبيقه $result = calculatePriceWithAllDiscounts($totalPrice, 15.0, $discountRate, $discountAmount, $points, $discountPerPoint, $useFixedPrice, $fixedTotalPrice); echo "السعر الأساسي: " . $result['base_price'] . "\n"; echo "الخصم بالنسبة المئوية: " . $result['percentage_discount'] . "\n"; echo "خصم النقاط: " . $result['points_discount'] . "\n"; echo "خصم السعر الثابت: " . $result['fixed_price_discount'] . "\n"; echo "السعر بعد الخصم: " . $result['price_after_discounts'] . "\n"; echo "مبلغ الضريبة: " . $result['tax_amount'] . "\n"; echo "السعر النهائي بعد الخصم والضريبة: " . $result['final_price'] . "\n"; ?>