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()
|
||||
|
||||
Reference in New Issue
Block a user