137 lines
3.9 KiB
PHP
137 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Component;
|
|
|
|
class OrderProductsCreate extends Component
|
|
{
|
|
public Collection $productInputs;
|
|
public Collection $serviceInputs;
|
|
|
|
public int $productTotal = 0;
|
|
|
|
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' => '',
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function calculateProductTotal($key)
|
|
{
|
|
$this->productTotal = 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([
|
|
['0' =>
|
|
[
|
|
'sku' => '',
|
|
'product_name' => '',
|
|
'product_color' => '',
|
|
'size_xs' => '',
|
|
'size_s' => '',
|
|
'size_m' => '',
|
|
'size_l' => '',
|
|
'size_xl' => '',
|
|
'size_2xl' => '',
|
|
'size_3xl' => '',
|
|
'size_osfa' => '',
|
|
]
|
|
]
|
|
]),
|
|
'serviceInputs' => collect([
|
|
['0' =>
|
|
[
|
|
'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');
|
|
}
|
|
}
|