You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ViewInvoice.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales\InvoiceResource\Pages;
  3. use App\Enums\Accounting\DocumentType;
  4. use App\Filament\Company\Resources\Sales\ClientResource;
  5. use App\Filament\Company\Resources\Sales\InvoiceResource;
  6. use App\Filament\Infolists\Components\BannerEntry;
  7. use App\Filament\Infolists\Components\DocumentPreview;
  8. use App\Models\Accounting\Invoice;
  9. use Filament\Actions;
  10. use Filament\Infolists\Components\Grid;
  11. use Filament\Infolists\Components\Section;
  12. use Filament\Infolists\Components\TextEntry;
  13. use Filament\Infolists\Infolist;
  14. use Filament\Resources\Pages\ViewRecord;
  15. use Filament\Support\Enums\FontWeight;
  16. use Filament\Support\Enums\IconPosition;
  17. use Illuminate\Support\HtmlString;
  18. class ViewInvoice extends ViewRecord
  19. {
  20. protected static string $resource = InvoiceResource::class;
  21. protected $listeners = [
  22. 'refresh' => '$refresh',
  23. ];
  24. protected function getHeaderActions(): array
  25. {
  26. return [
  27. Actions\EditAction::make()
  28. ->label('Edit invoice')
  29. ->outlined(),
  30. Actions\ActionGroup::make([
  31. Actions\ActionGroup::make([
  32. Invoice::getApproveDraftAction(),
  33. Invoice::getMarkAsSentAction(),
  34. Invoice::getPrintDocumentAction(),
  35. Invoice::getReplicateAction(),
  36. ])->dropdown(false),
  37. Actions\DeleteAction::make(),
  38. ])
  39. ->label('Actions')
  40. ->button()
  41. ->outlined()
  42. ->dropdownPlacement('bottom-end')
  43. ->icon('heroicon-m-chevron-down')
  44. ->iconPosition(IconPosition::After),
  45. ];
  46. }
  47. public function infolist(Infolist $infolist): Infolist
  48. {
  49. return $infolist
  50. ->schema([
  51. BannerEntry::make('inactiveAdjustments')
  52. ->label('Inactive adjustments')
  53. ->warning()
  54. ->icon('heroicon-o-exclamation-triangle')
  55. ->visible(fn (Invoice $record) => $record->hasInactiveAdjustments() && $record->canBeApproved())
  56. ->columnSpanFull()
  57. ->description(function (Invoice $record) {
  58. $inactiveAdjustments = collect();
  59. foreach ($record->lineItems as $lineItem) {
  60. foreach ($lineItem->adjustments as $adjustment) {
  61. if ($adjustment->isInactive() && $inactiveAdjustments->doesntContain($adjustment->name)) {
  62. $inactiveAdjustments->push($adjustment->name);
  63. }
  64. }
  65. }
  66. $adjustmentsList = $inactiveAdjustments->map(static function ($name) {
  67. return "<span class='font-medium'>{$name}</span>";
  68. })->join(', ');
  69. $output = "<p class='text-sm'>This invoice contains inactive adjustments that need to be addressed before approval: {$adjustmentsList}</p>";
  70. return new HtmlString($output);
  71. }),
  72. Section::make('Invoice Details')
  73. ->columns(4)
  74. ->schema([
  75. Grid::make(1)
  76. ->schema([
  77. TextEntry::make('invoice_number')
  78. ->label('Invoice #'),
  79. TextEntry::make('status')
  80. ->badge(),
  81. TextEntry::make('client.name')
  82. ->label('Client')
  83. ->color('primary')
  84. ->weight(FontWeight::SemiBold)
  85. ->url(static fn (Invoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
  86. TextEntry::make('amount_due')
  87. ->label('Amount due')
  88. ->currency(static fn (Invoice $record) => $record->currency_code),
  89. TextEntry::make('due_date')
  90. ->label('Due')
  91. ->asRelativeDay(),
  92. TextEntry::make('approved_at')
  93. ->label('Approved at')
  94. ->placeholder('Not Approved')
  95. ->date(),
  96. TextEntry::make('last_sent_at')
  97. ->label('Last sent')
  98. ->placeholder('Never')
  99. ->date(),
  100. TextEntry::make('paid_at')
  101. ->label('Paid at')
  102. ->placeholder('Not Paid')
  103. ->date(),
  104. ])->columnSpan(1),
  105. DocumentPreview::make()
  106. ->type(DocumentType::Invoice),
  107. ]),
  108. ]);
  109. }
  110. protected function getAllRelationManagers(): array
  111. {
  112. return [
  113. InvoiceResource\RelationManagers\PaymentsRelationManager::class,
  114. ];
  115. }
  116. }