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.

BillResource.php 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. namespace App\Filament\Company\Resources\Purchases;
  3. use App\Enums\Accounting\AdjustmentCategory;
  4. use App\Enums\Accounting\AdjustmentStatus;
  5. use App\Enums\Accounting\AdjustmentType;
  6. use App\Enums\Accounting\BillStatus;
  7. use App\Enums\Accounting\DocumentDiscountMethod;
  8. use App\Enums\Accounting\DocumentType;
  9. use App\Enums\Accounting\PaymentMethod;
  10. use App\Filament\Company\Resources\Purchases\BillResource\Pages;
  11. use App\Filament\Company\Resources\Purchases\VendorResource\RelationManagers\BillsRelationManager;
  12. use App\Filament\Forms\Components\CreateAdjustmentSelect;
  13. use App\Filament\Forms\Components\CreateCurrencySelect;
  14. use App\Filament\Forms\Components\DocumentTotals;
  15. use App\Filament\Tables\Actions\ReplicateBulkAction;
  16. use App\Filament\Tables\Columns;
  17. use App\Filament\Tables\Filters\DateRangeFilter;
  18. use App\Models\Accounting\Adjustment;
  19. use App\Models\Accounting\Bill;
  20. use App\Models\Accounting\DocumentLineItem;
  21. use App\Models\Banking\BankAccount;
  22. use App\Models\Common\Offering;
  23. use App\Models\Common\Vendor;
  24. use App\Utilities\Currency\CurrencyAccessor;
  25. use App\Utilities\Currency\CurrencyConverter;
  26. use App\Utilities\RateCalculator;
  27. use Awcodes\TableRepeater\Components\TableRepeater;
  28. use Awcodes\TableRepeater\Header;
  29. use Closure;
  30. use Filament\Forms;
  31. use Filament\Forms\Form;
  32. use Filament\Notifications\Notification;
  33. use Filament\Resources\Resource;
  34. use Filament\Support\Enums\Alignment;
  35. use Filament\Support\Enums\MaxWidth;
  36. use Filament\Tables;
  37. use Filament\Tables\Table;
  38. use Illuminate\Database\Eloquent\Builder;
  39. use Illuminate\Database\Eloquent\Collection;
  40. use Illuminate\Support\Facades\Auth;
  41. class BillResource extends Resource
  42. {
  43. protected static ?string $model = Bill::class;
  44. public static function form(Form $form): Form
  45. {
  46. $company = Auth::user()->currentCompany;
  47. $settings = $company->defaultBill;
  48. return $form
  49. ->schema([
  50. Forms\Components\Section::make('Bill Details')
  51. ->schema([
  52. Forms\Components\Split::make([
  53. Forms\Components\Group::make([
  54. Forms\Components\Select::make('vendor_id')
  55. ->relationship('vendor', 'name')
  56. ->preload()
  57. ->searchable()
  58. ->required()
  59. ->live()
  60. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  61. if (! $state) {
  62. return;
  63. }
  64. $currencyCode = Vendor::find($state)?->currency_code;
  65. if ($currencyCode) {
  66. $set('currency_code', $currencyCode);
  67. }
  68. }),
  69. CreateCurrencySelect::make('currency_code'),
  70. ]),
  71. Forms\Components\Group::make([
  72. Forms\Components\TextInput::make('bill_number')
  73. ->label('Bill number')
  74. ->default(static fn () => Bill::getNextDocumentNumber())
  75. ->required(),
  76. Forms\Components\TextInput::make('order_number')
  77. ->label('P.O/S.O Number'),
  78. Forms\Components\DatePicker::make('date')
  79. ->label('Bill date')
  80. ->default(now())
  81. ->disabled(function (?Bill $record) {
  82. return $record?->hasPayments();
  83. })
  84. ->required(),
  85. Forms\Components\DatePicker::make('due_date')
  86. ->label('Due date')
  87. ->default(function () use ($company) {
  88. return now()->addDays($company->defaultBill->payment_terms->getDays());
  89. })
  90. ->required(),
  91. Forms\Components\Select::make('discount_method')
  92. ->label('Discount method')
  93. ->options(DocumentDiscountMethod::class)
  94. ->selectablePlaceholder(false)
  95. ->default(DocumentDiscountMethod::PerLineItem)
  96. ->afterStateUpdated(function ($state, Forms\Set $set) {
  97. $discountMethod = DocumentDiscountMethod::parse($state);
  98. if ($discountMethod->isPerDocument()) {
  99. $set('lineItems.*.purchaseDiscounts', []);
  100. }
  101. })
  102. ->live(),
  103. ])->grow(true),
  104. ])->from('md'),
  105. TableRepeater::make('lineItems')
  106. ->relationship()
  107. ->saveRelationshipsUsing(null)
  108. ->dehydrated(true)
  109. ->headers(function (Forms\Get $get) use ($settings) {
  110. $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
  111. $headers = [
  112. Header::make($settings->resolveColumnLabel('item_name', 'Items'))
  113. ->width($hasDiscounts ? '15%' : '20%'),
  114. Header::make('Description')
  115. ->width($hasDiscounts ? '15%' : '20%'),
  116. Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
  117. ->width('10%'),
  118. Header::make($settings->resolveColumnLabel('price_name', 'Price'))
  119. ->width('10%'),
  120. Header::make('Taxes')
  121. ->width($hasDiscounts ? '20%' : '30%'),
  122. ];
  123. if ($hasDiscounts) {
  124. $headers[] = Header::make('Discounts')->width('20%');
  125. }
  126. $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
  127. ->width('10%')
  128. ->align('right');
  129. return $headers;
  130. })
  131. ->schema([
  132. Forms\Components\Select::make('offering_id')
  133. ->label('Item')
  134. ->relationship('purchasableOffering', 'name')
  135. ->preload()
  136. ->searchable()
  137. ->required()
  138. ->live()
  139. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
  140. $offeringId = $state;
  141. $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
  142. $isPerLineItem = $discountMethod->isPerLineItem();
  143. $existingTaxIds = [];
  144. $existingDiscountIds = [];
  145. if ($record) {
  146. $existingTaxIds = $record->purchaseTaxes()->pluck('adjustments.id')->toArray();
  147. if ($isPerLineItem) {
  148. $existingDiscountIds = $record->purchaseDiscounts()->pluck('adjustments.id')->toArray();
  149. }
  150. }
  151. $with = [
  152. 'purchaseTaxes' => static function ($query) use ($existingTaxIds) {
  153. $query->where(static function ($query) use ($existingTaxIds) {
  154. $query->where('status', AdjustmentStatus::Active)
  155. ->orWhereIn('adjustments.id', $existingTaxIds);
  156. });
  157. },
  158. ];
  159. if ($isPerLineItem) {
  160. $with['purchaseDiscounts'] = static function ($query) use ($existingDiscountIds) {
  161. $query->where(static function ($query) use ($existingDiscountIds) {
  162. $query->where('status', AdjustmentStatus::Active)
  163. ->orWhereIn('adjustments.id', $existingDiscountIds);
  164. });
  165. };
  166. }
  167. $offeringRecord = Offering::with($with)->find($offeringId);
  168. if (! $offeringRecord) {
  169. return;
  170. }
  171. $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
  172. $set('description', $offeringRecord->description);
  173. $set('unit_price', $unitPrice);
  174. $set('purchaseTaxes', $offeringRecord->purchaseTaxes->pluck('id')->toArray());
  175. if ($isPerLineItem) {
  176. $set('purchaseDiscounts', $offeringRecord->purchaseDiscounts->pluck('id')->toArray());
  177. }
  178. }),
  179. Forms\Components\TextInput::make('description'),
  180. Forms\Components\TextInput::make('quantity')
  181. ->required()
  182. ->numeric()
  183. ->live()
  184. ->maxValue(9999999999.99)
  185. ->default(1),
  186. Forms\Components\TextInput::make('unit_price')
  187. ->label('Price')
  188. ->hiddenLabel()
  189. ->numeric()
  190. ->live()
  191. ->maxValue(9999999999.99)
  192. ->default(0),
  193. CreateAdjustmentSelect::make('purchaseTaxes')
  194. ->label('Taxes')
  195. ->category(AdjustmentCategory::Tax)
  196. ->type(AdjustmentType::Purchase)
  197. ->adjustmentsRelationship('purchaseTaxes')
  198. ->saveRelationshipsUsing(null)
  199. ->dehydrated(true)
  200. ->preload()
  201. ->multiple()
  202. ->live()
  203. ->searchable(),
  204. CreateAdjustmentSelect::make('purchaseDiscounts')
  205. ->label('Discounts')
  206. ->category(AdjustmentCategory::Discount)
  207. ->type(AdjustmentType::Purchase)
  208. ->adjustmentsRelationship('purchaseDiscounts')
  209. ->saveRelationshipsUsing(null)
  210. ->dehydrated(true)
  211. ->multiple()
  212. ->live()
  213. ->hidden(function (Forms\Get $get) {
  214. $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
  215. return $discountMethod->isPerDocument();
  216. })
  217. ->searchable(),
  218. Forms\Components\Placeholder::make('total')
  219. ->hiddenLabel()
  220. ->extraAttributes(['class' => 'text-left sm:text-right'])
  221. ->content(function (Forms\Get $get) {
  222. $quantity = max((float) ($get('quantity') ?? 0), 0);
  223. $unitPrice = max((float) ($get('unit_price') ?? 0), 0);
  224. $purchaseTaxes = $get('purchaseTaxes') ?? [];
  225. $purchaseDiscounts = $get('purchaseDiscounts') ?? [];
  226. $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();
  227. $subtotal = $quantity * $unitPrice;
  228. $subtotalInCents = CurrencyConverter::convertToCents($subtotal, $currencyCode);
  229. $taxAmountInCents = Adjustment::whereIn('id', $purchaseTaxes)
  230. ->get()
  231. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  232. if ($adjustment->computation->isPercentage()) {
  233. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  234. } else {
  235. return $adjustment->getRawOriginal('rate');
  236. }
  237. });
  238. $discountAmountInCents = Adjustment::whereIn('id', $purchaseDiscounts)
  239. ->get()
  240. ->sum(function (Adjustment $adjustment) use ($subtotalInCents) {
  241. if ($adjustment->computation->isPercentage()) {
  242. return RateCalculator::calculatePercentage($subtotalInCents, $adjustment->getRawOriginal('rate'));
  243. } else {
  244. return $adjustment->getRawOriginal('rate');
  245. }
  246. });
  247. // Final total
  248. $totalInCents = $subtotalInCents + ($taxAmountInCents - $discountAmountInCents);
  249. return CurrencyConverter::formatCentsToMoney($totalInCents, $currencyCode);
  250. }),
  251. ]),
  252. DocumentTotals::make()
  253. ->type(DocumentType::Bill),
  254. ]),
  255. ]);
  256. }
  257. public static function table(Table $table): Table
  258. {
  259. return $table
  260. ->defaultSort('due_date')
  261. ->columns([
  262. Columns::id(),
  263. Tables\Columns\TextColumn::make('status')
  264. ->badge()
  265. ->searchable(),
  266. Tables\Columns\TextColumn::make('due_date')
  267. ->label('Due')
  268. ->asRelativeDay()
  269. ->sortable(),
  270. Tables\Columns\TextColumn::make('date')
  271. ->date()
  272. ->sortable(),
  273. Tables\Columns\TextColumn::make('bill_number')
  274. ->label('Number')
  275. ->searchable()
  276. ->sortable(),
  277. Tables\Columns\TextColumn::make('vendor.name')
  278. ->sortable()
  279. ->searchable()
  280. ->hiddenOn(BillsRelationManager::class),
  281. Tables\Columns\TextColumn::make('total')
  282. ->currencyWithConversion(static fn (Bill $record) => $record->currency_code)
  283. ->sortable()
  284. ->toggleable(),
  285. Tables\Columns\TextColumn::make('amount_paid')
  286. ->label('Amount paid')
  287. ->currencyWithConversion(static fn (Bill $record) => $record->currency_code)
  288. ->sortable()
  289. ->toggleable(),
  290. Tables\Columns\TextColumn::make('amount_due')
  291. ->label('Amount due')
  292. ->currencyWithConversion(static fn (Bill $record) => $record->currency_code)
  293. ->sortable(),
  294. ])
  295. ->filters([
  296. Tables\Filters\SelectFilter::make('vendor')
  297. ->relationship('vendor', 'name')
  298. ->searchable()
  299. ->preload()
  300. ->hiddenOn(BillsRelationManager::class),
  301. Tables\Filters\SelectFilter::make('status')
  302. ->options(BillStatus::class)
  303. ->native(false),
  304. Tables\Filters\TernaryFilter::make('has_payments')
  305. ->label('Has payments')
  306. ->queries(
  307. true: fn (Builder $query) => $query->whereHas('payments'),
  308. false: fn (Builder $query) => $query->whereDoesntHave('payments'),
  309. ),
  310. DateRangeFilter::make('date')
  311. ->fromLabel('From date')
  312. ->untilLabel('To date')
  313. ->indicatorLabel('Date'),
  314. DateRangeFilter::make('due_date')
  315. ->fromLabel('From due date')
  316. ->untilLabel('To due date')
  317. ->indicatorLabel('Due'),
  318. ])
  319. ->actions([
  320. Tables\Actions\ActionGroup::make([
  321. Tables\Actions\ActionGroup::make([
  322. Tables\Actions\EditAction::make()
  323. ->url(static fn (Bill $record) => Pages\EditBill::getUrl(['record' => $record])),
  324. Tables\Actions\ViewAction::make()
  325. ->url(static fn (Bill $record) => Pages\ViewBill::getUrl(['record' => $record])),
  326. Bill::getReplicateAction(Tables\Actions\ReplicateAction::class),
  327. Tables\Actions\Action::make('recordPayment')
  328. ->label('Record payment')
  329. ->stickyModalHeader()
  330. ->stickyModalFooter()
  331. ->modalFooterActionsAlignment(Alignment::End)
  332. ->modalWidth(MaxWidth::TwoExtraLarge)
  333. ->icon('heroicon-o-credit-card')
  334. ->visible(function (Bill $record) {
  335. return $record->canRecordPayment();
  336. })
  337. ->mountUsing(function (Bill $record, Form $form) {
  338. $form->fill([
  339. 'posted_at' => now(),
  340. 'amount' => $record->amount_due,
  341. ]);
  342. })
  343. ->databaseTransaction()
  344. ->successNotificationTitle('Payment recorded')
  345. ->form([
  346. Forms\Components\DatePicker::make('posted_at')
  347. ->label('Date'),
  348. Forms\Components\TextInput::make('amount')
  349. ->label('Amount')
  350. ->required()
  351. ->money(fn (Bill $record) => $record->currency_code)
  352. ->live(onBlur: true)
  353. ->helperText(function (Bill $record, $state) {
  354. $billCurrency = $record->currency_code;
  355. if (! CurrencyConverter::isValidAmount($state, $billCurrency)) {
  356. return null;
  357. }
  358. $amountDue = $record->getRawOriginal('amount_due');
  359. $amount = CurrencyConverter::convertToCents($state, $billCurrency);
  360. if ($amount <= 0) {
  361. return 'Please enter a valid positive amount';
  362. }
  363. $newAmountDue = $amountDue - $amount;
  364. return match (true) {
  365. $newAmountDue > 0 => 'Amount due after payment will be ' . CurrencyConverter::formatCentsToMoney($newAmountDue, $billCurrency),
  366. $newAmountDue === 0 => 'Bill will be fully paid',
  367. default => 'Amount exceeds bill total by ' . CurrencyConverter::formatCentsToMoney(abs($newAmountDue), $billCurrency),
  368. };
  369. })
  370. ->rules([
  371. static fn (Bill $record): Closure => static function (string $attribute, $value, Closure $fail) use ($record) {
  372. if (! CurrencyConverter::isValidAmount($value, $record->currency_code)) {
  373. $fail('Please enter a valid amount');
  374. }
  375. },
  376. ]),
  377. Forms\Components\Select::make('payment_method')
  378. ->label('Payment method')
  379. ->required()
  380. ->options(PaymentMethod::class),
  381. Forms\Components\Select::make('bank_account_id')
  382. ->label('Account')
  383. ->required()
  384. ->options(function () {
  385. return BankAccount::query()
  386. ->join('accounts', 'bank_accounts.account_id', '=', 'accounts.id')
  387. ->select(['bank_accounts.id', 'accounts.name'])
  388. ->pluck('accounts.name', 'bank_accounts.id')
  389. ->toArray();
  390. })
  391. ->searchable(),
  392. Forms\Components\Textarea::make('notes')
  393. ->label('Notes'),
  394. ])
  395. ->action(function (Bill $record, Tables\Actions\Action $action, array $data) {
  396. $record->recordPayment($data);
  397. $action->success();
  398. }),
  399. ])->dropdown(false),
  400. Tables\Actions\DeleteAction::make(),
  401. ]),
  402. ])
  403. ->bulkActions([
  404. Tables\Actions\BulkActionGroup::make([
  405. Tables\Actions\DeleteBulkAction::make(),
  406. ReplicateBulkAction::make()
  407. ->label('Replicate')
  408. ->modalWidth(MaxWidth::Large)
  409. ->modalDescription('Replicating bills will also replicate their line items. Are you sure you want to proceed?')
  410. ->successNotificationTitle('Bills replicated successfully')
  411. ->failureNotificationTitle('Failed to replicate bills')
  412. ->databaseTransaction()
  413. ->deselectRecordsAfterCompletion()
  414. ->excludeAttributes([
  415. 'status',
  416. 'amount_paid',
  417. 'amount_due',
  418. 'created_by',
  419. 'updated_by',
  420. 'created_at',
  421. 'updated_at',
  422. 'bill_number',
  423. 'date',
  424. 'due_date',
  425. 'paid_at',
  426. ])
  427. ->beforeReplicaSaved(function (Bill $replica) {
  428. $replica->status = BillStatus::Open;
  429. $replica->bill_number = Bill::getNextDocumentNumber();
  430. $replica->date = now();
  431. $replica->due_date = now()->addDays($replica->company->defaultBill->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('recordPayments')
  443. ->label('Record payments')
  444. ->icon('heroicon-o-credit-card')
  445. ->stickyModalHeader()
  446. ->stickyModalFooter()
  447. ->modalFooterActionsAlignment(Alignment::End)
  448. ->modalWidth(MaxWidth::TwoExtraLarge)
  449. ->databaseTransaction()
  450. ->successNotificationTitle('Payments recorded')
  451. ->failureNotificationTitle('Failed to record payments')
  452. ->deselectRecordsAfterCompletion()
  453. ->beforeFormFilled(function (Collection $records, Tables\Actions\BulkAction $action) {
  454. $isInvalid = $records->contains(fn (Bill $bill) => ! $bill->canRecordPayment());
  455. if ($isInvalid) {
  456. Notification::make()
  457. ->title('Payment recording failed')
  458. ->body('Bills that are either paid, voided, or are in a foreign currency cannot be processed through bulk payments. Please adjust your selection and try again.')
  459. ->persistent()
  460. ->danger()
  461. ->send();
  462. $action->cancel(true);
  463. }
  464. })
  465. ->mountUsing(function (Collection $records, Form $form) {
  466. $totalAmountDue = $records->sum(fn (Bill $bill) => $bill->getRawOriginal('amount_due'));
  467. $form->fill([
  468. 'posted_at' => now(),
  469. 'amount' => CurrencyConverter::convertCentsToFormatSimple($totalAmountDue),
  470. ]);
  471. })
  472. ->form([
  473. Forms\Components\DatePicker::make('posted_at')
  474. ->label('Date'),
  475. Forms\Components\TextInput::make('amount')
  476. ->label('Amount')
  477. ->required()
  478. ->money()
  479. ->rules([
  480. static fn (): Closure => static function (string $attribute, $value, Closure $fail) {
  481. if (! CurrencyConverter::isValidAmount($value)) {
  482. $fail('Please enter a valid amount');
  483. }
  484. },
  485. ]),
  486. Forms\Components\Select::make('payment_method')
  487. ->label('Payment method')
  488. ->required()
  489. ->options(PaymentMethod::class),
  490. Forms\Components\Select::make('bank_account_id')
  491. ->label('Account')
  492. ->required()
  493. ->options(function () {
  494. return BankAccount::query()
  495. ->join('accounts', 'bank_accounts.account_id', '=', 'accounts.id')
  496. ->select(['bank_accounts.id', 'accounts.name'])
  497. ->pluck('accounts.name', 'bank_accounts.id')
  498. ->toArray();
  499. })
  500. ->searchable(),
  501. Forms\Components\Textarea::make('notes')
  502. ->label('Notes'),
  503. ])
  504. ->before(function (Collection $records, Tables\Actions\BulkAction $action, array $data) {
  505. $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
  506. $totalAmountDue = $records->sum(fn (Bill $bill) => $bill->getRawOriginal('amount_due'));
  507. if ($totalPaymentAmount > $totalAmountDue) {
  508. $formattedTotalAmountDue = CurrencyConverter::formatCentsToMoney($totalAmountDue);
  509. Notification::make()
  510. ->title('Excess payment amount')
  511. ->body("The payment amount exceeds the total amount due of {$formattedTotalAmountDue}. Please adjust the payment amount and try again.")
  512. ->persistent()
  513. ->warning()
  514. ->send();
  515. $action->halt(true);
  516. }
  517. })
  518. ->action(function (Collection $records, Tables\Actions\BulkAction $action, array $data) {
  519. $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
  520. $remainingAmount = $totalPaymentAmount;
  521. $records->each(function (Bill $record) use (&$remainingAmount, $data) {
  522. $amountDue = $record->getRawOriginal('amount_due');
  523. if ($amountDue <= 0 || $remainingAmount <= 0) {
  524. return;
  525. }
  526. $paymentAmount = min($amountDue, $remainingAmount);
  527. $data['amount'] = CurrencyConverter::convertCentsToFormatSimple($paymentAmount);
  528. $record->recordPayment($data);
  529. $remainingAmount -= $paymentAmount;
  530. });
  531. $action->success();
  532. }),
  533. ]),
  534. ]);
  535. }
  536. public static function getPages(): array
  537. {
  538. return [
  539. 'index' => Pages\ListBills::route('/'),
  540. 'create' => Pages\CreateBill::route('/create'),
  541. 'view' => Pages\ViewBill::route('/{record}'),
  542. 'edit' => Pages\EditBill::route('/{record}/edit'),
  543. ];
  544. }
  545. public static function getWidgets(): array
  546. {
  547. return [
  548. BillResource\Widgets\BillOverview::class,
  549. ];
  550. }
  551. }