Hoan thien core finance v2 - Calculation Pipeline, Form Templates
This commit is contained in:
@@ -138,22 +138,33 @@ class ContractForm
|
||||
->label('Bảng chi tiết chiết khấu (Dạng Key-Value)')
|
||||
->columnSpanFull(),
|
||||
|
||||
Placeholder::make('final_value_display')
|
||||
->label('Giá trị sau chiết khấu')
|
||||
Placeholder::make('price_sheet')
|
||||
->label('Phiếu tính giá')
|
||||
->columnSpanFull()
|
||||
->content(function ($record, $get) {
|
||||
$totalValue = $record ? (float) $record->total_value : (float) ($get('total_value') ?? 0);
|
||||
$discountDetails = $record ? $record->discount_details : ($get('discount_details') ?? []);
|
||||
|
||||
if ($totalValue <= 0) {
|
||||
return new HtmlString("<div style='font-size: 0.9rem; color: #9ca3af;'>Chưa có giá trị hợp đồng để tính chiết khấu.</div>");
|
||||
->content(function ($record) {
|
||||
if (! $record || ! $record->calculation_log) {
|
||||
return new HtmlString("<div style='font-size: 0.9rem; color: #9ca3af;'>Chưa có dữ liệu tính toán. Vui lòng lưu hợp đồng để tạo phiếu tính giá.</div>");
|
||||
}
|
||||
|
||||
$result = \App\Services\DiscountEngine::calculate($totalValue, $discountDetails);
|
||||
$final = number_format($result['final_value']);
|
||||
$discount = number_format($result['discount_amount']);
|
||||
$steps = $record->calculation_log['price_sheet'] ?? [];
|
||||
if (empty($steps)) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return new HtmlString("<div style='font-size: 1.1rem; font-weight: bold; color: #16a34a;'>{$final} VNĐ</div><div style='font-size: 0.8rem; color: #9ca3af;'>Đã chiết khấu: {$discount} VNĐ</div>");
|
||||
$html = '<div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px;">';
|
||||
$html .= '<table style="width: 100%; border-collapse: collapse; font-size: 0.9rem;">';
|
||||
$html .= '<thead><tr style="border-bottom: 2px solid #e5e7eb;"><th style="text-align: left; padding: 8px;">Diễn giải</th><th style="text-align: right; padding: 8px;">Giá trị (VNĐ)</th></tr></thead><tbody>';
|
||||
|
||||
foreach ($steps as $step) {
|
||||
$desc = $step['description'];
|
||||
$value = number_format($step['value']);
|
||||
$isOverride = $step['is_overridden'] ? ' <span style="color: #f59e0b; font-size: 0.75rem;">(ghi đè)</span>' : '';
|
||||
$style = str_contains(strtolower($desc), 'tổng') ? 'font-weight: bold; border-top: 1px solid #e5e7eb;' : '';
|
||||
$html .= "<tr style='{$style}'><td style='padding: 8px;'>{$desc}{$isOverride}</td><td style='text-align: right; padding: 8px;'>{$value}</td></tr>";
|
||||
}
|
||||
|
||||
$html .= '</tbody></table></div>';
|
||||
return new HtmlString($html);
|
||||
}),
|
||||
]),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user