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

ViewRecurringInvoice.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales\RecurringInvoiceResource\Pages;
  3. use App\Enums\Accounting\DocumentType;
  4. use App\Filament\Company\Resources\Sales\ClientResource;
  5. use App\Filament\Company\Resources\Sales\InvoiceResource\Pages\ListInvoices;
  6. use App\Filament\Company\Resources\Sales\RecurringInvoiceResource;
  7. use App\Filament\Infolists\Components\BannerEntry;
  8. use App\Filament\Infolists\Components\DocumentPreview;
  9. use App\Models\Accounting\RecurringInvoice;
  10. use Filament\Actions;
  11. use Filament\Infolists\Components\Actions\Action;
  12. use Filament\Infolists\Components\Grid;
  13. use Filament\Infolists\Components\Section;
  14. use Filament\Infolists\Components\TextEntry;
  15. use Filament\Infolists\Infolist;
  16. use Filament\Resources\Pages\ViewRecord;
  17. use Filament\Support\Enums\FontWeight;
  18. use Filament\Support\Enums\IconPosition;
  19. use Filament\Support\Enums\IconSize;
  20. use Filament\Support\Enums\MaxWidth;
  21. use Illuminate\Support\HtmlString;
  22. use Illuminate\Support\Str;
  23. class ViewRecurringInvoice extends ViewRecord
  24. {
  25. protected static string $resource = RecurringInvoiceResource::class;
  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 recurring invoice')
  35. ->outlined(),
  36. Actions\ActionGroup::make([
  37. Actions\ActionGroup::make([
  38. RecurringInvoice::getManageScheduleAction(),
  39. RecurringInvoice::getApproveDraftAction(),
  40. RecurringInvoice::getPrintDocumentAction(),
  41. ])->dropdown(false),
  42. Actions\DeleteAction::make(),
  43. ])
  44. ->label('Actions')
  45. ->button()
  46. ->outlined()
  47. ->dropdownPlacement('bottom-end')
  48. ->icon('heroicon-c-chevron-down')
  49. ->iconSize(IconSize::Small)
  50. ->iconPosition(IconPosition::After),
  51. ];
  52. }
  53. public function infolist(Infolist $infolist): Infolist
  54. {
  55. return $infolist
  56. ->schema([
  57. BannerEntry::make('inactiveAdjustments')
  58. ->label('Inactive adjustments')
  59. ->warning()
  60. ->icon('heroicon-o-exclamation-triangle')
  61. ->visible(fn (RecurringInvoice $record) => $record->hasInactiveAdjustments() && $record->canBeApproved())
  62. ->columnSpanFull()
  63. ->description(function (RecurringInvoice $record) {
  64. $inactiveAdjustments = collect();
  65. foreach ($record->lineItems as $lineItem) {
  66. foreach ($lineItem->adjustments as $adjustment) {
  67. if ($adjustment->isInactive() && $inactiveAdjustments->doesntContain($adjustment->name)) {
  68. $inactiveAdjustments->push($adjustment->name);
  69. }
  70. }
  71. }
  72. $adjustmentsList = $inactiveAdjustments->map(static function ($name) {
  73. return "<span class='font-medium'>{$name}</span>";
  74. })->join(', ');
  75. $output = "<p class='text-sm'>This recurring invoice contains inactive adjustments that need to be addressed before approval: {$adjustmentsList}</p>";
  76. return new HtmlString($output);
  77. }),
  78. BannerEntry::make('scheduleIsNotSet')
  79. ->info()
  80. ->title('Schedule not set')
  81. ->description('The schedule for this recurring invoice has not been set. You must set a schedule before you can approve this draft and start creating invoices.')
  82. ->visible(fn (RecurringInvoice $record) => ! $record->hasValidStartDate())
  83. ->columnSpanFull()
  84. ->actions([
  85. RecurringInvoice::getManageScheduleAction(Action::class)
  86. ->outlined(),
  87. ]),
  88. BannerEntry::make('readyToApprove')
  89. ->info()
  90. ->title('Ready to Approve')
  91. ->description('This recurring invoice is ready for approval. Review the details, and approve it when you’re ready to start generating invoices.')
  92. ->visible(fn (RecurringInvoice $record) => $record->canBeApproved() && ! $record->hasInactiveAdjustments())
  93. ->columnSpanFull()
  94. ->actions([
  95. RecurringInvoice::getApproveDraftAction(Action::class)
  96. ->outlined(),
  97. ]),
  98. Section::make('Invoice Details')
  99. ->columns(4)
  100. ->schema([
  101. Grid::make(1)
  102. ->schema([
  103. TextEntry::make('status')
  104. ->badge(),
  105. TextEntry::make('client.name')
  106. ->label('Client')
  107. ->color('primary')
  108. ->weight(FontWeight::SemiBold)
  109. ->url(static fn (RecurringInvoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
  110. TextEntry::make('last_date')
  111. ->label('Last invoice')
  112. ->date()
  113. ->placeholder('Not Created'),
  114. TextEntry::make('next_date')
  115. ->label('Next invoice')
  116. ->placeholder('Not Scheduled')
  117. ->date(),
  118. TextEntry::make('schedule')
  119. ->label('Schedule')
  120. ->getStateUsing(function (RecurringInvoice $record) {
  121. return $record->getScheduleDescription();
  122. })
  123. ->helperText(function (RecurringInvoice $record) {
  124. return $record->getTimelineDescription();
  125. }),
  126. TextEntry::make('occurrences_count')
  127. ->label('Created to date')
  128. ->visible(static fn (RecurringInvoice $record) => $record->occurrences_count > 0)
  129. ->color('primary')
  130. ->weight(FontWeight::SemiBold)
  131. ->suffix(fn (RecurringInvoice $record) => Str::of(' invoice')->plural($record->occurrences_count))
  132. ->url(static function (RecurringInvoice $record) {
  133. return ListInvoices::getUrl(['recurringInvoice' => $record->id]);
  134. }),
  135. TextEntry::make('end_date')
  136. ->label('Ends on')
  137. ->date()
  138. ->visible(fn (RecurringInvoice $record) => $record->end_type?->isOn()),
  139. TextEntry::make('approved_at')
  140. ->label('Approved at')
  141. ->placeholder('Not Approved')
  142. ->date(),
  143. TextEntry::make('ended_at')
  144. ->label('Ended at')
  145. ->date()
  146. ->visible(fn (RecurringInvoice $record) => $record->ended_at),
  147. TextEntry::make('total')
  148. ->label('Invoice amount')
  149. ->currency(static fn (RecurringInvoice $record) => $record->currency_code),
  150. ])->columnSpan(1),
  151. DocumentPreview::make()
  152. ->type(DocumentType::RecurringInvoice),
  153. ]),
  154. ]);
  155. }
  156. }