Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Filament\Company\Resources\Sales\InvoiceResource\Pages;
  3. use App\Concerns\HandlePageRedirect;
  4. use App\Concerns\ManagesLineItems;
  5. use App\Filament\Company\Resources\Sales\InvoiceResource;
  6. use App\Models\Accounting\Invoice;
  7. use App\Models\Common\Client;
  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 CreateInvoice extends CreateRecord
  13. {
  14. use HandlePageRedirect;
  15. use ManagesLineItems;
  16. protected static string $resource = InvoiceResource::class;
  17. #[Url(as: 'client')]
  18. public ?int $clientId = null;
  19. public function mount(): void
  20. {
  21. parent::mount();
  22. if ($this->clientId) {
  23. $this->data['client_id'] = $this->clientId;
  24. if ($currencyCode = Client::find($this->clientId)?->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 Invoice $record */
  36. $record = parent::handleRecordCreation($data);
  37. $this->handleLineItems($record, collect($data['lineItems'] ?? []));
  38. $totals = $this->updateDocumentTotals($record, $data);
  39. $record->updateQuietly($totals);
  40. return $record;
  41. }
  42. }