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

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