chinh sua theo tieu chuan phan mem BDS_1
This commit is contained in:
@@ -14,11 +14,16 @@ class CreateContract extends CreateRecord
|
||||
{
|
||||
$contract = $this->record;
|
||||
|
||||
$template = null;
|
||||
|
||||
if ($contract->payment_template_id) {
|
||||
$template = $contract->paymentTemplate;
|
||||
if ($template) {
|
||||
ContractScheduleService::generateFromTemplate($contract, $template);
|
||||
}
|
||||
} elseif ($contract->sales_phase_id && $contract->salesPhase?->payment_template_id) {
|
||||
$template = $contract->salesPhase->paymentTemplate;
|
||||
}
|
||||
|
||||
if ($template) {
|
||||
ContractScheduleService::generateFromTemplate($contract, $template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\Contracts\Schemas;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\PaymentTemplate;
|
||||
use App\Models\SalesPhase;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
@@ -12,6 +13,7 @@ use Filament\Schemas\Components\Grid;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
@@ -41,9 +43,47 @@ class ContractForm
|
||||
$set('total_value', $product->total_price);
|
||||
$set('land_value', $product->qsdd_value);
|
||||
$set('foundation_value', $product->foundation_temp_value);
|
||||
$set('sales_phase_id', null);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
Select::make('sales_phase_id')
|
||||
->label('Đợt mở bán')
|
||||
->options(function (Get $get) {
|
||||
$productId = $get('product_id');
|
||||
if (! $productId) return [];
|
||||
$product = Product::find($productId);
|
||||
if (! $product) return [];
|
||||
return SalesPhase::where('project_id', $product->project_id)
|
||||
->whereIn('status', ['Chuẩn bị', 'Đang mở bán'])
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
->searchable()
|
||||
->preload()
|
||||
->live()
|
||||
->helperText('Chọn đợt mở bán để áp dụng giá và chính sách của đợt')
|
||||
->afterStateUpdated(function (Set $set, Get $get, $state) {
|
||||
$productId = $get('product_id');
|
||||
if ($state && $productId) {
|
||||
$phaseProduct = \App\Models\SalesPhaseProduct::where('sales_phase_id', $state)
|
||||
->where('product_id', $productId)
|
||||
->first();
|
||||
if ($phaseProduct) {
|
||||
$set('land_value', $phaseProduct->land_value ?? $get('land_value'));
|
||||
$set('foundation_value', $phaseProduct->foundation_value ?? $get('foundation_value'));
|
||||
$total = (float) ($phaseProduct->land_value ?? $get('land_value')) + (float) ($phaseProduct->foundation_value ?? $get('foundation_value'));
|
||||
if ($phaseProduct->sale_price > 0) {
|
||||
$total = (float) $phaseProduct->sale_price;
|
||||
}
|
||||
$set('total_value', $total);
|
||||
if ($phaseProduct->discount_details) {
|
||||
$set('discount_details', $phaseProduct->discount_details);
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
TextInput::make('contract_number')
|
||||
->label('Số HĐMB')
|
||||
->required()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases\Pages;
|
||||
|
||||
use App\Filament\Resources\SalesPhases\SalesPhaseResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSalesPhase extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SalesPhaseResource::class;
|
||||
}
|
||||
11
app/Filament/Resources/SalesPhases/Pages/EditSalesPhase.php
Normal file
11
app/Filament/Resources/SalesPhases/Pages/EditSalesPhase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases\Pages;
|
||||
|
||||
use App\Filament\Resources\SalesPhases\SalesPhaseResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSalesPhase extends EditRecord
|
||||
{
|
||||
protected static string $resource = SalesPhaseResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/SalesPhases/Pages/ListSalesPhases.php
Normal file
19
app/Filament/Resources/SalesPhases/Pages/ListSalesPhases.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases\Pages;
|
||||
|
||||
use App\Filament\Resources\SalesPhases\SalesPhaseResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSalesPhases extends ListRecords
|
||||
{
|
||||
protected static string $resource = SalesPhaseResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Filament/Resources/SalesPhases/SalesPhaseResource.php
Normal file
42
app/Filament/Resources/SalesPhases/SalesPhaseResource.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases;
|
||||
|
||||
use App\Filament\Resources\SalesPhases\Pages;
|
||||
use App\Models\SalesPhase;
|
||||
use App\Enums\NavigationGroup;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SalesPhases\Schemas\SalesPhaseForm;
|
||||
use App\Filament\Resources\SalesPhases\Tables\SalesPhasesTable;
|
||||
|
||||
class SalesPhaseResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SalesPhase::class;
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-rocket-launch';
|
||||
protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::WAREHOUSE->value;
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $modelLabel = 'Đợt mở bán';
|
||||
protected static ?string $pluralModelLabel = 'Đợt mở bán';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return SalesPhaseForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SalesPhasesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSalesPhases::route('/'),
|
||||
'create' => Pages\CreateSalesPhase::route('/create'),
|
||||
'edit' => Pages\EditSalesPhase::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
163
app/Filament/Resources/SalesPhases/Schemas/SalesPhaseForm.php
Normal file
163
app/Filament/Resources/SalesPhases/Schemas/SalesPhaseForm.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases\Schemas;
|
||||
|
||||
use App\Models\PaymentTemplate;
|
||||
use App\Models\Product;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
|
||||
class SalesPhaseForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
// SECTION 1: Thông tin đợt mở bán
|
||||
Section::make('Thông tin đợt mở bán')
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
Select::make('project_id')
|
||||
->label('Dự án')
|
||||
->relationship('project', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->live(),
|
||||
|
||||
TextInput::make('name')
|
||||
->label('Tên đợt mở bán')
|
||||
->placeholder('Đợt 1 - Mở bán tháng 5/2026')
|
||||
->required(),
|
||||
|
||||
TextInput::make('code')
|
||||
->label('Mã đợt')
|
||||
->placeholder('MB1')
|
||||
->required()
|
||||
->unique(ignoreRecord: true),
|
||||
]),
|
||||
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
DatePicker::make('start_date')
|
||||
->label('Ngày bắt đầu')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
DatePicker::make('end_date')
|
||||
->label('Ngày kết thúc')
|
||||
->nullable(),
|
||||
|
||||
Select::make('status')
|
||||
->label('Trạng thái')
|
||||
->options([
|
||||
'Chuẩn bị' => 'Chuẩn bị',
|
||||
'Đang mở bán' => 'Đang mở bán',
|
||||
'Tạm dừng' => 'Tạm dừng',
|
||||
'Đã đóng' => 'Đã đóng',
|
||||
])
|
||||
->default('Chuẩn bị')
|
||||
->required(),
|
||||
]),
|
||||
|
||||
Textarea::make('description')
|
||||
->label('Mô tả')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
|
||||
// SECTION 2: Chính sách & Lịch thanh toán
|
||||
Section::make('Chính sách & Lịch thanh toán')
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
Select::make('payment_template_id')
|
||||
->label('Mẫu lịch thanh toán')
|
||||
->relationship('paymentTemplate', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->helperText('Áp dụng cho các hợp đồng trong đợt mở bán này')
|
||||
->columnSpan(1),
|
||||
|
||||
KeyValue::make('discount_policy')
|
||||
->label('Chính sách chiết khấu mặc định')
|
||||
->keyLabel('Loại chiết khấu')
|
||||
->valueLabel('Giá trị')
|
||||
->helperText('Ví dụ: open_sale => 5%, wholesale => 3%')
|
||||
->columnSpan(1),
|
||||
]),
|
||||
]),
|
||||
|
||||
// SECTION 3: Danh sách sản phẩm trong đợt
|
||||
Section::make('Sản phẩm trong đợt mở bán')
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
Repeater::make('phaseProducts')
|
||||
->relationship('phaseProducts')
|
||||
->schema([
|
||||
Grid::make(4)
|
||||
->schema([
|
||||
Select::make('product_id')
|
||||
->label('Sản phẩm')
|
||||
->options(function (callable $get, $state) {
|
||||
$projectId = $get('../../project_id');
|
||||
if (! $projectId) return [];
|
||||
return Product::where('project_id', $projectId)
|
||||
->pluck('code', 'id');
|
||||
})
|
||||
->searchable()
|
||||
->required(),
|
||||
|
||||
TextInput::make('sale_price')
|
||||
->label('Giá bán đợt này')
|
||||
->numeric()
|
||||
->prefix('VND')
|
||||
->placeholder('Để trống nếu lấy giá gốc'),
|
||||
|
||||
TextInput::make('land_value')
|
||||
->label('Giá trị QSDĐ')
|
||||
->numeric()
|
||||
->prefix('VND'),
|
||||
|
||||
TextInput::make('foundation_value')
|
||||
->label('Giá trị móng')
|
||||
->numeric()
|
||||
->prefix('VND'),
|
||||
|
||||
KeyValue::make('discount_details')
|
||||
->label('Chiết khấu riêng')
|
||||
->keyLabel('Loại')
|
||||
->valueLabel('Giá trị')
|
||||
->columnSpan(2),
|
||||
|
||||
Select::make('status')
|
||||
->label('Trạng thái')
|
||||
->options([
|
||||
'Còn hàng' => 'Còn hàng',
|
||||
'Đã giữ' => 'Đã giữ chỗ',
|
||||
'Đã bán' => 'Đã bán',
|
||||
'Khóa' => 'Khóa',
|
||||
])
|
||||
->default('Còn hàng')
|
||||
->columnSpan(2),
|
||||
]),
|
||||
])
|
||||
->addActionLabel('Thêm sản phẩm vào đợt')
|
||||
->reorderable()
|
||||
->defaultItems(0)
|
||||
->collapsible(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SalesPhases\Tables;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SalesPhasesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Tên đợt')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('code')
|
||||
->label('Mã đợt')
|
||||
->searchable()
|
||||
->copyable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('project.name')
|
||||
->label('Dự án')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('start_date')
|
||||
->label('Bắt đầu')
|
||||
->date('d/m/Y')
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('end_date')
|
||||
->label('Kết thúc')
|
||||
->date('d/m/Y')
|
||||
->placeholder('Không giới hạn'),
|
||||
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label('Trạng thái')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'Đang mở bán' => 'success',
|
||||
'Chuẩn bị' => 'warning',
|
||||
'Tạm dừng' => 'danger',
|
||||
'Đã đóng' => 'gray',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
Tables\Columns\TextColumn::make('products_count')
|
||||
->label('Số SP')
|
||||
->counts('products'),
|
||||
|
||||
Tables\Columns\TextColumn::make('paymentTemplate.name')
|
||||
->label('Mẫu TT')
|
||||
->placeholder('Chưa chọn'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('project_id')
|
||||
->label('Dự án')
|
||||
->relationship('project', 'name'),
|
||||
|
||||
Tables\Filters\SelectFilter::make('status')
|
||||
->label('Trạng thái')
|
||||
->options([
|
||||
'Chuẩn bị' => 'Chuẩn bị',
|
||||
'Đang mở bán' => 'Đang mở bán',
|
||||
'Tạm dừng' => 'Tạm dừng',
|
||||
'Đã đóng' => 'Đã đóng',
|
||||
]),
|
||||
])
|
||||
->defaultSort('start_date', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -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