File tree Expand file tree Collapse file tree 4 files changed +46
-25
lines changed
Expand file tree Collapse file tree 4 files changed +46
-25
lines changed Original file line number Diff line number Diff line change 1414use Awcodes \TableRepeater \Header ;
1515use Filament \Facades \Filament ;
1616use Filament \Forms ;
17- use Filament \Forms \Components \TextInput ;
1817use Filament \Forms \Form ;
1918use Filament \Resources \Resource ;
2019use Filament \Tables ;
@@ -283,29 +282,7 @@ public static function table(Table $table): Table
283282 Tables \Actions \ViewAction::make (),
284283 Tables \Actions \ActionGroup::make ([
285284 Tables \Actions \Action::make ('Pay Amount ' )
286- ->form ([
287- Forms \Components \Group::make ([
288- TextInput::make ('paid_amount ' )
289- ->hint (function ($ record ) {
290- return 'You need to pay ' .$ record ->formatted_remaining_amount ;
291- })
292- ->minValue (1 )
293- ->maxValue (function ($ record ): float {
294- return $ record ->remaining_amount ;
295- })
296- ->numeric ()
297- ->required ()
298- ->hintAction (
299- Forms \Components \Actions \Action::make ('pay_in_full ' )
300- ->icon ('heroicon-m-arrow-down-tray ' )
301- ->action (function (Forms \Set $ set , $ state , $ record ) {
302- $ set ('paid_amount ' , $ record ->remaining_amount );
303- })
304- ),
305- TextInput::make ('reference_number ' ),
306- ])
307- ->columns (2 ),
308- ])
285+ ->form (Sale::getPayDueAmountForm ())
309286 ->color ('info ' )
310287 ->icon ('heroicon-m-banknotes ' )
311288 ->visible (fn ($ record ) => $ record ->remaining_amount > 0 )
Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ protected function getHeaderActions(): array
2828 'sale ' => $ record ,
2929 ]))
3030 ->openUrlInNewTab (),
31+ Action::make ('Pay Due Amount ' )
32+ ->form (Sale::getPayDueAmountForm ())
33+ ->color ('info ' )
34+ ->icon ('heroicon-m-banknotes ' )
35+ ->visible (fn ($ record ) => $ record ->remaining_amount > 0 )
36+ ->action (function ($ record , array $ data ) {
37+ $ record ->paid_amount += $ data ['paid_amount ' ];
38+ $ record ->reference_number = $ data ['reference_number ' ];
39+ $ record ->save ();
40+ }),
3141 ];
3242 }
3343
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ public static function getForm(): array
5555 ->prefix (config ('app.url ' ).'/ ' )
5656 ->required ()
5757 ->alphaDash ()
58- ->prohibitedIf ('slug ' , 'admin ' )
58+ ->prohibitedIf ('slug ' , ['admin ' ,
59+ 'horizon ' ])
5960 ->unique (ignoreRecord: true )
6061 ->mutateStateForValidationUsing (fn (string $ state ) => strtolower ($ state )),
6162 TextInput::make ('phone ' )
Original file line number Diff line number Diff line change 55use App \Enums \DiscountTypeEnum ;
66use App \Models \Traits \SerialGenerationTrait ;
77use App \Models \Traits \TenantTrait ;
8+ use Filament \Forms \Components \Actions \Action ;
9+ use Filament \Forms \Components \Group ;
10+ use Filament \Forms \Components \TextInput ;
11+ use Filament \Forms \Set ;
812use Illuminate \Database \Eloquent \Factories \HasFactory ;
913use Illuminate \Database \Eloquent \Model ;
1014use Illuminate \Database \Eloquent \Relations \BelongsTo ;
@@ -67,6 +71,35 @@ class Sale extends Model
6771 'formatted_discount ' ,
6872 ];
6973
74+ /**
75+ * @return array
76+ */
77+ public static function getPayDueAmountForm (): array
78+ {
79+ return [
80+ Group::make ([
81+ TextInput::make ('paid_amount ' )
82+ ->hint (function ($ record ) {
83+ return 'You need to pay ' .$ record ->formatted_remaining_amount ;
84+ })
85+ ->minValue (1 )
86+ ->maxValue (function ($ record ): float {
87+ return $ record ->remaining_amount ;
88+ })
89+ ->numeric ()
90+ ->required ()
91+ ->hintAction (
92+ Action::make ('pay_in_full ' )
93+ ->icon ('heroicon-m-arrow-down-tray ' )
94+ ->action (function (Set $ set , $ state , $ record ) {
95+ $ set ('paid_amount ' , $ record ->remaining_amount );
96+ })
97+ ),
98+ TextInput::make ('reference_number ' ),
99+ ]),
100+ ];
101+ }
102+
70103 /**
71104 * @return float
72105 */
You can’t perform that action at this time.
0 commit comments