use domain\Product\Accessory\Accessory; | use domain\Product\Accessory\Accessory; | ||||
use domain\Product\Product\Product; | use domain\Product\Product\Product; | ||||
use domain\Product\Product\ProductSolver; | use domain\Product\Product\ProductSolver; | ||||
use yii\base\ErrorException; | |||||
class OrderResolver extends AbstractResolver | class OrderResolver extends AbstractResolver | ||||
{ | { | ||||
public function getProductQuantityMaxOrderable(Product $product, Distribution $distribution, Order $orderCurrent = null): ?float | public function getProductQuantityMaxOrderable(Product $product, Distribution $distribution, Order $orderCurrent = null): ?float | ||||
{ | { | ||||
return $this->orderSolver->getProductQuantity($product, $orderCurrent ? [$orderCurrent] : []) | |||||
+ $this->getProductQuantityRemaining($product, $distribution, $orderCurrent); | |||||
$productQuantity = $this->orderSolver->getProductQuantity($product, $orderCurrent ? [$orderCurrent] : []); | |||||
$productQuantityRemaining = $this->getProductQuantityRemaining($product, $distribution, $orderCurrent); | |||||
if(is_null($productQuantityRemaining)) { | |||||
return null; | |||||
} | |||||
return $productQuantity + $productQuantityRemaining; | |||||
} | } | ||||
public function getQuantityOfAccessoryAvailableInDistribution( | public function getQuantityOfAccessoryAvailableInDistribution( |
<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 != null && (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="loadingProducts || product.quantity_remaining <= 0 || product.quantity_form >= product.quantity_max * product.coefficient_unit"> | |||||
:disabled="loadingProducts || (product.quantity_remaining != null && product.quantity_remaining <= 0) || (product.quantity_max != null && product.quantity_form >= product.quantity_max * product.coefficient_unit)"> | |||||
<i class="bi bi-plus-lg"></i></button> | <i class="bi bi-plus-lg"></i></button> | ||||
</span> | </span> | ||||
</div> | </div> |
}, | }, | ||||
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) | |||||
|| this.products[product.index].quantity_remaining == null) | |||||
&& (this.products[product.index].quantity_max == null | |||||
|| this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_max * this.products[product.index].coefficient_unit) | |||||
&& (this.products[product.index].quantity_remaining == null | |||||
|| (quantity <= (this.products[product.index].quantity_remaining * this.products[product.index].coefficient_unit))) | |||||
) { | ) { | ||||
var theQuantity = parseFloat(this.products[product.index].quantity_form) + parseFloat(quantity); | var theQuantity = parseFloat(this.products[product.index].quantity_form) + parseFloat(quantity); | ||||
this.products[product.index].quantity_form = parseFloat(theQuantity.toFixed(2)) ; | this.products[product.index].quantity_form = parseFloat(theQuantity.toFixed(2)) ; |