<script type="text/javascript">
    function zamanOrderToppingControllerPopup() {
        zamanEposDb.epos_order.get({orderId: Number(zamanEposCart.getEposCurrentId())}).then(function (anOrder) {
            if (typeof (anOrder) !== 'undefined') {
                if (Number(anOrder.isPaid) === 3) {
                    orderPaymentPreProcessor(anOrder);
                } else {
                    if ($.trim($('#cartSelectedLine').val())) {
                        $('#placeOrderTypeBlock').hide();
                        clearEposWorkArea();
                        $('.breadcurmb-category').html('<span style="color:#ddfc0d;">Choose Topping</span>');
                        $('.breadcurmb-menu').html('');
                        $('.menu-category.menu-button-inner').removeClass('active');
                        zamanEposDb.transaction('rw', [zamanEposDb.epos_nattrcategory, zamanEposDb.epos_nattr], () => {
                            zamanEposDb.epos_nattrcategory.where({status: '3'}).toArray().then(function (nattrCats) {
                                if (nattrCats.length > 0) {
                                    nattrCats.forEach(function (nattrCat) {
                                        zamanEposDb.epos_nattr.where({nattrcategory: nattrCat.id}).toArray().then(function (nattrCatItems) {
                                            var html = '';
                                            if (nattrCatItems.length > 0) {
                                                nattrCatItems.forEach(function (nattrCatItem) {
                                                    html += '<div class="menu-button" onclick="AddGlobalToppingToItem(\'' + nattrCatItem.title + '\',\'1\',\'' + nattrCatItem.price + '\')"><div class="menu-button-inner">' + nattrCatItem.title + '</div></div>';
                                                });
                                            }
                                            $('#eposCategoryMenuList').html(html);
                                        });
                                    });
                                }
                            });
                        });
                    } else {
                        warning('<?php echo $this->lang->line('warning') ?>', '<?php echo $this->lang->line('cart_item_select_msg') ?>', '<?php echo $this->lang->line('close') ?>');
                    }
                }
            } else {
                warning('<?php echo $this->lang->line('warning') ?>', '<?php echo $this->lang->line('load_order_in_cart') ?>', '<?php echo $this->lang->line('ok') ?>');
            }
        });
    }
    function AddGlobalToppingToItem(title, qty, price) {
        if ($.trim(title) && $.trim(qty) && $.trim(price)) {
            var line = $('#cartSelectedLine').val();
            var itemTopData = {};
            itemTopData.title = title;
            itemTopData.qty = parseInt(Number(qty));
            itemTopData.price = parseFloat(Number(price));
            itemTopData.set = '0';
            var activeLine = zamanEposCart.addGlobalTop(line, itemTopData);
            displayEposCart();
            setCartLine(activeLine);
            zamanEposPopupcloser();
        }
    }
</script>