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
@@ -52,6 +52,8 @@ class ProductController extends SuperController
->select($this->select)
->export($query_table);
$this->enrichAdminTablePrices($query_table['rows'] ?? null);
if (Schema::hasColumn((new Product)->getTable(), 'auto_open_at')) {
$query_table['auto_open_at'] = Product::selectRaw(
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_open_at)))) as avg_time'
@@ -83,6 +85,8 @@ class ProductController extends SuperController
->select($this->select)
->export($query_table);
$this->enrichAdminTablePrices($query_table['rows'] ?? null);
return $query_table;
}
@@ -557,6 +561,27 @@ class ProductController extends SuperController
});
}
/**
* جدول ادمین — قیمت لحظه‌ای روی مدل (بدون UPDATE دیتابیس)، مثل فرم ویرایش و اپ مشتری.
*
* @param iterable<Product>|null $rows
*/
private function enrichAdminTablePrices($rows): void
{
if ($rows === null || app(ConfigService::class)->isStore()) {
return;
}
$products = collect($rows)->filter(fn ($row) => $row instanceof Product);
if ($products->isEmpty()) {
return;
}
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->warmLivePriceCache();
$displayPriceService->enrichForApi($products);
}
private function filterProductData(array $data): array
{
if (!Product::hasPriceOffsetColumn()) {
@@ -616,6 +641,12 @@ class ProductController extends SuperController
unset($data['inventory']);
}
if (!Product::hasOverrideTradingHoursColumn()) {
unset($data['override_trading_hours']);
} elseif (array_key_exists('override_trading_hours', $data)) {
$data['override_trading_hours'] = !empty($data['override_trading_hours']);
}
return $data;
}
}