$distribution = $distributionManager->createDistributionIfNotExist($date); | $distribution = $distributionManager->createDistributionIfNotExist($date); | ||||
$ordersArray = $orderManager->findOrdersByDistribution($distribution); | $ordersArray = $orderManager->findOrdersByDistribution($distribution); | ||||
$ordersArrayObject = $ordersArray; | $ordersArrayObject = $ordersArray; | ||||
$productsArray = $productManager->findProductsByDistributionAsArray($distribution); | |||||
$productsArray = $productManager->findProductsByDistribution($distribution); | |||||
$json['products'] = $this->buildAjaxInfosResponseProducts($producer, $distribution, $productsArray, $ordersArray); | |||||
$json['products'] = $this->buildAjaxInfosResponseProducts($distribution, $productsArray, $ordersArray); | |||||
$json['distribution'] = $this->buildAjaxInfosResponseDistribution($distribution, $ordersArrayObject, $productsArray); | $json['distribution'] = $this->buildAjaxInfosResponseDistribution($distribution, $ordersArrayObject, $productsArray); | ||||
$json['orders'] = $this->buildAjaxInfosResponseOrders($ordersArray, $productsArray); | $json['orders'] = $this->buildAjaxInfosResponseOrders($ordersArray, $productsArray); | ||||
$json['points_sale'] = $this->buildAjaxInfosResponsePointsSale($distribution); | $json['points_sale'] = $this->buildAjaxInfosResponsePointsSale($distribution); | ||||
return $pointsSaleArray; | return $pointsSaleArray; | ||||
} | } | ||||
public function buildAjaxInfosResponseProducts(Producer $producer, Distribution $distribution, array &$productsArray, array $ordersArray) | |||||
public function buildAjaxInfosResponseProducts(Distribution $distribution, array $productsArray, array $ordersArray) | |||||
{ | { | ||||
$distributionManager = $this->getDistributionManager(); | $distributionManager = $this->getDistributionManager(); | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$productManager = $this->getProductManager(); | |||||
$jsonProductsArray = []; | |||||
foreach ($productsArray as &$theProduct) { | |||||
$productObject = $productManager->findOneProductById($theProduct['id']); | |||||
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); | |||||
$theProduct['quantity_ordered'] = $quantityOrder; | |||||
foreach ($productsArray as $product) { | |||||
$jsonProduct = $product->getAttributes(); | |||||
$quantityOrder = $orderManager->getProductQuantity($product, $ordersArray); | |||||
$jsonProduct['quantity_ordered'] = $quantityOrder; | |||||
if (!isset($theProduct['productDistribution'][0])) { | |||||
$theProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $productObject); | |||||
if (!isset($product->productDistribution[0])) { | |||||
$jsonProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $product)->getAttributes(); | |||||
} | |||||
else { | |||||
foreach($product->productDistribution as $key => $productDistribution) { | |||||
$jsonProduct['productDistribution'][$key] = $productDistribution->getAttributes(); | |||||
} | |||||
} | } | ||||
if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | |||||
$theProduct['quantity_remaining'] = null; | |||||
if (!is_numeric($product->productDistribution[0]->quantity_max)) { | |||||
$jsonProduct['quantity_remaining'] = null; | |||||
} else { | } else { | ||||
$theProduct['quantity_remaining'] = $theProduct['productDistribution'][0]['quantity_max'] - $quantityOrder; | |||||
$jsonProduct['quantity_remaining'] = $product->productDistribution[0]->quantity_max - $quantityOrder; | |||||
} | } | ||||
$theProduct['quantity_form'] = 0; | |||||
$jsonProduct['quantity_form'] = 0; | |||||
if (!isset($theProduct['taxRate'])) { | |||||
$theProduct['taxRate'] = $producer->taxRate; | |||||
if (!$product->taxRate) { | |||||
$jsonProduct['taxRate'] = $this->getProducerCurrent()->taxRate; | |||||
} | } | ||||
$jsonProductsArray[] = $jsonProduct; | |||||
} | } | ||||
return $productsArray; | |||||
return $jsonProductsArray; | |||||
} | } | ||||
public function buildAjaxInfosResponseProducer($producer) | public function buildAjaxInfosResponseProducer($producer) |
namespace common\helpers; | namespace common\helpers; | ||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\Producer\Producer\Wrapper\ProducerManager; | |||||
use common\logic\User\User\Service\UserSolver; | use common\logic\User\User\Service\UserSolver; | ||||
class GlobalParam | class GlobalParam | ||||
public static function getCurrentProducer() | public static function getCurrentProducer() | ||||
{ | { | ||||
$producerManager = ProducerManager::getInstance(); | |||||
if(!\Yii::$app->parameterBag->has('producer') || !\Yii::$app->parameterBag->get('producer')) { | if(!\Yii::$app->parameterBag->has('producer') || !\Yii::$app->parameterBag->get('producer')) { | ||||
\Yii::$app->parameterBag->set('producer', Producer::searchOne()); | |||||
\Yii::$app->parameterBag->set('producer', $producerManager->findOneProducerById(self::getCurrentProducerId())); | |||||
} | } | ||||
return \Yii::$app->parameterBag->get('producer'); | return \Yii::$app->parameterBag->get('producer'); |
self::JOIN_WITH => [ | self::JOIN_WITH => [ | ||||
'distribution', | 'distribution', | ||||
'user', | 'user', | ||||
'user.userProducer' | |||||
'user.userProducer', | |||||
//'payment' | |||||
], | ], | ||||
self::ORDER_BY => 'order.date ASC', | self::ORDER_BY => 'order.date ASC', | ||||
self::ATTRIBUTE_ID_PRODUCER => 'distribution.id_producer' | self::ATTRIBUTE_ID_PRODUCER => 'distribution.id_producer' | ||||
public function isCreditAutoPayment(Order $order) | public function isCreditAutoPayment(Order $order) | ||||
{ | { | ||||
$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||||
//$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||||
$pointSale = $order->pointSale; | |||||
if($pointSale) { | if($pointSale) { | ||||
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); | $creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); | ||||
public function isCreditContext(Order $order) | public function isCreditContext(Order $order) | ||||
{ | { | ||||
$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||||
//$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale); | |||||
$pointSale = $order->pointSale; | |||||
if($pointSale) { | if($pointSale) { | ||||
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); | $creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale); |
$order->paid_amount = 0; | $order->paid_amount = 0; | ||||
if (count($history)) { | |||||
foreach ($history as $ch) { | |||||
if ($history && count($history)) { | |||||
foreach ($order->payment as $ch) { | |||||
if ($ch->type == Payment::TYPE_PAYMENT) { | if ($ch->type == Payment::TYPE_PAYMENT) { | ||||
$order->paid_amount += $ch->amount; | $order->paid_amount += $ch->amount; | ||||
} elseif ($ch->type == Payment::TYPE_REFUND) { | } elseif ($ch->type == Payment::TYPE_REFUND) { |
{ | { | ||||
if (strlen($config)) { | if (strlen($config)) { | ||||
if (!$idProducer) { | if (!$idProducer) { | ||||
$idProducer = $this->getProducerContextId(); | |||||
$producer = $this->getProducerContext(); | |||||
} | |||||
else { | |||||
$producer = $this->findOneProducerById($idProducer); | |||||
} | } | ||||
$producer = $this->findOneProducerById($idProducer); | |||||
if ($producer) { | if ($producer) { | ||||
return $producer->$config; | return $producer->$config; | ||||
} | } |
public function afterFind() | public function afterFind() | ||||
{ | { | ||||
if ($this->taxRate == null) { | if ($this->taxRate == null) { | ||||
$producer = Producer::searchOne(['id' => $this->id_producer]); | |||||
if($this->id_producer == GlobalParam::getCurrentProducerId()) { | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
} | |||||
else { | |||||
$producer = Producer::searchOne(['id' => $this->id_producer]); | |||||
} | |||||
if ($producer) { | if ($producer) { | ||||
$this->populateRelation('taxRate', $producer->taxRate); | $this->populateRelation('taxRate', $producer->taxRate); | ||||
} | } | ||||
} | } | ||||
parent::afterFind(); | |||||
$productSolver = ProductSolver::getInstance(); | $productSolver = ProductSolver::getInstance(); | ||||
$this->wording_unit = $productSolver->strUnit($this->unit); | $this->wording_unit = $productSolver->strUnit($this->unit); | ||||
$this->price_with_tax = $productSolver->getPriceWithTax($this); | $this->price_with_tax = $productSolver->getPriceWithTax($this); | ||||
parent::afterFind(); | |||||
} | } | ||||
public function getProductDistribution() | public function getProductDistribution() |
{ | { | ||||
return [ | return [ | ||||
self::WITH => ['taxRate', 'productPointSale'], | self::WITH => ['taxRate', 'productPointSale'], | ||||
self::JOIN_WITH => [], | |||||
self::JOIN_WITH => ['productPrice'], | |||||
self::ORDER_BY => 'product.order ASC', | self::ORDER_BY => 'product.order ASC', | ||||
self::ATTRIBUTE_ID_PRODUCER => 'product.id_producer' | self::ATTRIBUTE_ID_PRODUCER => 'product.id_producer' | ||||
]; | ]; |
}, | }, | ||||
"require-dev": { | "require-dev": { | ||||
"yiisoft/yii2-codeception": "*", | "yiisoft/yii2-codeception": "*", | ||||
"yiisoft/yii2-debug": "*", | |||||
"yiisoft/yii2-debug": "^2.1", | |||||
"yiisoft/yii2-gii": "*", | "yiisoft/yii2-gii": "*", | ||||
"yiisoft/yii2-faker": "*", | "yiisoft/yii2-faker": "*", | ||||
"codeception/codeception": "^2.3", | "codeception/codeception": "^2.3", |
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||
"This file is @generated automatically" | "This file is @generated automatically" | ||||
], | ], | ||||
"content-hash": "1d287231533b2d1fef1047dd81b0e4d5", | |||||
"content-hash": "a8cbf9ba6bfa2f0b47fba2344732ac95", | |||||
"packages": [ | "packages": [ | ||||
{ | { | ||||
"name": "2amigos/yii2-chartjs-widget", | "name": "2amigos/yii2-chartjs-widget", | ||||
}, | }, | ||||
{ | { | ||||
"name": "yiisoft/yii2-debug", | "name": "yiisoft/yii2-debug", | ||||
"version": "2.1.22", | |||||
"version": "2.1.24", | |||||
"source": { | "source": { | ||||
"type": "git", | "type": "git", | ||||
"url": "https://github.com/yiisoft/yii2-debug.git", | "url": "https://github.com/yiisoft/yii2-debug.git", | ||||
"reference": "c0fa388c56b64edfb92987fdcc37d7a0243170d7" | |||||
"reference": "e15e954d0beb82b0b532f998f55e7275083de592" | |||||
}, | }, | ||||
"dist": { | "dist": { | ||||
"type": "zip", | "type": "zip", | ||||
"url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/c0fa388c56b64edfb92987fdcc37d7a0243170d7", | |||||
"reference": "c0fa388c56b64edfb92987fdcc37d7a0243170d7", | |||||
"url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/e15e954d0beb82b0b532f998f55e7275083de592", | |||||
"reference": "e15e954d0beb82b0b532f998f55e7275083de592", | |||||
"shasum": "" | "shasum": "" | ||||
}, | }, | ||||
"require": { | "require": { | ||||
"type": "tidelift" | "type": "tidelift" | ||||
} | } | ||||
], | ], | ||||
"time": "2022-11-18T17:29:27+00:00" | |||||
"time": "2023-07-10T06:07:43+00:00" | |||||
}, | }, | ||||
{ | { | ||||
"name": "yiisoft/yii2-faker", | "name": "yiisoft/yii2-faker", |