Browse Source

Installation Yii2 Debug bar + optimisation chargement distribution/ajax-infos

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
d4dd285601
9 changed files with 56 additions and 36 deletions
  1. +24
    -17
      backend/controllers/DistributionController.php
  2. +3
    -1
      common/helpers/GlobalParam.php
  3. +6
    -3
      common/logic/Order/Order/Repository/OrderRepository.php
  4. +2
    -2
      common/logic/Order/Order/Service/OrderBuilder.php
  5. +4
    -2
      common/logic/Producer/Producer/Repository/ProducerRepository.php
  6. +9
    -3
      common/logic/Product/Product/Model/Product.php
  7. +1
    -1
      common/logic/Product/Product/Repository/ProductRepository.php
  8. +1
    -1
      composer.json
  9. +6
    -6
      composer.lock

+ 24
- 17
backend/controllers/DistributionController.php View File

@@ -132,9 +132,9 @@ class DistributionController extends BackendController
$distribution = $distributionManager->createDistributionIfNotExist($date);
$ordersArray = $orderManager->findOrdersByDistribution($distribution);
$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['orders'] = $this->buildAjaxInfosResponseOrders($ordersArray, $productsArray);
$json['points_sale'] = $this->buildAjaxInfosResponsePointsSale($distribution);
@@ -175,35 +175,42 @@ class DistributionController extends BackendController
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();
$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 {
$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)

+ 3
- 1
common/helpers/GlobalParam.php View File

@@ -39,6 +39,7 @@
namespace common\helpers;

use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\User\Service\UserSolver;

class GlobalParam
@@ -60,8 +61,9 @@ class GlobalParam

public static function getCurrentProducer()
{
$producerManager = ProducerManager::getInstance();
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');

+ 6
- 3
common/logic/Order/Order/Repository/OrderRepository.php View File

@@ -72,7 +72,8 @@ class OrderRepository extends AbstractRepository
self::JOIN_WITH => [
'distribution',
'user',
'user.userProducer'
'user.userProducer',
//'payment'
],
self::ORDER_BY => 'order.date ASC',
self::ATTRIBUTE_ID_PRODUCER => 'distribution.id_producer'
@@ -324,7 +325,8 @@ class OrderRepository extends AbstractRepository

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) {
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale);
@@ -350,7 +352,8 @@ class OrderRepository extends AbstractRepository

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) {
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale);

+ 2
- 2
common/logic/Order/Order/Service/OrderBuilder.php View File

@@ -417,8 +417,8 @@ class OrderBuilder extends AbstractBuilder

$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) {
$order->paid_amount += $ch->amount;
} elseif ($ch->type == Payment::TYPE_REFUND) {

+ 4
- 2
common/logic/Producer/Producer/Repository/ProducerRepository.php View File

@@ -247,10 +247,12 @@ class ProducerRepository extends AbstractRepository
{
if (strlen($config)) {
if (!$idProducer) {
$idProducer = $this->getProducerContextId();
$producer = $this->getProducerContext();
}
else {
$producer = $this->findOneProducerById($idProducer);
}

$producer = $this->findOneProducerById($idProducer);
if ($producer) {
return $producer->$config;
}

+ 9
- 3
common/logic/Product/Product/Model/Product.php View File

@@ -178,17 +178,23 @@ class Product extends ActiveRecordCommon
public function afterFind()
{
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) {
$this->populateRelation('taxRate', $producer->taxRate);
}
}

parent::afterFind();

$productSolver = ProductSolver::getInstance();
$this->wording_unit = $productSolver->strUnit($this->unit);
$this->price_with_tax = $productSolver->getPriceWithTax($this);

parent::afterFind();
}

public function getProductDistribution()

+ 1
- 1
common/logic/Product/Product/Repository/ProductRepository.php View File

@@ -33,7 +33,7 @@ class ProductRepository extends AbstractRepository
{
return [
self::WITH => ['taxRate', 'productPointSale'],
self::JOIN_WITH => [],
self::JOIN_WITH => ['productPrice'],
self::ORDER_BY => 'product.order ASC',
self::ATTRIBUTE_ID_PRODUCER => 'product.id_producer'
];

+ 1
- 1
composer.json View File

@@ -41,7 +41,7 @@
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-debug": "^2.1",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*",
"codeception/codeception": "^2.3",

+ 6
- 6
composer.lock View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1d287231533b2d1fef1047dd81b0e4d5",
"content-hash": "a8cbf9ba6bfa2f0b47fba2344732ac95",
"packages": [
{
"name": "2amigos/yii2-chartjs-widget",
@@ -6410,16 +6410,16 @@
},
{
"name": "yiisoft/yii2-debug",
"version": "2.1.22",
"version": "2.1.24",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-debug.git",
"reference": "c0fa388c56b64edfb92987fdcc37d7a0243170d7"
"reference": "e15e954d0beb82b0b532f998f55e7275083de592"
},
"dist": {
"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": ""
},
"require": {
@@ -6496,7 +6496,7 @@
"type": "tidelift"
}
],
"time": "2022-11-18T17:29:27+00:00"
"time": "2023-07-10T06:07:43+00:00"
},
{
"name": "yiisoft/yii2-faker",

Loading…
Cancel
Save