diff --git a/.gitignore b/.gitignore index 4500b74..f027409 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ npm-debug.log yarn-error.log /.idea /.vscode + +khaneghi_user/ +.DS_Store diff --git a/app/Http/Controllers/Admin/CustomerSpecialPricePackageController.php b/app/Http/Controllers/Admin/CustomerSpecialPricePackageController.php index 74a339f..57e1deb 100644 --- a/app/Http/Controllers/Admin/CustomerSpecialPricePackageController.php +++ b/app/Http/Controllers/Admin/CustomerSpecialPricePackageController.php @@ -216,21 +216,40 @@ class CustomerSpecialPricePackageController extends Controller throw new UnprocessableEntityHttpException('حداقل یک محصول انتخاب کنید.'); } - $profitBuy = (int) preg_replace('/[^\d]/', '', (string) $request->input('profit_buy', 0)); - $profitSell = (int) preg_replace('/[^\d]/', '', (string) $request->input('profit_sell', 0)); + $profitBuy = $this->parseSignedRial($request->input('profit_buy', 0)); + $profitSell = $this->parseSignedRial($request->input('profit_sell', 0)); return [ 'title' => $title, 'customer_ids' => $customerIds, 'product_ids' => $productIds, 'category_names' => $categoryNames, - 'profit_buy' => max(0, $profitBuy), - 'profit_sell' => max(0, $profitSell), + 'profit_buy' => $profitBuy, + 'profit_sell' => $profitSell, 'show_product' => filter_var($request->input('show_product', true), FILTER_VALIDATE_BOOLEAN), 'is_active' => filter_var($request->input('is_active', true), FILTER_VALIDATE_BOOLEAN), ]; } + private function parseSignedRial(mixed $value): int + { + $raw = trim((string) $value); + $raw = str_replace(["\u{066C}", ',', '٬', ' ', 'ریال'], '', $raw); + $raw = strtr($raw, [ + '۰' => '0', '۱' => '1', '۲' => '2', '۳' => '3', '۴' => '4', + '۵' => '5', '۶' => '6', '۷' => '7', '۸' => '8', '۹' => '9', + '٠' => '0', '١' => '1', '٢' => '2', '٣' => '3', '٤' => '4', + '٥' => '5', '٦' => '6', '٧' => '7', '٨' => '8', '٩' => '9', + '−' => '-', '–' => '-', '—' => '-', + ]); + + $negative = str_starts_with($raw, '-'); + $digits = preg_replace('/\D/', '', $raw) ?? '0'; + $amount = (int) ($digits === '' ? '0' : $digits); + + return $negative ? -$amount : $amount; + } + private function syncRelations(CustomerSpecialPricePackage $package, array $data): void { $package->customers()->sync($data['customer_ids']); diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index 48d41d4..b862670 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -1461,7 +1461,7 @@ class SingleOrderController extends Controller throw new UnprocessableEntityHttpException('این محصول برای شما در دسترس نیست.'); } $specialAmt = $specialSvc->profitForDirection($specialRule, $direction); - if ($specialAmt > 0) { + if ($specialAmt !== 0) { $amount += $specialAmt; $keys[] = 'customer_special_pricing'; $lines[] = [ diff --git a/app/Services/CustomerSpecialPricingService.php b/app/Services/CustomerSpecialPricingService.php index 0a48389..8572335 100644 --- a/app/Services/CustomerSpecialPricingService.php +++ b/app/Services/CustomerSpecialPricingService.php @@ -142,17 +142,17 @@ class CustomerSpecialPricingService $buyExtra = (int) ($rule['profit_buy'] ?? 0); $sellExtra = (int) ($rule['profit_sell'] ?? 0); - if (isset($payload['buy']) && (int) $payload['buy'] > 0 && $buyExtra > 0) { - $payload['buy'] = (int) $payload['buy'] + $buyExtra; + if (isset($payload['buy']) && (int) $payload['buy'] > 0 && $buyExtra !== 0) { + $payload['buy'] = max(0, (int) $payload['buy'] + $buyExtra); } - if (isset($payload['sell']) && (int) $payload['sell'] > 0 && $sellExtra > 0) { + if (isset($payload['sell']) && (int) $payload['sell'] > 0 && $sellExtra !== 0) { $payload['sell'] = max(0, (int) $payload['sell'] - $sellExtra); } - if (isset($payload['price_last']) && (int) $payload['price_last'] > 0 && $buyExtra > 0) { - $payload['price_last'] = (int) $payload['price_last'] + $buyExtra; + if (isset($payload['price_last']) && (int) $payload['price_last'] > 0 && $buyExtra !== 0) { + $payload['price_last'] = max(0, (int) $payload['price_last'] + $buyExtra); } - if (isset($payload['priceLast']) && (int) $payload['priceLast'] > 0 && $buyExtra > 0) { - $payload['priceLast'] = (int) $payload['priceLast'] + $buyExtra; + if (isset($payload['priceLast']) && (int) $payload['priceLast'] > 0 && $buyExtra !== 0) { + $payload['priceLast'] = max(0, (int) $payload['priceLast'] + $buyExtra); } $payload['special_pricing'] = [ diff --git a/database/migrations/2026_08_16_000001_create_customer_special_price_packages_tables.php b/database/migrations/2026_08_16_000001_create_customer_special_price_packages_tables.php index b93edb1..ac78929 100644 --- a/database/migrations/2026_08_16_000001_create_customer_special_price_packages_tables.php +++ b/database/migrations/2026_08_16_000001_create_customer_special_price_packages_tables.php @@ -12,8 +12,8 @@ return new class extends Migration Schema::create('customer_special_price_packages', function (Blueprint $table) { $table->id(); $table->string('title'); - $table->unsignedBigInteger('profit_buy')->default(0); - $table->unsignedBigInteger('profit_sell')->default(0); + $table->bigInteger('profit_buy')->default(0); + $table->bigInteger('profit_sell')->default(0); $table->boolean('show_product')->default(true); $table->boolean('is_active')->default(true); $table->timestamps(); diff --git a/database/migrations/2026_08_17_000001_allow_negative_special_price_profits.php b/database/migrations/2026_08_17_000001_allow_negative_special_price_profits.php new file mode 100644 index 0000000..84676d3 --- /dev/null +++ b/database/migrations/2026_08_17_000001_allow_negative_special_price_profits.php @@ -0,0 +1,28 @@ +