|
|
|
|
|
|
|
|
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject); |
|
|
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject); |
|
|
|
|
|
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
|
|
|
|
|
|
$distribution = $distributionManager->createDistributionIfNotExist($date); |
|
|
$distribution = $distributionManager->createDistributionIfNotExist($date); |
|
|
$ordersArray = Order::searchAll([ |
|
|
|
|
|
'distribution.id' => $distribution->id, |
|
|
|
|
|
], [ |
|
|
|
|
|
'orderby' => 'user.lastname ASC, user.name ASC' |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$ordersArray = $orderManager->findOrdersByDistribution($distribution); |
|
|
$ordersArrayObject = $ordersArray; |
|
|
$ordersArrayObject = $ordersArray; |
|
|
|
|
|
$productsArray = $productManager->findProductsByDistributionAsArray($distribution); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// products |
|
|
|
|
|
$productsQuery = Product::find() |
|
|
|
|
|
->orWhere(['id_producer' => GlobalParam::getCurrentProducerId(),]) |
|
|
|
|
|
->joinWith([ |
|
|
|
|
|
'taxRate', |
|
|
|
|
|
'productDistribution' => function ($query) use ($distribution) { |
|
|
|
|
|
$query->andOnCondition( |
|
|
|
|
|
'product_distribution.id_distribution = ' . $distribution->id |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
]) |
|
|
|
|
|
->orderBy('product_distribution.active DESC, order ASC'); |
|
|
|
|
|
|
|
|
|
|
|
$productsArray = $productsQuery->asArray()->all(); |
|
|
|
|
|
$potentialRevenues = 0; |
|
|
|
|
|
$potentialWeight = 0; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($productsArray as &$theProduct) { |
|
|
|
|
|
$productObject = $productManager->findOneProductById($theProduct['id']); |
|
|
|
|
|
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); |
|
|
|
|
|
$theProduct['quantity_ordered'] = $quantityOrder; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($theProduct['productDistribution'][0])) { |
|
|
|
|
|
$theProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $productObject); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { |
|
|
|
|
|
$theProduct['quantity_remaining'] = null; |
|
|
|
|
|
} else { |
|
|
|
|
|
$theProduct['quantity_remaining'] = $theProduct['productDistribution'][0]['quantity_max'] - $quantityOrder; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$theProduct['quantity_form'] = 0; |
|
|
|
|
|
|
|
|
|
|
|
if ($theProduct['productDistribution'][0]['active'] && $theProduct['productDistribution'][0]['quantity_max']) { |
|
|
|
|
|
$potentialRevenues += $theProduct['productDistribution'][0]['quantity_max'] * $theProduct['price']; |
|
|
|
|
|
$potentialWeight += $theProduct['productDistribution'][0]['quantity_max'] * $theProduct['weight'] / 1000; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($theProduct['taxRate'])) { |
|
|
|
|
|
$theProduct['taxRate'] = $producer->taxRate; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$json['products'] = $productsArray; |
|
|
|
|
|
|
|
|
|
|
|
$json['distribution'] = $this->buildAjaxInfosResponseDistribution($distribution, $ordersArrayObject); |
|
|
|
|
|
$json['distribution']['potential_revenues'] = Price::format($potentialRevenues); |
|
|
|
|
|
$json['distribution']['potential_weight'] = number_format($potentialWeight, 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$json['products'] = $this->buildAjaxInfosResponseProducts($producer, $distribution, $productsArray, $ordersArray); |
|
|
|
|
|
$json['distribution'] = $this->buildAjaxInfosResponseDistribution($distribution, $ordersArrayObject, $productsArray); |
|
|
$json['orders'] = $this->buildAjaxInfosResponseOrders($ordersArray, $productsArray); |
|
|
$json['orders'] = $this->buildAjaxInfosResponseOrders($ordersArray, $productsArray); |
|
|
$json['points_sale'] = $pointSaleManager->findPointSalesByDistributionAsArray($distribution); |
|
|
$json['points_sale'] = $pointSaleManager->findPointSalesByDistributionAsArray($distribution); |
|
|
$json['delivery_notes'] = $this->buildAjaxInfosResponseDeliveryNotes($date); |
|
|
$json['delivery_notes'] = $this->buildAjaxInfosResponseDeliveryNotes($date); |
|
|
|
|
|
|
|
|
return $json; |
|
|
return $json; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function buildAjaxInfosResponseProducts(Producer $producer, Distribution $distribution, array &$productsArray, array $ordersArray) |
|
|
|
|
|
{ |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($productsArray as &$theProduct) { |
|
|
|
|
|
$productObject = $productManager->findOneProductById($theProduct['id']); |
|
|
|
|
|
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); |
|
|
|
|
|
$theProduct['quantity_ordered'] = $quantityOrder; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($theProduct['productDistribution'][0])) { |
|
|
|
|
|
$theProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $productObject); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { |
|
|
|
|
|
$theProduct['quantity_remaining'] = null; |
|
|
|
|
|
} else { |
|
|
|
|
|
$theProduct['quantity_remaining'] = $theProduct['productDistribution'][0]['quantity_max'] - $quantityOrder; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$theProduct['quantity_form'] = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($theProduct['taxRate'])) { |
|
|
|
|
|
$theProduct['taxRate'] = $producer->taxRate; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $productsArray; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function buildAjaxInfosResponseProducer($producer) |
|
|
public function buildAjaxInfosResponseProducer($producer) |
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function buildAjaxInfosResponseDistribution(Distribution $distribution, array $ordersArray) |
|
|
|
|
|
|
|
|
public function buildAjaxInfosResponseDistribution(Distribution $distribution, array $ordersArray, array $productsArray) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
$orderManager = $this->getOrderManager(); |
|
|
$orderManager = $this->getOrderManager(); |
|
|
$distributionJsonData = [ |
|
|
$distributionJsonData = [ |
|
|
'id' => $distribution->id, |
|
|
'id' => $distribution->id, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
$distributionJsonData['revenues'] = Price::format($revenues); |
|
|
$distributionJsonData['revenues'] = Price::format($revenues); |
|
|
$distributionJsonData['weight'] = number_format($weight, 2); |
|
|
$distributionJsonData['weight'] = number_format($weight, 2); |
|
|
|
|
|
$distributionJsonData['potential_revenues'] = Price::format($productManager->getProductDistributionPotentialRevenues($productsArray)); |
|
|
|
|
|
$distributionJsonData['potential_weight'] = number_format($productManager->getProductDistributionPotentialWeight($productsArray), 2); |
|
|
|
|
|
|
|
|
return $distributionJsonData; |
|
|
return $distributionJsonData; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$productOrderArray[$product['id']] = [ |
|
|
$productOrderArray[$product['id']] = [ |
|
|
'quantity' => 0, |
|
|
'quantity' => 0, |
|
|
'unit' => $product['unit'], |
|
|
'unit' => $product['unit'], |
|
|
'price' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), |
|
|
|
|
|
|
|
|
//'price' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
return [ |
|
|
return [ |