Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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