Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

EstimateResource.php 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
  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. ->numeric()
  256. ->live()
  257. ->maxValue(9999999999.99)
  258. ->default(0),
  259. Forms\Components\Group::make([
  260. CreateAdjustmentSelect::make('salesTaxes')
  261. ->label('Taxes')
  262. ->hiddenLabel()
  263. ->placeholder('Select taxes')
  264. ->category(AdjustmentCategory::Tax)
  265. ->type(AdjustmentType::Sales)
  266. ->adjustmentsRelationship('salesTaxes')
  267. ->saveRelationshipsUsing(null)
  268. ->dehydrated(true)
  269. ->inlineSuffix()
  270. ->preload()
  271. ->multiple()
  272. ->live()
  273. ->searchable(),
  274. CreateAdjustmentSelect::make('salesDiscounts')
  275. ->label('Discounts')
  276. ->hiddenLabel()
  277. ->placeholder('Select discounts')
  278. ->category(AdjustmentCategory::Discount)
  279. ->type(AdjustmentType::Sales)
  280. ->adjustmentsRelationship('salesDiscounts')
  281. ->saveRelationshipsUsing(null)
  282. ->dehydrated(true)
  283. ->inlineSuffix()
  284. ->multiple()
  285. ->live()
  286. ->hidden(function (Forms\Get $get) {
  287. $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
  288. return $discountMethod->isPerDocument();
  289. })
  290. ->searchable(),
  291. ])->columnSpan(1),
  292. Forms\Components\Placeholder::make('total')
  293. ->hiddenLabel()
  294. ->extraAttributes(['class' => 'text-left sm:text-right'])
  295. ->content(function (Forms\Get $get) {
  296. $quantity = max((float) ($get('quantity') ?? 0), 0);
  297. $unitPrice = max((float) ($get('unit_price') ?? 0), 0);
  298. $salesTaxes = $get('salesTaxes') ?? [];
  299. $salesDiscounts = $get('salesDiscounts') ?? [];
  300. $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();
  301. $subtotal = $quantity * $unitPrice;
  302. $subtotalInCents = CurrencyConverter::convertToCents($subtotal, $currencyCode);
  303. $taxAmountInCents = Adjustment::whereIn('id', $salesTaxes)
  304. ->get()
  305. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  306. if ($adjustment->computation->isPercentage()) {
  307. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  308. } else {
  309. return $adjustment->getRawOriginal('rate');
  310. }
  311. });
  312. $discountAmountInCents = Adjustment::whereIn('id', $salesDiscounts)
  313. ->get()
  314. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  315. if ($adjustment->computation->isPercentage()) {
  316. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  317. } else {
  318. return $adjustment->getRawOriginal('rate');
  319. }
  320. });
  321. // Final total
  322. $totalInCents = $subtotalInCents + ($taxAmountInCents - $discountAmountInCents);
  323. return CurrencyConverter::formatCentsToMoney($totalInCents, $currencyCode);
  324. }),
  325. ]),
  326. DocumentTotals::make()
  327. ->type(DocumentType::Estimate),
  328. Forms\Components\Textarea::make('terms')
  329. ->default($settings->terms)
  330. ->columnSpanFull(),
  331. ]),
  332. DocumentFooterSection::make('Estimate Footer')
  333. ->defaultFooter($settings->footer),
  334. ]);
  335. }
  336. public static function table(Table $table): Table
  337. {
  338. return $table
  339. ->defaultSort('expiration_date')
  340. ->columns([
  341. Columns::id(),
  342. Tables\Columns\TextColumn::make('status')
  343. ->badge()
  344. ->searchable(),
  345. Tables\Columns\TextColumn::make('expiration_date')
  346. ->label('Expiration date')
  347. ->asRelativeDay()
  348. ->sortable(),
  349. Tables\Columns\TextColumn::make('date')
  350. ->date()
  351. ->sortable(),
  352. Tables\Columns\TextColumn::make('estimate_number')
  353. ->label('Number')
  354. ->searchable()
  355. ->sortable(),
  356. Tables\Columns\TextColumn::make('client.name')
  357. ->sortable()
  358. ->searchable()
  359. ->hiddenOn(EstimatesRelationManager::class),
  360. Tables\Columns\TextColumn::make('total')
  361. ->currencyWithConversion(static fn (Estimate $record) => $record->currency_code)
  362. ->sortable()
  363. ->alignEnd(),
  364. ])
  365. ->filters([
  366. Tables\Filters\SelectFilter::make('client')
  367. ->relationship('client', 'name')
  368. ->searchable()
  369. ->preload()
  370. ->hiddenOn(EstimatesRelationManager::class),
  371. Tables\Filters\SelectFilter::make('status')
  372. ->options(EstimateStatus::class)
  373. ->native(false),
  374. DateRangeFilter::make('date')
  375. ->fromLabel('From date')
  376. ->untilLabel('To date')
  377. ->indicatorLabel('Date'),
  378. DateRangeFilter::make('expiration_date')
  379. ->fromLabel('From expiration date')
  380. ->untilLabel('To expiration date')
  381. ->indicatorLabel('Due'),
  382. ])
  383. ->actions([
  384. Tables\Actions\ActionGroup::make([
  385. Tables\Actions\ActionGroup::make([
  386. Tables\Actions\EditAction::make()
  387. ->url(static fn (Estimate $record) => Pages\EditEstimate::getUrl(['record' => $record])),
  388. Tables\Actions\ViewAction::make()
  389. ->url(static fn (Estimate $record) => Pages\ViewEstimate::getUrl(['record' => $record])),
  390. Estimate::getReplicateAction(Tables\Actions\ReplicateAction::class),
  391. Estimate::getApproveDraftAction(Tables\Actions\Action::class),
  392. Estimate::getMarkAsSentAction(Tables\Actions\Action::class),
  393. Estimate::getMarkAsAcceptedAction(Tables\Actions\Action::class),
  394. Estimate::getMarkAsDeclinedAction(Tables\Actions\Action::class),
  395. Estimate::getConvertToInvoiceAction(Tables\Actions\Action::class),
  396. ])->dropdown(false),
  397. Tables\Actions\DeleteAction::make(),
  398. ]),
  399. ])
  400. ->bulkActions([
  401. Tables\Actions\BulkActionGroup::make([
  402. Tables\Actions\DeleteBulkAction::make(),
  403. ReplicateBulkAction::make()
  404. ->label('Replicate')
  405. ->modalWidth(MaxWidth::Large)
  406. ->modalDescription('Replicating estimates will also replicate their line items. Are you sure you want to proceed?')
  407. ->successNotificationTitle('Estimates replicated successfully')
  408. ->failureNotificationTitle('Failed to replicate estimates')
  409. ->databaseTransaction()
  410. ->deselectRecordsAfterCompletion()
  411. ->excludeAttributes([
  412. 'estimate_number',
  413. 'date',
  414. 'expiration_date',
  415. 'approved_at',
  416. 'accepted_at',
  417. 'converted_at',
  418. 'declined_at',
  419. 'last_sent_at',
  420. 'last_viewed_at',
  421. 'status',
  422. 'created_by',
  423. 'updated_by',
  424. 'created_at',
  425. 'updated_at',
  426. ])
  427. ->beforeReplicaSaved(function (Estimate $replica) {
  428. $replica->status = EstimateStatus::Draft;
  429. $replica->estimate_number = Estimate::getNextDocumentNumber();
  430. $replica->date = now();
  431. $replica->expiration_date = now()->addDays($replica->company->defaultInvoice->payment_terms->getDays());
  432. })
  433. ->withReplicatedRelationships(['lineItems'])
  434. ->withExcludedRelationshipAttributes('lineItems', [
  435. 'subtotal',
  436. 'total',
  437. 'created_by',
  438. 'updated_by',
  439. 'created_at',
  440. 'updated_at',
  441. ]),
  442. Tables\Actions\BulkAction::make('approveDrafts')
  443. ->label('Approve')
  444. ->icon('heroicon-o-check-circle')
  445. ->databaseTransaction()
  446. ->successNotificationTitle('Estimates approved')
  447. ->failureNotificationTitle('Failed to approve estimates')
  448. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  449. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeApproved());
  450. if ($isInvalid) {
  451. Notification::make()
  452. ->title('Approval failed')
  453. ->body('Only draft estimates can be approved. Please adjust your selection and try again.')
  454. ->persistent()
  455. ->danger()
  456. ->send();
  457. $action->cancel(true);
  458. }
  459. })
  460. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  461. $records->each(function (Estimate $record) {
  462. $record->approveDraft();
  463. });
  464. $action->success();
  465. }),
  466. Tables\Actions\BulkAction::make('markAsSent')
  467. ->label('Mark as sent')
  468. ->icon('heroicon-o-paper-airplane')
  469. ->databaseTransaction()
  470. ->successNotificationTitle('Estimates sent')
  471. ->failureNotificationTitle('Failed to mark estimates as sent')
  472. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  473. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsSent());
  474. if ($isInvalid) {
  475. Notification::make()
  476. ->title('Sending failed')
  477. ->body('Only unsent estimates can be marked as sent. Please adjust your selection and try again.')
  478. ->persistent()
  479. ->danger()
  480. ->send();
  481. $action->cancel(true);
  482. }
  483. })
  484. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  485. $records->each(function (Estimate $record) {
  486. $record->markAsSent();
  487. });
  488. $action->success();
  489. }),
  490. Tables\Actions\BulkAction::make('markAsAccepted')
  491. ->label('Mark as accepted')
  492. ->icon('heroicon-o-check-badge')
  493. ->databaseTransaction()
  494. ->successNotificationTitle('Estimates accepted')
  495. ->failureNotificationTitle('Failed to mark estimates as accepted')
  496. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  497. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsAccepted());
  498. if ($isInvalid) {
  499. Notification::make()
  500. ->title('Acceptance failed')
  501. ->body('Only sent estimates that haven\'t been accepted can be marked as accepted. Please adjust your selection and try again.')
  502. ->persistent()
  503. ->danger()
  504. ->send();
  505. $action->cancel(true);
  506. }
  507. })
  508. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  509. $records->each(function (Estimate $record) {
  510. $record->markAsAccepted();
  511. });
  512. $action->success();
  513. }),
  514. Tables\Actions\BulkAction::make('markAsDeclined')
  515. ->label('Mark as declined')
  516. ->icon('heroicon-o-x-circle')
  517. ->requiresConfirmation()
  518. ->databaseTransaction()
  519. ->color('danger')
  520. ->modalHeading('Mark Estimates as Declined')
  521. ->modalDescription('Are you sure you want to mark the selected estimates as declined? This action cannot be undone.')
  522. ->successNotificationTitle('Estimates declined')
  523. ->failureNotificationTitle('Failed to mark estimates as declined')
  524. ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
  525. $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsDeclined());
  526. if ($isInvalid) {
  527. Notification::make()
  528. ->title('Declination failed')
  529. ->body('Only sent estimates that haven\'t been declined can be marked as declined. Please adjust your selection and try again.')
  530. ->persistent()
  531. ->danger()
  532. ->send();
  533. $action->cancel(true);
  534. }
  535. })
  536. ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
  537. $records->each(function (Estimate $record) {
  538. $record->markAsDeclined();
  539. });
  540. $action->success();
  541. }),
  542. ]),
  543. ]);
  544. }
  545. public static function getRelations(): array
  546. {
  547. return [
  548. //
  549. ];
  550. }
  551. public static function getPages(): array
  552. {
  553. return [
  554. 'index' => Pages\ListEstimates::route('/'),
  555. 'create' => Pages\CreateEstimate::route('/create'),
  556. 'view' => Pages\ViewEstimate::route('/{record}'),
  557. 'edit' => Pages\EditEstimate::route('/{record}/edit'),
  558. ];
  559. }
  560. public static function getWidgets(): array
  561. {
  562. return [
  563. Widgets\EstimateOverview::class,
  564. ];
  565. }
  566. }