Add product selection to service update

This commit is contained in:
Deon George 2025-05-16 21:42:29 +10:00
parent b33c052995
commit 622147d584
2 changed files with 21 additions and 0 deletions

View File

@ -412,6 +412,7 @@ class ServiceController extends Controller
'suspend_billing' => 'nullable|in:on', 'suspend_billing' => 'nullable|in:on',
'recur_schedule' => ['required',Rule::in(collect(Invoice::billing_periods)->keys())], 'recur_schedule' => ['required',Rule::in(collect(Invoice::billing_periods)->keys())],
'invoice_next_at' => 'nullable|date', 'invoice_next_at' => 'nullable|date',
'product_id'=>'required|exists:products,id',
'price' => 'nullable|numeric|min:0', // Price we charge the client, if we dont charge supplied/price 'price' => 'nullable|numeric|min:0', // Price we charge the client, if we dont charge supplied/price
'cost' => 'nullable|numeric|min:0', // Price we are charged by supplier, if we arent charged supplier/price 'cost' => 'nullable|numeric|min:0', // Price we are charged by supplier, if we arent charged supplier/price
'supplierid' => 'nullable|string|min:1', // As used on invoices 'supplierid' => 'nullable|string|min:1', // As used on invoices
@ -460,6 +461,7 @@ class ServiceController extends Controller
$o->price = $validated->get('price'); $o->price = $validated->get('price');
$o->cost = $validated->get('cost'); $o->cost = $validated->get('cost');
$o->supplierid = $validated->get('supplierid'); $o->supplierid = $validated->get('supplierid');
$o->product_id = $validated->get('product_id');
// Also update our service start_at date. // Also update our service start_at date.
// @todo We may want to make start_at/stop_at dynamic values calculated by the type records // @todo We may want to make start_at/stop_at dynamic values calculated by the type records

View File

@ -1,5 +1,6 @@
<!-- $o=Service::class --> <!-- $o=Service::class -->
@use(App\Models\Invoice) @use(App\Models\Invoice)
@use(App\Models\Product)
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
@ -43,6 +44,24 @@
</div> </div>
</div> </div>
<div class="row">
<div class="col-12">
<!-- PRODUCT -->
<x-leenooks::form.select name="product_id" icon="fa-list" label="Product" :helper="$o->product->category_name"
:value="$o->product_id"
:options="Product::get()
->filter(fn($item)=>($item->category === $o->product->category))
->sortBy('name')
->map(fn($item)=>[
'id'=>$item->id,
'value'=>sprintf('%s $%3.2f [%s/%3.2f]',
$item->name,
$o->account->taxed($item->base_charge)*Invoice::billing_change($item->billing_interval,Invoice::BILL_MONTHLY),
$item->supplied->name,
$o->account->taxed($item->base_cost)*Invoice::billing_change($item->billing_interval,Invoice::BILL_MONTHLY),
)])" :required="true"/>
</div>
</div>
<hr> <hr>
@includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.update',['o'=>$o->type]) @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.update',['o'=>$o->type])