<?php
/*
 * @author     M2E Pro Developers Team
 * @copyright  M2E LTD
 * @license    Commercial use is forbidden
 */

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Ebay_Account_Edit_Tabs_Order */

?>

<div id="block_notice_ebay_accounts_orders" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Orders'); ?>">
    <?php echo Mage::helper('M2ePro')->__(
        'Specify how M2E Pro should manage the Orders imported from eBay.<br/><br/>
        You are able to configure the different rules of <strong>Magento Order Creation</strong> considering whether the Item was listed via M2E Pro or by some other software.<br/><br/>
        Once eBay Order is imported, the <strong>Reserve Quantity</strong> feature will hold the Stock if Magento Order could not be created immediately in accordance with provided settings.<br/><br/>
        Besides, you can configure the <strong>Tax, Order Number</strong> and <strong>Order Status Mapping</strong> Settings for your Magento Orders as well as specify the automatic creation of invoices and shipment notifications.<br/><br/>
        More detailed information you can find <a href="%url%" target="_blank">here</a>.',
        Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'order-import'));
    ?>
</div>

<?php
    $formData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data') ? Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->toArray() : array();
    $formData['magento_orders_settings'] = !empty($formData['magento_orders_settings']) ? json_decode($formData['magento_orders_settings'], true) : array();

    $defaults = Mage::getModel('M2ePro/Ebay_Account_Builder')->getDefaultData();

    $formData = Mage::helper('M2ePro')->arrayReplaceRecursive($defaults, $formData);

    $isEdit = !!$this->getRequest()->getParam('id');
?>

<script type="text/javascript">

    // Data for current tab
    //-----------------------------
    Event.observe(window, 'load', function() {
        setTimeout(function() {
            $('magento_orders_listings_mode').observe('change', EbayAccountObj.magentoOrdersListingsModeChange);
            $('magento_orders_listings_store_mode').observe('change', EbayAccountObj.magentoOrdersListingsStoreModeChange);

            $('magento_orders_listings_other_mode').observe('change', EbayAccountObj.magentoOrdersListingsOtherModeChange);
            $('magento_orders_listings_other_product_mode').observe('change', EbayAccountObj.magentoOrdersListingsOtherProductModeChange);

            $('magento_orders_number_source').observe('change', EbayAccountObj.magentoOrdersNumberChange);
            $('magento_orders_number_prefix_prefix').observe('keyup', EbayAccountObj.magentoOrdersNumberChange);
            $('magento_orders_number_prefix_use_marketplace_prefix').observe('change', EbayAccountObj.magentoOrdersNumberChange);
            EbayAccountObj.renderOrderNumberExample();

            $('magento_orders_customer_mode').observe('change', EbayAccountObj.magentoOrdersCustomerModeChange);

            $('magento_orders_status_mapping_mode').observe('change', EbayAccountObj.magentoOrdersStatusMappingModeChange);

        }, 350);
    });
    //-----------------------------

</script>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_listings">

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Product Is Listed By M2E Pro'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_listings_mode"><?php echo Mage::helper('M2ePro')->__('Create Order in Magento'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_listings_mode" name="magento_orders_settings[listing][mode]" class="M2ePro-required-when-visible">
                            <option value="0" <?php if ($formData['magento_orders_settings']['listing']['mode'] == 0) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['magento_orders_settings']['listing']['mode'] == 1) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Choose whether a Magento Order should be created if an eBay Order is received for an eBay Item Listed using M2E Pro.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_listings_store_mode_container" <?php if($formData['magento_orders_settings']['listing']['mode'] == 0) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_listings_store_mode"><?php echo Mage::helper('M2ePro')->__('Magento Store View Source'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_listings_store_mode" name="magento_orders_settings[listing][store_mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT; ?>" <?php if ($formData['magento_orders_settings']['listing']['store_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Use Store View from Listing'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_CUSTOM; ?>" <?php if ($formData['magento_orders_settings']['listing']['store_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_CUSTOM) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Choose Store View Manually'); ?></option>
                        </select>
                        <p class="note">
                            <span>
                                <?php echo Mage::helper('M2ePro')->__(
                                    'Choose to specify the Magento Store View here or to keep the Magento Store View used in the M2E Pro Listing.'
                                ); ?>
                            </span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_listings_store_id_container" <?php if($formData['magento_orders_settings']['listing']['store_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Magento Store View'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value">
                        <?php echo $this->getChildHtml('magento_orders_listings_store_id'); ?>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('The Store the Orders will be placed in.'); ?></span>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_listings_other">

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Product Is Listed By Any Other Software'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_listings_other_mode"><?php echo Mage::helper('M2ePro')->__('Create Order in Magento'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_listings_other_mode" name="magento_orders_settings[listing_other][mode]" class="required-entry">
                            <option value="0" <?php if ($formData['magento_orders_settings']['listing_other']['mode'] == 0) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['magento_orders_settings']['listing_other']['mode'] == 1) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Choose whether a Magento Order should be created if an eBay Order is received for an item that does <b>not</b> belong to the M2E Pro Listing.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_listings_other_store_id_container" <?php if($formData['magento_orders_settings']['listing_other']['mode'] == 0) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Magento Store View'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value">
                        <?php echo $this->getChildHtml('magento_orders_listings_other_store_id'); ?>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('The Store the Orders will be placed in.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_listings_other_product_mode_container" <?php if($formData['magento_orders_settings']['listing_other']['mode'] == 0) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_listings_other_product_mode"><?php echo Mage::helper('M2ePro')->__('Product Not Found'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_listings_other_product_mode" name="magento_orders_settings[listing_other][product_mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE; ?>" <?php if ($formData['magento_orders_settings']['listing_other']['product_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Do Not Create Order'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IMPORT; ?>" <?php if ($formData['magento_orders_settings']['listing_other']['product_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IMPORT) echo ' selected="selected"';?>><?php echo Mage::helper('M2ePro')->__('Create Product and Order'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Choose what should happen if an Order is received for a Product that does not exist in your Magento Inventory.'); ?></span><br/>
                            <span id="magento_orders_listings_other_product_mode_note" <?php if ($formData['magento_orders_settings']['listing_other']['product_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE) echo 'style="display: none;"'; ?>><?php echo Mage::helper('M2ePro')->__(
                                '<br/><b>Note:</b> M2E Pro will create only Simple Magento Products. For Channel variational items it will create a Simple Product for each variation.
                                Please note that the Create Product and Order option is not meant for the creation of full-fledged products in your Magento catalog. <a href="%url%" target="_blank">See why</a>',
                                Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'order-import#1f3a275a97b5484ca89066d20c5b247c')
                            ) ?></span>
                        </p>
                        <?php $canShowBlock = $formData['magento_orders_settings']['listing_other']['product_mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IMPORT; ?>
                        <div id="magento_orders_listings_other_product_mode_warning" <?php if (!$canShowBlock): ?>style="display: none;"<?php endif; ?>>
                            <ul class="messages">
                                <li class="warning-msg">
                                    <?php echo Mage::helper('M2ePro')->__('Please note that a new Magento Product will be created if the corresponding SKU is not found in your Catalog.'); ?>
                                </li>
                            </ul>
                        </div>
                    </td>
                </tr>

                <tr id="magento_orders_listings_other_product_tax_class_id_container" <?php if (!$canShowBlock): ?>style="display: none;"<?php endif; ?>>
                    <td class="label">
                        <label for="magento_orders_listings_other_product_tax_class_id"><?php echo Mage::helper('M2ePro')->__('Product Tax Class') ?>: </label>
                    </td>
                    <td class="value">
                        <select id="magento_orders_listings_other_product_tax_class_id" name="magento_orders_settings[listing_other][product_tax_class_id]" class="M2ePro-required-when-visible">
                            <?php foreach ($this->productTaxClasses as $taxClass): ?>
                                <option value="<?php echo (int)$taxClass['value'] ?>" <?php if ($formData['magento_orders_settings']['listing_other']['product_tax_class_id'] == $taxClass['value']): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->escapeHtml($taxClass['label']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <p class="note">
                            <?php echo Mage::helper('M2ePro')->__('Tax Class which will be used for Products created by M2E Pro.'); ?>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_number" <?php if(($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Magento Order Number'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <div id="block_notice_ebay_accounts_orders_number" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Number Prefix'); ?>">
                <?php echo Mage::helper('M2ePro')->__('Sets Magento Order number basing on the Settings below'); ?>
            </div>

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_number_source"><?php echo Mage::helper('M2ePro')->__('Source'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_number_source" name="magento_orders_settings[number][source]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_NUMBER_SOURCE_MAGENTO; ?>" <?php if ($formData['magento_orders_settings']['number']['source'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_NUMBER_SOURCE_MAGENTO) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Magento'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_NUMBER_SOURCE_CHANNEL; ?>" <?php if ($formData['magento_orders_settings']['number']['source'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_NUMBER_SOURCE_CHANNEL) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('eBay'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('If source is set to Magento, Magento Order numbers are created basing on your Magento Settings. If source is set to eBay, Magento Order numbers are the same as eBay Order numbers.'); ?></span>
                        </p>
                    </td>
                </tr>
                <tr id="magento_orders_number_prefix_container">
                    <td class="label">
                        <label for="magento_orders_number_prefix_prefix"><?php echo Mage::helper('M2ePro')->__('General Prefix'); ?>:</label>
                    </td>
                    <td class="value" style="width: auto;">
                        <input id="magento_orders_number_prefix_prefix" maxlength="5" name="magento_orders_settings[number][prefix][prefix]" value="<?php echo $this->escapeHtml($formData['magento_orders_settings']['number']['prefix']['prefix']); ?>" type="text" class="M2ePro-account-order-number-prefix input-text" />
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Enter the prefix to be set before Magento Order number.'); ?></span>
                        </p>
                    </td>
                </tr>
                <tr id="magento_orders_number_use_marketplace_prefix_container">
                    <td class="label">
                        <label for="magento_orders_number_prefix_use_marketplace_prefix"><?php echo Mage::helper('M2ePro')->__('Use Marketplace ID as a prefix'); ?>:</label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_number_prefix_use_marketplace_prefix" name="magento_orders_settings[number][prefix][use_marketplace_prefix]" class="M2ePro-required-when-visible">
                            <option value="0" <?php if ($formData['magento_orders_settings']['number']['prefix']['use_marketplace_prefix'] == 0) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['magento_orders_settings']['number']['prefix']['use_marketplace_prefix'] == 1) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td class="label">
                        <label></label>
                    </td>
                    <td class="value" style="width: auto;">
                        <input type="hidden" id="sample_magento_order_id" value="<?php echo Mage::helper('M2ePro/Magento')->getNextMagentoOrderId(); ?>" />
                        <input type="hidden" id="sample_ebay_order_id" value="07-02610-01994" />
                        <input type="hidden" id="sample_marketplace_prefix" value="GB" />

                        <p class="note note-no-tool-tip">
                            <?php echo Mage::helper('M2ePro')->__('e.g.'); ?> <strong><span id="order_number_example_container"></span></strong>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_shipping_information">

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Shipping information'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_shipping_information_ship_by_date"><?php echo Mage::helper('M2ePro')->__('Import Ship by date to Magento order'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_shipping_information_ship_by_date" name="magento_orders_settings[shipping_information][ship_by_date]" class="M2ePro-required-when-visible">
                            <option value="1" <?php if ($formData['magento_orders_settings']['shipping_information']['ship_by_date'] == 1) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                            <option value="0" <?php if ($formData['magento_orders_settings']['shipping_information']['ship_by_date'] == 0) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                        </select>
                    </td>
                </tr>

                <tr id="magento_orders_shipping_information_container">
                    <td class="label">
                        <label for="magento_orders_shipping_address_region_override"><?php echo Mage::helper('M2ePro')->__('Override invalid Region/State required value') ?>:</label>
                    </td>
                    <td class="value">
                        <?php $regionOverride = !isset($formData['magento_orders_settings']['shipping_information']['shipping_address_region_override']) ? 1 : $formData['magento_orders_settings']['shipping_information']['shipping_address_region_override']?>
                        <select name="magento_orders_settings[shipping_information][shipping_address_region_override]" id="magento_orders_shipping_address_region_override">
                            <option value="0" <?php if (!$regionOverride): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('No') ?></option>
                            <option value="1" <?php if ($regionOverride): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes') ?></option>
                        </select>
                        <p class="note">
                            When enabled, the invalid Region/State value will be replaced with an alternative one to create an order in Magento.
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_shipping_information_skip_evtin_container">
                    <td class="label">
                        <label for="magento_orders_shipping_information_skip_evtin"><?php echo Mage::helper('M2ePro')->__('Skip eVTN') ?>:</label>
                    </td>
                    <td class="value">
                        <?php $isSkipEvtinOn = $formData['skip_evtin'] == 1 ?>
                        <select name="skip_evtin" id="magento_orders_shipping_information_skip_evtin">
                            <option value="0" <?php if (!$isSkipEvtinOn): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('No') ?></option>
                            <option value="1" <?php if ($isSkipEvtinOn): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes') ?></option>
                        </select>
                        <p class="note">
                            <?php echo Mage::helper('M2ePro')->__(
                                    'Set <b>Yes</b> if you want to exclude <a href="%url%" target="_blank">eVTN</a> from your Magento orders.',
                                    Mage::helper('M2ePro/Module_Support')->getSupportUrl('/support/solutions/articles/9000199785')
                            ); ?>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_customer" <?php if(($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Customer Settings'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_customer_mode"><?php echo Mage::helper('M2ePro')->__('Customer'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_customer_mode" name="magento_orders_settings[customer][mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_GUEST; ?>" <?php if ($formData['magento_orders_settings']['customer']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_GUEST) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Guest Account'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_PREDEFINED; ?>" <?php if ($formData['magento_orders_settings']['customer']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_PREDEFINED) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Predefined Customer'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_NEW; ?>" <?php if ($formData['magento_orders_settings']['customer']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_NEW) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Create New'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__(
                                '<b>Guest Account:</b> Magento Guest Checkout Option must be enabled to use this Option. Use the default Guest Account. Do not create a Customer Account.<br/><br/>
                                <b>Predefined Customer:</b> Use a specific Customer for all Orders. You should specify the Magento Customer ID to use.<br/><br/>
                                <b>Create New:</b> Create a new Customer in Magento for the Order. If an existing Magento Customer has the same email address as the email address used for the eBay Order, the Order will be assigned to that Customer instead.'
                            ); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_customer_id_container" <?php if($formData['magento_orders_settings']['customer']['mode'] != Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_PREDEFINED) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_customer_id"><?php echo Mage::helper('M2ePro')->__('Customer ID'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value" style="width: auto;">
                        <input id="magento_orders_customer_id" name="magento_orders_settings[customer][id]" value="<?php echo $this->escapeHtml($formData['magento_orders_settings']['customer']['id']); ?>" type="text" class="M2ePro-required-when-visible validate-digits M2ePro-account-customer-id input-text" />
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Enter Magento Customer ID.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_customer_new_website_id_container" <?php if($formData['magento_orders_settings']['customer']['mode'] != Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_NEW) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_customer_new_website_id"><?php echo Mage::helper('M2ePro')->__('Associate to Website'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_customer_new_website_id" name="magento_orders_settings[customer][website_id]" class="M2ePro-required-when-visible">
                            <option value="" <?php if ($formData['magento_orders_settings']['customer']['website_id'] == '') echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('-- Please Select --'); ?></option>
                            <?php foreach($this->websites as $website) { ?>
                                <option value="<?php echo $website['website_id']; ?>" <?php if ($formData['magento_orders_settings']['customer']['website_id'] == $website['website_id']) echo ' selected="selected"'; ?>><?php echo $website['name']; ?></option>
                            <?php } ?>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Website a Customer Account will be created for.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_customer_new_group_id_container" <?php if($formData['magento_orders_settings']['customer']['mode'] != Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_NEW) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_customer_new_group_id"><?php echo Mage::helper('M2ePro')->__('Customer Group'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_customer_new_group_id" name="magento_orders_settings[customer][group_id]" class="M2ePro-required-when-visible">
                            <option value="" <?php if ($formData['magento_orders_settings']['customer']['group_id'] == '') echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('-- Please Select --'); ?></option>
                            <?php foreach($this->groups as $group) { ?>
                                <option value="<?php echo $group['customer_group_id']; ?>" <?php if ($formData['magento_orders_settings']['customer']['group_id'] == $group['customer_group_id']) echo ' selected="selected"'; ?>><?php echo $group['customer_group_code']; ?></option>
                            <?php } ?>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Customer Group a Customer will be assigned to.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_customer_new_notifications_container" <?php if($formData['magento_orders_settings']['customer']['mode'] != Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CUSTOMER_MODE_NEW) echo 'style="display: none;"'; ?>>
                    <td class="label">
                        <label for="magento_orders_customer_new_notifications"><?php echo Mage::helper('M2ePro')->__('Send Emails When The Following Is Created'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_customer_new_notifications" name="magento_orders_settings[customer][notifications][]" multiple="multiple">
<!--                            <option value="customer_created" --><?php //if ($formData['magento_orders_settings']['customer']['notifications']['customer_created']) echo ' selected="selected"'; ?><!-->--><?php //echo Mage::helper('M2ePro')->__('Customer Account'); ?><!--</option>-->
                            <option value="order_created" <?php if ($formData['magento_orders_settings']['customer']['notifications']['order_created']) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Magento Order'); ?></option>
                            <option value="invoice_created" <?php if ($formData['magento_orders_settings']['customer']['notifications']['invoice_created']) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Invoice'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Necessary emails will be sent according to Magento Settings in Magento > System > Configuration > Sales Emails.<br/>Hold Ctrl Button, to choose more, than one Option.'); ?></span>
                        </p>
                    </td>
                </tr>

            </table>

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_customer_billing_address_mode"><?php echo Mage::helper('M2ePro')->__('Billing Address Usage'); ?>:</label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_customer_billing_address_mode" name="magento_orders_settings[customer][billing_address_mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::USE_SHIPPING_ADDRESS_AS_BILLING_ALWAYS; ?>"
                                <?php if ($formData['magento_orders_settings']['customer']['billing_address_mode'] == Ess_M2ePro_Model_Ebay_Account::USE_SHIPPING_ADDRESS_AS_BILLING_ALWAYS) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Always'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::USE_SHIPPING_ADDRESS_AS_BILLING_IF_SAME_CUSTOMER_AND_RECIPIENT; ?>" <?php if ($formData['magento_orders_settings']['customer']['billing_address_mode'] == Ess_M2ePro_Model_Ebay_Account::USE_SHIPPING_ADDRESS_AS_BILLING_IF_SAME_CUSTOMER_AND_RECIPIENT) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Buyer & Recipient have the same name'); ?></option>
                        </select>
                        <p class="note note-no-tool-tip">
                            <span><?php echo Mage::helper('M2ePro')->__('When to use shipping address as billing.'); ?></span>
                        </p>
                    </td>
                    <td class="value"  style="display: none">
                        <p class="note">
                            <span>
                                <?php echo Mage::helper('M2ePro')->__('Choose if you want to use your customer’s 
                                    shipping address as the billing one regularly or only if the buyer and recipient 
                                    have the same names.'); ?>
                            </span>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>
<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_rules" <?php if (($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Order Creation Rules'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">
            <div id="block_notice_ebay_accounts_magento_orders_rules" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Order Creation Rules'); ?>">
                <?php echo Mage::helper('M2ePro')->__(
                    'Choose the stage of the eBay Order process at which the Magento Order should be created.
                    You can also choose for how long to reserve Stock as soon as an eBay Order is received, to ensure you can fulfil the eBay Order in case there is a delay between the Order being made and the Magento Order being created.'
                ); ?>
            </div>

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_creation_mode"><?php echo Mage::helper('M2ePro')->__('Create Magento Order When') ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select name="magento_orders_settings[creation][mode]" id="magento_orders_creation_mode">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CREATE_CHECKOUT ?>" <?php if ($formData['magento_orders_settings']['creation']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CREATE_CHECKOUT): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('Checkout Is Completed') ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CREATE_CHECKOUT_AND_PAID ?>" <?php if ($formData['magento_orders_settings']['creation']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_CREATE_CHECKOUT_AND_PAID): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('Payment Is Received') ?></option>
                        </select>
                        <p class="note">
                            <?php echo Mage::helper('M2ePro')->__('Choose at which stage of eBay Order processing a Magento Order should be create') ?>
                        </p>
                    </td>
                </tr>

                <tr id="magento_orders_qty_reservation_days_container">
                    <td class="label">
                        <label for="magento_orders_qty_reservation_days"><?php echo Mage::helper('M2ePro')->__('Reserve Quantity') ?>:</label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select name="magento_orders_settings[qty_reservation][days]" id="magento_orders_qty_reservation_days">
                            <?php for ($day = 1; $day <= 14; $day++): ?>
                                <option value="<?php echo (int)$day ?>" <?php if ($formData['magento_orders_settings']['qty_reservation']['days'] == $day): ?>selected="selected"<?php endif; ?>>
                                    <?php if ($day == 1): ?>
                                        <?php echo Mage::helper('M2ePro')->__('For %number% day', $day) ?>
                                    <?php else: ?>
                                        <?php echo Mage::helper('M2ePro')->__('For %amount% days', $day) ?>
                                    <?php endif; ?>
                                </option>
                            <?php endfor; ?>
                        </select>
                        <p class="note">
                            <?php echo Mage::helper('M2ePro')->__('Choose for how long M2E Pro should reserve Magento Product quantity per eBay Order until Magento Order is created.') ?>
                        </p>
                    </td>
                </tr>

           </table>

        </div>
    </div>
</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_refund_and_cancellation" <?php if (($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Refund & Cancellation'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr id="magento_orders_refund_container">
                    <td class="label">
                        <label for="magento_orders_refund"><?php echo Mage::helper('M2ePro')->__('Cancel/Refund eBay orders') ?>:</label>
                    </td>
                    <td class="value">
                        <select name="magento_orders_settings[refund_and_cancellation][refund_mode]" id="magento_orders_refund">
                            <option value="0" <?php if (!$formData['magento_orders_settings']['refund_and_cancellation']['refund_mode']): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('No') ?></option>
                            <option value="1" <?php if ($formData['magento_orders_settings']['refund_and_cancellation']['refund_mode']): ?>selected="selected"<?php endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes') ?></option>
                        </select>
                        <p class="note">
                            <?php echo Mage::helper('M2ePro')->__(
                                'Enable to cancel or refund eBay orders and automatically update their statuses on the Channel. Find more details <a href="%url%" target="_blank">here</a>.',
                                Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'orders-cancelation-refund')
                            ); ?>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_tax" <?php if (($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Order Tax Settings'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_tax_mode"><?php echo Mage::helper('M2ePro')->__('Tax Source'); ?>: </label>
                    </td>

                    <td class="value" style="width: auto;">
                        <select id="magento_orders_tax_mode" name="magento_orders_settings[tax][mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_NONE; ?>"<?php if ($formData['magento_orders_settings']['tax']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_NONE) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('None'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_CHANNEL; ?>"<?php if ($formData['magento_orders_settings']['tax']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_CHANNEL) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('eBay'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_MAGENTO; ?>"<?php if ($formData['magento_orders_settings']['tax']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_MAGENTO) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Magento'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_MIXED; ?>"<?php if ($formData['magento_orders_settings']['tax']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_TAX_MODE_MIXED) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('eBay & Magento'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__(
                                    'Choose where the tax settings for your Magento Order will be taken from. See
                                    <a href="%url%" target="_blank">this article</a> for more details.',
                                    Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(
                                        null,
                                        null,
                                        'settings-for-tax-calculation#f51e5c654b3a47d3ba15b656f23c014f'
                                    )
                                ); ?></span>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<?php $statusList = $this->getMagentoOrderStatusList(); ?>

<div class="entry-edit" id="magento_block_ebay_accounts_magento_orders_status_mapping" <?php if (($formData['magento_orders_settings']['listing']['mode'] == 0 && $formData['magento_orders_settings']['listing_other']['mode'] == 0)) echo 'style="display: none;"'; ?>>

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Order Status Mapping'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <div id="block_notice_ebay_accounts_magento_orders_statuses" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Order Status Mapping'); ?>">
                <?php echo Mage::helper('M2ePro')->__(
                'Set the correspondence between eBay and Magento order statuses. The status of your Magento order will be updated based on these settings.'
                ); ?>
            </div>
            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label for="magento_orders_status_mapping_mode"><?php echo Mage::helper('M2ePro')->__('Status Mapping'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_status_mapping_mode" name="magento_orders_settings[status_mapping][mode]" class="M2ePro-required-when-visible">
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_DEFAULT; ?>" <?php if ($formData['magento_orders_settings']['status_mapping']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_DEFAULT) echo "selected='selected'"; ?>><?php echo Mage::helper('M2ePro')->__('Default Order Statuses'); ?></option>
                            <option value="<?php echo Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_CUSTOM; ?>" <?php if ($formData['magento_orders_settings']['status_mapping']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_CUSTOM) echo "selected='selected'"; ?>><?php echo Mage::helper('M2ePro')->__('Custom Order Statuses'); ?></option>
                        </select>
                    </td>
                </tr>

                <?php $isDisabledStatusStyle = ($formData['magento_orders_settings']['status_mapping']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_DEFAULT) ? "disabled='disabled'" : ''; ?>
                <?php
                    if ($formData['magento_orders_settings']['status_mapping']['mode'] == Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_MODE_DEFAULT) {
                        $formData['magento_orders_settings']['status_mapping']['new'] = Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_NEW;
                        $formData['magento_orders_settings']['status_mapping']['paid'] = Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_PAID;
                        $formData['magento_orders_settings']['status_mapping']['shipped'] = Ess_M2ePro_Model_Ebay_Account::MAGENTO_ORDERS_STATUS_MAPPING_SHIPPED;
                    }
                ?>

                <tr id="magento_orders_status_mapping_new_container">
                    <td class="label">
                        <label for="magento_orders_status_mapping_new"><?php echo Mage::helper('M2ePro')->__('Checkout Is Completed'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_status_mapping_new" name="magento_orders_settings[status_mapping][new]" class="M2ePro-required-when-visible" <?php echo $isDisabledStatusStyle; ?>>
                            <?php foreach ($statusList as $statusKey => $statusValue) { ?>
                                <option value="<?php echo $statusKey; ?>" <?php if ($formData['magento_orders_settings']['status_mapping']['new'] == $statusKey) echo 'selected="selected"'; ?>><?php echo $statusValue; ?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>

                <tr id="magento_orders_status_mapping_paid_container">
                    <td class="label">
                        <label for="magento_orders_status_mapping_paid"><?php echo Mage::helper('M2ePro')->__('Payment Is Completed'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_status_mapping_paid" name="magento_orders_settings[status_mapping][paid]" class="M2ePro-required-when-visible" <?php echo $isDisabledStatusStyle; ?>>
                            <?php foreach ($statusList as $statusKey => $statusValue) { ?>
                                <option value="<?php echo $statusKey; ?>" <?php if ($formData['magento_orders_settings']['status_mapping']['paid'] == $statusKey) echo 'selected="selected"'; ?>><?php echo $statusValue; ?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>

                <tr id="magento_orders_status_mapping_shipped_container" <?php echo $isDisabledStatusStyle; ?>>
                    <td class="label">
                        <label for="magento_orders_status_mapping_shipped"><?php echo Mage::helper('M2ePro')->__('Shipping Is Completed'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="magento_orders_status_mapping_shipped" name="magento_orders_settings[status_mapping][shipped]" class="M2ePro-required-when-visible" <?php echo $isDisabledStatusStyle; ?>>
                            <?php foreach ($statusList as $statusKey => $statusValue) { ?>
                                <option value="<?php echo $statusKey; ?>" <?php if ($formData['magento_orders_settings']['status_mapping']['shipped'] == $statusKey) echo 'selected="selected"'; ?>><?php echo $statusValue; ?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>
