<div style="display: none;">
    <div id="orderMiscItemInfoCollector">
        <div class="popup-header toolbar-header">
            <div class="popup-title"><?php echo $this->lang->line('miscellaneous') . ' ' . $this->lang->line('item') ?></div>
            <div class="popup-close-btn" onclick="zamanEposPopupcloser()"><span class="icon icon-cancel"></span></div>
        </div>
        <div class="popup-content">
            <form id="orderMiscAddForm">
                <div class="neworder-waiting">
                    <div class="text-center" id="orderMiscAddFormType"></div>
                    <div class="tab-group">
                        <div class="tab-item misc-food-type  kitchen" onclick="setMiscFoodType('kitchen')"><?php echo $this->lang->line('kitchen') ?></div>
                        <!--<div class="tab-item misc-food-type  bar" onclick="setMiscFoodType('bar')"><?php echo $this->lang->line('bar') ?></div>
                        <div class="tab-item misc-food-type  bakery" onclick="setMiscFoodType('bakery')"><?php echo $this->lang->line('bakery') ?></div>-->
                        <div class="tab-item misc-food-type  drinks" onclick="setMiscFoodType('drinks')"><?php echo $this->lang->line('drinks') ?></div>
                    </div>
                    <input type="hidden" name="type" value="kitchen" id="miscItemTypeFromAddMiscFrom">
                    <div class="clearfix"></div>
                    <div class="neworder-table-number collection-customer" style="width: 60%">
                        <div class="form-group">
                            <label><?php echo $this->lang->line('item') . ' ' . $this->lang->line('name') ?></label>
                            <input type="text" name="name" id="miscItemName" class="form-control" placeholder="<?php echo $this->lang->line('item') . ' ' . $this->lang->line('name') ?>">
                        </div>
                        <div class="clearfix"></div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">q</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">w</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">e</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">r</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">t</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">y</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">u</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">i</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">o</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">p</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">a</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">s</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">d</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">f</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">g</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">h</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">j</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">k</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">l</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">z</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">x</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">c</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">v</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">b</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">n</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey">m</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaActionKey">DEL</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaKey"> </div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscAlphaActionKey">CLR</div>
                        </div>
                    </div>
                    <div class="neworder-table-guest collection-phone" style="width: 20%">
                        <div class="form-group">
                            <label><?php echo $this->lang->line('price') ?></label>
                            <input type="text" name="price" id="miscItemPrice" class="form-control" placeholder="price">
                        </div>
                        <div class="clearfix"></div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">1</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">2</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">3</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">4</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">5</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">6</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">7</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">8</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">9</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">0</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryNumKey">.</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscPrimaryActionKey">CLR</div>
                        </div>
                    </div>
                    <div class="neworder-table-guest collection-time" style="width: 20%">
                        <div class="form-group">
                            <label><?php echo $this->lang->line('quantity') ?></label>
                            <input type="text" name="quantity"  id="miscItemQty" class="form-control" placeholder="quantity">
                        </div>
                        <div class="clearfix"></div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">1</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">2</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">3</div>

                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">4</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">5</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">6</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">7</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">8</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">9</div>
                        </div>
                        <div class="tab-group keypad">
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryActionKey">DEL</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryNumKey">0</div>
                            <div class="tab-item zaman-epos-nav quantity-digit keypad-key miscSecondaryActionKey">CLR</div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="tab-group config-submit">
                    <button type="submit" onclick="addMiscItem('orderMiscAddForm')"><span class="icon icon-folder"></span>&nbsp;<?php echo $this->lang->line('go') ?></button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    function zamanOrderMiscItemInfoControllerPopup() {
        zamanEposDb.epos_order.get({orderId: Number(zamanEposCart.getEposCurrentId())}).then(function (anOrder) {
            if (typeof (anOrder) !== 'undefined') {
                if (Number(anOrder.isPaid) === 3) {
                    orderPaymentPreProcessor(anOrder);
                } else {
                    $.colorbox({
                        inline: true,
                        scrolling: false,
                        href: "#orderMiscItemInfoCollector",
                        width: '100%',
                        height: 'auto',
                        maxWidth: "100%",
                        bottom: '0',
                        open: true,
                        closeButton: false,
                        transition: 'none',
                        overlayClose: false,
                        className: 'transparent-overlay',
                        onOpen: function () {
                            playBeepSound();
                            resetForm('orderMiscAddForm');
                            $('#miscItemTypeFromAddMiscFrom').val('kitchen');
                        },
                        onLoad: function () {
                            $('.misc-food-type').removeClass('active');
                            $('.misc-food-type.kitchen').addClass('active');
                        },
                        onComplete: function () {

                        },
                        onCleanup: function () {
                        },
                        onClosed: function () {
                            resetForm('orderMiscAddForm');
                        }
                    });
                }
            } else {
                warning('<?php echo $this->lang->line('warning') ?>', '<?php echo $this->lang->line('load_order_in_cart') ?>', '<?php echo $this->lang->line('ok') ?>');
            }
        });
    }
    function setMiscFoodType(type) {
        $('#miscItemTypeFromAddMiscFrom').val(type);
        $('.misc-food-type').removeClass('active');
        $('.misc-food-type.' + type).addClass('active');
    }
    function addMiscItem(formId) {
        $('#' + formId).validate({
            submitHandler: function () {
                var miscItemName = $('#miscItemName').val();
                var miscItemPrice = $('#miscItemPrice').val();
                var miscItemQty = $('#miscItemQty').val();
                var type = $('#' + formId + ' input[name=type]').val();
                customItemAddToCart(miscItemName, miscItemPrice, miscItemQty, type);
            },
            errorClass: "has-error",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
                $.colorbox.resize();
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
                $.colorbox.resize();
            },
            rules: {
                name: {required: true},
                price: {number: true, required: true},
                quantity: {number: true, required: true},
                type: {required: true}
            },
            errorPlacement: function (error, element) {
                errorPlacement(error, element);
            }
        });
    }
    function customItemAddToCart(miscItemName, miscItemPrice, miscItemQty, type) {
        var currentOrderId = zamanEposCart.getEposCurrentId();
        var cartData = new Array();
        zamanEposDb.epos_order.get({orderId: Number(currentOrderId)}).then(function (anOrder) {
            if (typeof (anOrder) === 'undefinded' || jQuery.isEmptyObject(anOrder)) {
                zamanNewOrderPageControllerPopup();
            } else {
                var cartArrayToCheck = zamanEposCart.listCart();
                if (cartArrayToCheck.length > 0) {
                    var miscCatIdList = new Array();
                    var miscMenuIdList = new Array();
                    for (var i in cartArrayToCheck) {
                        if (cartArrayToCheck[i].category >= 99999) {
                            miscCatIdList.push(parseInt(Number(cartArrayToCheck[i].category)));
                        }
                        if (cartArrayToCheck[i].menu >= 999999) {
                            miscMenuIdList.push(parseInt(Number(cartArrayToCheck[i].menu)));
                        }
                    }
                    if (miscCatIdList.length > 0 && miscMenuIdList.length > 0) {
                        cartData.category = Math.max(miscCatIdList) + 1;
                        cartData.menu = Math.max(miscMenuIdList) + 1;
                    } else {
                        cartData.category = Number(99999);
                        cartData.menu = Number(999999);
                    }
                } else {
                    cartData.category = Number(99999);
                    cartData.menu = Number(999999);
                }
                cartData.categoryTitle = 'miscellaneous';
                cartData.menuTitle = miscItemName;
                cartData.type = type;
                cartData.selection = 0;
                cartData.selectionTitle = '';
                cartData.price = parseFloat(Number(miscItemPrice));
                cartData.tax = 0;
                cartData.taxOption = 0;
                cartData.taxPercent = 0;
                cartData.taxIncluded = 'yes';
                cartData.discount = 0;
                cartData.discountOption = 0;
                cartData.qty = parseInt(Number(miscItemQty));
                cartData.setItem = zamanEposCart.listSetItem();
                cartData.Topping = zamanEposCart.listItemTopping();
                cartData.modifier = zamanEposCart.listItemModifier();
                cartData.sent = 'no';
                cartData.newQty = anOrder.status === '2' ? 0 : parseInt(Number(miscItemQty));
                var exitingCart = anOrder.cart;
                if (exitingCart.length > 0) {
                    for (var i in exitingCart) {
                        if (exitingCart[i].category === cartData.category && exitingCart[i].menu === cartData.menu && exitingCart[i].selection === cartData.selection) {
                            cartData.sent = 'yes';
                            cartData.newQty = parseInt(Number(miscItemQty));
                            break;
                        } else {
                            continue;
                        }
                    }
                }
                cartData.basePrice = parseFloat(Number(miscItemPrice));
                cartData.inPrice = parseFloat(Number(miscItemPrice));
                cartData.outPrice = parseFloat(Number(miscItemPrice));
                cartData.printat = 15;
                cartData.isFree = 'no';
                cartData.isFreeRule = 0;
                var cartLine = zamanEposCart.addItem(cartData);
                zamanEposCart.setEposCartNewQty(currentOrderId, cartData.newQty);
                clearAllOptions();
                $('#quantityBadge').text('1');
                zamanEposPopupcloser();
                displayEposCart();
                updateScroll();
                setCartLine(cartLine);
            }
        });
    }
</script>