feat: 修正庫存與撥補單邏輯並整合文件
1. 修復倉庫統計數據加總與樣式。 2. 修正可用庫存計算邏輯(排除不可銷售倉庫)。 3. 撥補單商品列表加入批號與效期顯示。 4. 修正撥補單儲存邏輯以支援精確批號轉移。 5. 整合 FEATURES.md 至 README.md。
This commit is contained in:
@@ -4,14 +4,12 @@ namespace App\Modules\Production\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Modules\Inventory\Models\Product;
|
||||
use App\Modules\Inventory\Models\Warehouse;
|
||||
use App\Modules\Core\Models\User;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
|
||||
class ProductionOrder extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ProductionOrderFactory> */
|
||||
use HasFactory;
|
||||
use HasFactory, LogsActivity;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
@@ -27,6 +25,38 @@ class ProductionOrder extends Model
|
||||
'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'production_date' => 'date',
|
||||
'expiry_date' => 'date',
|
||||
'output_quantity' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logOnly([
|
||||
'code',
|
||||
'status',
|
||||
'output_quantity',
|
||||
'output_batch_number',
|
||||
'production_date',
|
||||
'remark'
|
||||
])
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs()
|
||||
->setDescriptionForEvent(fn(string $eventName) => "生產工單已{$this->getEventDescription($eventName)}");
|
||||
}
|
||||
|
||||
protected function getEventDescription($eventName): string
|
||||
{
|
||||
return match ($eventName) {
|
||||
'created' => '建立',
|
||||
'updated' => '更新',
|
||||
'deleted' => '刪除',
|
||||
default => $eventName,
|
||||
};
|
||||
}
|
||||
|
||||
public static function generateCode()
|
||||
{
|
||||
$prefix = 'PO' . now()->format('Ymd');
|
||||
@@ -40,27 +70,28 @@ class ProductionOrder extends Model
|
||||
return $prefix . $sequence;
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
'order_date' => 'date',
|
||||
'start_date' => 'datetime',
|
||||
'completion_date' => 'datetime',
|
||||
'quantity' => 'decimal:2',
|
||||
'produced_quantity' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function product(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
/**
|
||||
* @deprecated 使用 InventoryServiceInterface 獲取產品資訊
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function warehouse(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
/**
|
||||
* @deprecated 使用 InventoryServiceInterface 獲取倉庫資訊
|
||||
*/
|
||||
public function warehouse()
|
||||
{
|
||||
return $this->belongsTo(Warehouse::class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
/**
|
||||
* @deprecated 使用 CoreServiceInterface 獲取使用者資訊
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function items(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
||||
Reference in New Issue
Block a user