feat: Enhance invoice creation and editing with improved part selection and error handling
This commit is contained in:
@ -52,6 +52,10 @@ class Create extends Component
|
|||||||
|
|
||||||
public $service_items = [];
|
public $service_items = [];
|
||||||
|
|
||||||
|
public $filteredParts = [];
|
||||||
|
|
||||||
|
public $partSearchTerms = [];
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->invoice_date = now()->format('Y-m-d');
|
$this->invoice_date = now()->format('Y-m-d');
|
||||||
@ -63,6 +67,9 @@ class Create extends Component
|
|||||||
$this->parts = Part::where('status', 'active')->orderBy('name')->get();
|
$this->parts = Part::where('status', 'active')->orderBy('name')->get();
|
||||||
$this->service_items = ServiceItem::where('status', 'active')->orderBy('service_name')->get();
|
$this->service_items = ServiceItem::where('status', 'active')->orderBy('service_name')->get();
|
||||||
|
|
||||||
|
// Initialize filtered parts and search terms for each line item
|
||||||
|
$this->filteredParts = $this->parts->toArray();
|
||||||
|
|
||||||
// Initialize with one empty line item
|
// Initialize with one empty line item
|
||||||
$this->addLineItem();
|
$this->addLineItem();
|
||||||
}
|
}
|
||||||
@ -181,10 +188,12 @@ class Create extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create invoice
|
// Create invoice
|
||||||
|
$branch = Branch::find($this->branch_id);
|
||||||
$invoice = Invoice::create([
|
$invoice = Invoice::create([
|
||||||
'customer_id' => $this->customer_id,
|
'customer_id' => $this->customer_id,
|
||||||
'branch_id' => $this->branch_id,
|
'branch_id' => $this->branch_id,
|
||||||
'created_by' => Auth::id(),
|
'created_by' => Auth::id(),
|
||||||
|
'invoice_number' => Invoice::generateInvoiceNumber($branch->code ?? 'MAIN'),
|
||||||
'invoice_date' => $this->invoice_date,
|
'invoice_date' => $this->invoice_date,
|
||||||
'due_date' => $this->due_date,
|
'due_date' => $this->due_date,
|
||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use App\Models\Estimate;
|
|||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Part;
|
use App\Models\Part;
|
||||||
use App\Models\ServiceItem;
|
use App\Models\ServiceItem;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Livewire\Attributes\Validate;
|
use Livewire\Attributes\Validate;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
@ -152,40 +153,59 @@ class CreateFromEstimate extends Component
|
|||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
$invoice = Invoice::create([
|
DB::transaction(function () {
|
||||||
'job_card_id' => $this->estimate->job_card_id,
|
$branch = Branch::find($this->branch_id);
|
||||||
'estimate_id' => $this->estimate->id,
|
$invoice = Invoice::create([
|
||||||
'customer_id' => $this->estimate->customer_id,
|
'job_card_id' => $this->estimate->job_card_id,
|
||||||
'branch_id' => $this->branch_id,
|
'estimate_id' => $this->estimate->id,
|
||||||
'created_by' => auth()->id(),
|
'customer_id' => $this->estimate->customer_id,
|
||||||
'invoice_number' => Invoice::generateInvoiceNumber($this->branch_id),
|
'branch_id' => $this->branch_id,
|
||||||
'subject' => $this->subject,
|
'created_by' => auth()->id(),
|
||||||
'description' => $this->description,
|
'invoice_number' => Invoice::generateInvoiceNumber($branch->code ?? 'MAIN'),
|
||||||
'invoice_date' => $this->invoice_date,
|
'subject' => $this->subject,
|
||||||
'due_date' => $this->due_date,
|
'description' => $this->description,
|
||||||
'subtotal' => $this->subtotal,
|
'invoice_date' => $this->invoice_date,
|
||||||
'tax_rate' => $this->tax_rate,
|
'due_date' => $this->due_date,
|
||||||
'tax_amount' => $this->taxAmount,
|
'subtotal' => $this->estimate->subtotal_amount,
|
||||||
'total_amount' => $this->total,
|
'tax_rate' => 10.0, // Default tax rate
|
||||||
'status' => 'draft',
|
'tax_amount' => $this->estimate->tax_amount,
|
||||||
]);
|
'total_amount' => $this->estimate->total_amount,
|
||||||
|
'status' => 'draft',
|
||||||
// Create line items
|
|
||||||
foreach ($this->lineItems as $item) {
|
|
||||||
$invoice->invoiceLineItems()->create([
|
|
||||||
'type' => $item['type'],
|
|
||||||
'service_item_id' => $item['service_item_id'] ?: null,
|
|
||||||
'part_id' => $item['part_id'] ?: null,
|
|
||||||
'description' => $item['description'],
|
|
||||||
'quantity' => $item['quantity'],
|
|
||||||
'unit_price' => $item['unit_price'],
|
|
||||||
'total' => $item['total'],
|
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
// Copy line items from estimate to invoice
|
||||||
|
foreach ($this->estimate->lineItems as $estimateItem) {
|
||||||
|
// Map estimate line item types to invoice line item types
|
||||||
|
$invoiceType = match ($estimateItem->type) {
|
||||||
|
'parts' => 'part',
|
||||||
|
'labour' => 'labour',
|
||||||
|
'miscellaneous' => 'other',
|
||||||
|
default => $estimateItem->type
|
||||||
|
};
|
||||||
|
|
||||||
|
$lineItemData = [
|
||||||
|
'type' => $invoiceType,
|
||||||
|
'description' => $estimateItem->description,
|
||||||
|
'quantity' => $estimateItem->quantity,
|
||||||
|
'unit_price' => $estimateItem->unit_price,
|
||||||
|
'total_amount' => $estimateItem->total_amount,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add part reference if it's a parts item
|
||||||
|
if ($estimateItem->type === 'parts' && $estimateItem->part_id) {
|
||||||
|
$lineItemData['part_id'] = $estimateItem->part_id;
|
||||||
|
$lineItemData['part_number'] = $estimateItem->part->part_number ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoice->invoiceLineItems()->create($lineItemData);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->invoice = $invoice;
|
||||||
|
});
|
||||||
|
|
||||||
session()->flash('success', 'Invoice created successfully from estimate.');
|
session()->flash('success', 'Invoice created successfully from estimate.');
|
||||||
|
|
||||||
return redirect()->route('invoices.show', $invoice);
|
return redirect()->route('invoices.show', $this->invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|||||||
@ -82,7 +82,7 @@
|
|||||||
Create Work Order
|
Create Work Order
|
||||||
</flux:menu.item>
|
</flux:menu.item>
|
||||||
@can('create', \App\Models\Invoice::class)
|
@can('create', \App\Models\Invoice::class)
|
||||||
<flux:menu.item icon="document-text" wire:click="convertToInvoice">
|
<flux:menu.item icon="document-text" href="{{ route('invoices.create-from-estimate', $estimate) }}">
|
||||||
Convert to Invoice
|
Convert to Invoice
|
||||||
</flux:menu.item>
|
</flux:menu.item>
|
||||||
@endcan
|
@endcan
|
||||||
|
|||||||
@ -1,171 +1,207 @@
|
|||||||
<div class="max-w-7xl mx-auto">
|
<div>
|
||||||
<div class="mb-6">
|
<x-slot name="title">Create Invoice from Estimate</x-slot>
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<div>
|
|
||||||
<h1 class="text-2xl font-semibold text-gray-900">Create Invoice from Estimate</h1>
|
|
||||||
<p class="mt-1 text-sm text-gray-600">Converting estimate #{{ $estimate->estimate_number }} to invoice</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex space-x-3">
|
|
||||||
<flux:button variant="outline" href="{{ route('estimates.show', $estimate) }}">
|
|
||||||
Back to Estimate
|
|
||||||
</flux:button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Estimate Reference -->
|
<div class="py-12">
|
||||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6">
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
<div class="flex items-center">
|
<div class="bg-white dark:bg-zinc-800 overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
<flux:icon name="document-text" class="h-5 w-5 text-blue-400 mr-2" />
|
<div class="p-6 text-zinc-900 dark:text-zinc-100">
|
||||||
<div>
|
<div class="flex justify-between items-center mb-6">
|
||||||
<h3 class="text-sm font-medium text-blue-800">Source Estimate</h3>
|
<div>
|
||||||
<p class="text-sm text-blue-600">{{ $estimate->subject }} - {{ $estimate->estimate_number }}</p>
|
<h2 class="text-2xl font-semibold">Create Invoice from Estimate #{{ $estimate->estimate_number }}</h2>
|
||||||
</div>
|
<p class="text-sm text-zinc-600 dark:text-zinc-400 mt-1">Converting estimate to invoice</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<a href="{{ route('invoices.index') }}" class="text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100">
|
||||||
|
← Back to Invoices
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form wire:submit="save" class="space-y-6">
|
@if ($errors->any())
|
||||||
|
<div class="mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded">
|
||||||
|
<ul>
|
||||||
|
@foreach ($errors->all() as $error)
|
||||||
|
<li>{{ $error }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form wire:submit="save" class="space-y-6">
|
||||||
<!-- Basic Information -->
|
<!-- Basic Information -->
|
||||||
<div class="bg-white shadow rounded-lg p-6">
|
<!-- Customer Information (Read-only) -->
|
||||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Invoice Details</h3>
|
<div class="bg-zinc-50 dark:bg-zinc-700 p-4 rounded-lg">
|
||||||
|
<h3 class="text-lg font-medium mb-4">Customer Information</h3>
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div class="space-y-2">
|
||||||
<div>
|
<p><strong>Name:</strong> {{ $estimate->customer->first_name }} {{ $estimate->customer->last_name }}</p>
|
||||||
<flux:field>
|
<p><strong>Email:</strong> {{ $estimate->customer->email }}</p>
|
||||||
<flux:label>Subject</flux:label>
|
<p><strong>Phone:</strong> {{ $estimate->customer->phone }}</p>
|
||||||
<flux:input wire:model="subject" placeholder="Invoice subject" />
|
</div>
|
||||||
<flux:error name="subject" />
|
</div>
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<!-- Estimate Information (Read-only) -->
|
||||||
<flux:field>
|
<div class="bg-zinc-50 dark:bg-zinc-700 p-4 rounded-lg">
|
||||||
<flux:label>Branch</flux:label>
|
<h3 class="text-lg font-medium mb-4">Original Estimate</h3>
|
||||||
<flux:select wire:model="branch_id">
|
<div class="space-y-2">
|
||||||
<flux:option value="">Select branch</flux:option>
|
<p><strong>Estimate #:</strong> {{ $estimate->estimate_number }}</p>
|
||||||
@foreach($branches as $branch)
|
<p><strong>Date:</strong> {{ $estimate->estimate_date->format('Y-m-d') }}</p>
|
||||||
<flux:option value="{{ $branch->id }}">{{ $branch->name }}</flux:option>
|
<p><strong>Total:</strong> ${{ number_format($estimate->total_amount, 2) }}</p>
|
||||||
@endforeach
|
<p><strong>Status:</strong> {{ ucfirst($estimate->status) }}</p>
|
||||||
</flux:select>
|
</div>
|
||||||
<flux:error name="branch_id" />
|
</div>
|
||||||
</flux:field>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<!-- Invoice Details -->
|
||||||
<flux:field>
|
<div class="bg-white dark:bg-zinc-800 shadow rounded-lg p-6">
|
||||||
<flux:label>Invoice Date</flux:label>
|
<h3 class="text-lg font-medium text-zinc-900 dark:text-zinc-100 mb-4">Invoice Details</h3>
|
||||||
<flux:input type="date" wire:model="invoice_date" />
|
|
||||||
<flux:error name="invoice_date" />
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
</flux:field>
|
<div>
|
||||||
</div>
|
<label for="subject" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||||
|
Invoice Subject *
|
||||||
|
</label>
|
||||||
|
<input type="text"
|
||||||
|
id="subject"
|
||||||
|
wire:model="subject"
|
||||||
|
placeholder="Invoice subject"
|
||||||
|
class="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm focus:outline-none focus:ring-orange-500 focus:border-orange-500 dark:bg-zinc-700 dark:text-zinc-100">
|
||||||
|
@error('subject')
|
||||||
|
<span class="text-red-500 text-sm">{{ $message }}</span>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<flux:field>
|
<label for="branch_id" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||||
<flux:label>Due Date</flux:label>
|
Branch *
|
||||||
<flux:input type="date" wire:model="due_date" />
|
</label>
|
||||||
<flux:error name="due_date" />
|
<select id="branch_id"
|
||||||
</flux:field>
|
wire:model="branch_id"
|
||||||
</div>
|
class="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm focus:outline-none focus:ring-orange-500 focus:border-orange-500 dark:bg-zinc-700 dark:text-zinc-100">
|
||||||
|
<option value="">Select branch</option>
|
||||||
|
@foreach($branches as $branch)
|
||||||
|
<option value="{{ $branch->id }}">{{ $branch->name }} ({{ $branch->code }})</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('branch_id')
|
||||||
|
<span class="text-red-500 text-sm">{{ $message }}</span>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="md:col-span-2">
|
<div>
|
||||||
<flux:field>
|
<label for="invoice_date" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||||
<flux:label>Description</flux:label>
|
Invoice Date *
|
||||||
<flux:textarea wire:model="description" rows="3" placeholder="Invoice description..." />
|
</label>
|
||||||
<flux:error name="description" />
|
<input type="date"
|
||||||
</flux:field>
|
id="invoice_date"
|
||||||
</div>
|
wire:model="invoice_date"
|
||||||
|
class="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm focus:outline-none focus:ring-orange-500 focus:border-orange-500 dark:bg-zinc-700 dark:text-zinc-100">
|
||||||
|
@error('invoice_date')
|
||||||
|
<span class="text-red-500 text-sm">{{ $message }}</span>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="due_date" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||||
|
Due Date *
|
||||||
|
</label>
|
||||||
|
<input type="date"
|
||||||
|
id="due_date"
|
||||||
|
wire:model="due_date"
|
||||||
|
class="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm focus:outline-none focus:ring-orange-500 focus:border-orange-500 dark:bg-zinc-700 dark:text-zinc-100">
|
||||||
|
@error('due_date')
|
||||||
|
<span class="text-red-500 text-sm">{{ $message }}</span>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="md:col-span-2">
|
||||||
|
<label for="description" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<textarea id="description"
|
||||||
|
wire:model="description"
|
||||||
|
rows="3"
|
||||||
|
placeholder="Additional notes or description for this invoice..."
|
||||||
|
class="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm focus:outline-none focus:ring-orange-500 focus:border-orange-500 dark:bg-zinc-700 dark:text-zinc-100"></textarea>
|
||||||
|
@error('description')
|
||||||
|
<span class="text-red-500 text-sm">{{ $message }}</span>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Line Items Preview -->
|
||||||
|
<div class="bg-white dark:bg-zinc-800 shadow rounded-lg p-6">
|
||||||
|
<h3 class="text-lg font-medium text-zinc-900 dark:text-zinc-100 mb-4">Line Items to be Converted</h3>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="min-w-full divide-y divide-zinc-200 dark:divide-zinc-600">
|
||||||
|
<thead class="bg-zinc-50 dark:bg-zinc-700">
|
||||||
|
<tr>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Type</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Item</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Description</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Qty</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Unit Price</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-zinc-500 dark:text-zinc-300 uppercase tracking-wider">Total</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="bg-white dark:bg-zinc-800 divide-y divide-zinc-200 dark:divide-zinc-600">
|
||||||
|
@foreach($estimate->lineItems as $item)
|
||||||
|
<tr>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
|
{{ ucfirst($item->type) }}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
|
@if($item->type === 'parts' && $item->part)
|
||||||
|
{{ $item->part->name }} ({{ $item->part->part_number }})
|
||||||
|
@else
|
||||||
|
{{ $item->description }}
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
|
{{ $item->description }}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
|
{{ $item->quantity }}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
|
${{ number_format($item->unit_price, 2) }}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-zinc-900 dark:text-zinc-100">
|
||||||
|
${{ number_format($item->total_amount, 2) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot class="bg-zinc-50 dark:bg-zinc-700">
|
||||||
|
<tr>
|
||||||
|
<td colspan="5" class="px-6 py-4 text-right text-sm font-medium text-zinc-900 dark:text-zinc-100">
|
||||||
|
Total Amount:
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-bold text-zinc-900 dark:text-zinc-100">
|
||||||
|
${{ number_format($estimate->total_amount, 2) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end space-x-4">
|
||||||
|
<a href="{{ route('invoices.index') }}"
|
||||||
|
class="px-4 py-2 border border-zinc-300 dark:border-zinc-600 rounded-md shadow-sm text-sm font-medium text-zinc-700 dark:text-zinc-300 bg-white dark:bg-zinc-800 hover:bg-zinc-50 dark:hover:bg-zinc-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
<button type="submit"
|
||||||
|
wire:loading.attr="disabled"
|
||||||
|
class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-orange-600 hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 disabled:opacity-50">
|
||||||
|
<span wire:loading.remove>Create Invoice</span>
|
||||||
|
<span wire:loading>Creating...</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Line Items -->
|
</div>
|
||||||
<div class="bg-white shadow rounded-lg p-6">
|
|
||||||
<div class="flex items-center justify-between mb-4">
|
|
||||||
<h3 class="text-lg font-medium text-gray-900">Line Items</h3>
|
|
||||||
<flux:button type="button" wire:click="addLineItem" variant="outline">
|
|
||||||
Add Item
|
|
||||||
</flux:button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-4">
|
|
||||||
@foreach($lineItems as $index => $item)
|
|
||||||
<div class="border border-gray-200 rounded-lg p-4">
|
|
||||||
<div class="flex items-center justify-between mb-4">
|
|
||||||
<h4 class="text-sm font-medium text-gray-900">Item {{ $index + 1 }}</h4>
|
|
||||||
@if(count($lineItems) > 1)
|
|
||||||
<flux:button type="button" wire:click="removeLineItem({{ $index }})" variant="danger" size="sm">
|
|
||||||
Remove
|
|
||||||
</flux:button>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-6 gap-4">
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Type</flux:label>
|
|
||||||
<flux:select wire:model="lineItems.{{ $index }}.type">
|
|
||||||
<flux:option value="service">Service</flux:option>
|
|
||||||
<flux:option value="part">Part</flux:option>
|
|
||||||
<flux:option value="other">Other</flux:option>
|
|
||||||
</flux:select>
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if($item['type'] === 'service')
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Service Item</flux:label>
|
|
||||||
<flux:select wire:model="lineItems.{{ $index }}.service_item_id">
|
|
||||||
<flux:option value="">Select service</flux:option>
|
|
||||||
@foreach($serviceItems as $serviceItem)
|
|
||||||
<flux:option value="{{ $serviceItem->id }}">{{ $serviceItem->name }} - ${{ number_format($serviceItem->price, 2) }}</flux:option>
|
|
||||||
@endforeach
|
|
||||||
</flux:select>
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
@elseif($item['type'] === 'part')
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Part</flux:label>
|
|
||||||
<select wire:model="lineItems.{{ $index }}.part_id" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
|
||||||
<option value="">Select part</option>
|
|
||||||
@foreach($parts as $part)
|
|
||||||
<option value="{{ $part->id }}">{{ $part->part_number }} - {{ $part->name }} - ${{ number_format($part->sell_price, 2) }}</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
@else
|
|
||||||
<div></div>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Description</flux:label>
|
|
||||||
<flux:input wire:model="lineItems.{{ $index }}.description" placeholder="Description" />
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Quantity</flux:label>
|
|
||||||
<flux:input type="number" wire:model="lineItems.{{ $index }}.quantity" min="1" step="1" />
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Unit Price</flux:label>
|
|
||||||
<flux:input type="number" wire:model="lineItems.{{ $index }}.unit_price" step="0.01" min="0" />
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<flux:field>
|
|
||||||
<flux:label>Total</flux:label>
|
|
||||||
<flux:input value="${{ number_format($item['total'], 2) }}" readonly />
|
|
||||||
</flux:field>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -78,7 +78,7 @@
|
|||||||
@if($item['type'] === 'parts')
|
@if($item['type'] === 'parts')
|
||||||
<div class="md:col-span-3">
|
<div class="md:col-span-3">
|
||||||
<flux:label>Part</flux:label>
|
<flux:label>Part</flux:label>
|
||||||
<select wire:model="line_items.{{ $index }}.part_id" class="w-full rounded-md border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
<select wire:model.live="line_items.{{ $index }}.part_id" class="w-full rounded-md border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||||
<option value="">Select part...</option>
|
<option value="">Select part...</option>
|
||||||
@if(count($parts) === 0)
|
@if(count($parts) === 0)
|
||||||
<option value="" disabled>No parts available</option>
|
<option value="" disabled>No parts available</option>
|
||||||
|
|||||||
@ -84,7 +84,7 @@
|
|||||||
@if($item['type'] === 'parts')
|
@if($item['type'] === 'parts')
|
||||||
<div class="md:col-span-3">
|
<div class="md:col-span-3">
|
||||||
<flux:label>Part</flux:label>
|
<flux:label>Part</flux:label>
|
||||||
<select wire:model="line_items.{{ $index }}.part_id" class="w-full rounded-md border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
<select wire:model.live="line_items.{{ $index }}.part_id" class="w-full rounded-md border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||||
<option value="">Select part...</option>
|
<option value="">Select part...</option>
|
||||||
@if(count($parts) === 0)
|
@if(count($parts) === 0)
|
||||||
<option value="" disabled>No parts available</option>
|
<option value="" disabled>No parts available</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user