<?php
if (!$form->isNew()) {
    $discount = Doctrine::getTable('DiscountPhone')->findOneByOrderId($form->getObject()->getId());
    $offers = $form->getObject()->getOffers();
    if (count($offers) > 0) {
        ?>
        <div class="advanced_custom">
            <?php
            if ($discount) {
                ?>
                <div>Использована скидка <?php echo $discount->getDiscount()->getTitle() . ' с ' . $discount->getActiveDiscount() . '%' ?></div>
                <?php
            }
            ?>
            <div class="advanced_custom__h">Товарные предложения<sup>&nbsp;<?php echo count($offers);?></sup></div>
            <div class="content">
                <table width="100%" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <th align="left" width="40%">Наименование</th>
                        <th align="right" width="20%">Количество</th>
                        <th align="right" width="20%">Цена</th>
                        <th align="right" width="20%">Сумма</th>
                    </tr>
                    <?php
                    $total = 0;
                    foreach ($offers as $offer) {
                        echo '<tr align="right"><td align="left">' . $offer['Offer']['Translation']['ru']['title'] . '</td><td>' . $offer['amount'] . '</td><td>' . number_format($offer['price']/$offer['amount'], 0, ',', ' ') . '&nbsp;₽</td><td><nobr>' . number_format($offer['price'], 0, ',', ' ') . '&nbsp;₽</nobr></td></tr>';
                        $total += $offer['price'];
                    }
                    echo '<tr class="advanced_custom__tr_divider_top"><td align="right" colspan="4"><nobr><b>Итого:&nbsp;</b>' . number_format($total, 0, ',', ' ') . '&nbsp;₽</nobr></td></tr>';
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
        <?php
    }
}
?>
<script type="text/javascript">
    $('#basket_order_delivery_type').change(function (e) {
        $('.sf_admin_form_field_delivery_price').css('display', (e.target.value == 'Самовывоз' ? 'none' : 'inline-block'));
        $('.sf_admin_form_field_delivery_address').css('display', (e.target.value == 'Самовывоз' ? 'none' : 'block'));
    }).change();
</script>