生產工單BOM以及批號完善
This commit is contained in:
@@ -9,13 +9,13 @@ class Inventory extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\InventoryFactory> */
|
||||
use HasFactory;
|
||||
use \Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use \Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
protected $fillable = [
|
||||
'warehouse_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
'safety_stock',
|
||||
'location',
|
||||
// 批號追溯欄位
|
||||
'batch_number',
|
||||
@@ -121,7 +121,9 @@ class Inventory extends Model
|
||||
$dateFormatted = date('Ymd', strtotime($arrivalDate));
|
||||
$prefix = "{$productCode}-{$originCountry}-{$dateFormatted}-";
|
||||
|
||||
$lastBatch = static::where('batch_number', 'like', "{$prefix}%")
|
||||
// 加入 withTrashed() 確保流水號不會撞到已刪除的紀錄
|
||||
$lastBatch = static::withTrashed()
|
||||
->where('batch_number', 'like', "{$prefix}%")
|
||||
->orderByDesc('batch_number')
|
||||
->first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user