<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage_Bundle
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * @see Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer
 */
?>

<?php $_item = $this->getItem() ?>
<?php $items = $this->getChilds($_item); ?>
<?php $_count = count ($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

<?php if($this->getOrderOptions() || $_item->getDescription()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif; ?>

<?php foreach ($items as $_item): ?>
    <?php $this->setPriceDataObject($_item) ?>
    <?php if ($_item->getOrderItem()->getParentItem()): ?>
        <?php $attributes = $this->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td><div class="option-label"><?php echo $attributes['option_label'] ?></div></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td class="last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <tr<?php echo (++$_index==$_count && !$_showlastRow)?' class="border"':'' ?>>
        <?php if (!$_item->getOrderItem()->getParentItem()): ?>
        <td><h5 class="title"><?php echo $this->htmlEscape($_item->getName()) ?></h5>
            <div>
                <strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong>
                <?php echo implode('<br />', Mage::helper('catalog')->splitSku($_item->getSku())); ?>
            </div>
        <?php else: ?>
        <td><div class="option-value"><?php echo $this->getValueHtml($_item)?></div></td>
        <?php endif; ?>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-excl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Excl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceAttribute('price') ?>
                    </span>
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                      <span class="price-incl-tax">
                      <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Incl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceInclTax($_item); ?>
                    </span>
                <?php endif; ?>
            <?php else: ?>
                &nbsp;
                        <?php endif; ?>
        </td>
        <td class="a-center">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $_item->getQty()*1 ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-excl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Excl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceAttribute('row_total') ?>
                    </span>
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-incl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Incl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displaySubtotalInclTax($_item); ?>
                    </span>
                <?php endif; ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPriceAttribute('tax_amount') ?>
            <?php else: ?>
                &nbsp;
                        <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPriceAttribute('discount_amount') ?>
            <?php else: ?>
                &nbsp;
                        <?php endif; ?>
        </td>
        <td class="a-right last">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPrices(
                    $_item->getBaseRowTotal()+$_item->getBaseTaxAmount()-$_item->getBaseDiscountAmount(),
                    $_item->getRowTotal()+$_item->getTaxAmount()-$_item->getDiscountAmount()
                ) ?>
             <?php else: ?>
                 &nbsp;
            <?php endif; ?>
        </td>
    </tr>
<?php endforeach; ?>
<?php if($_showlastRow): ?>
    <tr class="border">
        <td>
            <?php if ($this->getOrderOptions()): ?>
                <dl class="item-options">
                <?php foreach ($this->getOrderOptions() as $option): ?>
                    <dt><?php echo $option['label'] ?></dt>
                    <dd><?php echo $this->htmlEscape($option['value']); ?></dd>
                <?php endforeach; ?>
                </dl>
            <?php endif; ?>
            <?php echo $this->getItem()->getDescription() ?>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
<?php endif; ?>
