您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ViewEstimate.php 5.2KB

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