Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(document).on('click', ".create-scheme", function() {
                loadScheme("main-content");
        });

        $(document).on('click', "#schemes-paginated .next",
                function() {
                        var category = $('#partner-category').val();
                        var searchText = $("#scheme-item-search-text").val();

                        var category = $('#partner-category').val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        if (typeof (category) == "undefined" || !category) {
                                category = "";
                        }

                        if ((searchText) && (category)) {

                                var params = {};
                                params['searchItem'] = currentItem.itemId;
                                params['partnerType'] = category
                                loadPaginatedNextItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');

                        } else if ((searchText)) {
                                var params = {};
                                params['searchItem'] = currentItem.itemId;
                                loadPaginatedNextItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');

                        } else {
                                var params = {};
                                params['partnerType'] = category
                                loadPaginatedNextItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');
                        }
                        $(this).blur();
                });

        $(document).on('click', "#schemes-paginated .previous",
                function() {
                        var searchText = $("#scheme-item-search-text").val();
                        var category = $('#partner-category').val();
                        // var searchTxt=$("#scheme-search-text").val();
                        console.log(searchText);
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        if (typeof (category) == "undefined" || !category) {
                                category = "";
                        }

                        console.log(searchText)

                        if ((searchText) && (category)) {

                                var params = {};
                                params['searchItem'] = currentItem.itemId;
                                params['partnerType'] = category
                                loadPaginatedPreviousItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');

                        } else if ((searchText)) {
                                var params = {};
                                params['searchItem'] = currentItem.itemId;
                                loadPaginatedPreviousItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');

                        } else {
                                var params = {};
                                params['partnerType'] = category
                                loadPaginatedPreviousItems('/getPaginatedSchemes', params,
                                        'schemes-paginated', 'schemes-table',
                                        'scheme-details-container');
                        }
                        $(this).blur();
                });

        $(document).on('click', ".scheme-details", function() {
                var schemeId = $(this).attr('data');
                console.log("schemeId = " + schemeId);
                loadSchemeDetails(schemeId, "scheme-details-container");
        });

        $(document).on('click', ".active-scheme", function() {
                var schemeId = $(this).attr('data');
                console.log("active-scheme id : " + schemeId);
                var start = $("#schemes-paginated .start").text();
                // var end = $( "#schemes-paginated .end" ).text();
                var offset = start - 1;
                if (confirm("Are you sure you want to Active Scheme!") == true) {
                        activeScheme(schemeId, offset, "schemes-table");
                }
        });

        $(document).on('click', ".expire-scheme", function() {
                var schemeId = $(this).attr('data');
                var expireDate = startDate;
                var start = $("#schemes-paginated .start").text();
                // var end = $( "#schemes-paginated .end" ).text();
                var offset = start - 1;
                if (confirm("Are you sure you want to Expire Scheme!") == true) {
                        expireScheme(schemeId, expireDate, offset, "schemes-table");
                }
        });
        $(document).on('click', "#extendDatetime-button",
                function() {
                        console.log("extendAll button click");
                        var extendDatetime = $('input[name="extendDatetime"]')
                                .val();
                        console.log("extendDatetime : " + extendDatetime);
                        if (extendDatetime) {
                                if (confirm("Are you sure you want to Extend expireDateTime for All Scheme!") == true) {
                                        extendAllScheme(extendDatetime, "schemes-table")
                                }
                        } else {
                                alert("feild can't be blank");
                        }
                });
        $(document).on('click', "#extendScheme-button",
                function() {
                        console.log("extend button click");
                        var extendDatetime = $('input[name="extendScheme"]')
                                .val();
                        var schemeId = $('#schemeId').val()
                        console.log("extendDatetime : " + extendDatetime);
                        console.log(schemeId);
                        if (extendDatetime) {
                                if (confirm("Are you sure you want to Extend expireDateTime for Scheme!") == true) {
                                        extendSchemeById(schemeId)
                                }
                        } else {
                                alert("feild can't be blank");
                        }
                });

        $(document).on('click', ".schemes", function() {
                console.log("Active Schemes Button Clicked...")

                bootbox.confirm({
                        message: "<div class = 'disclosurehindata'> <img src='resources/images/disclosure.png' style='width:100%'> </div>"
                        ,
                        buttons: {
                                confirm: {
                                        label: 'I agree',
                                        className: 'btn-success'
                                },
                                cancel: {
                                        label: 'I disagree',
                                        className: 'btn-danger'
                                }
                        },
                        callback: function(result) {
                                if (result == true) {
                                        schemes("main-content");
                                }
                        }
                });

        });

        $(document).on('click', ".margin-calculator", function() {
                console.log("Active Schemes Button Clicked...")
                marginCalculator("main-content");
        });

        $(document).on('click', ".schemes-download-page", function() {
                console.log("Schemes Download Clicked...")
                loadSchemesDownloadPage("main-content");
        });

        $(document).on('click', ".schemes-update", function() {
                loadSchemeUpdatePage("main-content");
        });

        $(document).on('click', ".add-item", function() {

                schemeIds = $("#schemeids").val();
                itemIds = $("#itemids").val();
                console.log(schemeIds);
                console.log(itemIds);
                if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
                        if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
                                alert("fields shouldn't be blank");
                                return;
                        }
                        updateSingleScheme(schemeIds, itemIds);
                }
        });
        $(document).on('click', ".add-schemes", function() {

                schemeIds = $("#schemeids").val();
                itemIds = $("#itemids").val();
                console.log(schemeIds);
                console.log(itemIds);
                if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
                        if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
                                alert("fields shouldn't be blank");
                                return;
                        }
                        updateSchemes(schemeIds, itemIds);
                }
        });
        $(document).on('click', ".delete-schemes", function() {
                if (confirm("Are you sure you want to delete Scheme!") == true) {
                        schemeId = $(this).data('schemeid');
                        itemId = $(this).data('itemid');
                        console.log(schemeId);
                        console.log(itemId);
                        deleteScheme(schemeId, itemId);
                }
        });

        $(document).on('click', "#scheme-search-button",
                function() {
                        var searchText = $("#scheme-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        doGetAjaxRequestHandler(context + "/getSchemes?searchTerm="
                                + searchText, function(response) {
                                        $('#' + "main-content").html(response);
                                });
                });

        $(document).on("keyup", "#scheme-search-text", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#scheme-search-button").click();
                }
        });
        $(document).on('click', "#scheme-item-search-button", function() {
                var searchText = $("#scheme-item-search-text").val();
                var date = $(".schemes-date").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                        alert("please select item");
                        return;
                }
                if (typeof currentItem != "undefined") {
                        console.log(currentItem);
                        loadSchemeItemSearchInfo(currentItem, date);
                } else {
                        console.log("reeffff")
                        alert("Data No Found")
                }
        });

        $(document).on('click', ".categoryWiseSchemeHistory",
                function() {
                        var category = $('#partner-category').val();
                        console.log(category);

                        doGetAjaxRequestHandler(context + "/getSchemes?partnerType="
                                + category, function(response) {
                                        $('#' + "main-content").html(response);
                                        $('#partner-category').val(category);
                                        window.dispatchEvent(new Event('resize'));
                                });

                });

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

function configureTagListingItemsDescriptionDropDown() {
        $('.tagListingItemsDescription').multiselect({
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '180px',
                numberDisplayed: 1,
                nonSelectedText: 'Items',
                nSelectedText: ' - Items Selected',
                allSelectedText: 'All Items Selected',
                enableFiltering: true,
                enableCaseInsensitiveFiltering: true
        });
}

function schemesDownload() {
        console.log("downloadItemLedgerReport Button clicked")
        var startDateTime = $('input[name="startDateTime"]').val();
        console.log("startDateTime : " + startDateTime);
        var endDateTime = $('input[name="endDateTime"]').val();
        console.log("endDateTime : " + endDateTime);
        doAjaxGetDownload(context + "/schemes/download?startDateTime="
                + startDateTime + "&endDateTime=" + endDateTime,
                "SchemesReport.xlsx");
}
function selectedbrand() {
        var brands = $('#tag-listing-brands').val();
        console.log(brands);
        if (brands) {
                loadTagListingItemsDescriptionByBrand(
                        "tag-listing-items-description-container", brands);
        }
}
function loadSchemeDetails(schemeId, domId) {
        doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
                function(response) {
                        $('#' + domId).html(response);
                        window.dispatchEvent(new Event('resize'));
                });
}

function activeScheme(schemeId, offset, domId) {
        doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
                + "&offset=" + offset, function(response) {
                        $('#' + domId).html(response);
                        $('#scheme-details-container').html('');
                });

}

function expireScheme(schemeId, expireDate, offset, domId) {
        doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
                + "&offset=" + offset + "&expireTimestamp=" + expireDate, function(
                        response) {
                alert("Scheme - " + schemeId + " marked for expiry successfully!");
                $('#' + domId).html(response);
                $('#scheme-details-container').html('');
        });
}
function extendAllScheme(domId) {
        doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
                .stringify(startDate), function(response) {
                        if (response == 'true') {
                                alert("Scheme All Extended successfully");
                                schemes("main-content");
                        } else {
                                alert("No scheme Activated Currently");
                                schemes("main-content");
                        }
                });

}
function extendSchemeById(schemeId) {
        doPostAjaxRequestWithJsonHandler(context + "/extendSchemeById?schemeId="
                + schemeId, JSON.stringify(startDate), function(response) {
                        if (response == 'true') {
                                alert("Scheme extended successfully");
                                schemes("main-content");
                        } else {
                                alert("Scheme already Expired");
                                schemes("main-content");
                        }
                });

}

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

}

function loadTagListingItemsDescriptionByBrand(domId, brands) {
        doPostAjaxRequestWithJsonHandler(context + '/getTagListingItemsByBrand',
                JSON.stringify(brands), function(response) {
                        $('#' + domId).html(response);
                        debugger;
                        configureTagListingItemsDescriptionDropDown();
                });

}

function schemes(domId) {
        doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
                $('#' + domId).html(response);
        });
}
function marginCalculator(domId) {
        doGetAjaxRequestHandler(context + "/getMarginCalculator", function(response) {
                $('#' + domId).html(response);
        });
}

function loadSchemesDownloadPage(domId) {
        doGetAjaxRequestHandler(context + "/schemes/downloadPage", function(
                response) {
                $('#' + domId).html(response);
        });
}

function loadSchemeUpdatePage(domId) {
        doGetAjaxRequestHandler(context + "/schemes/update-schemes-page", function(
                response) {
                $('#' + domId).html(response);
        });
}

function updateSingleScheme(shcemeIds, itemIds) {
        doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
                .stringify({
                        "itemIds": itemIds.split(",").map(Number),
                        "schemeIds": schemeIds.split(",").map(Number)
                }), function(response) {
                        if (response == 'true') {
                                alert("Item Added to scheme successfully");
                                // $('#newItemToSchemeModal').modal('hide');
                                loadSchemeDetails(shcemeIds, "scheme-details-container");
                        } else {
                                alert("Item already present");
                                loadSchemeDetails(shcemeIds, "scheme-details-container");
                        }
                });
}
function updateSchemes(shcemeIds, itemIds) {
        doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
                .stringify({
                        "itemIds": itemIds.split(",").map(Number),
                        "schemeIds": schemeIds.split(",").map(Number)
                }), function(response) {
                        if (response == 'true') {
                                alert("Item Added to scheme successfully");
                                // $('#newItemToSchemeModal').modal('hide');
                                loadSchemeUpdatePage("main-content");
                        }
                });
}
function deleteScheme(shcemeId, itemId) {
        doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + shcemeId
                + "&itemId=" + itemId, function(response) {
                        if (response == 'true') {
                                alert("ItemId Deleted successfully from Scheme");
                                loadSchemeDetails(shcemeId, "scheme-details-container");
                        }
                });
}
function loadSearchScheme(domId, search_text) {
        doGetAjaxRequestHandler(context + "/searchScheme?searchTerm="
                + search_text, function(response) {
                        $('#' + domId).html(response);
                });
}
function loadSearchItemScheme(domId, selected_item, date) {
        var category = $('#partner-category').val();
        var searchText = $("#scheme-item-search-text").val();

        var category = $('#partner-category').val();

        console.log(category)

        if (typeof (searchText) == "undefined" || !searchText) {
                searchText = "";
        }
        if (typeof (category) == "undefined" || !category) {
                category = "";
        }
        if ((searchText) && (category)) {
                doGetAjaxRequestHandler(context + "/getSchemes?searchItem="
                        + selected_item.itemId + "&partnerType=" + category, function(
                                response) {
                        $('#' + domId).html(response);
                        $('#partner-category').val(category);
                        $('#scheme-item-search-text').val(selected_item.itemDescription);

                });
        } else if ((searchText)) {
                doGetAjaxRequestHandler(`${context}/getSchemes?searchItem=${selected_item.itemId}&date=${date}`, function(response) {
                        $('#' + domId).html(response);
                        $('#scheme-item-search-text').val(selected_item.itemDescription);

                });

        }

}
function loadSchemeSearchInfo(search_text) {
        loadSearchScheme("main-content", search_text);
}
function loadSchemeItemSearchInfo(selectedItem, date) {
        loadSearchItemScheme("main-content", selectedItem, date);
}