added some feature for accounting and price

This commit is contained in:
2026-06-28 15:16:39 +03:30
parent 9f92466ada
commit 3801e5ee88
11 changed files with 423 additions and 39 deletions
+28 -5
View File
@@ -580,21 +580,46 @@ class ConfigService
return $current >= $openStr && $current <= $closeStr;
}
/** ساعت کاری سراسری (close_price) + بازه auto_open_at/auto_close_at هر محصول */
/**
* آیا محصول بازه زمانی اختصاصی خودش را override کرده؟
* فقط وقتی سوییچ override_trading_hours روشن باشد و بازه معتبری (شروع != پایان) داشته باشد.
*/
public function productOverridesTradingHours(Product $product): bool
{
if (!Product::hasOverrideTradingHoursColumn()) {
return false;
}
if (!($product->override_trading_hours ?? false)) {
return false;
}
return $this->hasProductTradingWindow($product->auto_open_at, $product->auto_close_at);
}
/**
* ساعت معامله یک محصول:
* - اگر سوییچ override محصول روشن باشد → فقط بازه خود محصول حاکم است (سراسری نادیده گرفته می‌شود).
* - در غیر این صورت → فیلتر سراسری close_price + startDay/endDay اعمال می‌شود.
*/
public function isProductWithinTradingHours(Product $product, ?Carbon $now = null): bool
{
if ($this->productOverridesTradingHours($product)) {
return $this->isWithinTimeWindow($product->auto_open_at, $product->auto_close_at, $now);
}
if ($this->isClosePriceEnabled() && $this->isOutsideTradingHours($now)) {
return false;
}
return $this->isWithinTimeWindow($product->auto_open_at, $product->auto_close_at, $now);
return true;
}
public function productTradingClosedMessage(Product $product): string
{
$title = trim((string) ($product->title ?? 'محصول'));
if ($this->hasProductTradingWindow($product->auto_open_at, $product->auto_close_at)) {
if ($this->productOverridesTradingHours($product)) {
$open = $this->formatProductTime($product->auto_open_at);
$close = $this->formatProductTime($product->auto_close_at);
@@ -606,8 +631,6 @@ class ConfigService
public function assertProductTradingOpen(Product $product, ?Carbon $now = null): void
{
$this->assertTradingOpen($now);
if (!$this->isProductWithinTradingHours($product, $now)) {
throw new UnprocessableEntityHttpException($this->productTradingClosedMessage($product));
}