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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales\EstimateResource\Pages;
  3. use App\Enums\Accounting\DocumentType;
  4. use App\Filament\Company\Resources\Sales\ClientResource;
  5. use App\Filament\Company\Resources\Sales\EstimateResource;
  6. use App\Filament\Infolists\Components\BannerEntry;
  7. use App\Filament\Infolists\Components\DocumentPreview;
  8. use App\Models\Accounting\Estimate;
  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 ViewEstimate extends ViewRecord
  21. {
  22. protected static string $resource = EstimateResource::class;
  23. protected $listeners = [
  24. 'refresh' => '$refresh',
  25. ];
  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 estimate')
  35. ->outlined(),
  36. Actions\ActionGroup::make([
  37. Actions\ActionGroup::make([
  38. Estimate::getApproveDraftAction(),
  39. Estimate::getMarkAsSentAction(),
  40. Estimate::getMarkAsAcceptedAction(),
  41. Estimate::getMarkAsDeclinedAction(),
  42. Estimate::getPrintDocumentAction(),
  43. Estimate::getReplicateAction(),
  44. Estimate::getConvertToInvoiceAction(),
  45. ])->dropdown(false),
  46. Actions\DeleteAction::make(),
  47. ])
  48. ->label('Actions')
  49. ->button()
  50. ->outlined()
  51. ->dropdownPlacement('bottom-end')
  52. ->icon('heroicon-c-chevron-down')
  53. ->iconSize(IconSize::Small)
  54. ->iconPosition(IconPosition::After),
  55. ];
  56. }
  57. public function infolist(Infolist $infolist): Infolist
  58. {
  59. return $infolist
  60. ->schema([
  61. BannerEntry::make('inactiveAdjustments')
  62. ->label('Inactive adjustments')
  63. ->warning()
  64. ->icon('heroicon-o-exclamation-triangle')
  65. ->visible(fn (Estimate $record) => $record->hasInactiveAdjustments() && $record->canBeApproved())
  66. ->columnSpanFull()
  67. ->description(function (Estimate $record) {
  68. $inactiveAdjustments = collect();
  69. foreach ($record->lineItems as $lineItem) {
  70. foreach ($lineItem->adjustments as $adjustment) {
  71. if ($adjustment->isInactive() && $inactiveAdjustments->doesntContain($adjustment->name)) {
  72. $inactiveAdjustments->push($adjustment->name);
  73. }
  74. }
  75. }
  76. $adjustmentsList = $inactiveAdjustments->map(static function ($name) {
  77. return "<span class='font-medium'>{$name}</span>";
  78. })->join(', ');
  79. $output = "<p class='text-sm'>This estimate contains inactive adjustments that need to be addressed before approval: {$adjustmentsList}</p>";
  80. return new HtmlString($output);
  81. }),
  82. Section::make('Estimate Details')
  83. ->columns(4)
  84. ->schema([
  85. Grid::make(1)
  86. ->schema([
  87. TextEntry::make('estimate_number')
  88. ->label('Estimate #'),
  89. TextEntry::make('status')
  90. ->badge(),
  91. TextEntry::make('client.name')
  92. ->label('Client')
  93. ->color('primary')
  94. ->weight(FontWeight::SemiBold)
  95. ->url(static fn (Estimate $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
  96. TextEntry::make('expiration_date')
  97. ->label('Expiration date')
  98. ->asRelativeDay(),
  99. TextEntry::make('approved_at')
  100. ->label('Approved at')
  101. ->placeholder('Not Approved')
  102. ->date(),
  103. TextEntry::make('last_sent_at')
  104. ->label('Last sent')
  105. ->placeholder('Never')
  106. ->date(),
  107. TextEntry::make('accepted_at')
  108. ->label('Accepted at')
  109. ->placeholder('Not Accepted')
  110. ->date(),
  111. ])->columnSpan(1),
  112. DocumentPreview::make()
  113. ->type(DocumentType::Estimate),
  114. ]),
  115. ]);
  116. }
  117. }