Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ViewInvoice.php 5.5KB

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