feat(inventory): 實作過期與瑕疵庫存總計顯示,並強化庫存明細過期提示
This commit is contained in:
@@ -55,6 +55,19 @@ class WarehouseController extends Controller
|
||||
->orWhere('expiry_date', '>=', now());
|
||||
});
|
||||
}], 'total_value')
|
||||
->withSum(['inventories as abnormal_amount' => function ($query) {
|
||||
$query->where('quantity', '>', 0)
|
||||
->where(function ($q) {
|
||||
$q->where('quality_status', '!=', 'normal')
|
||||
->orWhere(function ($sq) {
|
||||
$sq->whereNotNull('expiry_date')
|
||||
->where('expiry_date', '<', now());
|
||||
})
|
||||
->orWhereHas('warehouse', function ($wq) {
|
||||
$wq->where('type', \App\Enums\WarehouseType::QUARANTINE);
|
||||
});
|
||||
});
|
||||
}], 'total_value')
|
||||
->addSelect(['low_stock_count' => function ($query) {
|
||||
$query->selectRaw('count(*)')
|
||||
->from('warehouse_product_safety_stocks as ss')
|
||||
@@ -85,6 +98,17 @@ class WarehouseController extends Controller
|
||||
$q->whereNull('expiry_date')
|
||||
->orWhere('expiry_date', '>=', now());
|
||||
})->sum('total_value'),
|
||||
'abnormal_amount' => \App\Modules\Inventory\Models\Inventory::where('quantity', '>', 0)
|
||||
->where(function ($q) {
|
||||
$q->where('quality_status', '!=', 'normal')
|
||||
->orWhere(function ($sq) {
|
||||
$sq->whereNotNull('expiry_date')
|
||||
->where('expiry_date', '<', now());
|
||||
})
|
||||
->orWhereHas('warehouse', function ($wq) {
|
||||
$wq->where('type', \App\Enums\WarehouseType::QUARANTINE);
|
||||
});
|
||||
})->sum('total_value'),
|
||||
'book_stock' => \App\Modules\Inventory\Models\Inventory::sum('quantity'),
|
||||
'book_amount' => \App\Modules\Inventory\Models\Inventory::sum('total_value'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user