chinh sua theo tieu chuan phan mem BDS_1
This commit is contained in:
@@ -41,6 +41,11 @@ class Contract extends Model
|
||||
return $this->belongsTo(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function salesPhase()
|
||||
{
|
||||
return $this->belongsTo(SalesPhase::class);
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->belongsToMany(Customer::class, 'contract_customers')
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ class Project extends Model
|
||||
{
|
||||
return $this->hasMany(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function salesPhases()
|
||||
{
|
||||
return $this->hasMany(SalesPhase::class)->orderBy('start_date', 'desc');
|
||||
}
|
||||
}
|
||||
|
||||
43
app/Models/SalesPhase.php
Normal file
43
app/Models/SalesPhase.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SalesPhase extends Model
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'discount_policy' => 'array',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
];
|
||||
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function paymentTemplate()
|
||||
{
|
||||
return $this->belongsTo(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function phaseProducts()
|
||||
{
|
||||
return $this->hasMany(SalesPhaseProduct::class);
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'sales_phase_products')
|
||||
->using(SalesPhaseProduct::class)
|
||||
->withPivot('id', 'sale_price', 'land_value', 'foundation_value', 'discount_details', 'status')
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
33
app/Models/SalesPhaseProduct.php
Normal file
33
app/Models/SalesPhaseProduct.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class SalesPhaseProduct extends Pivot
|
||||
{
|
||||
use HasUuids, HasFactory;
|
||||
|
||||
protected $table = 'sales_phase_products';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'sale_price' => 'decimal:2',
|
||||
'land_value' => 'decimal:2',
|
||||
'foundation_value' => 'decimal:2',
|
||||
'discount_details' => 'array',
|
||||
];
|
||||
|
||||
public function salesPhase()
|
||||
{
|
||||
return $this->belongsTo(SalesPhase::class);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user