<div style="display: none;">
    <div id="zamanDeliveryCustomPlanControllerPopup">
        <div class="popup-header toolbar-header">
            <div class="popup-title"><?php echo $this->lang->line('delivery_plan') . ' ' . $this->lang->line('for') ?> &nbsp;<span id="deliveryPlanAreaText"></span></div>
            <div class="popup-close-btn" onclick="zamanEposPopupcloser()"><span class="icon icon-cancel"></span></div>
        </div>
        <div class="popup-content">
            <div class="pane">
                <form id="zamanDeliveryCustomPlanForm">
                    <div class="delivery-custom-plan-form-block">
                        <input type="hidden" name="area" id="deliveryCustomPlanArea" class="form-control" placeholder="<?php echo $this->lang->line('area') ?>"/>
                        <div style="width: 33%; padding: 2px; float: left; border-right: 1px solid #627f94">
                            <div class="form-group">
                                <label><?php echo $this->lang->line('delivery_charge') ?></label>
                                <input type="text" id="zamanCustomDeliveryFeeOnPopup" name="delivery_charge" class="form-control" placeholder="<?php echo $this->lang->line('delivery_charge') ?>"/>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">1</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">2</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">3</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">4</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">5</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">6</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">7</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">8</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">9</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">0</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryNumKey">.</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key customtDeliveryChargePrimaryActionKey">CLR</div>
                            </div>
                        </div>
                        <div style="width: 33%; padding: 2px; float: left; border-right: 1px solid #627f94">
                            <div class="form-group">
                                <label><?php echo $this->lang->line('delivery_waiting_time') ?> (mins)</label>
                                <input type="text" id="zamanCustomDeliveryWaitingTimeOnPopup"  name="waiting_time" class="form-control" placeholder="<?php echo $this->lang->line('delivery_waiting_time') ?>"/>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">10</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">15</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">20</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">25</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">30</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">35</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">40</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">45</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">55</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryActionKey">DEL</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryNumKey">60</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryWaitingTimePrimaryActionKey">CLR</div>
                            </div>
                        </div>
                        <div style="width: 33%; padding: 2px; float: left;">
                            <div class="form-group">
                                <label><?php echo $this->lang->line('minimum_order_amount') ?></label>
                                <input type="text" id="zamanCustomDeliveryMinOrderOnPopup"  name="min_order" class="form-control" placeholder="<?php echo $this->lang->line('minimum_order_amount') ?>"/>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">1</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">2</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">3</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">4</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">5</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">6</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">7</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">8</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">9</div>
                            </div>
                            <div class="tab-group keypad">
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">0</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryNumKeyCustom">.</div>
                                <div class="tab-item zaman-epos-nav quantity-digit keypad-key deliveryMinOorderPrimaryActionKeyCustom">CLR</div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-group config-submit">
                        <button type="submit" onclick="validateDeliveryCustomPlan('zamanDeliveryCustomPlanForm')"><span class="icon icon-folder"></span>&nbsp;<?php echo $this->lang->line('go') ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function zamanDeliveryCustomPlanControllerPopup(area) {
        $.colorbox({
            inline: true,
            scrolling: false,
            href: "#zamanDeliveryCustomPlanControllerPopup",
            width: '60%',
            height: 'auto',
            maxWidth: "100%",
            open: true,
            closeButton: false,
            transition: 'none',
            overlayClose: false,
            onOpen: function () {
                $('#deliveryPlanAreaText').text(area);
                resetForm('zamanDeliveryCustomPlanForm');

            },
            onLoad: function () {
                $('#deliveryCustomPlanArea').val(area);

            },
            onComplete: function () {

            },
            onCleanup: function () {
            },
            onClosed: function () {
                resetForm('zamanDeliveryCustomPlanForm');
            }
        });
    }
    function validateDeliveryCustomPlan(formId) {
        $('#' + formId).validate({
            submitHandler: function () {
                var area = $('#deliveryCustomPlanArea').val();
                var delivery_charge = $('#zamanCustomDeliveryFeeOnPopup').val();
                var waiting_time = $('#zamanCustomDeliveryWaitingTimeOnPopup').val();
                var min_order = $('#zamanCustomDeliveryMinOrderOnPopup').val();
                if (checkInternetConnection()) {
                    $('.page-loader').show()
                    $.ajax({
                        url: '<?php echo site_url('settings/save_deliveryplan') ?>',
                        data: {'area': area, 'delivery_charge': delivery_charge, 'waiting_time': waiting_time, 'min_order': min_order, 'update': 'no'},
                        type: 'post',
                        dataType: 'json',
                        success: function (response) {
                            if (response.status) {
                                zamanEposDb.epos_deliveryplan.add(response.plan);
                                preCheckDeliveryPlan(area, delivery_charge, min_order, waiting_time);
                                zamanEposPopupcloser();
                            } else {
                                zamanEposDb.epos_deliveryplan.add({'area': area, 'delivery_charge': delivery_charge, 'waiting_time': waiting_time, 'min_order': min_order});
                                preCheckDeliveryPlan(area, delivery_charge, min_order, waiting_time);
                            }
                        }
                    });
                } else {
                    zamanEposDb.epos_deliveryplan.add({'area': area, 'delivery_charge': delivery_charge, 'waiting_time': waiting_time, 'min_order': min_order});
                    preCheckDeliveryPlan(area, delivery_charge, min_order, waiting_time);
                }

            },
            errorClass: "has-error",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            ignore: ":hidden",
            rules: {
                area: {required: true},
                waiting_time: {number: true, required: true},
                delivery_charge: {number: true, required: true}
            },
            messages: {
                area: '<?php echo sprintf($this->lang->line('item_required'), $this->lang->line('area')) ?>',
                waiting_time: '<?php echo sprintf($this->lang->line('item_required'), $this->lang->line('delivery_waiting_time')) ?>',
                delivery_charge: '<?php echo sprintf($this->lang->line('item_required'), $this->lang->line('delivery_charge')) ?>'
            },
            errorPlacement: function (error, element) {
                errorPlacement(error, element);
            }
        });
    }
</script>






