feat: 統一各模組分頁組件佈局並新增系統設定功能相關檔案
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m5s
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m5s
This commit is contained in:
@@ -36,7 +36,11 @@ class ActivityLogController extends Controller
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$sortBy = $request->input('sort_by', 'created_at');
|
||||
$sortOrder = $request->input('sort_order', 'desc');
|
||||
|
||||
|
||||
46
app/Modules/Core/Controllers/SystemSettingController.php
Normal file
46
app/Modules/Core/Controllers/SystemSettingController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Core\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Modules\Core\Models\SystemSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SystemSettingController extends Controller
|
||||
{
|
||||
/**
|
||||
* 顯示系統設定頁面
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$settings = SystemSetting::all()->groupBy('group');
|
||||
|
||||
return Inertia::render('Admin/Setting/Index', [
|
||||
'settings' => $settings,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新系統設定
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'settings' => 'required|array',
|
||||
'settings.*.key' => 'required|string|exists:system_settings,key',
|
||||
'settings.*.value' => 'nullable',
|
||||
]);
|
||||
|
||||
foreach ($validated['settings'] as $item) {
|
||||
SystemSetting::where('key', $item['key'])->update([
|
||||
'value' => $item['value']
|
||||
]);
|
||||
}
|
||||
|
||||
// 清除記憶體快取,確保後續讀取拿到最新值
|
||||
SystemSetting::clearCache();
|
||||
|
||||
return redirect()->back()->with('success', '系統設定已更新');
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,12 @@ class UserController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$sortBy = $request->input('sort_by', 'id');
|
||||
$sortOrder = $request->input('sort_order', 'asc');
|
||||
$search = $request->input('search');
|
||||
|
||||
61
app/Modules/Core/Models/SystemSetting.php
Normal file
61
app/Modules/Core/Models/SystemSetting.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SystemSetting extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'group',
|
||||
'key',
|
||||
'value',
|
||||
'type',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* 同請求內的記憶體快取,避免重複查詢 DB
|
||||
* PHP 請求結束後自動釋放,無需額外處理失效
|
||||
*/
|
||||
protected static array $cache = [];
|
||||
|
||||
/**
|
||||
* 取得特定設定值(含記憶體快取)
|
||||
*/
|
||||
public static function getVal(string $key, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, static::$cache)) {
|
||||
return static::$cache[$key];
|
||||
}
|
||||
|
||||
$setting = self::where('key', $key)->first();
|
||||
|
||||
if (!$setting) {
|
||||
static::$cache[$key] = $default;
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = $setting->value;
|
||||
|
||||
// 根據 type 進行類別轉換
|
||||
$resolved = match ($setting->type) {
|
||||
'integer', 'number' => (int) $value,
|
||||
'boolean', 'bool' => filter_var($value, FILTER_VALIDATE_BOOLEAN),
|
||||
'json', 'array' => json_decode($value, true),
|
||||
default => $value,
|
||||
};
|
||||
|
||||
static::$cache[$key] = $resolved;
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除記憶體快取(儲存設定後應呼叫)
|
||||
*/
|
||||
public static function clearCache(): void
|
||||
{
|
||||
static::$cache = [];
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Modules\Core\Controllers\ProfileController;
|
||||
use App\Modules\Core\Controllers\RoleController;
|
||||
use App\Modules\Core\Controllers\UserController;
|
||||
use App\Modules\Core\Controllers\ActivityLogController;
|
||||
use App\Modules\Core\Controllers\SystemSettingController;
|
||||
|
||||
// 登入/登出路由
|
||||
Route::get('/login', [LoginController::class, 'show'])->name('login');
|
||||
@@ -56,5 +57,10 @@ Route::middleware('auth')->group(function () {
|
||||
Route::get('/activity-logs', [ActivityLogController::class, 'index'])->name('activity-logs.index');
|
||||
});
|
||||
|
||||
Route::middleware('permission:system.settings.view')->group(function () {
|
||||
Route::get('/settings', [SystemSettingController::class, 'index'])->name('settings.index');
|
||||
Route::post('/settings', [SystemSettingController::class, 'update'])->name('settings.update');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,11 @@ class AccountPayableController extends Controller
|
||||
$query->where('due_date', '<=', $request->date_end);
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$payables = $query->latest()->paginate($perPage)->withQueryString();
|
||||
|
||||
// Manual Hydration for Vendors
|
||||
|
||||
@@ -27,7 +27,11 @@ class AccountingReportController extends Controller
|
||||
$allRecords = $reportData['records'];
|
||||
|
||||
// 3. Manual Pagination
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$page = $request->input('page', 1);
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ class AccountPayableService
|
||||
'total_amount' => collect($receiptData['items'] ?? [])->sum('total_amount'),
|
||||
'tax_amount' => 0, // 假設後續會實作稅額計算,目前預設為 0
|
||||
'status' => AccountPayable::STATUS_PENDING,
|
||||
// 設定應付日期,預設為進貨後 30 天 (可依據供應商設定調整)
|
||||
'due_date' => now()->addDays(30)->toDateString(),
|
||||
// 設定應付日期,預設為進貨後天數 (由系統設定決定,預設 30 天)
|
||||
'due_date' => now()->addDays(\App\Modules\Core\Models\SystemSetting::getVal('finance.ap_payment_days', 30))->toDateString(),
|
||||
'created_by' => $userId,
|
||||
'remarks' => "由進貨單 {$receiptData['code']} 自動生成",
|
||||
]);
|
||||
|
||||
@@ -94,7 +94,13 @@ class FinanceService implements FinanceServiceInterface
|
||||
$sortDirection = $filters['sort_direction'] ?? 'desc';
|
||||
$query->orderBy($sortField, $sortDirection);
|
||||
|
||||
return $query->paginate($filters['per_page'] ?? 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) ($filters['per_page'] ?? $defaultPerPage);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getUniqueCategories(): Collection
|
||||
|
||||
@@ -29,7 +29,13 @@ class SalesOrderController extends Controller
|
||||
// 排序
|
||||
$query->orderBy('sold_at', 'desc');
|
||||
|
||||
$orders = $query->paginate($request->input('per_page', 10))
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$orders = $query->paginate($perPage)
|
||||
->withQueryString();
|
||||
|
||||
return Inertia::render('Integration/SalesOrders/Index', [
|
||||
|
||||
@@ -131,7 +131,7 @@ interface InventoryServiceInterface
|
||||
* @param int $perPage 每頁筆數
|
||||
* @return array
|
||||
*/
|
||||
public function getStockQueryData(array $filters = [], int $perPage = 10): array;
|
||||
public function getStockQueryData(array $filters = [], ?int $perPage = null): array;
|
||||
|
||||
/**
|
||||
* Get statistics for the dashboard.
|
||||
|
||||
@@ -39,7 +39,11 @@ class AdjustDocController extends Controller
|
||||
$query->where('warehouse_id', $request->warehouse_id);
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$docs = $query->orderByDesc('created_at')
|
||||
->paginate($perPage)
|
||||
->withQueryString()
|
||||
|
||||
@@ -35,9 +35,11 @@ class CountDocController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = 10;
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$countQuery = function ($query) {
|
||||
|
||||
@@ -63,7 +63,11 @@ class GoodsReceiptController extends Controller
|
||||
}
|
||||
|
||||
// 每頁筆數
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$receipts = $query->orderBy('created_at', 'desc')
|
||||
->paginate($perPage)
|
||||
|
||||
@@ -24,7 +24,12 @@ class InventoryAnalysisController extends Controller
|
||||
'warehouse_id', 'category_id', 'search', 'per_page', 'sort_by', 'sort_order', 'status'
|
||||
]);
|
||||
|
||||
$analysisData = $this->turnoverService->getAnalysisData($filters, $request->input('per_page', 10));
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$analysisData = $this->turnoverService->getAnalysisData($filters, $perPage);
|
||||
$kpis = $this->turnoverService->getKPIs($filters);
|
||||
|
||||
return Inertia::render('Inventory/Analysis/Index', [
|
||||
|
||||
@@ -35,7 +35,12 @@ class InventoryReportController extends Controller
|
||||
$filters['date_to'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
$reportData = $this->reportService->getReportData($filters, $request->input('per_page', 10));
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$reportData = $this->reportService->getReportData($filters, $perPage);
|
||||
$summary = $this->reportService->getSummary($filters);
|
||||
|
||||
return Inertia::render('Inventory/Report/Index', [
|
||||
|
||||
@@ -37,9 +37,11 @@ class ProductController extends Controller
|
||||
$query->where('category_id', $request->category_id);
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = 10;
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$sortField = $request->input('sort_field', 'id');
|
||||
|
||||
@@ -24,7 +24,12 @@ class StockQueryController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
$filters = $request->only(['warehouse_id', 'category_id', 'search', 'status', 'sort_by', 'sort_order', 'per_page']);
|
||||
$perPage = (int) ($filters['per_page'] ?? 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) ($filters['per_page'] ?? $defaultPerPage);
|
||||
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$result = $this->inventoryService->getStockQueryData($filters, $perPage);
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class StoreRequisitionController extends Controller
|
||||
$query->orderBy('id', 'desc');
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$requisitions = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
// 水和倉庫名稱與使用者名稱
|
||||
|
||||
@@ -42,7 +42,11 @@ class TransferOrderController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$orders = $query->orderByDesc('created_at')
|
||||
->paginate($perPage)
|
||||
->withQueryString()
|
||||
|
||||
@@ -24,9 +24,11 @@ class WarehouseController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = 10;
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$warehouses = $query->withSum('inventories as book_stock', 'quantity') // 帳面庫存 = 所有庫存總和
|
||||
|
||||
@@ -23,8 +23,9 @@ class InventoryReportService
|
||||
* @param int|null $perPage 每頁筆數
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection
|
||||
*/
|
||||
public function getReportData(array $filters, ?int $perPage = 10)
|
||||
public function getReportData(array $filters, ?int $perPage = null)
|
||||
{
|
||||
$perPage = $perPage ?? \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$dateFrom = $filters['date_from'] ?? null;
|
||||
$dateTo = $filters['date_to'] ?? null;
|
||||
$warehouseId = $filters['warehouse_id'] ?? null;
|
||||
@@ -197,8 +198,9 @@ class InventoryReportService
|
||||
/**
|
||||
* 取得特定商品的庫存異動明細
|
||||
*/
|
||||
public function getProductDetails($productId, array $filters, ?int $perPage = 20)
|
||||
public function getProductDetails($productId, array $filters, ?int $perPage = null)
|
||||
{
|
||||
$perPage = $perPage ?? \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$dateFrom = $filters['date_from'] ?? null;
|
||||
$dateTo = $filters['date_to'] ?? null;
|
||||
$warehouseId = $filters['warehouse_id'] ?? null;
|
||||
|
||||
@@ -258,10 +258,12 @@ class InventoryService implements InventoryServiceInterface
|
||||
/**
|
||||
* 即時庫存查詢:統計卡片 + 分頁明細
|
||||
*/
|
||||
public function getStockQueryData(array $filters = [], int $perPage = 10): array
|
||||
public function getStockQueryData(array $filters = [], ?int $perPage = null): array
|
||||
{
|
||||
$perPage = $perPage ?? \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$today = now()->toDateString();
|
||||
$expiryThreshold = now()->addDays(30)->toDateString();
|
||||
$expiryDays = \App\Modules\Core\Models\SystemSetting::getVal('inventory.expiry_warning_days', 30);
|
||||
$expiryThreshold = now()->addDays($expiryDays)->toDateString();
|
||||
|
||||
// 基礎查詢
|
||||
$query = Inventory::query()
|
||||
@@ -492,7 +494,8 @@ class InventoryService implements InventoryServiceInterface
|
||||
public function getDashboardStats(): array
|
||||
{
|
||||
$today = now()->toDateString();
|
||||
$expiryThreshold = now()->addDays(30)->toDateString();
|
||||
$expiryDays = \App\Modules\Core\Models\SystemSetting::getVal('inventory.expiry_warning_days', 30);
|
||||
$expiryThreshold = now()->addDays($expiryDays)->toDateString();
|
||||
|
||||
// 1. 庫存品項數 (明細總數)
|
||||
$totalItems = DB::table('inventories')
|
||||
|
||||
@@ -12,8 +12,9 @@ class TurnoverService
|
||||
/**
|
||||
* Get inventory turnover analysis data
|
||||
*/
|
||||
public function getAnalysisData(array $filters, int $perPage = 20)
|
||||
public function getAnalysisData(array $filters, ?int $perPage = null)
|
||||
{
|
||||
$perPage = $perPage ?? \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$warehouseId = $filters['warehouse_id'] ?? null;
|
||||
$categoryId = $filters['category_id'] ?? null;
|
||||
$search = $filters['search'] ?? null;
|
||||
@@ -60,7 +61,8 @@ class TurnoverService
|
||||
// Given potentially large data, subquery per row might be slow, but for pagination it's okay-ish.
|
||||
// Better approach: Join with a subquery of aggregated transactions.
|
||||
|
||||
$thirtyDaysAgo = Carbon::now()->subDays(30);
|
||||
$analysisDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.analysis_period_days', 30);
|
||||
$thirtyDaysAgo = Carbon::now()->subDays($analysisDays);
|
||||
|
||||
// Subquery for 30-day sales
|
||||
$salesSubquery = InventoryTransaction::query()
|
||||
@@ -111,7 +113,7 @@ class TurnoverService
|
||||
// Turnover Days Calculation in SQL: (stock / (sales_30d / 30)) => (stock * 30) / sales_30d
|
||||
// Handle division by zero: if sales_30d is 0, turnover is 'Inf' (or very high number like 9999)
|
||||
$turnoverDaysSql = "CASE WHEN COALESCE(sales_30d.sales_qty_30d, 0) > 0
|
||||
THEN (COALESCE(SUM(inventories.quantity), 0) * 30) / sales_30d.sales_qty_30d
|
||||
THEN (COALESCE(SUM(inventories.quantity), 0) * $analysisDays) / sales_30d.sales_qty_30d
|
||||
ELSE 9999 END";
|
||||
|
||||
$query->addSelect(DB::raw("$turnoverDaysSql as turnover_days"));
|
||||
@@ -125,7 +127,8 @@ class TurnoverService
|
||||
// For dead stock, definitive IS stock > 0.
|
||||
|
||||
if ($statusFilter === 'dead') {
|
||||
$ninetyDaysAgo = Carbon::now()->subDays(90);
|
||||
$deadStockDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.dead_stock_days', 90);
|
||||
$ninetyDaysAgo = Carbon::now()->subDays($deadStockDays);
|
||||
$query->havingRaw("current_stock > 0 AND (last_sale_date < ? OR last_sale_date IS NULL)", [$ninetyDaysAgo]);
|
||||
}
|
||||
|
||||
@@ -146,10 +149,13 @@ class TurnoverService
|
||||
$lastSale = $item->last_sale_date ? Carbon::parse($item->last_sale_date) : null;
|
||||
$daysSinceSale = $lastSale ? $lastSale->diffInDays(Carbon::now()) : 9999;
|
||||
|
||||
if ($item->current_stock > 0 && $daysSinceSale > 90) {
|
||||
$deadStockDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.dead_stock_days', 90);
|
||||
$slowMovingDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.slow_moving_days', 60);
|
||||
|
||||
if ($item->current_stock > 0 && $daysSinceSale > $deadStockDays) {
|
||||
$item->status = 'dead'; // 滯銷
|
||||
$item->status_label = '滯銷';
|
||||
} elseif ($item->current_stock > 0 && $item->turnover_days > 60) {
|
||||
} elseif ($item->current_stock > 0 && $item->turnover_days > $slowMovingDays) {
|
||||
$item->status = 'slow'; // 週轉慢
|
||||
$item->status_label = '週轉慢';
|
||||
} elseif ($item->current_stock == 0) {
|
||||
@@ -187,8 +193,8 @@ class TurnoverService
|
||||
// 2. Dead Stock Value (No sale in 90 days)
|
||||
// Need last sale date for each product-location or just product?
|
||||
// Assuming dead stock is product-level logic for simplicity.
|
||||
|
||||
$ninetyDaysAgo = Carbon::now()->subDays(90);
|
||||
$deadStockDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.dead_stock_days', 90);
|
||||
$ninetyDaysAgo = Carbon::now()->subDays($deadStockDays);
|
||||
|
||||
// Get IDs of products sold in last 90 days
|
||||
$soldProductIds = InventoryTransaction::query()
|
||||
@@ -225,17 +231,17 @@ class TurnoverService
|
||||
// Simplified: (Total Stock / Total Sales 30d) * 30
|
||||
|
||||
$totalStock = (clone $buildInvQuery())->sum('inventories.quantity');
|
||||
|
||||
$totalSales30d = DB::table('inventory_transactions')
|
||||
->join('inventories', 'inventory_transactions.inventory_id', '=', 'inventories.id')
|
||||
->join('products', 'inventories.product_id', '=', 'products.id')
|
||||
->where('inventory_transactions.type', '出庫')
|
||||
->where('inventory_transactions.actual_time', '>=', Carbon::now()->subDays(30))
|
||||
->when($warehouseId, fn($q) => $q->where('inventories.warehouse_id', $warehouseId))
|
||||
->when($categoryId, fn($q) => $q->where('products.category_id', $categoryId))
|
||||
->sum(DB::raw('ABS(inventory_transactions.quantity)'));
|
||||
|
||||
$avgTurnoverDays = $totalSales30d > 0 ? ($totalStock * 30) / $totalSales30d : 0;
|
||||
$analysisDays = \App\Modules\Core\Models\SystemSetting::getVal('turnover.analysis_period_days', 30);
|
||||
$totalSales30d = DB::table('inventory_transactions')
|
||||
->join('inventories', 'inventory_transactions.inventory_id', '=', 'inventories.id')
|
||||
->join('products', 'inventories.product_id', '=', 'products.id')
|
||||
->where('inventory_transactions.type', '出庫')
|
||||
->where('inventory_transactions.actual_time', '>=', Carbon::now()->subDays($analysisDays))
|
||||
->when($warehouseId, fn($q) => $q->where('inventories.warehouse_id', $warehouseId))
|
||||
->when($categoryId, fn($q) => $q->where('products.category_id', $categoryId))
|
||||
->sum(DB::raw('ABS(inventory_transactions.quantity)'));
|
||||
|
||||
$avgTurnoverDays = $totalSales30d > 0 ? ($totalStock * $analysisDays) / $totalSales30d : 0;
|
||||
|
||||
return [
|
||||
'total_stock_value' => $totalValue,
|
||||
|
||||
@@ -66,7 +66,11 @@ class PurchaseOrderController extends Controller
|
||||
$query->orderBy($sortField, $sortDirection);
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$orders = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
// 2. 手動注入倉庫與使用者資料
|
||||
|
||||
@@ -35,11 +35,12 @@ class PurchaseReturnController extends Controller
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
|
||||
$purchaseReturns = $query->paginate(15)->withQueryString();
|
||||
$perPage = $request->input('per_page', 15);
|
||||
$purchaseReturns = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
return Inertia::render('PurchaseReturn/Index', [
|
||||
'purchaseReturns' => $purchaseReturns,
|
||||
'filters' => $request->only(['search', 'status']),
|
||||
'filters' => $request->only(['search', 'status', 'per_page']),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,11 @@ class ShippingOrderController extends Controller
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$orders = $query->orderBy('id', 'desc')->paginate($perPage)->withQueryString();
|
||||
|
||||
// 水和倉庫與使用者
|
||||
|
||||
@@ -44,7 +44,11 @@ class VendorController extends Controller
|
||||
$sortDirection = 'desc';
|
||||
}
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$vendors = $query->orderBy($sortField, $sortDirection)
|
||||
->paginate($perPage)
|
||||
|
||||
@@ -62,7 +62,11 @@ class ProductionOrderController extends Controller
|
||||
$query->orderBy($request->input('sort_field', 'created_at'), $request->input('sort_direction', 'desc'));
|
||||
|
||||
// 分頁
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$productionOrders = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
// --- 手動資料水和 (Manual Hydration) ---
|
||||
|
||||
@@ -40,7 +40,13 @@ class RecipeController extends Controller
|
||||
|
||||
$query->orderBy($request->input('sort_field', 'created_at'), $request->input('sort_direction', 'desc'));
|
||||
|
||||
$recipes = $query->paginate($request->input('per_page', 10))->withQueryString();
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = (int) $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array($perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
|
||||
$recipes = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
// Manual Hydration
|
||||
$productIds = $recipes->pluck('product_id')->unique()->filter()->toArray();
|
||||
|
||||
@@ -15,7 +15,11 @@ class SalesImportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$search = $request->input('search');
|
||||
|
||||
$batches = SalesImportBatch::with('importer')
|
||||
@@ -65,7 +69,11 @@ class SalesImportController extends Controller
|
||||
{
|
||||
$import->load(['items', 'importer']);
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$defaultPerPage = \App\Modules\Core\Models\SystemSetting::getVal('display.per_page', 10);
|
||||
$perPage = $request->input('per_page', $defaultPerPage);
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$paginatedItems = $import->items()->paginate($perPage)->withQueryString();
|
||||
|
||||
// Manual Hydration for Products and Warehouses
|
||||
|
||||
Reference in New Issue
Block a user