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.

EstimateResource.php 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales;
  3. use App\Enums\Accounting\AdjustmentCategory;
  4. use App\Enums\Accounting\AdjustmentStatus;
  5. use App\Enums\Accounting\AdjustmentType;
  6. use App\Enums\Accounting\DocumentDiscountMethod;
  7. use App\Enums\Accounting\DocumentType;
  8. use App\Enums\Accounting\EstimateStatus;
  9. use App\Enums\Setting\PaymentTerms;
  10. use App\Filament\Company\Resources\Sales\ClientResource\RelationManagers\EstimatesRelationManager;
  11. use App\Filament\Company\Resources\Sales\EstimateResource\Pages;
  12. use App\Filament\Company\Resources\Sales\EstimateResource\Widgets;
  13. use App\Filament\Forms\Components\CreateAdjustmentSelect;
  14. use App\Filament\Forms\Components\CreateClientSelect;
  15. use App\Filament\Forms\Components\CreateCurrencySelect;
  16. use App\Filament\Forms\Components\CreateOfferingSelect;
  17. use App\Filament\Forms\Components\CustomTableRepeater;
  18. use App\Filament\Forms\Components\DocumentFooterSection;
  19. use App\Filament\Forms\Components\DocumentHeaderSection;
  20. use App\Filament\Forms\Components\DocumentTotals;
  21. use App\Filament\Tables\Actions\ReplicateBulkAction;
  22. use App\Filament\Tables\Columns;
  23. use App\Filament\Tables\Filters\DateRangeFilter;
  24. use App\Models\Accounting\Adjustment;
  25. use App\Models\Accounting\DocumentLineItem;
  26. use App\Models\Accounting\Estimate;
  27. use App\Models\Common\Client;
  28. use App\Models\Common\Offering;
  29. use App\Utilities\Currency\CurrencyAccessor;
  30. use App\Utilities\Currency\CurrencyConverter;
  31. use App\Utilities\RateCalculator;
  32. use Awcodes\TableRepeater\Header;
  33. use Filament\Forms;
  34. use Filament\Forms\Form;
  35. use Filament\Notifications\Notification;
  36. use Filament\Resources\Resource;
  37. use Filament\Support\Enums\MaxWidth;
  38. use Filament\Tables;
  39. use Filament\Tables\Table;
  40. use Guava\FilamentClusters\Forms\Cluster;
  41. use Illuminate\Database\Eloquent\Collection;
  42. use Illuminate\Support\Carbon;
  43. use Illuminate\Support\Facades\Auth;
  44. class EstimateResource extends Resource
  45. {
  46. protected static ?string $model = Estimate::class;
  47. public static function form(Form $form): Form
  48. {
  49. $company = Auth::user()->currentCompany;
  50. $settings = $company->defaultEstimate;
  51. return $form
  52. ->schema([
  53. DocumentHeaderSection::make('Estimate Header')
  54. ->defaultHeader($settings->header)
  55. ->defaultSubheader($settings->subheader),
  56. Forms\Components\Section::make('Estimate Details')
  57. ->schema([
  58. Forms\Components\Split::make([
  59. Forms\Components\Group::make([
  60. CreateClientSelect::make('client_id')
  61. ->label('Client')
  62. ->required()
  63. ->live()
  64. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  65. if (! $state) {
  66. return;
  67. }
  68. $currencyCode = Client::find($state)?->currency_code;
  69. if ($currencyCode) {
  70. $set('currency_code', $currencyCode);
  71. }
  72. }),
  73. CreateCurrencySelect::make('currency_code'),
  74. ]),
  75. Forms\Components\Group::make([
  76. Forms\Components\TextInput::make('estimate_number')
  77. ->label('Estimate number')
  78. ->default(static fn () => Estimate::getNextDocumentNumber()),
  79. Forms\Components\TextInput::make('reference_number')
  80. ->label('Reference number'),
  81. Cluster::make([
  82. Forms\Components\DatePicker::make('date')
  83. ->label('Estimate date')
  84. ->live()
  85. ->default(now())
  86. ->columnSpan(2)
  87. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  88. $date = $state;
  89. $expirationDate = $get('expiration_date');
  90. if ($date && $expirationDate && $date > $expirationDate) {
  91. $set('expiration_date', $date);
  92. }
  93. $paymentTerms = $get('payment_terms');
  94. if ($date && $paymentTerms && $paymentTerms !== 'custom') {
  95. $terms = PaymentTerms::parse($paymentTerms);
  96. $set('expiration_date', Carbon::parse($date)->addDays($terms->getDays())->toDateString());
  97. }
  98. }),
  99. Forms\Components\Select::make('payment_terms')
  100. ->label('Payment terms')
  101. ->options(function () {
  102. return collect(PaymentTerms::cases())
  103. ->mapWithKeys(function (PaymentTerms $paymentTerm) {
  104. return [$paymentTerm->value => $paymentTerm->getLabel()];
  105. })
  106. ->put('custom', 'Custom')
  107. ->toArray();
  108. })
  109. ->selectablePlaceholder(false)
  110. ->default($settings->payment_terms->value)
  111. ->live()
  112. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  113. if (! $state || $state === 'custom') {
  114. return;
  115. }
  116. $date = $get('date');
  117. if ($date) {
  118. $terms = PaymentTerms::parse($state);
  119. $set('expiration_date', Carbon::parse($date)->addDays($terms->getDays())->toDateString());
  120. }
  121. }),
  122. ])
  123. ->label('Estimate date')
  124. ->columns(3),
  125. Forms\Components\DatePicker::make('expiration_date')
  126. ->label('Expiration date')
  127. ->default(function () use ($settings) {
  128. return now()->addDays($settings->payment_terms->getDays());
  129. })
  130. ->minDate(static function (Forms\Get $get) {
  131. return $get('date') ?? now();
  132. })
  133. ->live()
  134. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  135. if (! $state) {
  136. return;
  137. }
  138. $date = $get('date');
  139. $paymentTerms = $get('payment_terms');
  140. if (! $date || $paymentTerms === 'custom') {
  141. return;
  142. }
  143. $term = PaymentTerms::parse($paymentTerms);
  144. $expected = Carbon::parse($date)->addDays($term->getDays());
  145. if (! Carbon::parse($state)->isSameDay($expected)) {
  146. $set('payment_terms', 'custom');
  147. }
  148. }),
  149. Forms\Components\Select::make('discount_method')
  150. ->label('Discount method')
  151. ->options(DocumentDiscountMethod::class)
  152. ->softRequired()
  153. ->default($settings->discount_method)
  154. ->afterStateUpdated(function ($state, Forms\Set $set) {
  155. $discountMethod = DocumentDiscountMethod::parse($state);
  156. if ($discountMethod->isPerDocument()) {
  157. $set('lineItems.*.salesDiscounts', []);
  158. }
  159. })
  160. ->live(),
  161. ])->grow(true),
  162. ])->from('md'),
  163. CustomTableRepeater::make('lineItems')
  164. ->hiddenLabel()
  165. ->relationship()
  166. ->saveRelationshipsUsing(null)
  167. ->dehydrated(true)
  168. ->reorderable()
  169. ->orderColumn('line_number')
  170. ->reorderAtStart()
  171. ->cloneable()
  172. ->addActionLabel('Add an item')
  173. ->headers(function (Forms\Get $get) use ($settings) {
  174. $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
  175. $headers = [
  176. Header::make($settings->resolveColumnLabel('item_name', 'Items'))
  177. ->width('30%'),
  178. Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
  179. ->width('10%'),
  180. Header::make($settings->resolveColumnLabel('price_name', 'Price'))
  181. ->width('10%'),
  182. ];
  183. if ($hasDiscounts) {
  184. $headers[] = Header::make('Adjustments')->width('30%');
  185. } else {
  186. $headers[] = Header::make('Taxes')->width('30%');
  187. }
  188. $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
  189. ->width('10%')
  190. ->align('right');
  191. return $headers;
  192. })
  193. ->schema([
  194. Forms\Components\Group::make([
  195. CreateOfferingSelect::make('offering_id')
  196. ->label('Item')
  197. ->hiddenLabel()
  198. ->placeholder('Select item')
  199. ->required()
  200. ->live()
  201. ->inlineSuffix()
  202. ->sellable()
  203. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
  204. $offeringId = $state;
  205. $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
  206. $isPerLineItem = $discountMethod->isPerLineItem();
  207. $existingTaxIds = [];
  208. $existingDiscountIds = [];
  209. if ($record) {
  210. $existingTaxIds = $record->salesTaxes()->pluck('adjustments.id')->toArray();
  211. if ($isPerLineItem) {
  212. $existingDiscountIds = $record->salesDiscounts()->pluck('adjustments.id')->toArray();
  213. }
  214. }
  215. $with = [
  216. 'salesTaxes' => static function ($query) use ($existingTaxIds) {
  217. $query->where(static function ($query) use ($existingTaxIds) {
  218. $query->where('status', AdjustmentStatus::Active)
  219. ->orWhereIn('adjustments.id', $existingTaxIds);
  220. });
  221. },
  222. ];
  223. if ($isPerLineItem) {
  224. $with['salesDiscounts'] = static function ($query) use ($existingDiscountIds) {
  225. $query->where(static function ($query) use ($existingDiscountIds) {
  226. $query->where('status', AdjustmentStatus::Active)
  227. ->orWhereIn('adjustments.id', $existingDiscountIds);
  228. });
  229. };
  230. }
  231. $offeringRecord = Offering::with($with)->find($offeringId);
  232. if (! $offeringRecord) {
  233. return;
  234. }
  235. $unitPrice = CurrencyConverter::convertCentsToFormatSimple($offeringRecord->price, 'USD');
  236. $set('description', $offeringRecord->description);
  237. $set('unit_price', $unitPrice);
  238. $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
  239. if ($isPerLineItem) {
  240. $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
  241. }
  242. }),
  243. Forms\Components\TextInput::make('description')
  244. ->placeholder('Enter item description')
  245. ->hiddenLabel(),
  246. ])->columnSpan(1),
  247. Forms\Components\TextInput::make('quantity')
  248. ->required()
  249. ->numeric()
  250. ->live()
  251. ->maxValue(9999999999.99)
  252. ->default(1),
  253. Forms\Components\TextInput::make('unit_price')
  254. ->hiddenLabel()
  255. ->money(useAffix: false)
  256. ->live()
  257. ->default(0),
  258. Forms\Components\Group::make([
  259. CreateAdjustmentSelect::make('salesTaxes')
  260. ->label('Taxes')
  261. ->hiddenLabel()
  262. ->placeholder('Select taxes')
  263. ->category(AdjustmentCategory::Tax)
  264. ->type(AdjustmentType::Sales)
  265. ->adjustmentsRelationship('salesTaxes')
  266. ->saveRelationshipsUsing(null)
  267. ->dehydrated(true)
  268. ->inlineSuffix()
  269. ->preload()
  270. ->multiple()
  271. ->live()
  272. ->searchable(),
  273. CreateAdjustmentSelect::make('salesDiscounts')
  274. ->label('Discounts')
  275. ->hiddenLabel()
  276. ->placeholder('Select discounts')
  277. ->category(AdjustmentCategory::Discount)
  278. ->type(AdjustmentType::Sales)
  279. ->adjustmentsRelationship('salesDiscounts')
  280. ->saveRelationshipsUsing(null)
  281. ->dehydrated(true)
  282. ->inlineSuffix()
  283. ->multiple()
  284. ->live()
  285. ->hidden(function (Forms\Get $get) {
  286. $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
  287. return $discountMethod->isPerDocument();
  288. })
  289. ->searchable(),
  290. ])->columnSpan(1),
  291. Forms\Components\Placeholder::make('total')
  292. ->hiddenLabel()
  293. ->extraAttributes(['class' => 'text-left sm:text-right'])
  294. ->content(function (Forms\Get $get) {
  295. $quantity = max((float) ($get('quantity') ?? 0), 0);
  296. $unitPrice = CurrencyConverter::isValidAmount($get('unit_price'), 'USD')
  297. ? CurrencyConverter::convertToFloat($get('unit_price'), 'USD')
  298. : 0;
  299. $salesTaxes = $get('salesTaxes') ?? [];
  300. $salesDiscounts = $get('salesDiscounts') ?? [];
  301. $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();
  302. $subtotal = $quantity * $unitPrice;
  303. $subtotalInCents = CurrencyConverter::convertToCents($subtotal, $currencyCode);
  304. $taxAmountInCents = Adjustment::whereIn('id', $salesTaxes)
  305. ->get()
  306. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  307. if ($adjustment->computation->isPercentage()) {
  308. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  309. } else {
  310. return $adjustment->getRawOriginal('rate');
  311. }
  312. });
  313. $discountAmountInCents = Adjustment::whereIn('id', $salesDiscounts)
  314. ->get()
  315. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  316. if ($adjustment->computation->isPercentage()) {
  317. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  318. } else {
  319. return $adjustment->getRawOriginal('rate');
  320. }
  321. });
  322. // Final total
  323. $totalInCents = $subtotalInCents + ($taxAmountInCents - $discountAmountInCents);
  324. return CurrencyConverter::formatCentsToMoney($totalInCents, $currencyCode);
  325. }),
  326. ]),
  327. DocumentTotals::make()
  328. ->type(DocumentType::Estimate),
  329. Forms\Components\Textarea::make('terms')
  330. ->default($settings->terms)
  331. ->columnSpanFull(),
  332. ]),
  333. DocumentFooterSection::make('Estimate Footer')
  334. ->defaultFooter($settings->footer),
  335. ]);
  336. }
  337. public static function table(Table $table): Table
  338. {
  339. return $table
  340. ->defaultSort('expiration_date')
  341. ->columns([
  342. Columns::id(),
  343. Tables\Columns\TextColumn::make('status')
  344. ->badge()
  345. ->searchable(),
  346. Tables\Columns\TextColumn::make('expiration_date')
  347. ->label('Expiration date')
  348. ->asRelativeDay()
  349. ->sortable(),
  350. Tables\Columns\TextColumn::make('date')
  351. ->date()
  352. ->sortable(),
  353. Tables\Columns\TextColumn::make('estimate_number')
  354. ->label('Number')
  355. ->searchable()
  356. ->sortable(),
  357. Tables\Columns\TextColumn::make('client.name')
  358. ->sortable()
  359. ->searchable()
  360. ->hiddenOn(EstimatesRelationManager::class),
  361. Tables\Columns\TextColumn::make('total')
  362. ->currencyWithConversion(static fn (Estimate $record) => $record->currency_code)
  363. ->sortable()
  364. ->alignEnd(),
  365. ])
  366. ->filters([
  367. Tables\Filters\SelectFilter::make('client')
  368. ->relationship('client', 'name')
  369. ->searchable()
  370. ->preload()
  371. ->hiddenOn(EstimatesRelationManager::class),
  372. Tables\Filters\SelectFilter::make('status')
  373. ->options(EstimateStatus::class)
  374. ->native(false),
  375. DateRangeFilter::make('date')
  376. ->fromLabel('From date')
  377. ->untilLabel('To date')
  378. ->indicatorLabel('Date'),
  379. DateRangeFilter::make('expiration_date')
  380. ->fromLabel('From expiration date')
  381. ->untilLabel('To expiration date')
  382. ->indicatorLabel('Due'),
  383. ])
  384. ->actions([
  385. Tables\Actions\ActionGroup::make([
  386. Tables\Actions\ActionGroup::make([
  387. Tables\Actions\EditAction::make()
  388. ->url(static fn (Estimate $record) => Pages\EditEstimate::getUrl(['record' => $record])),
  389. Tables\Actions\ViewAction::make()
  390. ->url(static fn (Estimate $record) => Pages\ViewEstimate::getUrl(['record' => $record])),
  391. Estimate::getReplicateAction(Tables\Actions\ReplicateAction::class),
  392. Estimate::getApproveDraftAction(Tables\Actions\Action::class),
  393. Estimate::getMarkAsSentAction(Tables\Actions\Action::class),
  394. Estimate::getMarkAsAcceptedAction(Tables\Actions\Action::class),
  395. Estimate::getMarkAsDeclinedAction(Tables\Actions\Action::class),
  396. Estimate::getConvertToInvoiceAction(Tables\Actions\Action::class),
  397. ])->dropdown(false),
  398. Tables\Actions\DeleteAction::make(),
  399. ]),
  400. ])
  401. ->bulkActions([
  402. Tables\Actions\BulkActionGroup::make([
  403. Tables\Actions\DeleteBulkAction::make(),
  404. ReplicateBulkAction::make()
  405. ->label('Replicate')
  406. ->modalWidth(MaxWidth::Large)
  407. ->modalDescription('Replicating estimates will also replicate their line items. Are you sure you want to proceed?')
  408. ->successNotificationTitle('Estimates replicated successfully')
  409. ->failureNotificationTitle('Failed to replicate estimates')
  410. ->databaseTransaction()
  411. ->deselectRecordsAfterCompletion()
  412. ->excludeAttributes([
  413. 'estimate_number',
  414. 'date',
  415. 'expiration_date',
  416. 'approved_at',
  417. 'accepted_at',
  418. 'converted_at',
  419. 'declined_at',
  420. 'last_sent_at',
  421. 'last_viewed_at',
  422. 'status',
  423. 'created_by',
  424. 'updated_by',
  425. 'created_at',
  426. 'updated_at',
  427. ])
  428. ->beforeReplicaSaved(function (Estimate $replica) {
  429. $replica->status = EstimateStatus::Draft;
  430. $replica->estimate_number = Estimate::getNextDocumentNumber();
  431. $replica->date = now();
  432. $replica->expiration_date = now()->addDays($replica->company->defaultInvoice->payment_terms->getDays());
  433. })
  434. ->withReplicatedRelationships(['lineItems'])
  435. ->withExcludedRelationshipAttributes('lineItems', [
  436. 'subtotal',
  437. 'total',
  438. 'created_by',
  439. 'updated_by',
  440. 'created_at',
  441. 'updated_at',
  442. ]),
  443. Tables\Actions\BulkAction::make('approveDrafts')
  444. ->label('Approve')
  445. ->icon('heroicon-o-check-circle')
  446. ->databaseTransaction()
  447. ->successNotificationTitle('Estimates approved')
  448. ->failureNotificationTitle('Failed to approve estimates')
  449. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  450. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeApproved());
  451. if ($isInvalid) {
  452. Notification::make()
  453. ->title('Approval failed')
  454. ->body('Only draft estimates can be approved. Please adjust your selection and try again.')
  455. ->persistent()
  456. ->danger()
  457. ->send();
  458. $action->cancel(true);
  459. }
  460. })
  461. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  462. $records->each(function (Estimate $record) {
  463. $record->approveDraft();
  464. });
  465. $action->success();
  466. }),
  467. Tables\Actions\BulkAction::make('markAsSent')
  468. ->label('Mark as sent')
  469. ->icon('heroicon-o-paper-airplane')
  470. ->databaseTransaction()
  471. ->successNotificationTitle('Estimates sent')
  472. ->failureNotificationTitle('Failed to mark estimates as sent')
  473. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  474. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsSent());
  475. if ($isInvalid) {
  476. Notification::make()
  477. ->title('Sending failed')
  478. ->body('Only unsent estimates can be marked as sent. Please adjust your selection and try again.')
  479. ->persistent()
  480. ->danger()
  481. ->send();
  482. $action->cancel(true);
  483. }
  484. })
  485. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  486. $records->each(function (Estimate $record) {
  487. $record->markAsSent();
  488. });
  489. $action->success();
  490. }),
  491. Tables\Actions\BulkAction::make('markAsAccepted')
  492. ->label('Mark as accepted')
  493. ->icon('heroicon-o-check-badge')
  494. ->databaseTransaction()
  495. ->successNotificationTitle('Estimates accepted')
  496. ->failureNotificationTitle('Failed to mark estimates as accepted')
  497. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  498. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsAccepted());
  499. if ($isInvalid) {
  500. Notification::make()
  501. ->title('Acceptance failed')
  502. ->body('Only sent estimates that haven\'t been accepted can be marked as accepted. Please adjust your selection and try again.')
  503. ->persistent()
  504. ->danger()
  505. ->send();
  506. $action->cancel(true);
  507. }
  508. })
  509. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  510. $records->each(function (Estimate $record) {
  511. $record->markAsAccepted();
  512. });
  513. $action->success();
  514. }),
  515. Tables\Actions\BulkAction::make('markAsDeclined')
  516. ->label('Mark as declined')
  517. ->icon('heroicon-o-x-circle')
  518. ->requiresConfirmation()
  519. ->databaseTransaction()
  520. ->color('danger')
  521. ->modalHeading('Mark Estimates as Declined')
  522. ->modalDescription('Are you sure you want to mark the selected estimates as declined? This action cannot be undone.')
  523. ->successNotificationTitle('Estimates declined')
  524. ->failureNotificationTitle('Failed to mark estimates as declined')
  525. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  526. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsDeclined());
  527. if ($isInvalid) {
  528. Notification::make()
  529. ->title('Declination failed')
  530. ->body('Only sent estimates that haven\'t been declined can be marked as declined. Please adjust your selection and try again.')
  531. ->persistent()
  532. ->danger()
  533. ->send();
  534. $action->cancel(true);
  535. }
  536. })
  537. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  538. $records->each(function (Estimate $record) {
  539. $record->markAsDeclined();
  540. });
  541. $action->success();
  542. }),
  543. ]),
  544. ]);
  545. }
  546. public static function getRelations(): array
  547. {
  548. return [
  549. //
  550. ];
  551. }
  552. public static function getPages(): array
  553. {
  554. return [
  555. 'index' => Pages\ListEstimates::route('/'),
  556. 'create' => Pages\CreateEstimate::route('/create'),
  557. 'view' => Pages\ViewEstimate::route('/{record}'),
  558. 'edit' => Pages\EditEstimate::route('/{record}/edit'),
  559. ];
  560. }
  561. public static function getWidgets(): array
  562. {
  563. return [
  564. Widgets\EstimateOverview::class,
  565. ];
  566. }
  567. }