<?php

$volDisType[] = JHtml::_('select.option', DISCOUNT_TYPE_VALUE, AFactory::getConfig()->mainCurrency);
$volDisType[] = JHtml::_('select.option', DISCOUNT_TYPE_PERCENT, '%');

$volDisPer[] = JHtml::_('select.option', DISCOUNT_PER_UNIT, JText::_('PEAR_RESERVATION_UNIT'));
$volDisPer[] = JHtml::_('select.option', DISCOUNT_PER_RESERVATION, JText::_('PEAR_WHOLE_RESERVATION'));

$volDisUnit[] = JHtml::_('select.option', DISCOUNT_TO_UNIT, JText::_('UNITS_COUNT'));
$volDisUnit[] = JHtml::_('select.option', DISCOUNT_TO_QUANTITY, JText::_('QUANTITY'));

?>
<?php if (isset($this->volDisItem->discount_include_supplements)) { ?>
    <input type="hidden" name="<?php echo $this->volDisPrefix ?>discount_include_supplements<?php echo $this->volDisSuffix ?>" value="<?php echo $this->volDisItem->discount_include_supplements ?>"/>
    <label class="inline hasTip" title="<?php echo JText::_('DISCOUNT_INCLUDE_SUPPLEMENTS') . '::' . JText::_('DISCOUNT_INCLUDE_SUPPLEMENTS_TIP') ?>">
        <input type="checkbox" class="inputCheckbox" id="discount_include_supplements<?php echo $this->volDisId ?>" name="fake[]" <?php if ($this->volDisItem->discount_include_supplements) { ?>checked="checked"<?php } ?> onchange="ACommon.check(this);"/>
        <span class="checkboxLabel"><?php echo JText::_('DISCOUNT_INCLUDE_SUPPLEMENTS') ?></span>
    </label>
    <div class="clr"></div>
<?php } ?>
<?php if (isset($this->volDisItem->discount_all_units)) { ?>
    <input type="hidden" name="<?php echo $this->volDisPrefix ?>discount_all_units<?php echo $this->volDisSuffix ?>" value="<?php echo $this->volDisItem->discount_all_units ?>"/>
    <label class="inline hasTip" title="<?php echo $this->escape(JText::_('DISCOUNT_ALL_UNITS')) ?>::<?php echo $this->escape(JText::_('DISCOUNT_ALL_UNITS_TIP')) ?>">
        <input type="checkbox" class="inputCheckbox" id="<?php echo 'discount_all_units' . $this->volDisId ?>" name="another_fake[]" <?php if ($this->volDisItem->discount_all_units) { ?>checked="checked"<?php } ?> onchange="ACommon.check(this);"/>
        <span class="checkboxLabel"><?php echo JText::_('DISCOUNT_ALL_UNITS') ?></span>
    </label>
<?php } ?>
<label for=""><?php echo JText::_('VOLUME_UNIT') ?></label>
<?php echo JHTML::_('select.genericlist', $volDisUnit, $this->volDisPrefix . 'volume_type' . $this->volDisSuffix, '', 'value', 'text', $this->volDisItem->volume_type) ?>
<table class="template">
    <thead>
    <tr>
        <th class="hasTip" title="<?php echo $this->escape(JText::_('VOLUME')) ?>::<?php echo $this->escape(JText::_('VOLUME_TIP')) ?>"><?php echo JText::_('VOLUME') ?></th>
        <th class="hasTip" title="<?php echo $this->escape(JText::_('DISCOUNT')) ?>::<?php echo $this->escape(JText::_('DISCOUNT_TIP')) ?>"><?php echo JText::_('DISCOUNT') ?></th>
        <th></th>
    </tr>
    </thead>

    <tbody>
    <?php
    array_unshift($this->volDisItem->volume_discount, array('count' => '', 'value' => '', 'type' => 0));
    foreach ($this->volDisItem->volume_discount as $vdi => $volDis) { ?>
        <tr<?php if (!$vdi) { ?> style="display: none" class="disrow"<?php } ?>>
            <td>
                <input type="text" name="dis_count[]" value="<?php echo JArrayHelper::getValue($volDis, 'count') ?>" class="number" onkeyup="ACommon.toInt(this)"/>
            </td>
            <td>
                <input type="text" name="dis_value[]" value="<?php echo JArrayHelper::getValue($volDis, 'value') ?>" class="number" onkeyup="ACommon.toFloat(this, true)"/>
                <?php echo JHTML::_('select.genericlist', $volDisType, 'dis_type[]', 'class="inline"', 'value', 'text', JArrayHelper::getValue($volDis, 'type')) ?>
                <?php if ($this->volDisPer) { ?>
                    <?php echo JHTML::_('select.genericlist', $volDisPer, 'dis_per[]', 'class="inline" style="width: 65px !important"', 'value', 'text', JArrayHelper::getValue($volDis, 'per')) ?>
                <?php } ?>
            </td>
            <td>
                <button onclick="return EditSubject.removeDiscount(this)" class="hasTip transparent" title="<?php echo $this->escape(JText::_('REMOVE_DISCOUNT')) ?>">
                    <?php echo JHtml::_('image', 'admin/publish_r.png', JText::_('REMOVE_DISCOUNT'), null, true) ?>
                </button>
            </td>
        </tr>
    <?php } ?>

    <?php if (count($this->volDisItem->volume_discount) == 1) { ?>
        <tr class="nonediscount">
            <td colspan="4"><?php echo JText::_('NONE_DISCOUNT') ?></td>
        </tr>
    <?php } ?>
    </tbody>
</table>

<button onclick="return EditSubject.addDiscount(this)" class="hasTip transparent" title="<?php echo $this->escape(JText::_('ADD_DISCOUNT')) ?>">
    <?php echo JHtml::_('image', 'admin/expandall.png', JText::_('ADD_DISCOUNT'), null, true) ?>
    <span><?php echo JText::_('ADD_DISCOUNT') ?></span>
</button>
<input type="hidden" name="<?php echo $this->volDisPrefix ?>volume_discount<?php echo $this->volDisSuffix ?>" value=""/>