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.6KB

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