Create invoice working
This commit is contained in:
parent
0dc3160678
commit
f85d4f20bb
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\InvoiceStatus;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Attributes\Validate;
|
||||||
|
use Flux\Flux;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
#[Validate('required|integer|exists:clients,id')]
|
||||||
|
public int $client_id;
|
||||||
|
|
||||||
|
public InvoiceStatus $status = InvoiceStatus::DRAFT;
|
||||||
|
|
||||||
|
#[Validate('nullable|string')]
|
||||||
|
public ?string $notes = null;
|
||||||
|
|
||||||
|
#[Validate('nullable|string')]
|
||||||
|
public ?string $internal_notes = null;
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
$this->validate();
|
||||||
|
|
||||||
|
Invoice::create([
|
||||||
|
'client_id' => $this->client_id,
|
||||||
|
'status' => $this->status,
|
||||||
|
'notes' => $this->notes,
|
||||||
|
'internal_notes' => $this->notes,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->reset();
|
||||||
|
Flux::modal('create-invoice')->close();
|
||||||
|
$this->dispatch('invoice-created');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function clients()
|
||||||
|
{
|
||||||
|
return Client::where('status', 'active')->orderBy('abbreviation')->get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<flux:modal.trigger name="create-invoice">
|
||||||
|
<flux:button icon="plus" variant="primary">
|
||||||
|
Create Invoice
|
||||||
|
</flux:button>
|
||||||
|
</flux:modal.trigger>
|
||||||
|
|
||||||
|
<flux:modal name="create-invoice" class="md:w-96">
|
||||||
|
<form wire:submit="save" class="space-y-6">
|
||||||
|
<flux:heading size="lg">Create Invoice</flux:heading>
|
||||||
|
|
||||||
|
<flux:select wire:model="client_id" label="Client" placeholder="Choose client...">
|
||||||
|
@foreach($this->clients as $client)
|
||||||
|
<flux:select.option :value="$client->id">{{ $client->name }}</flux:select.option>
|
||||||
|
@endforeach
|
||||||
|
</flux:select>
|
||||||
|
|
||||||
|
<flux:textarea wire:model="notes" label="Notes" placeholder="Add notes to this invoice..."></flux:textarea>
|
||||||
|
<flux:textarea wire:model="internal_notes" label="Internal Notes" placeholder="Add internal notes to this invoice..."></flux:textarea>
|
||||||
|
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<flux:spacer />
|
||||||
|
<flux:button type="submit" variant="primary">Create</flux:button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</flux:modal>
|
||||||
|
</div>
|
||||||
|
|
@ -5,6 +5,7 @@ use App\Models\Invoice;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
|
||||||
|
|
||||||
new class extends Component {
|
new class extends Component {
|
||||||
|
|
@ -23,6 +24,9 @@ new class extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[On('invoice-created')]
|
||||||
|
public function refresh(): void {}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function invoices()
|
public function invoices()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<x-layouts::app :title="__('Contacts')">
|
<x-layouts::app :title="__('Contacts')">
|
||||||
<div class="max-w-7xl mx-auto space-y-4">
|
<div class="max-w-7xl mx-auto space-y-4">
|
||||||
{{-- <div class="flex justify-end">--}}
|
<div class="flex justify-end">
|
||||||
{{-- <livewire:create-contact />--}}
|
<livewire:create-invoice />
|
||||||
{{-- </div>--}}
|
</div>
|
||||||
<livewire:invoice-list />
|
<livewire:invoice-list />
|
||||||
</div>
|
</div>
|
||||||
</x-layouts::app>
|
</x-layouts::app>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue