added some feature for accounting and price
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user