Đóng gói cuối tuần

This commit is contained in:
2026-04-18 04:46:01 +00:00
parent 761b34916b
commit 3cef1c40df
37 changed files with 1266 additions and 301 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
class Contract extends Model
{
@@ -12,15 +13,59 @@ class Contract extends Model
protected $guarded = [];
// 1 Hợp đồng thuộc về 1 Sản phẩm
protected $casts = [
'metadata' => 'array',
'total_value' => 'decimal:2',
'paid_amount' => 'decimal:2',
'remaining_amount' => 'decimal:2',
'excess_amount' => 'decimal:2',
'signing_date' => 'date',
];
public function product()
{
return $this->belongsTo(Product::class);
}
// 1 Hợp đồng có thể có nhiều Khách hàng (Đồng sở hữu)
public function customers()
{
return $this->belongsToMany(Customer::class, 'contract_customers')->withPivot('role', 'transfer_order')->withTimestamps();
return $this->belongsToMany(Customer::class, 'contract_customers')
->withPivot('role', 'transfer_order')
->withTimestamps();
}
}
public function appendices()
{
return $this->hasMany(Appendix::class);
}
public function paymentSchedule()
{
return $this->hasOne(PaymentSchedule::class);
}
/**
* Lấy trực tiếp các đợt thanh toán của hợp đồng này
*/
public function scheduleItems(): HasManyThrough
{
return $this->hasManyThrough(
PaymentScheduleItem::class,
PaymentSchedule::class,
'contract_id', // Khóa ngoại trên bảng PaymentSchedule
'schedule_id', // Khóa ngoại trên bảng PaymentScheduleItem
'id', // Khóa chính trên bảng Contract
'id' // Khóa chính trên bảng PaymentSchedule
);
}
public function payments()
{
return $this->hasMany(Payment::class);
}
public function paymentFines()
{
return $this->hasMany(PaymentFine::class);
}
}