Browse Source

Export PDF : regroupement des ProductOrder par id_product

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
000f68e39f
2 changed files with 34 additions and 5 deletions
  1. +7
    -5
      backend/views/document/download.php
  2. +27
    -0
      common/models/Document.php

+ 7
- 5
backend/views/document/download.php View File

@@ -41,31 +41,33 @@
<th>Prix unitaire HT</th>
<th>Quantité</th>
<th>Unité</th>
<th>TVA</th>
<th>Prix HT</th>
</tr>
</thead>
<tbody>
<?php foreach($document->orders as $order): ?>
<?php foreach($order->productOrder as $productOrder): ?>
<?php foreach($document->getProductsOrders() as $product): ?>
<?php foreach($product as $productOrder): ?>
<tr>
<td class="align-left"><?= Html::encode($productOrder->product->name) ?></td>
<td class="align-center"><?= Price::format($productOrder->product->getPrice()) ?></td>
<td class="align-center"><?= $productOrder->quantity ?></td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
<td class="align-center"><?= $productOrder->product->taxRate->value * 100 ?> %</td>
<td class="align-center"><?= Price::format($productOrder->product->getPrice() * $productOrder->quantity) ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<tr>
<td class="align-right" colspan="4"><strong>Total HT</strong></td>
<td class="align-right" colspan="5"><strong>Total HT</strong></td>
<td class="align-center"><?= Price::format($document->getAmount()) ?></td>
</tr>
<tr>
<td class="align-right" colspan="4"><strong>TVA</strong></td>
<td class="align-right" colspan="5"><strong>TVA</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax() - $document->getAmount()) ?></td>
</tr>
<tr>
<td class="align-right" colspan="4"><strong>Total TTC</strong></td>
<td class="align-right" colspan="5"><strong>Total TTC</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax()) ?></td>
</tr>
</tbody>

+ 27
- 0
common/models/Document.php View File

@@ -263,5 +263,32 @@ class Document extends ActiveRecordCommon
{
return $this->isStatus(self::STATUS_VALID) ;
}
public function getProductsOrders() {
$productsOrdersArray = [] ;
if($this->orders && count($this->orders)) {
foreach($this->orders as $order) {
foreach($order->productOrder as $productOrder) {
if(!isset($productsOrdersArray[$productOrder->id_product])) {
$productsOrdersArray[$productOrder->id_product] = [$productOrder] ;
}
else {
$productOrderMatch = false ;
foreach($productsOrdersArray[$productOrder->id_product] as &$theProductOrder) {
if($theProductOrder->unit == $productOrder->unit && $theProductOrder->price == $productOrder->price) {
$theProductOrder->quantity += $productOrder->quantity ;
$productOrderMatch = true ;
}
}
if(!$productOrderMatch) {
$productsOrdersArray[$productOrder->id_product][] = $productOrder ;
}
}
}
}
}

return $productsOrdersArray ;
}

}

Loading…
Cancel
Save