topnotch_ordersystem/app/Livewire/OrderProductsCreate.php

134 lines
3.8 KiB
PHP
Raw Normal View History

2024-09-09 15:29:31 -07:00
<?php
namespace App\Livewire;
use Illuminate\Support\Collection;
use Livewire\Component;
class OrderProductsCreate extends Component
{
public Collection $productInputs;
public Collection $serviceInputs;
public function addProductInput()
{
$index = $this->productInputs->count();
$this->productInputs->push([
$index => [
'sku' => '',
'product_name' => '',
'product_color' => '',
'size_xs' => '',
'size_s' => '',
'size_m' => '',
'size_l' => '',
'size_xl' => '',
'size_2xl' => '',
'size_3xl' => '',
'size_osfa' => '',
'product_total' => '',
]
]);
}
public function calculateProductTotal($key)
{
$this->productInputs[$key]['product_total'] =
// intval($this->productInputs[$key]['size_xs']) +
// intval($this->productInputs[$key]['size_s']) +
// intval($this->productInputs[$key]['size_m']) +
// intval($this->productInputs[$key]['size_l']) +
// intval($this->productInputs[$key]['size_xl']) +
// intval($this->productInputs[$key]['size_2xl']) +
intval($this->productInputs[$key]['size_3xl']) +
intval($this->productInputs[$key]['size_osfa']);
}
public function determineAddProductRow($key)
{
if ($key == $this->productInputs->count()) {
$this->addProductInput();
}
}
public function determineAddServiceProductRow($key)
{
if ($key == $this->serviceInputs->count()) {
$this->addServiceInput();
}
}
public function removeProductInput($key)
{
if ($this->productInputs->count() > 1) {
$this->productInputs->pull($key);
}
}
public function addServiceInput()
{
$this->serviceInputs->push([
$this->serviceInputs->count() => [
'sku' => '',
'product_name' => '',
'product_color' => '',
'logo_name' => '',
'setup_number' => '',
'service_width' => '',
'service_height' => '',
'service_setup_unit' => '',
'service_setup_price' => '',
'service_total' => '',
]
]);
}
public function removeServiceInput($key)
{
if ($this->serviceInputs->count() > 1) {
$this->serviceInputs->pull($key);
}
}
public function mount()
{
$this->fill([
'productInputs' => collect([
[
'sku' => '',
'product_name' => '',
'product_color' => '',
'size_xs' => '',
'size_s' => '',
'size_m' => '',
'size_l' => '',
'size_xl' => '',
'size_2xl' => '',
'size_3xl' => '',
'size_osfa' => '',
'product_total' => '0',
]
]),
'serviceInputs' => collect([
[
'sku' => '',
'product_name' => '',
'product_color' => '',
'logo_name' => '',
'setup_number' => '',
'service_width' => '',
'service_height' => '',
'service_setup_unit' => '',
'service_setup_price' => '',
'service_total' => '',
]
]),
]);
}
public function render()
{
return view('livewire.order-products-create');
}
}