@@ -155,6 +155,7 @@ function ($component) {
155
155
->label ('VAT (Value-Added Tax) ' )
156
156
->suffix ('% ' )
157
157
->lazy ()
158
+ ->default (0 )
158
159
->afterStateUpdated (function (Forms \Set $ set , Forms \Get $ get ) {
159
160
self ::updateTotalAmount ($ get , $ set );
160
161
})
@@ -183,27 +184,32 @@ function ($component) {
183
184
->label ('Total amount ' )
184
185
->suffix ($ currency )
185
186
->disabled (),
186
- Forms \Components \Select::make ('payment_type_id ' )
187
- ->relationship ('paymentType ' , 'name ' )
188
- ->required (),
187
+ Forms \Components \Group::make ([
188
+ Forms \Components \Select::make ('payment_type_id ' )
189
+ ->relationship ('paymentType ' , 'name ' )
190
+ ->required (),
191
+ Forms \Components \TextInput::make ('reference_number ' ),
192
+ ])
193
+ ->columns (2 ),
189
194
Forms \Components \Group::make ([
190
195
Forms \Components \TextInput::make ('paid_amount ' )
191
196
->suffix ($ currency )
197
+ ->default (0 )
192
198
->required ()
193
199
->minValue (0 )
194
- ->maxValue (fn ($ get ) => floatval (str_replace (', ' , '' , $ get ('total_amount ' ))) ?? 0 )
200
+ ->maxValue (fn ($ get ) => floatval (str_replace (', ' , '' , $ get ('total_amount ' ))) ?? 0 )
195
201
->numeric (),
196
202
Forms \Components \Actions::make ([
197
203
Forms \Components \Actions \Action::make ('pay_full ' )
198
204
->label ('Pay in full ' )
199
205
->color ('success ' )
200
206
->action (
201
- fn ($ set , $ get ) => $ set (
207
+ fn ($ set , $ get ) => $ set (
202
208
'paid_amount ' ,
203
209
str_replace (', ' , '' , $ get ('total_amount ' ))
204
210
)
205
211
)
206
- ->visible (fn ($ operation ) => $ operation === 'create ' ),
212
+ ->visible (fn ($ operation ) => $ operation === 'create ' ),
207
213
]),
208
214
]),
209
215
]),
@@ -215,17 +221,20 @@ public static function table(Table $table): Table
215
221
return $ table
216
222
->columns ([
217
223
Tables \Columns \TextColumn::make ('invoice_number ' )
218
- ->searchable (),
224
+ ->searchable ()
225
+ ->sortable (),
219
226
Tables \Columns \TextColumn::make ('sale_date ' )
220
227
->date ()
221
228
->sortable (),
222
229
Tables \Columns \TextColumn::make ('pay_until ' )
223
230
->label ('Due Date ' )
224
- ->formatStateUsing (fn ($ state ) => now ()->addDays ($ state )->format ('M d, Y ' )),
231
+ ->formatStateUsing (fn ($ state ) => now ()->addDays ($ state )->format ('M d, Y ' ))
232
+ ->sortable (),
225
233
Tables \Columns \TextColumn::make ('total_amount ' )
226
- ->money (fn ($ record ) => $ record ->company ->getCurrency ()),
234
+ ->money (fn ($ record ) => $ record ->company ->getCurrency ())
235
+ ->sortable (),
227
236
Tables \Columns \TextColumn::make ('remaining_amount ' )
228
- ->money (fn ($ record ) => $ record ->company ->getCurrency ())
237
+ ->money (fn ($ record ) => $ record ->company ->getCurrency ())
229
238
->sortable (),
230
239
Tables \Columns \TextColumn::make ('customer.name ' )
231
240
->numeric ()
@@ -234,7 +243,8 @@ public static function table(Table $table): Table
234
243
->numeric ()
235
244
->sortable (),
236
245
Tables \Columns \TextColumn::make ('user.name ' )
237
- ->label ('Created By ' ),
246
+ ->label ('Created By ' )
247
+ ->sortable (),
238
248
Tables \Columns \TextColumn::make ('created_at ' )
239
249
->dateTime ()
240
250
->sortable ()
@@ -256,35 +266,40 @@ public static function table(Table $table): Table
256
266
Tables \Actions \ActionGroup::make ([
257
267
Tables \Actions \Action::make ('Pay Amount ' )
258
268
->form ([
259
- TextInput::make ('paid_amount ' )
260
- ->hint (function ($ record ) {
261
- return 'You need to pay ' .$ record ->formatted_remaining_amount ;
262
- })
263
- ->minValue (1 )
264
- ->maxValue (function ($ record ): float {
265
- return $ record ->remaining_amount ;
266
- })
267
- ->numeric ()
268
- ->required ()
269
- ->hintAction (
270
- Forms \Components \Actions \Action::make ('pay_in_full ' )
271
- ->icon ('heroicon-m-arrow-down-tray ' )
272
- ->action (function (Forms \Set $ set , $ state , $ record ) {
273
- $ set ('paid_amount ' , $ record ->remaining_amount );
274
- })
275
- ),
269
+ Forms \Components \Group::make ([
270
+ TextInput::make ('paid_amount ' )
271
+ ->hint (function ($ record ) {
272
+ return 'You need to pay ' .$ record ->formatted_remaining_amount ;
273
+ })
274
+ ->minValue (1 )
275
+ ->maxValue (function ($ record ): float {
276
+ return $ record ->remaining_amount ;
277
+ })
278
+ ->numeric ()
279
+ ->required ()
280
+ ->hintAction (
281
+ Forms \Components \Actions \Action::make ('pay_in_full ' )
282
+ ->icon ('heroicon-m-arrow-down-tray ' )
283
+ ->action (function (Forms \Set $ set , $ state , $ record ) {
284
+ $ set ('paid_amount ' , $ record ->remaining_amount );
285
+ })
286
+ ),
287
+ TextInput::make ('reference_number ' ),
288
+ ])
289
+ ->columns (2 ),
276
290
])
277
291
->color ('info ' )
278
292
->icon ('heroicon-m-banknotes ' )
279
- ->visible (fn ($ record ) => $ record ->remaining_amount > 0 )
293
+ ->visible (fn ($ record ) => $ record ->remaining_amount > 0 )
280
294
->action (function ($ record , array $ data ) {
281
295
$ record ->paid_amount += $ data ['paid_amount ' ];
296
+ $ record ->reference_number = $ data ['reference_number ' ];
282
297
$ record ->save ();
283
298
}),
284
299
Tables \Actions \Action::make ('Download Invoice ' )
285
300
->icon ('heroicon-o-document-arrow-down ' )
286
301
->color ('success ' )
287
- ->url (fn (Sale $ record ) => route ('app.sales.generate-invoice ' , [
302
+ ->url (fn (Sale $ record ) => route ('app.sales.generate-invoice ' , [
288
303
'company ' => session ('company_id ' ),
289
304
'sale ' => $ record ,
290
305
]))
@@ -295,7 +310,8 @@ public static function table(Table $table): Table
295
310
Tables \Actions \BulkActionGroup::make ([
296
311
ExportBulkAction::make (),
297
312
]),
298
- ]);
313
+ ])
314
+ ->defaultSort ('sale_date ' , 'desc ' );
299
315
}
300
316
301
317
public static function getRelations (): array
@@ -333,12 +349,12 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
333
349
{
334
350
// Retrieve all selected products and remove empty rows
335
351
$ selectedProducts = collect ($ get ('saleItems ' ))->filter (
336
- fn ($ item ) => ! empty ($ item ['product_id ' ]) && ! empty ($ item ['quantity ' ])
352
+ fn ($ item ) => !empty ($ item ['product_id ' ]) && !empty ($ item ['quantity ' ])
337
353
);
338
354
339
355
// Calculate subtotal based on the selected products and quantities
340
356
$ subtotal = $ selectedProducts ->reduce (function ($ subtotal , $ product ) {
341
- return $ subtotal + ((float ) $ product ['unit_cost ' ] * (float ) $ product ['quantity ' ]);
357
+ return $ subtotal + ((float )$ product ['unit_cost ' ] * (float )$ product ['quantity ' ]);
342
358
}, 0 );
343
359
344
360
// Update the state with the new values
@@ -353,21 +369,21 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
353
369
*/
354
370
public static function updateTotalAmount (Forms \Get $ get , Forms \Set $ set ): void
355
371
{
356
- $ subTotal = (float ) str_replace (', ' , '' , $ get ('sub_total ' ));
372
+ $ subTotal = (float )str_replace (', ' , '' , $ get ('sub_total ' ));
357
373
$ vatField = $ get ('vat ' );
358
- $ discount = (float ) str_replace (', ' , '' , $ get ('discount ' ));
374
+ $ discount = (float )str_replace (', ' , '' , $ get ('discount ' ));
359
375
$ discountType = $ get ('discount_type ' );
360
376
361
377
if (empty ($ subTotal )) {
362
378
$ subTotal = 0 ;
363
379
}
364
380
365
- if (! empty ($ discount )) {
381
+ if (!empty ($ discount )) {
366
382
$ subTotal = self ::calculateAfterDiscount ($ subTotal , $ discount , $ discountType );
367
383
}
368
384
369
385
$ vat = 0 ;
370
- if (! empty ($ vatField )) {
386
+ if (!empty ($ vatField )) {
371
387
$ vat = $ subTotal * ($ vatField / 100 );
372
388
}
373
389
0 commit comments