feat: add discount management and PDF export for transmittals
- Create Discount model, migration, and Filament resource with relation to Client - Add PDF export functionality for transmittals using DomPDF - Include discount type selection in sales transactions - Fix account filtering logic in expense resource - Update export job to generate PDF instead of Excel
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Filament\Resources\SaleResource\Pages;
|
||||
use App\Models\Account;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Client;
|
||||
use App\Models\Discount;
|
||||
use App\Models\Sale;
|
||||
use Awcodes\TableRepeater\Components\TableRepeater;
|
||||
use Awcodes\TableRepeater\Header;
|
||||
@@ -30,17 +31,17 @@ class SaleResource extends Resource
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Select::make('client')
|
||||
->default(request()->query('client_id'))
|
||||
->default(fn () => request()->integer('client_id'))
|
||||
->options(Client::query()->get()->pluck('company', 'id'))
|
||||
->afterStateUpdated(function ($set, $get) {
|
||||
$set('branch_id', '');
|
||||
})
|
||||
->disabled()
|
||||
->required()
|
||||
->live(),
|
||||
Select::make('branch_id')
|
||||
@@ -72,6 +73,8 @@ class SaleResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getSeries(Get $get): string
|
||||
{
|
||||
$branch = Branch::find($get('branch_id'));
|
||||
@@ -98,6 +101,7 @@ class SaleResource extends Resource
|
||||
Header::make('Output Tax'),
|
||||
Header::make('Withholding Tax'),
|
||||
Header::make('Discount'),
|
||||
Header::make('Discount Type'),
|
||||
Header::make('Net Amount'),
|
||||
];
|
||||
}
|
||||
@@ -136,7 +140,7 @@ class SaleResource extends Resource
|
||||
->numeric()
|
||||
->nullable()
|
||||
->live()
|
||||
->readOnly()
|
||||
->readOnly(fn (Get $get) => $get('exempt') == 0)
|
||||
->default(0),
|
||||
Hidden::make('happened_on')->default(fn (Get $get) => $get('../../happened_on')),
|
||||
Hidden::make('with_discount')->default(fn (Get $get) => $get('../../with_discount')),
|
||||
@@ -159,6 +163,9 @@ class SaleResource extends Resource
|
||||
->readOnly()
|
||||
->visible(fn (Get $get) => $get('../../with_discount'))
|
||||
->live(),
|
||||
Select::make('discount_type')
|
||||
->options(fn (Get $get) => static::getDiscountOptions($get))
|
||||
->visible(fn (Get $get) => $get('../../with_discount')),
|
||||
TextInput::make('net_amount')->numeric()->default(0),
|
||||
];
|
||||
}
|
||||
@@ -184,6 +191,13 @@ class SaleResource extends Resource
|
||||
return $query->get()->pluck('account', 'id');
|
||||
}
|
||||
|
||||
private static function getDiscountOptions(Get $get)
|
||||
{
|
||||
$query = Discount::query()->where('client_id', $get('../../client'));
|
||||
|
||||
return $query->pluck('discount', 'id');
|
||||
}
|
||||
|
||||
private static function setDefaultFormValues(Get $get, Set $set, ?string $old, ?string $state)
|
||||
{
|
||||
$exempt = (float) $get('exempt');
|
||||
|
||||
Reference in New Issue
Block a user