'date', 'invoice_date' => 'date', 'total_amount' => 'decimal:2', 'tax_amount' => 'decimal:2', 'grand_total' => 'decimal:2', 'invoice_amount' => 'decimal:2', ]; protected $appends = [ 'poNumber', 'supplierId', 'supplierName', 'expectedDate', 'totalAmount', 'createdBy', 'warehouse_name', 'createdAt', 'invoiceNumber', 'invoiceDate', 'invoiceAmount', ]; public function getCreatedAtAttribute() { return $this->attributes['created_at']; } public function getPoNumberAttribute(): string { return $this->code; } public function getSupplierIdAttribute(): string { return (string) $this->vendor_id; } public function getSupplierNameAttribute(): string { return $this->vendor ? $this->vendor->name : ''; } public function getExpectedDateAttribute(): ?string { return $this->expected_delivery_date ? $this->expected_delivery_date->format('Y-m-d') : null; } public function getTotalAmountAttribute(): float { return (float) ($this->attributes['total_amount'] ?? 0); } public function getCreatedByAttribute(): string { return $this->user ? $this->user->name : '系統'; } public function getWarehouseNameAttribute(): string { return $this->warehouse ? $this->warehouse->name : ''; } public function getInvoiceNumberAttribute(): ?string { return $this->attributes['invoice_number'] ?? null; } public function getInvoiceDateAttribute(): ?string { $date = $this->attributes['invoice_date'] ?? null; return $date ? \Illuminate\Support\Carbon::parse($date)->format('Y-m-d') : null; } public function getInvoiceAmountAttribute(): ?float { return isset($this->attributes['invoice_amount']) ? (float) $this->attributes['invoice_amount'] : null; } public function vendor(): BelongsTo { return $this->belongsTo(Vendor::class); } public function warehouse(): BelongsTo { return $this->belongsTo(Warehouse::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function items(): HasMany { return $this->hasMany(PurchaseOrderItem::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logAll() ->logOnlyDirty() ->dontSubmitEmptyLogs(); } }