chinh sua theo tieu chuan phan mem BDS_1

This commit is contained in:
2026-04-28 08:49:28 +00:00
parent e229da5e8c
commit 0712046f4b
18 changed files with 623 additions and 59 deletions

View File

@@ -42,4 +42,25 @@ class Product extends Model
{
return $this->hasMany(Appendix::class);
}
public function salesPhases()
{
return $this->belongsToMany(SalesPhase::class, 'sales_phase_products')
->using(SalesPhaseProduct::class)
->withPivot('id', 'sale_price', 'land_value', 'foundation_value', 'discount_details', 'status')
->withTimestamps();
}
public function activeSalesPhase()
{
return $this->salesPhases()
->wherePivot('status', 'Còn hàng')
->where('sales_phases.status', 'Đang mở bán')
->whereDate('sales_phases.start_date', '<=', now())
->where(function ($q) {
$q->whereNull('sales_phases.end_date')
->orWhereDate('sales_phases.end_date', '>=', now());
})
->first();
}
}