78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class PurchaseOrder extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'purchase_orders';
|
|
|
|
protected $fillable = [
|
|
'po_no',
|
|
'warehouse_id',
|
|
'supplier_id',
|
|
'brand_id',
|
|
'expected_arrival',
|
|
'shipping_method',
|
|
'freight',
|
|
'category',
|
|
'total_amount',
|
|
'status',
|
|
'remark',
|
|
'audit_comment',
|
|
'pushed',
|
|
'cloud_system',
|
|
'pushed_to_cloud',
|
|
'pushed_at',
|
|
'cloud_response',
|
|
];
|
|
|
|
protected $casts = [
|
|
'expected_arrival' => 'date',
|
|
'freight' => 'decimal:2',
|
|
'total_amount' => 'decimal:2',
|
|
'pushed' => 'boolean',
|
|
'pushed_to_cloud' => 'boolean',
|
|
'pushed_at' => 'datetime',
|
|
];
|
|
|
|
public function warehouse()
|
|
{
|
|
return $this->belongsTo(Warehouse::class);
|
|
}
|
|
|
|
public function supplier()
|
|
{
|
|
return $this->belongsTo(Supplier::class);
|
|
}
|
|
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(Brand::class);
|
|
}
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany(PurchaseOrderItem::class);
|
|
}
|
|
|
|
public function receivingOrders()
|
|
{
|
|
return $this->hasMany(ReceivingOrder::class, 'po_id');
|
|
}
|
|
|
|
public function getStatusLabelAttribute()
|
|
{
|
|
$labels = [
|
|
'draft' => '草稿',
|
|
'under_review' => '待审核',
|
|
'approved' => '已审核',
|
|
'rejected' => '已驳回',
|
|
'completed' => '已完成',
|
|
];
|
|
return $labels[$this->status] ?? $this->status;
|
|
}
|
|
} |