<?php

use common\helpers\Price;
use common\logic\Product\Product\Model\Product;
use yii\helpers\Html;

$documentManager = $this->getDocumentManager();
$productManager = $this->getProductManager();

?>

<tr class="<?php if(isset($displayOrders) && $displayOrders): ?>order<?php endif; ?>">
        <td class="align-left">
                <?php if($productOrder->product): ?>
                    <?= Html::encode($productOrder->product->name) ?>
                <?php endif; ?>
                <?php if($productOrder->unit == 'piece' && isset($productOrder->product->weight) && $productOrder->product->weight): ?>
                        <span class="weight"> / <?= $productOrder->product->weight ?> g</span>
                <?php endif; ?>
                <?php if($productOrder->product && strlen($productOrder->product->description) && $displayProductDescription): ?>
                        <br /><small><?= Html::encode($productOrder->product->description) ?></small>
                <?php endif; ?>
        </td>

        <?php
            $price = $productOrder->getPrice() ;
            if($documentManager->isInvoicePrice($document) && $productOrder->getInvoicePrice()) {
                    $price = $productOrder->getInvoicePrice() ;
            }
        ?>

        <?php if($displayPrices): ?>
                <td class="align-center">
                    <?= Price::format($price, $documentPriceDecimals) ?>
                </td>
        <?php endif; ?>
        <td class="align-center">
            <?= $productOrder->quantity *  Product::$unitsArray[$productOrder->unit]['coefficient'] ?>
        </td>
        <td class="align-center"><?=  $productManager->strUnit($productOrder->unit, 'wording') ?></td>
        <?php if($displayPrices): ?>
                <?php if($producer->taxRate->value != 0): ?>
                        <td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>
                <?php endif; ?>
                <td class="align-center">
                        <?php if($documentManager->getClass($document) == ''): ?>
                                <?= Price::format($price * $productOrder->quantity) ?>
                        <?php else: ?>
                                <?= Price::format($price * $productOrder->quantity) ?>
                        <?php endif; ?>
                </td>
        <?php endif; ?>
</tr>
