|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionAjaxInfos(string $date = '', int $pointSaleId = 0, string $productsJson = null) |
|
|
|
|
|
|
|
|
public function actionAjaxInfos(string $date = '', int $pointSaleId = 0, string $productsJson = null, bool $loadingProducts = false) |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
$productsArray = json_decode($productsJson, true); |
|
|
$productsArray = json_decode($productsJson, true); |
|
|
|
|
|
|
|
|
$pointSale = $this->getPointSaleModule()->findOnePointSaleById($pointSaleId); |
|
|
$pointSale = $this->getPointSaleModule()->findOnePointSaleById($pointSaleId); |
|
|
$order = $this->getOrderUser($date, $pointSale); |
|
|
$order = $this->getOrderUser($date, $pointSale); |
|
|
|
|
|
|
|
|
return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order, $productsArray); |
|
|
|
|
|
|
|
|
return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order, $productsArray, $loadingProducts); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function buildJsonAjaxInfos( |
|
|
public function buildJsonAjaxInfos( |
|
|
|
|
|
|
|
|
PointSale $pointSale = null, |
|
|
PointSale $pointSale = null, |
|
|
User $user = null, |
|
|
User $user = null, |
|
|
Order $order = null, |
|
|
Order $order = null, |
|
|
array $productsArray = null |
|
|
|
|
|
|
|
|
array $productsArray = null, |
|
|
|
|
|
bool $loadingProducts = false |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
$orderModule = $this->getOrderModule(); |
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
|
|
|
|
|
$product['photo'] = Image::getThumbnailSmall($product['photo']); |
|
|
$product['photo'] = Image::getThumbnailSmall($product['photo']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$quantityOrder = $orderModule->getResolver()->getProductQuantityByDistribution($productObject, $distribution); |
|
|
|
|
|
|
|
|
$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_ordered'] = $quantityOrder; |
|
|
$product['quantity_max'] = $orderModule->getResolver()->getProductQuantityMax($productObject, $distribution); |
|
|
$product['quantity_max'] = $orderModule->getResolver()->getProductQuantityMax($productObject, $distribution); |
|
|
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution); |
|
|
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution); |
|
|
$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; |
|
|
|
|
|
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], 'wording_unit', true); |
|
|
|
|
|
|
|
|
if ($order) { |
|
|
if ($order) { |
|
|
|
|
|
|
|
|
$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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$quantityOrderUser = $orderModule->getSolver()->getProductQuantity($productObject, [$orderOverride], true); |
|
|
|
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
|
|
|
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution, $orderOverride); |
|
|
$product['quantity_remaining'] = $orderModule->getResolver()->getProductQuantityRemaining($productObject, $distribution, $orderOverride); |
|
|
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; |
|
|
|
|
|
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['step'] = $productOrder->step; |
|
|
$product['step'] = $productOrder->step; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
$product['quantity_form'] = 0; |
|
|
|
|
|
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], 'wording_unit', true); |
|
|
|
|
|
} |
|
|
} |
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
|
|
|
|