'dashboard', 'resources.invoice' => 'invoices.index', 'domains/billing/seo.create_invoice.title' => ''])] #[Seo(title: 'domains/billing/seo.create_invoice.title')] class extends Component { use HasSeoAttributes; use HasLayoutDataAttributes; use WithToast; public InvoiceForm $form; #[Computed] public function clients(): Collection { return Client::all(['id', 'name'])->pluck('name', 'id'); } #[Computed] public function schema(): array { return $this->form->type ?->schema() ->withContext($this->form->client_detail) ->getSchema() ?? []; } public function saveDraft(DraftInvoice $createInvoice): void { $this->form->validate(); try { $createInvoice->execute($this->form->toDTO()); $this->success(__('domains/billing.messages.invoice.draft_success')); } catch (\Throwable $th) { $this->error($th->getMessage()); } } public function searchStudentAdmission(): void { try { $detail = $this->form->client_detail; $feeRate = SearchAdmissionSchedulePricing::fetch( admissionTrack: $detail['admission_track'], academicProgram: $detail['academic_program'], studyProgram: $detail['study_program'], termEntry: $detail['term_entry'], feeType: $detail['fee_type'] ); $product = SearchProductInfo::fetch(model: $feeRate->getMorphClass(), model_id: $feeRate->id); $this->form->items = []; $this->form->addItem( code: $product->code, name: $product->name, quantity: 1, price: $feeRate->amount, discount: new Money(0), product_id: $product->id, coa_id: $product->chart_of_account_id ); $this->form->populatePricing(); } catch (Exception $exception) { $this->error($exception->getMessage()); } } public function createInvoice(IssueInvoice $issueInvoice): void { $this->form->validate(); try { $issueInvoice->execute($this->form->toDTO()); $this->success(__('domains/billing.messages.invoice.issue_success')); sleep(5); $this->redirect(route('invoices.index')); } catch (\Throwable $th) { $this->error($th->getMessage()); } } };