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.

CreateBill.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Filament\Company\Resources\Purchases\BillResource\Pages;
  3. use App\Concerns\HandlePageRedirect;
  4. use App\Concerns\ManagesLineItems;
  5. use App\Filament\Company\Resources\Purchases\BillResource;
  6. use App\Models\Accounting\Bill;
  7. use App\Models\Common\Vendor;
  8. use Filament\Resources\Pages\CreateRecord;
  9. use Filament\Support\Enums\MaxWidth;
  10. use Illuminate\Database\Eloquent\Model;
  11. use Livewire\Attributes\Url;
  12. class CreateBill extends CreateRecord
  13. {
  14. use HandlePageRedirect;
  15. use ManagesLineItems;
  16. protected static string $resource = BillResource::class;
  17. #[Url(as: 'vendor')]
  18. public ?int $vendorId = null;
  19. public function mount(): void
  20. {
  21. parent::mount();
  22. if ($this->vendorId) {
  23. $this->data['vendor_id'] = $this->vendorId;
  24. if ($currencyCode = Vendor::find($this->vendorId)?->currency_code) {
  25. $this->data['currency_code'] = $currencyCode;
  26. }
  27. }
  28. }
  29. public function getMaxContentWidth(): MaxWidth | string | null
  30. {
  31. return MaxWidth::Full;
  32. }
  33. protected function handleRecordCreation(array $data): Model
  34. {
  35. /** @var Bill $record */
  36. $record = parent::handleRecordCreation($data);
  37. $this->handleLineItems($record, collect($data['lineItems'] ?? []));
  38. $totals = $this->updateDocumentTotals($record, $data);
  39. $record->updateQuietly($totals);
  40. if (! $record->initialTransaction) {
  41. $record->createInitialTransaction();
  42. }
  43. return $record;
  44. }
  45. }