Subversion Repositories SmartDukaan

Rev

Rev 27596 | Rev 27754 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(".good_inventory").live('click', function() {
                loadGoodInventory("main-content", "");
        });

        $(".catalog").live('click', function() {
                // clear pendingOrderId
                if (typeof pendingPO != "undefined") {
                        delete pendingPO;
                        delete pendingPOCustomer;
                }
                loadCatalog("main-content", "");
        });
        var accesories = false;
        $('.accesoriesClass').live('click', function() {
                accesories = true;

                doGetAjaxRequestHandler(context + "/getCatalog?accesories=" + true,
                        function(response) {
                                $('#main-content').html(response);
                        });


        });

        var brand = null;
        $('.cover').live('click', function() {
                console.log('hello');

                brand = $(this).data('stockbrand');
                console.log(brand);
                doGetAjaxRequestHandler(context + "/getCatalog?brand=" + brand,
                        function(response) {
                                $('#main-content').html(response);
                        });
        });

        $('.add-compare-checkbox').live('change', function() {

                let catalogitemid = [$(this).data("catalogitemid")];
                let checked = $(this).is(':checked');
                console.log(checked);
                $cbToModify = $(this).closest('table').find('tr').find('input:checkbox').filter(function() {
                        return ($(this).data("catalogitemid") == catalogitemid && $(this).is(':checked') != checked);
                });

                let count = 0;
                $cbToModify.prop("checked", checked).prop("disabled", checked);
                let cbToCondition = $(this).closest('table').find('tr').find('input:checkbox').filter(function() {
                        return ($(this).is(':checked') != checked);
                });

                $('#add-to-compare-check').closest('table').find('tr').each(function() {

                        var row = $(this);

                        if (row.find('input[name="compare-check"]').is(':checked')) {
                                count++;

                        }
                });

                console.log(count);
                $cbToModify.prop("checked", checked).prop("disabled", checked);

        });

        $("#Go-compare-button").live('click', function() {

                console.log('helo');
                var gocatalogitemid = [];

                $('table').find('input[type="checkbox"]:enabled:checked').each(function(el) {
                        gocatalogitemid.push($(this).data("catalogitemid"));
                });
                console.log(gocatalogitemid);
                if (gocatalogitemid.length < 4) {

                        doAjaxRequestHandler(`${context}/getProductCompareInfo?catalogIds=` + gocatalogitemid.join(","), "GET",
                                function(response) {
                                        console.log(response)
                                        $('#' + "main-content").html(response);
                                });
                }

        });


        $(document).on('click', '#catalog-button', function() {

                loadSimilarCatalog("main-content", "");
        });



        $('.view-invoices').live('click', function() {
                loadInvoice();
        });


        $(".review_order").live('click', function() {
                loadOrder("main-content");
        });

        $(".notify_cancel").live('click', function() {
                loadNotifyCancelOrder("main-content");
        });

        $(".keep-a-tab").live('click', function() {
                loadtabOrder("main-content");
        });

        $(".notify_order").live('click', function() {
                loadnotifyOrder("main-content");
        });

        $(".item_aging").live('click', function() {
                getInventoryItemAgingByInterval("main-content", "");
        });

        $("#item-aging-search-button").live('click', function() {
                searchContent = $("#item-aging-search-text").val();
                if (typeof (searchContent) == "undefined" || !searchContent) {
                        searchContent = "";
                }
                getInventoryItemAgingByInterval("main-content", searchContent);
        });

        $("#item-aging-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#item-aging-search-button").click();
                }
        });

        $("#item-aging-paginated .next").live('click', function() {
                var end = $("#item-aging-paginated .end").text();
                getItemAgingNextPreviousItems(end, "");
                $("#item-aging-paginated .next").blur();
        });

        $("#item-aging-paginated .previous").live('click', function() {
                var start = $("#item-aging-paginated .start").text();
                getItemAgingNextPreviousItems(start - 11, "");
                $("#item-aging-paginated .previous").blur();
        });

        $(".download_aging_report").live('click', function() {
                downloadAgingReport();
        });

        $(".download_reports").live('click', function() {
                downloadReports();
        });

        $(".item-ledger-report-download-page").live('click', function() {
                loadItemLedgerReportDownloadPage("main-content");
        });

        $(".bad_inventory").live('click', function() {
                loadBadInventory("main-content", "");
        });

        $("#good-inventory-paginated .next").live(
                'click',
                function() {
                        var searchText = $("#good-inventory-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";

                        }
                        var params = {};
                        params['searchTerm'] = searchText;
                        loadPaginatedNextItems('/getPaginatedCurrentInventorySnapshot',
                                params, 'good-inventory-paginated',
                                'good-inventory-table', null);
                        $(this).blur();
                });

        $("#good-inventory-paginated .previous").live(
                'click',
                function() {
                        var searchText = $("#good-inventory-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        var params = {};
                        params['searchTerm'] = searchText;
                        loadPaginatedPreviousItems(
                                '/getPaginatedCurrentInventorySnapshot', params,
                                'good-inventory-paginated', 'good-inventory-table',
                                null);
                        $(this).blur();
                });

        $("#good-inventory-search-button").live('click', function() {
                var searchText = $("#good-inventory-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                }
                loadGoodInventorySearchInfo(searchText);
        });

        $("#good-inventory-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#good-inventory-search-button").click();
                }
        });

        $("#catalog-paginated .next").live(
                'click',
                function() {
                        var searchText = $("#catalog-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }

                        var searchItem = $("#catalog-search-text-compare").val();
                        console.log(searchItem)

                        var params = {};

                        if (searchItem) {
                                params['itemId'] = currentItem.itemId;
                        }
                        console.log(brand);
                        if (brand != null) {
                                params['brand'] = brand;
                        }

                        if (accesories == true) {
                                params['accesories'] = accesories;
                        }


                        params['searchTerm'] = searchText;
                        console.log(params)
                        loadPaginatedCatalogNextItems('/getPaginatedCatalog', params,
                                'catalog-paginated', 'catalog-table', null);
                        $(this).blur();
                });

        $("#catalog-paginated .previous").live(
                'click', function() {
                        var searchText = $("#catalog-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        var searchItem = $("#catalog-search-text-compare").val();
                        console.log(searchItem)

                        var params = {};

                        if (searchItem) {
                                params['itemId'] = currentItem.itemId;
                        }
                        console.log(brand);
                        if (brand != null) {
                                params['brand'] = brand;
                        }

                        if (accesories == true) {
                                params['accesories'] = accesories;
                        }
                        params['searchTerm'] = searchText;
                        console.log(params)

                        loadPaginatedCatalogPreviousItem('/getPaginatedCatalog', params,
                                'catalog-paginated', 'catalog-table', null);
                        $(this).blur();
                });

        $("#catalog-search-button").live('click', function() {
                var searchText = $("#catalog-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                }
                loadCatalogSearchInfo(searchText);
        });

        $("#catalog-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#catalog-search-button").click();
                }
        });

        $(".cancellation").live(
                "click",
                function(e) {
                        orderid = $(this).data('orderid');
                        itemId = $(this).data('itemid');

                        doGetAjaxRequestHandler(context
                                + "/getcancelOrderItems?itemId=" + itemId, function(
                                        response) {
                                $('.cancel-order-container .modal-content').html(response);
                                $("#textreason").hide();
                        });
                });

        $(".cancel-order-submit").live("click", function(e) {
                requestcancelOrder();
        });
        $(".keepatab").live("click", function(e) {
                orderid = $(this).data('orderid');
                cancelOrder(orderid, "KEEP_A_TAB")

        });

        $(".request-cancel").live('click', function() {

        });

        $(".mk_button").on("click", function() {

        });

        $(".closeOrder")
                .live(
                        "click",
                        function(e) {
                                orderid = $(this).data('orderid');
                                if (confirm("Are you sure you want to close the order") == true) {

                                        doPostAjaxRequestHandler(context
                                                + "/closeOrder?orderId=" + orderd,
                                                function(response) {
                                                        if (response == 'true') {
                                                                alert("successfully close");
                                                                loadtabOrder("main-content");
                                                        }
                                                });
                                }

                        });
        $('#notify-table').find(':checkbox').live('change', function(e) {
                var colormessage = [];
                $("#notify-table input[type=checkbox]:checked").each(function() {

                        var row = $(this).closest("tr")[0];
                        colormessage.push(row.cells[0].innerText);

                        console.log(colormessage)
                });

                $("#colorValue").text(colormessage);
        });

        $('#cancel-order-table').find(':checkbox').live('change', function(e) {
                var orderId = [];

                $("#cancel-order-table input[type=checkbox]:checked").each(function() {
                        var currentRow = $(this).closest("tr");

                        orderId.push(currentRow.find("td:eq(2)").html());

                });

                selectedOrderId = $('#orderIds').val(orderId);
                console.log(selectedOrderId);
        });

        $('#overridemessage').live('change', function() {
                if ($(this).is(':checked')) {
                        $('#textnotifymessage').show();
                        $('#textnotifymessage').focus();
                } else {
                        $('#textnotifymessage').hide();
                }
        });

        $(".notify-cancel-order-submit")
                .live(
                        "click",
                        function(e) {
                                var jsonObject = {};
                                var orderAndItemIdsJson = [];
                                var orderAndItemIds;
                                var orderIds;
                                var message;
                                message = $('#textNotifyCancellationMessage').val();

                                var partnerchecked = $("input[name='partnerCancelOrderCheck']:checked").length;

                                if (!partnerchecked) {
                                        alert("You must check at least one partner.");
                                        return false;
                                }

                                if (message === "") {
                                        alert("message is required");
                                        return false;
                                }

                                $('#partner-cancel-order-table')
                                        .find('tr')
                                        .each(
                                                function() {
                                                        var row = $(this);

                                                        console.log(row);
                                                        if (row
                                                                .find(
                                                                        'input[name="partnerCancelOrderCheck"]')
                                                                .is(':checked')) {
                                                                var currentRow = $(this)
                                                                        .closest("tr");

                                                                var col5 = currentRow.find(
                                                                        "td:eq(1)").html();
                                                                var col6 = currentRow.find(
                                                                        "td:eq(2)").html();

                                                                orderIds = {
                                                                        "orderId": col6,
                                                                        "olditemId": col5
                                                                }
                                                                orderAndItemIdsJson
                                                                        .push(orderIds)

                                                        }

                                                });

                                jsonObject['orderIds'] = orderAndItemIdsJson;
                                jsonObject['message'] = message
                                console.log(jsonObject)

                                if (confirm("Are you sure you want to notify the order") == true) {

                                        doPostAjaxRequestWithJsonHandler(context
                                                + "/notifyCancelOrder", JSON
                                                        .stringify(jsonObject), function(response) {
                                                                if (response == 'true') {
                                                                        alert("successfully notify");
                                                                        $('#notifyCancelOrder').modal('hide');
                                                                        $('.modal-backdrop').remove();
                                                                        loadOrder("main-content");
                                                                }
                                                        });
                                }

                        });
        $(".notify-submit")
                .live(
                        "click",
                        function(e) {

                                var jsonObject = {};
                                var orderIdsJSon = [];
                                var ItemIdsJson = [];
                                var itemIds;
                                var orderIds;
                                var message;

                                if ($('#overridemessage').is(':checked')) {
                                        message = $('#textnotifymessage').val();
                                } else {
                                        message = $('#notifymsg').text();
                                }

                                console.log(message);
                                var itemchecked = $("input[name='itemCheck']:checked").length;

                                if (!itemchecked) {
                                        alert("You must check at least one item.");
                                        return false;
                                }
                                var partnerchecked = $("input[name='partnerCheck']:checked").length;

                                if (!partnerchecked) {
                                        alert("You must check at least one partner.");
                                        return false;
                                }

                                if (message === "") {
                                        alert("message is required");
                                        return false;
                                }

                                $('#notify-table')
                                        .find('tr')
                                        .each(
                                                function() {
                                                        var row = $(this);

                                                        console.log(row);
                                                        if (row.find(
                                                                'input[name="itemCheck"]')
                                                                .is(':checked')) {
                                                                var currentRow = $(this)
                                                                        .closest("tr");

                                                                var col1 = currentRow
                                                                        .find(
                                                                                "td:eq(0) input[type='checkbox']")
                                                                        .val(); // get current
                                                                // row 1st TD
                                                                // value
                                                                var col2 = currentRow
                                                                        .find(
                                                                                "td:eq(1) input[name='responseTime']")
                                                                        .data('daterangepicker').startDate
                                                                        .format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);// get
                                                                // current
                                                                // row 2nd TD
                                                                var col3 = currentRow
                                                                        .find(
                                                                                "td:eq(2) input[name='procuredDate']")
                                                                        .data('daterangepicker').startDate
                                                                        .format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
                                                                // get current
                                                                // row 3rd TD

                                                                itemIds = {
                                                                        "itemId": col1,
                                                                        "responseTime": col2,
                                                                        "procuredTime": col3

                                                                }
                                                                ItemIdsJson.push(itemIds);
                                                        }

                                                });

                                $('#notify-order-table').find('tr').each(
                                        function() {
                                                var row = $(this);

                                                console.log(row);
                                                if (row.find('input[name="partnerCheck"]')
                                                        .is(':checked')) {
                                                        var currentRow = $(this).closest("tr");

                                                        var col5 = currentRow.find("td:eq(2)")
                                                                .html();
                                                        var col6 = currentRow.find("td:eq(1)")
                                                                .html();

                                                        orderIds = {
                                                                "orderId": col5,
                                                                "olditemId": col6
                                                        }
                                                        orderIdsJSon.push(orderIds)
                                                }
                                        });

                                jsonObject['itemIds'] = ItemIdsJson;
                                jsonObject['orderIds'] = orderIdsJSon;
                                jsonObject['message'] = message;

                                console.log(jsonObject)

                                if (confirm("Are you sure you want to notify the order") == true) {

                                        doPostAjaxRequestWithJsonHandler(context
                                                + "/notifyOrder", JSON
                                                        .stringify(jsonObject), function(response) {
                                                                if (response == 'true') {
                                                                        alert("successfully notify");
                                                                        $('#notifyOrder').modal('hide');
                                                                        $('.modal-backdrop').remove();
                                                                        loadOrder("main-content");
                                                                }
                                                        });
                                }

                        });

        $(".change-notify-request")
                .live(
                        "click",
                        function(e) {

                                var jsonObject = {};
                                var orderIdsJSon = [];
                                var orderIds;

                                $('#notify-cancel-order-list-table').find('tr').each(
                                        function() {
                                                var row = $(this);

                                                console.log(row);
                                                if (row.find(
                                                        'input[name="cancelOrderCheck"]')
                                                        .is(':checked')) {
                                                        var currentRow = $(this).closest("tr");
                                                        var col5 = currentRow.find("td:eq(1)")
                                                                .html();
                                                        var col6 = currentRow.find("td:eq(2)")
                                                                .html();

                                                        orderIds = {
                                                                "orderId": col6,
                                                                "olditemId": col5
                                                        }
                                                        orderIdsJSon.push(orderIds)
                                                }
                                        });
                                console.log(orderIdsJSon)
                                jsonObject['orderIds'] = orderIdsJSon;
                                console.log(jsonObject)
                                if (confirm("Are you sure you want to update notify order") == true) {

                                        doPostAjaxRequestWithJsonHandler(context
                                                + "/changeNotifyCancelRequest", JSON
                                                        .stringify(jsonObject), function(response) {
                                                                if (response == 'true') {
                                                                        alert("successfully Update");
                                                                        $('#notifyCancelOrderList').modal('hide');
                                                                        $('.modal-backdrop').remove();
                                                                        loadNotifyCancelOrder("main-content");
                                                                }
                                                        });
                                }
                        });

});

function getItemColor(catalogId, itemId) {
        console.log(catalogId);

        doGetAjaxRequestHandler(context + "/getNotifyItemColor?catalogItemId="
                + catalogId + "&itemId=" + itemId, function(response) {
                        $('.notify-container .modal-content').html(response);
                        $('#textnotifymessage').hide();
                });
}

function getItems(catalogItemId) {
        doGetAjaxRequestHandler(context + "/getItems?catalogItemId="
                + catalogItemId, function(response) {
                        $('.notify-cancel-order-container .modal-content').html(response);

                });
}

function loadGoodInventory(domId, search_text) {
        doGetAjaxRequestHandler(context
                + "/getCurrentInventorySnapshot?searchTerm=" + search_text,
                function(response) {
                        $('#' + domId).html(response);
                });
}

function loadCatalog(domId, search_text) {
        doGetAjaxRequestHandler(context + "/getCatalog?searchTerm=" + search_text,
                function(response) {
                        $('#' + domId).html(response);
                });

}

function loadSimilarCatalog(domId, catalogItemId) {
        console.log(currentItem);
        var searchText = $("#catalog-search-text-compare").val();
        console.log(searchText)
        doGetAjaxRequestHandler(context + "/getCatalog?itemId=" + currentItem.itemId,
                function(response) {
                        $('#' + domId).html(response);

                        $("#catalog-search-text-compare").val(currentItem.itemDescription)
                });

}


function loadOrder(domId) {
        doGetAjaxRequestHandler(context + "/getInProcessOrder", function(response) {
                $('#' + domId).html(response);
        });

}

function loadtabOrder(domId) {
        doGetAjaxRequestHandler(context + "/getKeepInTabOrder", function(response) {
                $('#' + domId).html(response);
        });

}

function loadnotifyOrder(domId) {
        doGetAjaxRequestHandler(context + "/getAllNotifyOrder", function(response) {
                $('#' + domId).html(response);
        });

}

function getInventoryItemAgingByInterval(domId, searchContent) {
        doPostAjaxRequestWithJsonHandler(
                context + "/getInventoryItemAgingByInterval?searchContent="
                + searchContent, JSON.stringify([5, 15, 30, 45]),
                function(response) {
                        $('#' + domId).html(response);
                });
}

function downloadAgingReport() {
        data = JSON.stringify([5, 15, 30, 45]), doAjaxPostDownload(context
                + "/downloadInventoryItemAgingByInterval", data,
                "InventoryItemAging.xlsx");

}

function downloadReports() {
        doGetAjaxRequestHandler(context + "/reports", function(response) {
                $('#main-content').html(response);
        });
}

function downloadItemLedgerReport() {
        console.log("downloadItemLedgerReport Button clicked")
        var dateWise = $("#dateWise").get(0).checked;
        doAjaxGetDownload(context + "/itemLedger/complete/download?startDateTime="
                + startDate + "&endDateTime=" + endDate + "&dateWise=" + dateWise,
                "ItemCompleteLedegerReport.xlsx");
}

function getItemAgingNextPreviousItems(offset, searchContent) {
        console.log("getItemAgingNextPreviousItems() called");
        doPostAjaxRequestWithJsonHandler(context
                + "/getInventoryItemAgingByInterval?offset=" + offset
                + "&searchContent=" + searchContent, JSON
                        .stringify([5, 15, 30, 45]), function(response) {
                                $('#main-content').html(response);
                        });

}

function loadBadInventory(domId, search_text) {
        doGetAjaxRequestHandler(context + "/getBadInventorySnapshot?searchTerm="
                + search_text, function(response) {
                        $('#' + domId).html(response);
                });
}

function loadGoodInventorySearchInfo(search_text) {
        loadGoodInventory("main-content", search_text);
}

function loadCatalogSearchInfo(search_text) {
        loadCatalog("main-content", search_text);
}

function loadItemLedgerReportDownloadPage(domId) {
        doGetAjaxRequestHandler(context + "/itemLedger/downloadPage", function(
                response) {
                $('#' + domId).html(response);
        });
}
function myFunction() {
        var val = $("#selectreason").val();
        console.log(val);
        if (val == "other") {
                $("#textreason").show();
        } else {
                $("#textreason").hide();
        }

}
function requestcancelOrder() {
        var jsonObject = {};
        var orderIdsJson = [];

        val = $('#selectreason').val();
        if (val == "other") {
                reason = $('#textreason').val();
        } else {
                reason = val;
        }
        console.log(reason);

        if (reason == "" || reason == null || reason == undefined) {
                alert("reason field can't be empty");
                return false;
        }

        var partnerOrderCheck = $("input[name='partnerOrderCheck']:checked").length;

        if (!partnerOrderCheck) {
                alert("You must check at least one order.");
                return false;
        }

        var orderIds = $('#orderIds').val()
        selectedOrder = orderIds.split(',');
        console.log(selectedOrder);
        jsonObject['orderIds'] = selectedOrder;
        jsonObject['reason'] = reason;

        console.log(jsonObject)

        if (confirm("Are you sure you want to cancel the order") == true) {

                doPostAjaxRequestWithJsonHandler(context + "/cancelOrder", JSON
                        .stringify(jsonObject), function(response) {
                                if (response == 'true') {
                                        alert("successfully cancel");
                                        $('#cancelOrder').modal('hide');
                                        $('.modal-backdrop').remove();
                                        loadOrder("main-content");
                                }
                        });
        }

}

function loadNotifyCancelOrder(domId) {
        doGetAjaxRequestHandler(context + "/getNotifiedCancelOrder", function(
                response) {
                $('#' + domId).html(response);
        });
}

function getNotifyCancelItems(itemId, OrderId) {
        doGetAjaxRequestHandler(context + "/getNotifyItems?itemId=" + itemId,
                function(response) {
                        $('.notify-cancel-order-Items-container .modal-content').html(
                                response);

                });
}

function loadInvoice(serialNumber) {
        let url = `${context}/view-invoices`;
        if (typeof serialNumber != "undefined") {
                url = `${url}?serialNumber=${serialNumber}`;
                doAjaxGetDownload(url, `invoice-${serialNumber}.pdf`)
        } else {
                doGetAjaxRequestHandler(url, function(response) {
                        $('#main-content').html(response);
                });
        }
}