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.

InvoiceResource.php 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales;
  3. use App\Enums\Accounting\InvoiceStatus;
  4. use App\Enums\Accounting\JournalEntryType;
  5. use App\Enums\Accounting\TransactionType;
  6. use App\Filament\Company\Resources\Sales\InvoiceResource\Pages;
  7. use App\Models\Accounting\Account;
  8. use App\Models\Accounting\Adjustment;
  9. use App\Models\Accounting\DocumentLineItem;
  10. use App\Models\Accounting\Invoice;
  11. use App\Models\Banking\BankAccount;
  12. use App\Models\Common\Offering;
  13. use App\Utilities\Currency\CurrencyAccessor;
  14. use App\Utilities\Currency\CurrencyConverter;
  15. use Awcodes\TableRepeater\Components\TableRepeater;
  16. use Awcodes\TableRepeater\Header;
  17. use Carbon\CarbonInterface;
  18. use Filament\Forms;
  19. use Filament\Forms\Components\FileUpload;
  20. use Filament\Forms\Form;
  21. use Filament\Resources\Resource;
  22. use Filament\Support\Enums\MaxWidth;
  23. use Filament\Tables;
  24. use Filament\Tables\Table;
  25. use Illuminate\Database\Eloquent\Model;
  26. use Illuminate\Support\Carbon;
  27. use Illuminate\Support\Facades\Auth;
  28. use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
  29. class InvoiceResource extends Resource
  30. {
  31. protected static ?string $model = Invoice::class;
  32. protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
  33. public static function form(Form $form): Form
  34. {
  35. $company = Auth::user()->currentCompany;
  36. return $form
  37. ->schema([
  38. Forms\Components\Section::make('Invoice Header')
  39. ->collapsible()
  40. ->schema([
  41. Forms\Components\Split::make([
  42. Forms\Components\Group::make([
  43. FileUpload::make('logo')
  44. ->openable()
  45. ->maxSize(1024)
  46. ->localizeLabel()
  47. ->visibility('public')
  48. ->disk('public')
  49. ->directory('logos/document')
  50. ->imageResizeMode('contain')
  51. ->imageCropAspectRatio('3:2')
  52. ->panelAspectRatio('3:2')
  53. ->maxWidth(MaxWidth::ExtraSmall)
  54. ->panelLayout('integrated')
  55. ->removeUploadedFileButtonPosition('center bottom')
  56. ->uploadButtonPosition('center bottom')
  57. ->uploadProgressIndicatorPosition('center bottom')
  58. ->getUploadedFileNameForStorageUsing(
  59. static fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
  60. ->prepend(Auth::user()->currentCompany->id . '_'),
  61. )
  62. ->acceptedFileTypes(['image/png', 'image/jpeg', 'image/gif']),
  63. ]),
  64. Forms\Components\Group::make([
  65. Forms\Components\TextInput::make('header')
  66. ->default(fn () => $company->defaultInvoice->header),
  67. Forms\Components\TextInput::make('subheader')
  68. ->default(fn () => $company->defaultInvoice->subheader),
  69. Forms\Components\View::make('filament.forms.components.company-info')
  70. ->viewData([
  71. 'company_name' => $company->name,
  72. 'company_address' => $company->profile->address,
  73. 'company_city' => $company->profile->city?->name,
  74. 'company_state' => $company->profile->state?->name,
  75. 'company_zip' => $company->profile->zip_code,
  76. 'company_country' => $company->profile->state?->country->name,
  77. ]),
  78. ])->grow(true),
  79. ])->from('md'),
  80. ]),
  81. Forms\Components\Section::make('Invoice Details')
  82. ->schema([
  83. Forms\Components\Split::make([
  84. Forms\Components\Group::make([
  85. Forms\Components\Select::make('client_id')
  86. ->relationship('client', 'name')
  87. ->preload()
  88. ->searchable()
  89. ->required(),
  90. ]),
  91. Forms\Components\Group::make([
  92. Forms\Components\TextInput::make('invoice_number')
  93. ->label('Invoice Number')
  94. ->default(fn () => Invoice::getNextDocumentNumber()),
  95. Forms\Components\TextInput::make('order_number')
  96. ->label('P.O/S.O Number'),
  97. Forms\Components\DatePicker::make('date')
  98. ->label('Invoice Date')
  99. ->default(now()),
  100. Forms\Components\DatePicker::make('due_date')
  101. ->label('Payment Due')
  102. ->default(function () use ($company) {
  103. return now()->addDays($company->defaultInvoice->payment_terms->getDays());
  104. }),
  105. ])->grow(true),
  106. ])->from('md'),
  107. TableRepeater::make('lineItems')
  108. ->relationship()
  109. ->saveRelationshipsUsing(function (TableRepeater $component, Forms\Contracts\HasForms $livewire, ?array $state) {
  110. if (! is_array($state)) {
  111. $state = [];
  112. }
  113. $relationship = $component->getRelationship();
  114. $existingRecords = $component->getCachedExistingRecords();
  115. $recordsToDelete = [];
  116. foreach ($existingRecords->pluck($relationship->getRelated()->getKeyName()) as $keyToCheckForDeletion) {
  117. if (array_key_exists("record-{$keyToCheckForDeletion}", $state)) {
  118. continue;
  119. }
  120. $recordsToDelete[] = $keyToCheckForDeletion;
  121. $existingRecords->forget("record-{$keyToCheckForDeletion}");
  122. }
  123. $relationship
  124. ->whereKey($recordsToDelete)
  125. ->get()
  126. ->each(static fn (Model $record) => $record->delete());
  127. $childComponentContainers = $component->getChildComponentContainers(
  128. withHidden: $component->shouldSaveRelationshipsWhenHidden(),
  129. );
  130. $itemOrder = 1;
  131. $orderColumn = $component->getOrderColumn();
  132. $translatableContentDriver = $livewire->makeFilamentTranslatableContentDriver();
  133. foreach ($childComponentContainers as $itemKey => $item) {
  134. $itemData = $item->getState(shouldCallHooksBefore: false);
  135. if ($orderColumn) {
  136. $itemData[$orderColumn] = $itemOrder;
  137. $itemOrder++;
  138. }
  139. if ($record = ($existingRecords[$itemKey] ?? null)) {
  140. $itemData = $component->mutateRelationshipDataBeforeSave($itemData, record: $record);
  141. if ($itemData === null) {
  142. continue;
  143. }
  144. $translatableContentDriver ?
  145. $translatableContentDriver->updateRecord($record, $itemData) :
  146. $record->fill($itemData)->save();
  147. continue;
  148. }
  149. $relatedModel = $component->getRelatedModel();
  150. $itemData = $component->mutateRelationshipDataBeforeCreate($itemData);
  151. if ($itemData === null) {
  152. continue;
  153. }
  154. if ($translatableContentDriver) {
  155. $record = $translatableContentDriver->makeRecord($relatedModel, $itemData);
  156. } else {
  157. $record = new $relatedModel;
  158. $record->fill($itemData);
  159. }
  160. $record = $relationship->save($record);
  161. $item->model($record)->saveRelationships();
  162. $existingRecords->push($record);
  163. }
  164. $component->getRecord()->setRelation($component->getRelationshipName(), $existingRecords);
  165. /** @var Invoice $invoice */
  166. $invoice = $component->getRecord();
  167. // Recalculate totals for line items
  168. $invoice->lineItems()->each(function (DocumentLineItem $lineItem) {
  169. $lineItem->updateQuietly([
  170. 'tax_total' => $lineItem->calculateTaxTotal()->getAmount(),
  171. 'discount_total' => $lineItem->calculateDiscountTotal()->getAmount(),
  172. ]);
  173. });
  174. $subtotal = $invoice->lineItems()->sum('subtotal') / 100;
  175. $taxTotal = $invoice->lineItems()->sum('tax_total') / 100;
  176. $discountTotal = $invoice->lineItems()->sum('discount_total') / 100;
  177. $grandTotal = $subtotal + $taxTotal - $discountTotal;
  178. $invoice->updateQuietly([
  179. 'subtotal' => $subtotal,
  180. 'tax_total' => $taxTotal,
  181. 'discount_total' => $discountTotal,
  182. 'total' => $grandTotal,
  183. ]);
  184. })
  185. ->headers([
  186. Header::make('Items')->width('15%'),
  187. Header::make('Description')->width('25%'),
  188. Header::make('Quantity')->width('10%'),
  189. Header::make('Price')->width('10%'),
  190. Header::make('Taxes')->width('15%'),
  191. Header::make('Discounts')->width('15%'),
  192. Header::make('Amount')->width('10%')->align('right'),
  193. ])
  194. ->schema([
  195. Forms\Components\Select::make('offering_id')
  196. ->relationship('sellableOffering', 'name')
  197. ->preload()
  198. ->searchable()
  199. ->required()
  200. ->live()
  201. ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
  202. $offeringId = $state;
  203. $offeringRecord = Offering::with('salesTaxes')->find($offeringId);
  204. if ($offeringRecord) {
  205. $set('description', $offeringRecord->description);
  206. $set('unit_price', $offeringRecord->price);
  207. $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
  208. $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
  209. }
  210. }),
  211. Forms\Components\TextInput::make('description'),
  212. Forms\Components\TextInput::make('quantity')
  213. ->required()
  214. ->numeric()
  215. ->live()
  216. ->default(1),
  217. Forms\Components\TextInput::make('unit_price')
  218. ->hiddenLabel()
  219. ->numeric()
  220. ->live()
  221. ->default(0),
  222. Forms\Components\Select::make('salesTaxes')
  223. ->relationship('salesTaxes', 'name')
  224. ->preload()
  225. ->multiple()
  226. ->live()
  227. ->searchable(),
  228. Forms\Components\Select::make('salesDiscounts')
  229. ->relationship('salesDiscounts', 'name')
  230. ->preload()
  231. ->multiple()
  232. ->live()
  233. ->searchable(),
  234. Forms\Components\Placeholder::make('total')
  235. ->hiddenLabel()
  236. ->content(function (Forms\Get $get) {
  237. $quantity = max((float) ($get('quantity') ?? 0), 0);
  238. $unitPrice = max((float) ($get('unit_price') ?? 0), 0);
  239. $salesTaxes = $get('salesTaxes') ?? [];
  240. $salesDiscounts = $get('salesDiscounts') ?? [];
  241. $subtotal = $quantity * $unitPrice;
  242. // Calculate tax amount based on subtotal
  243. $taxAmount = 0;
  244. if (! empty($salesTaxes)) {
  245. $taxRates = Adjustment::whereIn('id', $salesTaxes)->pluck('rate');
  246. $taxAmount = collect($taxRates)->sum(fn ($rate) => $subtotal * ($rate / 100));
  247. }
  248. // Calculate discount amount based on subtotal
  249. $discountAmount = 0;
  250. if (! empty($salesDiscounts)) {
  251. $discountRates = Adjustment::whereIn('id', $salesDiscounts)->pluck('rate');
  252. $discountAmount = collect($discountRates)->sum(fn ($rate) => $subtotal * ($rate / 100));
  253. }
  254. // Final total
  255. $total = $subtotal + ($taxAmount - $discountAmount);
  256. return money($total, CurrencyAccessor::getDefaultCurrency(), true)->format();
  257. }),
  258. ]),
  259. Forms\Components\Grid::make(6)
  260. ->schema([
  261. Forms\Components\ViewField::make('totals')
  262. ->columnStart(5)
  263. ->columnSpan(2)
  264. ->view('filament.forms.components.invoice-totals'),
  265. ]),
  266. // Forms\Components\Repeater::make('lineItems')
  267. // ->relationship()
  268. // ->columns(8)
  269. // ->schema([
  270. // Forms\Components\Select::make('offering_id')
  271. // ->relationship('offering', 'name')
  272. // ->preload()
  273. // ->columnSpan(2)
  274. // ->searchable()
  275. // ->required()
  276. // ->live()
  277. // ->afterStateUpdated(function (Forms\Set $set, $state) {
  278. // $offeringId = $state;
  279. // $offeringRecord = Offering::with('salesTaxes')->find($offeringId);
  280. //
  281. // if ($offeringRecord) {
  282. // $set('description', $offeringRecord->description);
  283. // $set('unit_price', $offeringRecord->price);
  284. // $set('total', $offeringRecord->price);
  285. //
  286. // $salesTaxes = $offeringRecord->salesTaxes->map(function ($tax) {
  287. // return [
  288. // 'id' => $tax->id,
  289. // 'amount' => null, // Amount will be calculated dynamically
  290. // ];
  291. // })->toArray();
  292. //
  293. // $set('taxes', $salesTaxes);
  294. // }
  295. // }),
  296. // Forms\Components\TextInput::make('description')
  297. // ->columnSpan(3)
  298. // ->required(),
  299. // Forms\Components\TextInput::make('quantity')
  300. // ->required()
  301. // ->numeric()
  302. // ->live()
  303. // ->default(1),
  304. // Forms\Components\TextInput::make('unit_price')
  305. // ->live()
  306. // ->numeric()
  307. // ->default(0),
  308. // Forms\Components\Placeholder::make('total')
  309. // ->content(function (Forms\Get $get) {
  310. // $quantity = $get('quantity');
  311. // $unitPrice = $get('unit_price');
  312. //
  313. // if ($quantity && $unitPrice) {
  314. // return $quantity * $unitPrice;
  315. // }
  316. // }),
  317. // TableRepeater::make('taxes')
  318. // ->relationship()
  319. // ->columnSpanFull()
  320. // ->columnStart(6)
  321. // ->headers([
  322. // Header::make('')->width('200px'),
  323. // Header::make('')->width('50px')->align('right'),
  324. // ])
  325. // ->defaultItems(0)
  326. // ->schema([
  327. // Forms\Components\Select::make('id') // The ID of the adjustment being attached.
  328. // ->label('Tax Adjustment')
  329. // ->options(
  330. // Adjustment::query()
  331. // ->where('category', AdjustmentCategory::Tax)
  332. // ->pluck('name', 'id')
  333. // )
  334. // ->preload()
  335. // ->searchable()
  336. // ->required()
  337. // ->live(),
  338. // Forms\Components\Placeholder::make('amount')
  339. // ->hiddenLabel()
  340. // ->content(function (Forms\Get $get) {
  341. // $quantity = $get('../../quantity') ?? 0; // Get parent quantity
  342. // $unitPrice = $get('../../unit_price') ?? 0; // Get parent unit price
  343. // $rate = Adjustment::find($get('id'))->rate ?? 0;
  344. //
  345. // $total = $quantity * $unitPrice;
  346. //
  347. // return $total * ($rate / 100);
  348. // }),
  349. // ]),
  350. // ]),
  351. Forms\Components\Textarea::make('terms')
  352. ->columnSpanFull(),
  353. ]),
  354. Forms\Components\Section::make('Invoice Footer')
  355. ->collapsible()
  356. ->schema([
  357. Forms\Components\Textarea::make('footer')
  358. ->columnSpanFull(),
  359. ]),
  360. ]);
  361. }
  362. public static function table(Table $table): Table
  363. {
  364. return $table
  365. ->columns([
  366. Tables\Columns\TextColumn::make('status')
  367. ->badge()
  368. ->searchable(),
  369. Tables\Columns\TextColumn::make('due_date')
  370. ->label('Due')
  371. ->formatStateUsing(function (Tables\Columns\TextColumn $column, mixed $state) {
  372. if (blank($state)) {
  373. return null;
  374. }
  375. $date = Carbon::parse($state)
  376. ->setTimezone($timezone ?? $column->getTimezone());
  377. if ($date->isToday()) {
  378. return 'Today';
  379. }
  380. return $date->diffForHumans([
  381. 'options' => CarbonInterface::ONE_DAY_WORDS,
  382. ]);
  383. })
  384. ->sortable(),
  385. Tables\Columns\TextColumn::make('date')
  386. ->date()
  387. ->sortable(),
  388. Tables\Columns\TextColumn::make('invoice_number')
  389. ->label('Number')
  390. ->searchable(),
  391. Tables\Columns\TextColumn::make('client.name')
  392. ->sortable(),
  393. Tables\Columns\TextColumn::make('total')
  394. ->currency(),
  395. Tables\Columns\TextColumn::make('amount_paid')
  396. ->label('Amount Paid')
  397. ->currency(),
  398. Tables\Columns\TextColumn::make('amount_due')
  399. ->label('Amount Due')
  400. ->currency(),
  401. ])
  402. ->filters([
  403. //
  404. ])
  405. ->actions([
  406. Tables\Actions\ActionGroup::make([
  407. Tables\Actions\EditAction::make(),
  408. Tables\Actions\ViewAction::make(),
  409. Tables\Actions\DeleteAction::make(),
  410. Tables\Actions\ReplicateAction::make()
  411. ->label('Duplicate')
  412. ->excludeAttributes(['status', 'amount_paid', 'amount_due', 'created_by', 'updated_by', 'created_at', 'updated_at', 'invoice_number', 'date', 'due_date'])
  413. ->modal(false)
  414. ->beforeReplicaSaved(function (Invoice $original, Invoice $replica) {
  415. $replica->status = InvoiceStatus::Draft;
  416. $replica->invoice_number = Invoice::getNextDocumentNumber();
  417. $replica->date = now();
  418. $replica->due_date = now()->addDays($original->company->defaultInvoice->payment_terms->getDays());
  419. })
  420. ->after(function (Invoice $original, Invoice $replica) {
  421. $original->lineItems->each(function (DocumentLineItem $lineItem) use ($replica) {
  422. $replicaLineItem = $lineItem->replicate([
  423. 'documentable_id',
  424. 'documentable_type',
  425. 'subtotal',
  426. 'total',
  427. 'created_by',
  428. 'updated_by',
  429. 'created_at',
  430. 'updated_at',
  431. ]);
  432. $replicaLineItem->documentable_id = $replica->id;
  433. $replicaLineItem->documentable_type = $replica->getMorphClass();
  434. $replicaLineItem->save();
  435. $replicaLineItem->adjustments()->sync($lineItem->adjustments->pluck('id'));
  436. });
  437. })
  438. ->successRedirectUrl(function (Invoice $replica) {
  439. return InvoiceResource::getUrl('edit', ['record' => $replica]);
  440. }),
  441. Tables\Actions\Action::make('approveDraft')
  442. ->label('Approve')
  443. ->icon('heroicon-o-check-circle')
  444. ->visible(function (Invoice $record) {
  445. return $record->isDraft();
  446. })
  447. ->action(function (Invoice $record) {
  448. $transaction = $record->transactions()->create([
  449. 'type' => TransactionType::Journal,
  450. 'posted_at' => now(),
  451. 'amount' => $record->total,
  452. 'description' => 'Invoice Approval for Invoice #' . $record->invoice_number,
  453. ]);
  454. $transaction->journalEntries()->create([
  455. 'type' => JournalEntryType::Debit,
  456. 'account_id' => Account::where('name', 'Accounts Receivable')->first()->id,
  457. 'amount' => $record->total,
  458. 'description' => $transaction->description,
  459. ]);
  460. foreach ($record->lineItems as $lineItem) {
  461. $transaction->journalEntries()->create([
  462. 'type' => JournalEntryType::Credit,
  463. 'account_id' => $lineItem->offering->income_account_id,
  464. 'amount' => $lineItem->subtotal,
  465. 'description' => $transaction->description,
  466. ]);
  467. foreach ($lineItem->adjustments as $adjustment) {
  468. $transaction->journalEntries()->create([
  469. 'type' => $adjustment->category->isDiscount() ? JournalEntryType::Debit : JournalEntryType::Credit,
  470. 'account_id' => $adjustment->account_id,
  471. 'amount' => $lineItem->calculateAdjustmentTotal($adjustment)->getAmount(),
  472. 'description' => $transaction->description,
  473. ]);
  474. }
  475. }
  476. $record->updateQuietly([
  477. 'status' => InvoiceStatus::Unsent,
  478. ]);
  479. }),
  480. Tables\Actions\Action::make('markAsSent')
  481. ->label('Mark as Sent')
  482. ->icon('heroicon-o-paper-airplane')
  483. ->visible(function (Invoice $record) {
  484. return $record->status === InvoiceStatus::Unsent;
  485. })
  486. ->action(function (Invoice $record) {
  487. $record->updateQuietly([
  488. 'status' => InvoiceStatus::Sent,
  489. ]);
  490. }),
  491. Tables\Actions\Action::make('recordPayment')
  492. ->label('Record Payment')
  493. ->modalWidth(MaxWidth::TwoExtraLarge)
  494. ->icon('heroicon-o-credit-card')
  495. ->visible(function (Invoice $record) {
  496. return $record->canRecordPayment();
  497. })
  498. ->mountUsing(function (Invoice $record, Form $form) {
  499. $form->fill([
  500. 'posted_at' => now(),
  501. 'amount' => $record->amount_due,
  502. ]);
  503. })
  504. ->form([
  505. Forms\Components\DatePicker::make('posted_at')
  506. ->label('Payment Date'),
  507. Forms\Components\TextInput::make('amount')
  508. ->label('Amount')
  509. ->required()
  510. ->money(),
  511. Forms\Components\Select::make('payment_method')
  512. ->label('Payment Method')
  513. ->options([
  514. 'bank_payment' => 'Bank Payment',
  515. 'cash' => 'Cash',
  516. 'check' => 'Check',
  517. 'credit_card' => 'Credit Card',
  518. 'paypal' => 'PayPal',
  519. 'other' => 'Other',
  520. ]),
  521. Forms\Components\Select::make('bank_account_id')
  522. ->label('Account')
  523. ->options(BankAccount::query()
  524. ->get()
  525. ->pluck('account.name', 'id'))
  526. ->searchable(),
  527. Forms\Components\Textarea::make('notes')
  528. ->label('Notes'),
  529. ])
  530. ->action(function (Invoice $record, array $data) {
  531. $payment = $record->transactions()->create([
  532. 'type' => TransactionType::Deposit,
  533. 'is_payment' => true,
  534. 'posted_at' => $data['posted_at'],
  535. 'amount' => $data['amount'],
  536. 'payment_method' => $data['payment_method'],
  537. 'bank_account_id' => $data['bank_account_id'],
  538. 'account_id' => Account::where('name', 'Accounts Receivable')->first()?->id,
  539. 'description' => 'Payment for Invoice #' . $record->invoice_number,
  540. 'notes' => $data['notes'] ?? null,
  541. ]);
  542. $amountPaid = $record->getRawOriginal('amount_paid');
  543. $paymentAmount = $payment->getRawOriginal('amount');
  544. $totalAmount = $record->getRawOriginal('total');
  545. $newAmountPaid = $amountPaid + $paymentAmount;
  546. $record->amount_paid = CurrencyConverter::convertCentsToFloat($newAmountPaid);
  547. if ($newAmountPaid > $totalAmount) {
  548. $record->status = InvoiceStatus::Overpaid;
  549. } elseif ($newAmountPaid === $totalAmount) {
  550. $record->status = InvoiceStatus::Paid;
  551. } else {
  552. $record->status = InvoiceStatus::Partial;
  553. }
  554. $record->save();
  555. }),
  556. ]),
  557. ])
  558. ->bulkActions([
  559. Tables\Actions\BulkActionGroup::make([
  560. Tables\Actions\DeleteBulkAction::make(),
  561. ]),
  562. ]);
  563. }
  564. public static function getRelations(): array
  565. {
  566. return [
  567. //
  568. ];
  569. }
  570. public static function getPages(): array
  571. {
  572. return [
  573. 'index' => Pages\ListInvoices::route('/'),
  574. 'create' => Pages\CreateInvoice::route('/create'),
  575. 'view' => Pages\ViewInvoice::route('/{record}'),
  576. 'edit' => Pages\EditInvoice::route('/{record}/edit'),
  577. ];
  578. }
  579. }