You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
4.3 KiB
PHP
159 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Exception;
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Component;
|
|
|
|
class OrderProductsCreate extends Component
|
|
{
|
|
public Collection $productInputs;
|
|
|
|
public Collection $serviceInputs;
|
|
|
|
public array $sizes = [];
|
|
|
|
public array $totals = [];
|
|
|
|
public array $units = [];
|
|
|
|
public array $prices = [];
|
|
|
|
public array $priceTotals = [];
|
|
|
|
public int $totalQuantity = 0;
|
|
|
|
public string $totalPrice = '$0.00';
|
|
|
|
public function updated()
|
|
{
|
|
try {
|
|
foreach ($this->sizes as $index => $size) {
|
|
$this->totals[$index] = array_sum($size);
|
|
}
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
try {
|
|
foreach ($this->units as $index => $unit) {
|
|
$this->priceTotals[$index] = $unit * $this->prices[$index];
|
|
}
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
$this->totalQuantity = array_sum($this->totals);
|
|
|
|
$this->totalPrice = '$'.number_format(round(array_sum($this->priceTotals), 2), 2);
|
|
|
|
}
|
|
|
|
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 determineAddProductRow($index)
|
|
{
|
|
if ($index == $this->productInputs->count() - 1) {
|
|
$this->addProductInput();
|
|
}
|
|
}
|
|
|
|
public function determineAddServiceProductRow($index)
|
|
{
|
|
if ($index == $this->serviceInputs->count() - 1) {
|
|
$this->addServiceInput();
|
|
}
|
|
}
|
|
|
|
public function removeProductInput($key)
|
|
{
|
|
if ($this->productInputs->count() > 1) {
|
|
$this->productInputs->pull($key);
|
|
}
|
|
}
|
|
|
|
public function addServiceInput()
|
|
{
|
|
$this->serviceInputs->push([
|
|
$this->serviceInputs->count() => [
|
|
'service_name' => '',
|
|
'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');
|
|
}
|
|
}
|