ソースを参照

Export PDF : regroupement des ProductOrder par id_product

refactoring
コミット
000f68e39f
2個のファイルの変更34行の追加5行の削除
  1. +7
    -5
      backend/views/document/download.php
  2. +27
    -0
      common/models/Document.php

+ 7
- 5
backend/views/document/download.php ファイルの表示

@@ -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 ファイルの表示

@@ -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 ;
}

}

読み込み中…
キャンセル
保存