Browse Source

[backend] Factures : tri des produits

refactoring
Guillaume 3 years ago
parent
commit
9d0f012958
1 changed files with 11 additions and 4 deletions
  1. +11
    -4
      common/models/Document.php

+ 11
- 4
common/models/Document.php View File

@@ -342,12 +342,16 @@ class Document extends ActiveRecordCommon
if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) {
if (!isset($productsOrdersArray[$productOrder->id_product])) {

//$indexProductOrder = $productOrder->id_product ;
$indexProductOrder = $productOrder->product->order ;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$newProductOrder = clone $productOrder ;
$productsOrdersArray[$productOrder->id_product] = [$newProductOrder];
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$productOrder->id_product] as &$theProductOrder) {
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
if ($theProductOrder->unit == $productOrder->unit
&& ($theProductOrder->price == $productOrder->price
|| ($this->isInvoicePrice()
@@ -357,13 +361,16 @@ class Document extends ActiveRecordCommon
}
}
if (!$productOrderMatch) {
$productsOrdersArray[$productOrder->id_product][] = $productOrder;
$productsOrdersArray[$indexProductOrder][] = $productOrder;
}
}
}
}
}

// tri des orderProduct par product.order
ksort($productsOrdersArray);

return $productsOrdersArray;
}


Loading…
Cancel
Save