Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ViewRecurringInvoice.php 8.2KB

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