Browse Source

[backend] Correction bug double produit à la fin de la liste dans les distributions

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
abf4e321d6
1 changed files with 10 additions and 11 deletions
  1. +10
    -11
      backend/controllers/DistributionController.php

+ 10
- 11
backend/controllers/DistributionController.php View File

@@ -118,7 +118,6 @@ class DistributionController extends BackendController
// products
$productsArray = Product::find()
->orWhere(['id_producer' => Producer::getId(),])
->orWhere(['id_producer' => 0,]) // produit "Don"
->joinWith(['productDistribution' => function($query) use($distribution) {
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ;
}])
@@ -128,17 +127,17 @@ class DistributionController extends BackendController
$potentialRevenues = 0;
$potentialWeight = 0;
foreach($productsArray as &$product) {
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ;
$product['quantity_ordered'] = $quantityOrder ;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ;
if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ;
$product['quantity_form'] = 0 ;
foreach($productsArray as &$theProduct) {
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ;
$theProduct['quantity_ordered'] = $quantityOrder ;
$theProduct['quantity_remaining'] = $theProduct['quantity_max'] - $quantityOrder ;
if($theProduct['quantity_remaining'] < 0) $theProduct['quantity_remaining'] = 0 ;
$theProduct['quantity_form'] = 0 ;
if($product['productDistribution'][0]['active'] && $product['productDistribution'][0]['quantity_max']) {
$potentialRevenues += $product['productDistribution'][0]['quantity_max'] * $product['price'];
$potentialWeight += $product['productDistribution'][0]['quantity_max'] * $product['weight'] / 1000;
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;
}
}

Loading…
Cancel
Save