You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ViewEstimate.php 5.2KB

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