<?php
/**
 * OpenMage
 *
 * 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 at https://opensource.org/license/afl-3-0-php
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
 * @copyright   Copyright (c) 2021-2024 The OpenMage Contributors (https://www.openmage.org)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var Mage_Adminhtml_Block_Sales_Order_Invoice_Create_Form $this */
?>
<form id="edit_form" method="post" action="<?php echo $this->getSaveUrl() ?>">
    <?php echo $this->getBlockHtml('formkey')?>
    <?php $_order = $this->getInvoice()->getOrder() ?>
    <?php echo $this->getChildHtml('order_info') ?>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="box-left">
    <?php else: ?>
    <div class="box-right">
    <?php endif ?>

        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-payment-method"><?php echo Mage::helper('sales')->__('Payment Information') ?></h4>
            </div>
            <fieldset>
                <div><?php echo $this->getChildHtml('order_payment') ?></div>
                <div><?php echo Mage::helper('sales')->__('Order was placed using %s', $_order->getOrderCurrencyCode()) ?></div>
            </fieldset>
        </div>
    </div>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="box-right">
        <!--Shipping Address-->
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-shipping-method"><?php echo Mage::helper('sales')->__('Shipping Information') ?></h4>
            </div>
            <fieldset>
                <div>
                    <strong><?php echo $this->escapeHtml($_order->getShippingDescription()) ?></strong>
                    <?php echo $this->helper('sales')->__('Total Shipping Charges'); ?>:

                    <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
                        <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
                    <?php else: ?>
                        <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif ?>
                    <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>

                    <?php echo $_excl; ?>
                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                        (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                    <?php endif ?>
                </div>
                <?php if ($this->canCreateShipment() && $this->canShipPartiallyItem()): ?>
                <p class="nm">
                    <label for="invoice_do_shipment" class="normal"><?php echo Mage::helper('sales')->__('Create Shipment') ?></label>
                    <input type="checkbox" name="invoice[do_shipment]" id="invoice_do_shipment" value="1" <?php echo $this->hasInvoiceShipmentTypeMismatch()?' disabled="disabled"':'' ?> />
                </p>
                <?php if ($this->hasInvoiceShipmentTypeMismatch()): ?>
                    <small><?php echo $this->__('Some items in this order have different invoice and shipment types. You can create shipment only after the invoice is created.') ?></small>
                    <?php endif ?>
                <?php endif ?>
                <div id="tracking" style="display:none;"><?php echo $this->getChildHtml('tracking',false) ?></div>
            </fieldset>
        </div>
    </div>
    <?php endif ?>
    <div class="clear"></div>

    <div class="entry-edit">
        <div class="entry-edit-head">
            <?php
                $_itemsGridLabel = $this->getForcedShipmentCreate()?'Items to Invoice and Ship':'Items to Invoice';
            ?>
            <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('%s', $_itemsGridLabel) ?></h4>
        </div>
    </div>
    <div id="invoice_item_container">
          <?php echo $this->getChildHtml('order_items') ?>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var createShipment = $('invoice_do_shipment');
    if (createShipment) {
        createShipment.observe('click', function(e){
            if (createShipment.checked) {
                document.getElementById('tracking').style.display = 'block';
            } else {
                document.getElementById('tracking').style.display = 'none'
            }
        })
    }

    /*forced creating of shipment*/
    var forcedShipmentCreate = <?php echo $this->getForcedShipmentCreate() ?>;
    var shipmentElement = $('invoice_do_shipment');
    if (forcedShipmentCreate && shipmentElement) {
        shipmentElement.checked = true;
        shipmentElement.disabled = true;
        document.getElementById('tracking').style.display = 'block';
    }
//]]>
</script>
