|
@@ -321,91 +321,6 @@ class InvoiceResource extends Resource
|
321
|
321
|
->columnSpan(2)
|
322
|
322
|
->view('filament.forms.components.invoice-totals'),
|
323
|
323
|
]),
|
324
|
|
- // Forms\Components\Repeater::make('lineItems')
|
325
|
|
- // ->relationship()
|
326
|
|
- // ->columns(8)
|
327
|
|
- // ->schema([
|
328
|
|
- // Forms\Components\Select::make('offering_id')
|
329
|
|
- // ->relationship('offering', 'name')
|
330
|
|
- // ->preload()
|
331
|
|
- // ->columnSpan(2)
|
332
|
|
- // ->searchable()
|
333
|
|
- // ->required()
|
334
|
|
- // ->live()
|
335
|
|
- // ->afterStateUpdated(function (Forms\Set $set, $state) {
|
336
|
|
- // $offeringId = $state;
|
337
|
|
- // $offeringRecord = Offering::with('salesTaxes')->find($offeringId);
|
338
|
|
- //
|
339
|
|
- // if ($offeringRecord) {
|
340
|
|
- // $set('description', $offeringRecord->description);
|
341
|
|
- // $set('unit_price', $offeringRecord->price);
|
342
|
|
- // $set('total', $offeringRecord->price);
|
343
|
|
- //
|
344
|
|
- // $salesTaxes = $offeringRecord->salesTaxes->map(function ($tax) {
|
345
|
|
- // return [
|
346
|
|
- // 'id' => $tax->id,
|
347
|
|
- // 'amount' => null, // Amount will be calculated dynamically
|
348
|
|
- // ];
|
349
|
|
- // })->toArray();
|
350
|
|
- //
|
351
|
|
- // $set('taxes', $salesTaxes);
|
352
|
|
- // }
|
353
|
|
- // }),
|
354
|
|
- // Forms\Components\TextInput::make('description')
|
355
|
|
- // ->columnSpan(3)
|
356
|
|
- // ->required(),
|
357
|
|
- // Forms\Components\TextInput::make('quantity')
|
358
|
|
- // ->required()
|
359
|
|
- // ->numeric()
|
360
|
|
- // ->live()
|
361
|
|
- // ->default(1),
|
362
|
|
- // Forms\Components\TextInput::make('unit_price')
|
363
|
|
- // ->live()
|
364
|
|
- // ->numeric()
|
365
|
|
- // ->default(0),
|
366
|
|
- // Forms\Components\Placeholder::make('total')
|
367
|
|
- // ->content(function (Forms\Get $get) {
|
368
|
|
- // $quantity = $get('quantity');
|
369
|
|
- // $unitPrice = $get('unit_price');
|
370
|
|
- //
|
371
|
|
- // if ($quantity && $unitPrice) {
|
372
|
|
- // return $quantity * $unitPrice;
|
373
|
|
- // }
|
374
|
|
- // }),
|
375
|
|
- // TableRepeater::make('taxes')
|
376
|
|
- // ->relationship()
|
377
|
|
- // ->columnSpanFull()
|
378
|
|
- // ->columnStart(6)
|
379
|
|
- // ->headers([
|
380
|
|
- // Header::make('')->width('200px'),
|
381
|
|
- // Header::make('')->width('50px')->align('right'),
|
382
|
|
- // ])
|
383
|
|
- // ->defaultItems(0)
|
384
|
|
- // ->schema([
|
385
|
|
- // Forms\Components\Select::make('id') // The ID of the adjustment being attached.
|
386
|
|
- // ->label('Tax Adjustment')
|
387
|
|
- // ->options(
|
388
|
|
- // Adjustment::query()
|
389
|
|
- // ->where('category', AdjustmentCategory::Tax)
|
390
|
|
- // ->pluck('name', 'id')
|
391
|
|
- // )
|
392
|
|
- // ->preload()
|
393
|
|
- // ->searchable()
|
394
|
|
- // ->required()
|
395
|
|
- // ->live(),
|
396
|
|
- // Forms\Components\Placeholder::make('amount')
|
397
|
|
- // ->hiddenLabel()
|
398
|
|
- // ->content(function (Forms\Get $get) {
|
399
|
|
- // $quantity = $get('../../quantity') ?? 0; // Get parent quantity
|
400
|
|
- // $unitPrice = $get('../../unit_price') ?? 0; // Get parent unit price
|
401
|
|
- // $rate = Adjustment::find($get('id'))->rate ?? 0;
|
402
|
|
- //
|
403
|
|
- // $total = $quantity * $unitPrice;
|
404
|
|
- //
|
405
|
|
- // return $total * ($rate / 100);
|
406
|
|
- // }),
|
407
|
|
- // ]),
|
408
|
|
- // ]),
|
409
|
324
|
Forms\Components\Textarea::make('terms')
|
410
|
325
|
->columnSpanFull(),
|
411
|
326
|
]),
|
|
@@ -495,68 +410,9 @@ class InvoiceResource extends Resource
|
495
|
410
|
Tables\Actions\EditAction::make(),
|
496
|
411
|
Tables\Actions\ViewAction::make(),
|
497
|
412
|
Tables\Actions\DeleteAction::make(),
|
498
|
|
- Tables\Actions\ReplicateAction::make()
|
499
|
|
- ->label('Duplicate')
|
500
|
|
- ->excludeAttributes(['status', 'amount_paid', 'amount_due', 'created_by', 'updated_by', 'created_at', 'updated_at', 'invoice_number', 'date', 'due_date'])
|
501
|
|
- ->modal(false)
|
502
|
|
- ->beforeReplicaSaved(function (Invoice $original, Invoice $replica) {
|
503
|
|
- $replica->status = InvoiceStatus::Draft;
|
504
|
|
- $replica->invoice_number = Invoice::getNextDocumentNumber();
|
505
|
|
- $replica->date = now();
|
506
|
|
- $replica->due_date = now()->addDays($original->company->defaultInvoice->payment_terms->getDays());
|
507
|
|
- })
|
508
|
|
- ->databaseTransaction()
|
509
|
|
- ->after(function (Invoice $original, Invoice $replica) {
|
510
|
|
- $original->lineItems->each(function (DocumentLineItem $lineItem) use ($replica) {
|
511
|
|
- $replicaLineItem = $lineItem->replicate([
|
512
|
|
- 'documentable_id',
|
513
|
|
- 'documentable_type',
|
514
|
|
- 'subtotal',
|
515
|
|
- 'total',
|
516
|
|
- 'created_by',
|
517
|
|
- 'updated_by',
|
518
|
|
- 'created_at',
|
519
|
|
- 'updated_at',
|
520
|
|
- ]);
|
521
|
|
-
|
522
|
|
- $replicaLineItem->documentable_id = $replica->id;
|
523
|
|
- $replicaLineItem->documentable_type = $replica->getMorphClass();
|
524
|
|
-
|
525
|
|
- $replicaLineItem->save();
|
526
|
|
-
|
527
|
|
- $replicaLineItem->adjustments()->sync($lineItem->adjustments->pluck('id'));
|
528
|
|
- });
|
529
|
|
- })
|
530
|
|
- ->successRedirectUrl(function (Invoice $replica) {
|
531
|
|
- return InvoiceResource::getUrl('edit', ['record' => $replica]);
|
532
|
|
- }),
|
533
|
|
- Tables\Actions\Action::make('approveDraft')
|
534
|
|
- ->label('Approve')
|
535
|
|
- ->icon('heroicon-o-check-circle')
|
536
|
|
- ->visible(function (Invoice $record) {
|
537
|
|
- return $record->isDraft();
|
538
|
|
- })
|
539
|
|
- ->databaseTransaction()
|
540
|
|
- ->successNotificationTitle('Invoice Approved')
|
541
|
|
- ->action(function (Invoice $record, Tables\Actions\Action $action) {
|
542
|
|
- $record->approveDraft();
|
543
|
|
-
|
544
|
|
- $action->success();
|
545
|
|
- }),
|
546
|
|
- Tables\Actions\Action::make('markAsSent')
|
547
|
|
- ->label('Mark as Sent')
|
548
|
|
- ->icon('heroicon-o-paper-airplane')
|
549
|
|
- ->visible(function (Invoice $record) {
|
550
|
|
- return $record->status === InvoiceStatus::Unsent;
|
551
|
|
- })
|
552
|
|
- ->successNotificationTitle('Invoice Sent')
|
553
|
|
- ->action(function (Invoice $record, Tables\Actions\Action $action) {
|
554
|
|
- $record->update([
|
555
|
|
- 'status' => InvoiceStatus::Sent,
|
556
|
|
- ]);
|
557
|
|
-
|
558
|
|
- $action->success();
|
559
|
|
- }),
|
|
413
|
+ Invoice::getReplicateAction(Tables\Actions\ReplicateAction::class),
|
|
414
|
+ Invoice::getApproveDraftAction(Tables\Actions\Action::class),
|
|
415
|
+ Invoice::getMarkAsSentAction(Tables\Actions\Action::class),
|
560
|
416
|
Tables\Actions\Action::make('recordPayment')
|
561
|
417
|
->label(fn (Invoice $record) => $record->status === InvoiceStatus::Overpaid ? 'Refund Overpayment' : 'Record Payment')
|
562
|
418
|
->stickyModalHeader()
|