Đóng gói cuối tuần
This commit is contained in:
31
app/Models/Appendix.php
Normal file
31
app/Models/Appendix.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Appendix extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $table = 'appendices'; // Đảm bảo khớp với migration
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'custom_data' => 'array',
|
||||
'signing_date' => 'date',
|
||||
];
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(Contract::class);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
30
app/Models/Payment.php
Normal file
30
app/Models/Payment.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'decimal:2',
|
||||
'paid_date' => 'date',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(Contract::class);
|
||||
}
|
||||
|
||||
public function scheduleItem()
|
||||
{
|
||||
return $this->belongsTo(PaymentScheduleItem::class, 'schedule_item_id');
|
||||
}
|
||||
}
|
||||
25
app/Models/PaymentFine.php
Normal file
25
app/Models/PaymentFine.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentFine extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'decimal:2',
|
||||
'due_date' => 'date',
|
||||
'paid_date' => 'date',
|
||||
];
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(Contract::class);
|
||||
}
|
||||
}
|
||||
29
app/Models/PaymentSchedule.php
Normal file
29
app/Models/PaymentSchedule.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentSchedule extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(Contract::class);
|
||||
}
|
||||
|
||||
public function template()
|
||||
{
|
||||
return $this->belongsTo(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PaymentScheduleItem::class, 'schedule_id');
|
||||
}
|
||||
}
|
||||
37
app/Models/PaymentScheduleItem.php
Normal file
37
app/Models/PaymentScheduleItem.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\PaymentType;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentScheduleItem extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'type' => PaymentType::class,
|
||||
'amount' => 'decimal:2',
|
||||
'percentage' => 'decimal:2',
|
||||
'due_date' => 'date',
|
||||
];
|
||||
|
||||
public function template()
|
||||
{
|
||||
return $this->belongsTo(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function schedule()
|
||||
{
|
||||
return $this->belongsTo(PaymentSchedule::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class, 'schedule_item_id');
|
||||
}
|
||||
}
|
||||
28
app/Models/PaymentTemplate.php
Normal file
28
app/Models/PaymentTemplate.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentTemplate extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'is_default' => 'boolean',
|
||||
];
|
||||
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PaymentScheduleItem::class, 'template_id');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ProductType;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -12,20 +13,33 @@ class Product extends Model
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
// Ép kiểu JSON để Filament có thể đọc/ghi dữ liệu linh hoạt (tầng, hướng, mặt tiền...)
|
||||
protected $casts = [
|
||||
'product_type' => ProductType::class,
|
||||
'custom_data' => 'array',
|
||||
'infrastructure_status' => 'array',
|
||||
'area' => 'decimal:2',
|
||||
'price_per_unit' => 'decimal:2',
|
||||
'total_price' => 'decimal:2',
|
||||
'building_density' => 'decimal:2',
|
||||
];
|
||||
|
||||
// Khai báo mối quan hệ V3: 1 Sản phẩm thuộc về 1 Dự án
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
// Đón đầu cho các bước tiếp theo: 1 Sản phẩm có nhiều Hợp đồng
|
||||
public function contracts()
|
||||
{
|
||||
return $this->hasMany(Contract::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function settlements()
|
||||
{
|
||||
return $this->hasMany(Settlement::class);
|
||||
}
|
||||
|
||||
public function appendices()
|
||||
{
|
||||
return $this->hasMany(Appendix::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,15 @@ class Project extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = []; // Cho phép lưu tất cả các cột
|
||||
protected $guarded = [];
|
||||
|
||||
// Khai báo mối quan hệ: 1 Dự án có nhiều Sản phẩm
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function paymentTemplates()
|
||||
{
|
||||
return $this->hasMany(PaymentTemplate::class);
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Models/Settlement.php
Normal file
26
app/Models/Settlement.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Settlement extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'temp_value' => 'decimal:2',
|
||||
'final_value' => 'decimal:2',
|
||||
'difference' => 'decimal:2',
|
||||
'issue_date' => 'date',
|
||||
];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user