feat(production): 優化生產單 BOM 原物料選取邏輯,支援商品 -> 倉庫 -> 批號連動與 API 分佈查詢

This commit is contained in:
2026-02-04 13:08:05 +08:00
parent a0c450d229
commit 4ba85ce446
17 changed files with 285 additions and 227 deletions

View File

@@ -187,20 +187,20 @@ class PurchaseOrderController extends Controller
try {
DB::beginTransaction();
// 生成單號POYYYYMMDD001
// 生成單號PO-YYYYMMDD-01
$today = now()->format('Ymd');
$prefix = 'PO' . $today;
$prefix = 'PO-' . $today . '-';
$lastOrder = PurchaseOrder::where('code', 'like', $prefix . '%')
->lockForUpdate() // 鎖定以避免並發衝突
->orderBy('code', 'desc')
->first();
if ($lastOrder) {
// 取得最後 3 碼序號並加 1
$lastSequence = intval(substr($lastOrder->code, -3));
$sequence = str_pad($lastSequence + 1, 3, '0', STR_PAD_LEFT);
// 取得最後 2 碼序號並加 1
$lastSequence = intval(substr($lastOrder->code, -2));
$sequence = str_pad($lastSequence + 1, 2, '0', STR_PAD_LEFT);
} else {
$sequence = '001';
$sequence = '01';
}
$code = $prefix . $sequence;