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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\IconPosition;
  16. use Illuminate\Support\HtmlString;
  17. class ViewEstimate extends ViewRecord
  18. {
  19. protected static string $resource = EstimateResource::class;
  20. protected $listeners = [
  21. 'refresh' => '$refresh',
  22. ];
  23. protected function getHeaderActions(): array
  24. {
  25. return [
  26. Actions\EditAction::make()
  27. ->label('Edit estimate')
  28. ->outlined(),
  29. Actions\ActionGroup::make([
  30. Actions\ActionGroup::make([
  31. Estimate::getApproveDraftAction(),
  32. Estimate::getMarkAsSentAction(),
  33. Estimate::getMarkAsAcceptedAction(),
  34. Estimate::getMarkAsDeclinedAction(),
  35. Estimate::getPrintDocumentAction(),
  36. Estimate::getReplicateAction(),
  37. Estimate::getConvertToInvoiceAction(),
  38. ])->dropdown(false),
  39. Actions\DeleteAction::make(),
  40. ])
  41. ->label('Actions')
  42. ->button()
  43. ->outlined()
  44. ->dropdownPlacement('bottom-end')
  45. ->icon('heroicon-m-chevron-down')
  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 (Estimate $record) => $record->hasInactiveAdjustments() && $record->canBeApproved())
  58. ->columnSpanFull()
  59. ->description(function (Estimate $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 estimate contains inactive adjustments that need to be addressed before approval: {$adjustmentsList}</p>";
  72. return new HtmlString($output);
  73. }),
  74. Section::make('Estimate Details')
  75. ->columns(4)
  76. ->schema([
  77. Grid::make(1)
  78. ->schema([
  79. TextEntry::make('estimate_number')
  80. ->label('Estimate #'),
  81. TextEntry::make('status')
  82. ->badge(),
  83. TextEntry::make('client.name')
  84. ->label('Client')
  85. ->url(static fn (Estimate $record) => ClientResource::getUrl('view', ['record' => $record->client_id]))
  86. ->link(),
  87. TextEntry::make('expiration_date')
  88. ->label('Expiration date')
  89. ->asRelativeDay(),
  90. TextEntry::make('approved_at')
  91. ->label('Approved at')
  92. ->placeholder('Not Approved')
  93. ->date(),
  94. TextEntry::make('last_sent_at')
  95. ->label('Last sent')
  96. ->placeholder('Never')
  97. ->date(),
  98. TextEntry::make('accepted_at')
  99. ->label('Accepted at')
  100. ->placeholder('Not Accepted')
  101. ->date(),
  102. ])->columnSpan(1),
  103. DocumentPreview::make()
  104. ->type(DocumentType::Estimate),
  105. ]),
  106. ]);
  107. }
  108. }