use domain\Producer\Producer\Producer; | use domain\Producer\Producer\Producer; | ||||
use domain\Producer\Producer\ProducerRepository; | use domain\Producer\Producer\ProducerRepository; | ||||
use domain\Producer\Producer\ProducerSolver; | use domain\Producer\Producer\ProducerSolver; | ||||
use domain\Product\Product\Product; | |||||
use domain\Product\Product\ProductRepository; | use domain\Product\Product\ProductRepository; | ||||
use domain\Product\Product\ProductSolver; | use domain\Product\Product\ProductSolver; | ||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
return $order; | return $order; | ||||
} | } | ||||
public function addOrUpdateOrderFromArray(Order $orderOverride, array $ordersArray): array | |||||
public function addOrUpdateOrIgnoreOrderFromArray(Order $orderOverride, array $ordersArray, bool $ignoreOrderCurrent = false): array | |||||
{ | { | ||||
$override = false; | $override = false; | ||||
foreach($ordersArray as $key => $order) { | foreach($ordersArray as $key => $order) { | ||||
if($order->id == $orderOverride->id) { | if($order->id == $orderOverride->id) { | ||||
$ordersArray[$key] = $orderOverride; | |||||
$override = true; | |||||
if($ignoreOrderCurrent) { | |||||
unset($ordersArray[$key]); | |||||
} | |||||
else { | |||||
$ordersArray[$key] = $orderOverride; | |||||
$override = true; | |||||
} | |||||
} | } | ||||
} | } | ||||
if(!$override) { | |||||
if(!$override && !$ignoreOrderCurrent) { | |||||
$ordersArray[] = $orderOverride; | $ordersArray[] = $orderOverride; | ||||
} | } | ||||
return $ordersArray; | return $ordersArray; | ||||
} | } | ||||
public function deleteProductOrderQuantity(Order $order, Product $product, float $quantity) | |||||
{ | |||||
foreach($order->productOrder as $productOrder) { | |||||
if($productOrder->id_product == $product->id) { | |||||
$productOrder->quantity -= $quantity; | |||||
} | |||||
} | |||||
} | |||||
public function initDateUpdate(Order $order) | public function initDateUpdate(Order $order) | ||||
{ | { | ||||
$order->date_update = date('Y-m-d H:i:s');; | $order->date_update = date('Y-m-d H:i:s');; |
Product $product, | Product $product, | ||||
Distribution $distribution, | Distribution $distribution, | ||||
bool $inNumberOfPieces = false, | bool $inNumberOfPieces = false, | ||||
Order $orderOverride = null | |||||
Order $orderCurrent = null, | |||||
bool $ignoreOrderCurrent = false | |||||
): float | ): float | ||||
{ | { | ||||
if(!isset($this->ordersArrayCachedByDistribution[$distribution->id])) { | if(!isset($this->ordersArrayCachedByDistribution[$distribution->id])) { | ||||
$this->ordersArrayCachedByDistribution[$distribution->id] = $this->orderRepository->findOrdersByDistribution($distribution); | $this->ordersArrayCachedByDistribution[$distribution->id] = $this->orderRepository->findOrdersByDistribution($distribution); | ||||
} | } | ||||
$ordersArray = $this->ordersArrayCachedByDistribution[$distribution->id]; | $ordersArray = $this->ordersArrayCachedByDistribution[$distribution->id]; | ||||
if($orderOverride) { | |||||
$ordersArray = $this->orderBuilder->addOrUpdateOrderFromArray($orderOverride, $ordersArray); | |||||
if($orderCurrent) { | |||||
$ordersArray = $this->orderBuilder->addOrUpdateOrIgnoreOrderFromArray($orderCurrent, $ordersArray, $ignoreOrderCurrent); | |||||
} | } | ||||
$productQuantity = $this->orderSolver->getProductQuantity($product, $ordersArray); | $productQuantity = $this->orderSolver->getProductQuantity($product, $ordersArray); | ||||
return $quantityMax; | return $quantityMax; | ||||
} | } | ||||
public function getProductQuantityMaxOrderable(Product $product, Distribution $distribution, Order $orderCurrent = null): ?float | |||||
{ | |||||
return $this->getProductQuantityRemaining($product, $distribution, $orderCurrent, true); | |||||
} | |||||
public function getQuantityOfAccessoryAvailableInDistribution( | public function getQuantityOfAccessoryAvailableInDistribution( | ||||
Accessory $accessory, | Accessory $accessory, | ||||
Distribution $distribution, | Distribution $distribution, | ||||
Order $orderOverride = null | |||||
Order $orderCurrent = null, | |||||
bool $ignoreOrderCurrent = false | |||||
): int | ): int | ||||
{ | { | ||||
$quantityOfAccessoryUsed = 0; | $quantityOfAccessoryUsed = 0; | ||||
$productAccessory->getProduct(), | $productAccessory->getProduct(), | ||||
$distribution, | $distribution, | ||||
true, | true, | ||||
$orderOverride | |||||
$orderCurrent, | |||||
$ignoreOrderCurrent | |||||
); | ); | ||||
} | } | ||||
public function getSmallestQuantityAccessoryAvailable( | public function getSmallestQuantityAccessoryAvailable( | ||||
Product $product, | Product $product, | ||||
Distribution $distribution, | Distribution $distribution, | ||||
Order $orderOverride = null | |||||
Order $orderCurrent = null, | |||||
bool $ignoreOrderCurrent = false | |||||
): ?int | ): ?int | ||||
{ | { | ||||
$smallestQuantity = null; | $smallestQuantity = null; | ||||
$quantityAccessoryAvailableInDistribution = $this->getQuantityOfAccessoryAvailableInDistribution( | $quantityAccessoryAvailableInDistribution = $this->getQuantityOfAccessoryAvailableInDistribution( | ||||
$productAccessory->getAccessory(), | $productAccessory->getAccessory(), | ||||
$distribution, | $distribution, | ||||
$orderOverride | |||||
$orderCurrent, | |||||
$ignoreOrderCurrent | |||||
); | ); | ||||
$smallestQuantity = is_null($smallestQuantity) ? $quantityAccessoryAvailableInDistribution | $smallestQuantity = is_null($smallestQuantity) ? $quantityAccessoryAvailableInDistribution | ||||
: min($smallestQuantity, $quantityAccessoryAvailableInDistribution); | : min($smallestQuantity, $quantityAccessoryAvailableInDistribution); | ||||
public function getProductQuantityRemaining( | public function getProductQuantityRemaining( | ||||
Product $product, | Product $product, | ||||
Distribution $distribution, | Distribution $distribution, | ||||
Order $orderOverride = null | |||||
Order $orderCurrent = null, | |||||
bool $ignoreOrderCurrent = false | |||||
): ?float | ): ?float | ||||
{ | { | ||||
$productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product); | $productDistribution = $this->productDistributionRepository->findOneProductDistribution($distribution, $product); | ||||
$product, | $product, | ||||
$distribution, | $distribution, | ||||
false, | false, | ||||
$orderOverride | |||||
$orderCurrent, | |||||
$ignoreOrderCurrent | |||||
); | ); | ||||
$quantityRemaining = is_null($productDistribution->quantity_max) ? null | $quantityRemaining = is_null($productDistribution->quantity_max) ? null | ||||
: ($productDistribution->quantity_max - $quantityOrder); | : ($productDistribution->quantity_max - $quantityOrder); | ||||
$smallestQuantityAccessoryAvailable = $this->getSmallestQuantityAccessoryAvailable( | $smallestQuantityAccessoryAvailable = $this->getSmallestQuantityAccessoryAvailable( | ||||
$product, | $product, | ||||
$distribution, | $distribution, | ||||
$orderOverride | |||||
$orderCurrent, | |||||
$ignoreOrderCurrent | |||||
); | ); | ||||
if (!is_null($smallestQuantityAccessoryAvailable)) { | if (!is_null($smallestQuantityAccessoryAvailable)) { | ||||
$smallestQuantityAccessoryAvailable = $this->productSolver->getWeightOrNumberOfPieces($smallestQuantityAccessoryAvailable, $product); | $smallestQuantityAccessoryAvailable = $this->productSolver->getWeightOrNumberOfPieces($smallestQuantityAccessoryAvailable, $product); |
$productsArrayFilter = $productModule->filterProductsByPointSale($productsArray, $pointSale); | $productsArrayFilter = $productModule->filterProductsByPointSale($productsArray, $pointSale); | ||||
$orderCurrent = $order; | |||||
if(count($productsFormArray)) { | |||||
$productOrdersArray = []; | |||||
foreach($productsFormArray as $idProduct => $quantityProduct) { | |||||
if($idProduct) { | |||||
$productObject1 = $productModule->getRepository()->findOneProductById($idProduct); | |||||
$productOrdersArray[$idProduct] = [ | |||||
'quantity' => $quantityProduct / $productModule->getSolver()->getUnitCoefficient($productObject1) | |||||
]; | |||||
} | |||||
} | |||||
$orderCurrent = $orderModule->getBuilder()->instanciateOrderFromProductOrdersArray($productOrdersArray, $orderCurrent); | |||||
} | |||||
$indexProduct = 0; | $indexProduct = 0; | ||||
foreach ($productsArrayFilter as $key => &$product) { | foreach ($productsArrayFilter as $key => &$product) { | ||||
$productObject = $product; | $productObject = $product; | ||||
] | ] | ||||
); | ); | ||||
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; | |||||
if (is_null($product['photo']) || strlen($product['photo']) == 0) { | if (is_null($product['photo']) || strlen($product['photo']) == 0) { | ||||
$product['photo'] = ''; | $product['photo'] = ''; | ||||
} | } | ||||
$product['photo'] = Image::getThumbnailSmall($product['photo']); | $product['photo'] = Image::getThumbnailSmall($product['photo']); | ||||
} | } | ||||
$orderOverride = $order; | |||||
if(count($productsFormArray)) { | |||||
$productOrdersArray = []; | |||||
foreach($productsFormArray as $idProduct => $quantityProduct) { | |||||
if($idProduct) { | |||||
$productObject1 = $productModule->getRepository()->findOneProductById($idProduct); | |||||
$productOrdersArray[$idProduct] = [ | |||||
'quantity' => $quantityProduct / $productModule->getSolver()->getUnitCoefficient($productObject1) | |||||
]; | |||||
} | |||||
} | |||||
$orderOverride = $orderModule->getBuilder()->instanciateOrderFromProductOrdersArray($productOrdersArray, $orderOverride); | |||||
} | |||||
$quantityOrder = $orderModule->getResolver()->getProductQuantityByDistribution($productObject, $distribution, false, $orderOverride); | |||||
$product['quantity_ordered'] = $quantityOrder; | |||||
$product['quantity_max'] = $orderModule->getResolver()->getProductQuantityMax($productObject, $distribution); | |||||
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution); | |||||
$coefficientUnit = Product::$unitsArray[$product['unit']]['coefficient']; | |||||
$product['coefficient_unit'] = $coefficientUnit; | |||||
$product['quantity_max'] = $orderModule->getResolver()->getProductQuantityMaxOrderable($productObject, $distribution, $orderCurrent); | |||||
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution, $orderCurrent); | |||||
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_UNIT, true); | $product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_UNIT, true); | ||||
$product['wording_unit_ref'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_SHORT, true); | $product['wording_unit_ref'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_SHORT, true); | ||||
$quantityOrderUser = $orderModule->getSolver()->getProductQuantity($productObject, $orderOverride ? [$orderOverride] : [], true); | |||||
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; | |||||
$quantityOrderUser = $orderModule->getSolver()->getProductQuantity($productObject, $orderCurrent ? [$orderCurrent] : [], true); | |||||
$product['quantity_form'] = $quantityOrderUser * $coefficientUnit; | |||||
if($product['quantity_remaining'] < 0 && $product['quantity_form']) { | |||||
$product['quantity_form'] = $product['quantity_form'] + ($product['quantity_remaining'] * $coefficientUnit); | |||||
$orderModule->getBuilder()->deleteProductOrderQuantity($orderCurrent, $productObject, abs($product['quantity_remaining'])); | |||||
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution, $orderCurrent); | |||||
} | |||||
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], 'wording_unit', true); | $product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], 'wording_unit', true); | ||||
if ($order) { | if ($order) { | ||||
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution, $orderOverride); | |||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if ($productOrder->id_product == $product['id']) { | if ($productOrder->id_product == $product['id']) { | ||||
$product['wording_unit'] = $productModule->getSolver()->strUnit($productOrder->product, 'wording_unit', true); | $product['wording_unit'] = $productModule->getSolver()->strUnit($productOrder->product, 'wording_unit', true); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$product['coefficient_unit'] = $coefficient_unit; | |||||
if ($product['quantity_remaining'] < 0) { | |||||
$product['quantity_remaining'] = 0; | |||||
} | |||||
$product['index'] = $indexProduct++; | $product['index'] = $indexProduct++; | ||||
} | } | ||||
<span v-if="product.weight">({{ product.weight }} g)</span> | <span v-if="product.weight">({{ product.weight }} g)</span> | ||||
</span> | </span> | ||||
<div> | <div> | ||||
<span v-if="product.quantity_max > 0 && (product.quantity_remaining == 0 || product.quantity_remaining * product.coefficient_unit < product.step)" | |||||
<span v-if="product.quantity_max > 0 && (product.quantity_remaining <= 0 || product.quantity_remaining * product.coefficient_unit < product.step)" | |||||
class="badge bg-danger">Épuisé</span> | class="badge bg-danger">Épuisé</span> | ||||
</div> | </div> | ||||
<div class="description" v-if="product.description.length"> | <div class="description" v-if="product.description.length"> | ||||
<button class="btn btn-secondary btn-plus" | <button class="btn btn-secondary btn-plus" | ||||
type="button" | type="button" | ||||
@click="productQuantityClick(product, product.unit == 'piece' ? 1 : parseFloat(product.step))" | @click="productQuantityClick(product, product.unit == 'piece' ? 1 : parseFloat(product.step))" | ||||
:disabled="product.quantity_remaining == 0 || loadingProducts"> | |||||
:disabled="product.quantity_remaining <= 0 || product.quantity_form >= product.quantity_max || loadingProducts"> | |||||
<i class="bi bi-plus-lg"></i></button> | <i class="bi bi-plus-lg"></i></button> | ||||
</span> | </span> | ||||
</div> | </div> |
loading: false, | loading: false, | ||||
loadingProducts: false, | loadingProducts: false, | ||||
loadingInit: true, | loadingInit: true, | ||||
cancelTokenSource: null, | |||||
step: null, | step: null, | ||||
producer: null, | producer: null, | ||||
user: null, | user: null, | ||||
var app = this ; | var app = this ; | ||||
if(loadingProducts) { | if(loadingProducts) { | ||||
this.loadingProducts = true ; | |||||
if(app.cancelTokenSource !== null) { | |||||
app.cancelTokenSource.cancel(); | |||||
} | |||||
} | } | ||||
else { | else { | ||||
this.loading = true ; | this.loading = true ; | ||||
app.products = [] ; | app.products = [] ; | ||||
} | } | ||||
axios.get("ajax-infos",{params: { | |||||
date : this.getDate(), | |||||
pointSaleId: this.pointSaleActiveId ? this.pointSaleActiveId : (this.pointSaleActive ? this.pointSaleActive.id : 0), | |||||
productsJson: this.getProductsArray(), | |||||
loadingProducts: loadingProducts | |||||
app.cancelTokenSource = axios.CancelToken.source(); | |||||
axios.get("ajax-infos",{ | |||||
cancelToken: app.cancelTokenSource.token, | |||||
params: { | |||||
date : this.getDate(), | |||||
pointSaleId: this.pointSaleActiveId ? this.pointSaleActiveId : (this.pointSaleActive ? this.pointSaleActive.id : 0), | |||||
productsJson: this.getProductsArray(), | |||||
loadingProducts: loadingProducts | |||||
}}) | }}) | ||||
.catch(function (thrown) { | |||||
if (axios.isCancel(thrown)) { | |||||
//console.log('Request canceled', thrown.message); | |||||
//return Promise.reject(thrown); | |||||
} | |||||
}) | |||||
.then(function(response) { | .then(function(response) { | ||||
app.calendar.attrs = []; | |||||
app.calendar.availableDates = []; | |||||
var distributions = response.data.distributions; | |||||
app.distributions = distributions; | |||||
if (distributions.length) { | |||||
var arrayDate; | |||||
var highlightStyle = { | |||||
style: { | |||||
background: 'white', | |||||
border: 'solid 2px #198754' | |||||
}, | |||||
contentStyle: { | |||||
color: '#198754' | |||||
} | |||||
}; | |||||
for (var i = 0; i < distributions.length; i++) { | |||||
app.calendar.attrs.push({ | |||||
highlight: highlightStyle, | |||||
dates: distributions[i].date | |||||
}); | |||||
if(response) { | |||||
app.calendar.attrs = []; | |||||
app.calendar.availableDates = []; | |||||
var distributions = response.data.distributions; | |||||
app.distributions = distributions; | |||||
if (distributions.length) { | |||||
var arrayDate; | |||||
var highlightStyle = { | |||||
style: { | |||||
background: 'white', | |||||
border: 'solid 2px #198754' | |||||
}, | |||||
contentStyle: { | |||||
color: '#198754' | |||||
} | |||||
}; | |||||
for (var i = 0; i < distributions.length; i++) { | |||||
app.calendar.attrs.push({ | |||||
highlight: highlightStyle, | |||||
dates: distributions[i].date | |||||
}); | |||||
arrayDate = distributions[i].date.split('-'); | |||||
app.calendar.availableDates.push({ | |||||
highlight: highlightStyle, | |||||
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | |||||
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | |||||
}); | |||||
arrayDate = distributions[i].date.split('-'); | |||||
app.calendar.availableDates.push({ | |||||
highlight: highlightStyle, | |||||
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | |||||
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | |||||
}); | |||||
} | |||||
} | } | ||||
} | |||||
if(response.data.leave_period) { | |||||
leavePeriodStartDateArray = response.data.leave_period.start.split('-'); | |||||
leavePeriodEndDateArray = response.data.leave_period.end.split('-'); | |||||
if (response.data.leave_period) { | |||||
leavePeriodStartDateArray = response.data.leave_period.start.split('-'); | |||||
leavePeriodEndDateArray = response.data.leave_period.end.split('-'); | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
style: { | |||||
//background: '#E09F3E' | |||||
background: 'gray' | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
style: { | |||||
//background: '#E09F3E' | |||||
background: 'gray' | |||||
}, | |||||
contentStyle: { | |||||
color: 'white' | |||||
} | |||||
}, | }, | ||||
contentStyle: { | |||||
color: 'white' | |||||
} | |||||
}, | |||||
dates: { | |||||
start: new Date(leavePeriodStartDateArray[0], leavePeriodStartDateArray[1] - 1, leavePeriodStartDateArray[2]), | |||||
end: new Date(leavePeriodEndDateArray[0], leavePeriodEndDateArray[1] - 1, leavePeriodEndDateArray[2]) | |||||
}, | |||||
popover: { | |||||
label: 'En congé', | |||||
hideIndicator: true, | |||||
isInteractive: true | |||||
}, | |||||
}); | |||||
} | |||||
dates: { | |||||
start: new Date(leavePeriodStartDateArray[0], leavePeriodStartDateArray[1] - 1, leavePeriodStartDateArray[2]), | |||||
end: new Date(leavePeriodEndDateArray[0], leavePeriodEndDateArray[1] - 1, leavePeriodEndDateArray[2]) | |||||
}, | |||||
popover: { | |||||
label: 'En congé', | |||||
hideIndicator: true, | |||||
isInteractive: true | |||||
}, | |||||
}); | |||||
} | |||||
if (response.data.distribution) { | |||||
app.distribution = response.data.distribution; | |||||
} | |||||
if (response.data.distribution) { | |||||
app.distribution = response.data.distribution; | |||||
} | |||||
var orders = []; | |||||
if (response.data.orders) { | |||||
orders = response.data.orders; | |||||
} | |||||
var orders = []; | |||||
if (response.data.orders) { | |||||
orders = response.data.orders; | |||||
} | |||||
if (orders.length) { | |||||
for (var i = 0; i < orders.length; i++) { | |||||
arrayDate = orders[i].date_distribution.split('-'); | |||||
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]); | |||||
if (app.isAvailableDate(dateOrder)) { | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
style: { | |||||
background: '#198754' | |||||
if (orders.length) { | |||||
for (var i = 0; i < orders.length; i++) { | |||||
arrayDate = orders[i].date_distribution.split('-'); | |||||
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]); | |||||
if (app.isAvailableDate(dateOrder)) { | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
style: { | |||||
background: '#198754' | |||||
}, | |||||
contentStyle: { | |||||
color: 'white' | |||||
} | |||||
}, | }, | ||||
contentStyle: { | |||||
color: 'white' | |||||
} | |||||
}, | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' (' + app.formatPrice(orders[i].amount_total)+')', | |||||
hideIndicator: true, | |||||
isInteractive: true | |||||
}, | |||||
dates: orders[i].date_distribution | |||||
}); | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' (' + app.formatPrice(orders[i].amount_total) + ')', | |||||
hideIndicator: true, | |||||
isInteractive: true | |||||
}, | |||||
dates: orders[i].date_distribution | |||||
}); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | |||||
app.producer = response.data.producer; | |||||
app.user = response.data.user; | |||||
app.useCredit = response.data.producer.use_credit_checked_default; | |||||
app.producer = response.data.producer; | |||||
app.user = response.data.user; | |||||
app.useCredit = response.data.producer.use_credit_checked_default; | |||||
if (response.data.points_sale) { | |||||
app.pointsSale = []; | |||||
var orderPointSale = 0; | |||||
for (var key in response.data.points_sale) { | |||||
response.data.points_sale[key].order = orderPointSale++; | |||||
app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key]; | |||||
if (response.data.points_sale) { | |||||
app.pointsSale = []; | |||||
var orderPointSale = 0; | |||||
for (var key in response.data.points_sale) { | |||||
response.data.points_sale[key].order = orderPointSale++; | |||||
app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key]; | |||||
if(!app.pointsSaleCodes[response.data.points_sale[key].id]) { | |||||
app.pointsSaleCodes[response.data.points_sale[key].id] = ''; | |||||
Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | |||||
if (!app.pointsSaleCodes[response.data.points_sale[key].id]) { | |||||
app.pointsSaleCodes[response.data.points_sale[key].id] = ''; | |||||
Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | |||||
if(app.pointSaleActiveId) { | |||||
app.pointSaleActive = app.getPointSale(app.pointSaleActiveId); | |||||
} | |||||
if(app.pointSaleActive) { | |||||
if(app.producer.credit | |||||
&& app.pointSaleActive.payment_method_credit | |||||
&& (app.pointSaleActive.credit_functioning == 'mandatory' | |||||
|| (app.pointSaleActive.credit_functioning == 'user' && app.user.credit_active) | |||||
|| (app.pointSaleActive.credit_functioning == 'optional' && response.data.producer.use_credit_checked_default))) { | |||||
app.paymentMethod = 'credit'; | |||||
if (app.pointSaleActiveId) { | |||||
app.pointSaleActive = app.getPointSale(app.pointSaleActiveId); | |||||
} | } | ||||
else if(app.pointSaleActive.payment_method_onsite) { | |||||
app.paymentMethod = 'onsite'; | |||||
if (app.pointSaleActive) { | |||||
if (app.producer.credit | |||||
&& app.pointSaleActive.payment_method_credit | |||||
&& (app.pointSaleActive.credit_functioning == 'mandatory' | |||||
|| (app.pointSaleActive.credit_functioning == 'user' && app.user.credit_active) | |||||
|| (app.pointSaleActive.credit_functioning == 'optional' && response.data.producer.use_credit_checked_default))) { | |||||
app.paymentMethod = 'credit'; | |||||
} else if (app.pointSaleActive.payment_method_onsite) { | |||||
app.paymentMethod = 'onsite'; | |||||
} else if (app.pointSaleActive.payment_method_online) { | |||||
app.paymentMethod = 'online'; | |||||
} | |||||
} | } | ||||
else if(app.pointSaleActive.payment_method_online) { | |||||
app.paymentMethod = 'online'; | |||||
if (app.isChangeState('point-sale', 'point-sale', 'date')) { | |||||
app.date = null; | |||||
app.dateFormat = null; | |||||
} | } | ||||
} | |||||
if(app.isChangeState('point-sale', 'point-sale', 'date')) { | |||||
app.date = null ; | |||||
app.dateFormat = null ; | |||||
} | |||||
// update order | |||||
var updateOrder = false; | |||||
if (app.isChangeState('date', 'point-sale', 'products') | |||||
|| app.isChangeState('date', 'date', 'point-sale') | |||||
|| app.isChangeState('point-sale', 'date', 'products') | |||||
|| app.isChangeState('point-sale', 'point-sale', 'date')) { | |||||
// update order | |||||
var updateOrder = false ; | |||||
if(app.isChangeState('date', 'point-sale', 'products') | |||||
|| app.isChangeState('date', 'date', 'point-sale') | |||||
|| app.isChangeState('point-sale', 'date', 'products') | |||||
|| app.isChangeState('point-sale', 'point-sale', 'date')) { | |||||
updateOrder = true; | |||||
} | |||||
updateOrder = true ; | |||||
} | |||||
if (updateOrder) { | |||||
app.updateOrder(response); | |||||
} | |||||
if(updateOrder) { | |||||
app.updateOrder(response); | |||||
} | |||||
if (type == 'first') { | |||||
if (app.getDate() && app.pointSaleActive) { | |||||
app.step = 'products'; | |||||
if (response.data.products) { | |||||
app.products = response.data.products; | |||||
} | |||||
if(type == 'first') { | |||||
if(app.getDate() && app.pointSaleActive) { | |||||
app.step = 'products' ; | |||||
if(response.data.products) { | |||||
app.products = response.data.products; | |||||
app.updateOrder(response); | |||||
} else if (app.producer.option_order_entry_point == 'point-sale') { | |||||
app.step = 'point-sale'; | |||||
} else if (app.getDate() && app.producer && app.producer.option_order_entry_point == 'date') { | |||||
app.step = 'point-sale'; | |||||
} else { | |||||
app.step = 'date'; | |||||
} | } | ||||
app.updateOrder(response); | |||||
} | } | ||||
else if(app.producer.option_order_entry_point == 'point-sale') { | |||||
app.step = 'point-sale' ; | |||||
} | |||||
else if(app.getDate() && app.producer && app.producer.option_order_entry_point == 'date') { | |||||
app.step = 'point-sale' ; | |||||
} | |||||
else { | |||||
app.step = 'date' ; | |||||
} | |||||
} | |||||
if(response.data.categories) { | |||||
app.categories = response.data.categories ; | |||||
for(keyCategory in response.data.categories) { | |||||
var category = response.data.categories[keyCategory]; | |||||
if(category.id && app.countProductsByCategory(category)) { | |||||
app.setCategoryCurrent(category, true) ; | |||||
break; | |||||
if (response.data.categories) { | |||||
app.categories = response.data.categories; | |||||
for (keyCategory in response.data.categories) { | |||||
var category = response.data.categories[keyCategory]; | |||||
if (category.id && app.countProductsByCategory(category)) { | |||||
app.setCategoryCurrent(category, true); | |||||
break; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | |||||
setTimeout(function() { | |||||
app.responsive(); | |||||
opendistrib_products(); | |||||
}, 500); | |||||
setTimeout(function () { | |||||
app.responsive(); | |||||
opendistrib_products(); | |||||
}, 500); | |||||
app.loading = false ; | |||||
app.loadingProducts = false ; | |||||
app.loadingInit = false ; | |||||
app.loading = false; | |||||
app.loadingProducts = false; | |||||
app.loadingInit = false; | |||||
} | |||||
}); | }); | ||||
}, | }, | ||||
updateOrder: function(response) { | updateOrder: function(response) { | ||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
if(this.products[product.index].quantity_form + quantity >= 0 | if(this.products[product.index].quantity_form + quantity >= 0 | ||||
&& this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_max * this.products[product.index].coefficient_unit | |||||
&& (quantity <= (this.products[product.index].quantity_remaining * this.products[product.index].coefficient_unit) | && (quantity <= (this.products[product.index].quantity_remaining * this.products[product.index].coefficient_unit) | ||||
|| this.products[product.index].quantity_remaining == null) | || this.products[product.index].quantity_remaining == null) | ||||
) { | ) { |