Subversion Repositories SmartDukaan

Rev

Rev 36421 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

const SCHEME_DETAILS_CONTAINER = "scheme-details-container";

$(function() {
        $(document).on('click', ".create-scheme", function() {
                loadScheme("main-content");
        });
        $(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!")) {
                        activeScheme(schemeId, offset, "schemes-table");
                }
        });


        $(document).on('click', ".scheme-imei-history", function() {
                loadImeiWiseScheme("main-content");
        });

        $(document).on('click', ".expire-scheme", function() {
                var schemeId = $(this).attr('data');
                var expireDate = getDatesFromPicker('input[name="expireSchemeById"]').endDate;
                if (confirm("Are you sure you want to Expire Scheme!")) {
                        expireScheme(schemeId, expireDate, "schemes-table");
                }
        });
        $(document).on('click', "#extendDatetime-button",
                function() {
                        console.log("extendAll button click");
                        var extendDatetime = getDatesFromPicker('input[name="extendDatetime"]')
                                .endDate;
                        console.log("extendDatetime : " + extendDatetime);
                        if (extendDatetime) {
                                if (confirm("Are you sure you want to Extend expireDateTime for All Scheme!")) {
                                        extendAllScheme(extendDatetime);
                                }
                        } else {
                                alert("feild can't be blank");
                        }
                });
        $(document).on('click', "#extendScheme-button",
                function() {
                        console.log("extend button click");
                        var extendDatetime = getDatesFromPicker('input[name="extendSchemeById"]').endDate;
                        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(extendDatetime, schemeId);
                                }
                        } else {
                                alert("field can't be blank");
                        }
                });


        $(document).on('click', ".monthy-investment",
                function() {
                        console.log("hello evaluateActualInvestmentPayout");
                        window.location.href = context + "/evaluateActualInvestmentPayout";

                });

        $(document).on('click', ".process-investment", function() {
                if (confirm("Are you sure you want to Process Investment")) {
                        processInvestment();
                }
        });


        $(document).on('click', ".processInvestmentDryRun",
                function() {
                        console.log("processInvestmentDryRun");
                        window.location.href = context + "/processInvestmentDryRun";

                });

        $(document).on('click', ".brand-wise-income",
                function() {
                        var brand = $(this).data('brand');

                        var status = $(this).data('status');
                        var month = $(this).data('month');

                        brandWiseIncome(brand, month, status);

                });

        $(document).on('click', ".imei_wise_income",
                function() {


                        var catalogItemId = $(this).data('catalogitemid');
                        var month = $(this).data('month');

                        console.log(catalogItemId);
                        imeiWiseIncome(catalogItemId, month);

                });

        $(document).on('change', "#month-wise-income", function() {
                var month = $(this).val();

                monthWiseIncome(month, "main-content");
        });


        $(document).on('click', ".schemes", function() {
                schemes("main-content");
                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) {
                                }
                        }
                });*/

        });

        $(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() {
                var schemeIds = $("#schemeids").val();
                // Read from modal model multi-select if available, else fall back to text input
                var selectedModels = $(".modalCatalogItems").val();
                var catalogIds;
                if (selectedModels && selectedModels.length > 0) {
                        catalogIds = selectedModels.join(",");
                } else {
                        catalogIds = $("#catalogids").val();
                }
                if (!schemeIds || !catalogIds || catalogIds.trim().length === 0) {
                        alert("Scheme ID and at least one Model are required");
                        return;
                }
                // Filter out catalogs that already exist in the scheme
                var existingCatalogs = [];
                $('#' + SCHEME_DETAILS_CONTAINER + ' tr[data-catalogid]').each(function() {
                        existingCatalogs.push(String($(this).data('catalogid')));
                });
                var requestedIds = catalogIds.split(",");
                var duplicates = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) >= 0; });
                var newIds = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) < 0; });
                if (newIds.length === 0) {
                        alert("All selected models already exist in this scheme");
                        return;
                }
                if (duplicates.length > 0) {
                        alert("Skipping already existing catalog IDs: " + duplicates.join(", "));
                }
                catalogIds = newIds.join(",");
                if (confirm("Add " + newIds.length + " model(s) to Scheme?")) {
                        updateSingleScheme(schemeIds, catalogIds);
                }
        });
        $(document).on('click', ".add-schemes", function() {

                let schemeIds = $("#schemeids").val();
                let catalogIds = $("#catalogids").val();

                if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
                        if (catalogIds.trim().length === 0 || schemeIds.trim().length === 0) {
                                alert("fields shouldn't be blank");
                                return;
                        }
                        updateSchemes(schemeIds, catalogIds);
                }
        });

        $(document).on('click', ".process-sellIn", function() {
    let purchaseInvoiceNumber=$("#invoiceNumbers1").val();
    if (confirm("Are you sure you want to Process SellIn") == true) {
                        if (purchaseInvoiceNumber.trim().length === 0) {
                                alert("fields shouldn't be blank");
                                return;
                        }
                        processSellin(purchaseInvoiceNumber);
                }

        });

        $(document).on('click', ".process-sellOut", function() {
    let fofoOrderInvoiceNumber=$("#invoiceNumbers2").val();
    if (confirm("Are you sure you want to Process SellOut") == true) {
                                if (fofoOrderInvoiceNumber.trim().length === 0) {
                                        alert("fields shouldn't be blank");
                                        return;
                                }
                                processSellout(fofoOrderInvoiceNumber);
                        }

    });

        // --- scheme details fragment (scheme-details.vm) ----------------------
        // These live here rather than in the template because that fragment is
        // injected with .html(), which re-executes any inline <script> it carries,
        // and a successful save re-injects it. Binding there stacked one more
        // $(document) listener per load until a single click fired N identical PUTs
        // and the idempotency guard rejected all but the first. Scheme-level values
        // are read from data- attributes at click time, so a handler always acts on
        // the scheme currently on screen instead of the one it was rendered with.
        $(document).on('click', ".add-scheme", function() {
                $("#newItemToSchemeModal").modal({ backdrop: true, show: true });
        });

        $(document).on('hidden.bs.modal', "#newItemToSchemeModal", function() {
                $("#addSchemeForm").trigger("reset");
        });

        $(document).on('shown.bs.modal', "#newItemToSchemeModal", function() {
                var root = schemeDetailsRoot(this);
                initSingleDatePicker($('input[name="addItemStartDate"]'), root.attr('data-scheme-start'), "down");
                initSingleDatePicker($('input[name="addItemEndDate"]'), root.attr('data-scheme-end'), "down");
                var categoryId = $('#modal-category-list').val();
                if (categoryId) {
                        loadSchemeModalBrands(categoryId);
                }
        });

        $(document).on('change', "#modal-category-list", function() {
                var categoryId = $(this).val();
                if (categoryId) {
                        loadSchemeModalBrands(categoryId);
                }
        });

        $(document).on('click', ".edit-item-dates", function() {
                var row = $(this).closest('tr');
                var root = schemeDetailsRoot(this);
                toggleItemDateEdit(row, true);
                var startInput = row.find('.edit-start-date');
                var endInput = row.find('.edit-end-date');
                // An item with no window of its own opens on the scheme's own window.
                if (!startInput.data('daterangepicker')) {
                        initSingleDatePicker(startInput, startInput.val() || root.attr('data-scheme-start'), "down");
                        initSingleDatePicker(endInput, endInput.val() || root.attr('data-scheme-end'), "down");
                }
        });

        $(document).on('click', ".cancel-item-dates", function() {
                toggleItemDateEdit($(this).closest('tr'), false);
        });

        $(document).on('click', ".save-item-dates", function() {
                var row = $(this).closest('tr');
                var startDate = row.find('.edit-start-date').val();
                var endDate = row.find('.edit-end-date').val();
                if (!startDate || !endDate) {
                        alert("Both start date and end date are required");
                        return;
                }
                updateSchemeItemWindow(schemeDetailsRoot(this).attr('data-scheme-id'),
                        row.data('schemeitemid'), startDate, endDate);
        });

        $(document).on('click', ".delete-schemes", function() {
                if (confirm("Delete model from Scheme?") == true) {
                        schemeId = $(this).data('schemeid');
                        catalogId = $(this).data('catalogid');
                        deleteScheme(schemeId, catalogId);
                }
        });

        $(document).on('click', "#scheme-search-button",
                function() {
                        var searchText = $("#scheme-search-text").val();
                        if (typeof (searchText) == "undefined" || !searchText) {
                                searchText = "";
                        }
                        doGetAjaxRequestHandler(context + "/getSchemes?searchScheme="
                                + 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', "#scheme-imei-search-button", function() {
                var searchText = $("#scheme-imei-search-text").val();
                var date = $(".schemes-date").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                        alert("please select imei");
                        return;
                }
                if (typeof imei != "undefined") {
                        console.log(imei);
                        loadSchemeImeiSearchInfo(imei, date);
                } else {
                        console.log("reeffff")
                        alert("Data No Found")
                }
        });

        $(document).on('click', "#scheme-imei-wise-search-button", function() {
                var searchText = $("#scheme-imei-wise-search-text").val();
                var date = $(".schemes-date").val();
                if (typeof (searchText) === "undefined" || !searchText) {
                        searchText = "";
                        alert("please select imei");
                        return;
                }
                if (typeof imei !== "undefined") {
                        console.log(imei);
                        var searchText = $("#scheme-imei-wise-search-text").val();

                        if ((searchText)) {
                                doGetAjaxRequestHandler(`${context}/getSchemesByImei?searchImei=${searchText}`, function(response) {
                                        $('#' +  "main-content").html(response);
                                        $('#scheme-imei-search-text').val(searchText);

                                });
                        }
                } 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();
                }
        });
});

// Every brand/model picker on the scheme screens wants the same multiselect;
// the label set was the only thing that genuinely varied between the copies.
// Pass overrides for the rare case that also needs a different width.
function configureMultiselect(selector, label, overrides) {
        $(selector).multiselect($.extend({
                includeSelectAllOption: true,
                multiple: true,
                maxHeight: 200,
                buttonWidth: '180px',
                numberDisplayed: 1,
                nonSelectedText: label,
                nSelectedText: ' - ' + label + ' Selected',
                allSelectedText: 'All ' + label + ' Selected',
                enableFiltering: true,
                enableCaseInsensitiveFiltering: true
        }, overrides || {}));
}

function configureTagListingItemsDescriptionDropDown() {
        configureMultiselect('.catalogItemsDescription', 'Models');
}

// The fragment root carries the scheme's id and window as data- attributes.
// Falls back to the container when the caller sits outside the root.
function schemeDetailsRoot(el) {
        var root = $(el).closest('[data-scheme-id]');
        return root.length ? root : $('#' + SCHEME_DETAILS_CONTAINER + ' [data-scheme-id]').first();
}

function toggleItemDateEdit(row, editing) {
        row.find('.date-display').toggle(!editing);
        row.find('.date-edit').toggle(editing);
        row.find('.edit-item-dates').toggle(!editing);
        row.find('.save-item-dates, .cancel-item-dates').toggle(editing);
}

// Row values are rendered DD/MM/YYYY; scheme-level fallbacks are raw timestamps.
function initSingleDatePicker(input, value, drops) {
        var startMoment = /^\d{2}\/\d{2}\/\d{4}$/.test(value || '')
                ? moment(value, 'DD/MM/YYYY')
                : moment(value);
        input.daterangepicker($.extend(getSingleDatePicker(startMoment), { "drops": drops }));
}

// Re-run on every injection: unlike the delegated handlers these bind directly
// to elements that the fragment replaces, so they cannot be bound once up front.
function initSchemeDetails(domId) {
        var root = $('#' + domId).find('[data-scheme-id]');
        if (root.length === 0) {
                return;
        }
        root.find('input[name="extendSchemeById"]').daterangepicker($.extend(getSingleDatePicker(), { "drops": "up" }));
        initSingleDatePicker(root.find('input[name="expireSchemeById"]'), root.attr('data-scheme-end'), "up");
}

// The modal reuses the page-level brand/model endpoints; its selects are re-id'd
// so they do not clash with the create-scheme page rendered behind it.
function loadSchemeModalBrands(categoryId) {
        loadBrandsByCategory('modal-brand-list', categoryId, function() {
                $('#modal-brand-list select').attr('id', 'modal-tag-listing-brands');
                configureMultiselect('#modal-tag-listing-brands', 'Brands');
                $('#modal-tag-listing-brands').on('change', function() {
                        var brands = $(this).val();
                        if (brands) {
                                loadSchemeModalModels(categoryId, brands);
                        }
                });
        });
}

function loadSchemeModalModels(categoryId, brands) {
        loadCatalogDescriptionByBrands('modal-models-list', categoryId, brands, function() {
                $('#modal-models-list select').addClass('modalCatalogItems');
                configureMultiselect('.modalCatalogItems', 'Models', { buttonWidth: '220px' });
        });
}

function schemesDownload() {
        let pickerData = getDatesFromPicker('input[name="startEndDateTime"]')
        doAjaxGetDownload(context + "/schemes/download?" +
                "startDateTime=" + pickerData.startDate
                + "&endDateTime=" + pickerData.endDate,
                "SchemesReport.xlsx");
}

function selectedbrand(categoryId) {
        var brands = $('#tag-listing-brands').val();
        if (brands) {
                loadCatalogDescriptionByBrands(
                        "tag-listing-items-description-container", categoryId, brands);
        }
}

function categoryChanged() {
        let categoryId = $('#category-list').val();
        if (categoryId) {
                loadBrandsByCategory(
                        "brand-list", categoryId);
        }
}

function loadSchemeDetails(schemeId, domId) {
        domId = domId || SCHEME_DETAILS_CONTAINER;
        doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
                function(response) {
                        $('#' + domId).html(response);
                        initSchemeDetails(domId);
                        window.dispatchEvent(new Event('resize'));
                });
}

function updateSchemeItemWindow(schemeId, schemeItemId, startDate, endDate) {
        doPutAjaxRequestHandler(context + "/scheme/item/window?schemeItemId=" + schemeItemId
                + "&startDate=" + encodeURIComponent(toIsoDateTime(startDate, false))
                + "&endDate=" + encodeURIComponent(toIsoDateTime(endDate, true)),
                function(response) {
                        loadSchemeDetails(schemeId, SCHEME_DETAILS_CONTAINER);
                });
}

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, domId) {
        doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
                + "&expireTimestamp=" + expireDate, function(
                        response) {
                alert("Scheme - " + schemeId + " marked for expiry successfully!");
                $('#' + domId).html(response);
                $('#' + SCHEME_DETAILS_CONTAINER).html('');
        });
}

function extendAllScheme(extendDate) {
        doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
                .stringify(extendDate), function(response) {
                        if (response == 'true') {
                                alert("Scheme All Extended successfully");
                                schemes("main-content");
                        } else {
                                alert("No scheme Activated Currently");
                                schemes("main-content");
                        }
                });

}

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

function processInvestment() {
        doPostAjaxRequestWithJsonHandler(context + "/payMonthlyInvestment", function(response) {
                alert("InvestmentPayout processed successfully");
        });
}

function loadScheme(domId) {
        doGetAjaxRequestHandler(context + "/createScheme", function(response) {
                $('#' + domId).html(response);
                createSchemeOnReady();
                categoryChanged();
                $('input[name="dateRange"]').daterangepicker(getRangedDatePicker());
        });

}

function loadImeiWiseScheme(domId) {
        doGetAjaxRequestHandler(context + "/getSchemesByImei",
                function(response) {
                        $('#' + domId).html(response);

                });
}

function loadCatalogDescriptionByBrands(domId, categoryId, brands, afterRender) {
        let brandsString = brands.join(",")
        doGetAjaxRequestHandler(`${context}/getCatalogDescriptionByBrands?categoryId=${categoryId}&brands=${brandsString}`,
                function(response) {
                        $('#' + domId).html(response);
                        (afterRender || configureTagListingItemsDescriptionDropDown)();
                });

}

function loadBrandsByCategory(domId, categoryId, afterRender) {
        doGetAjaxRequestHandler(`${context}/getBrandsByCategory?categoryId=${categoryId}`,
                function(response) {
                        $('#' + domId).html(response);
                        (afterRender || configureBrandsDropDown)();
                });
}

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 brandWiseIncome(brand, month, status) {
        console.log(brand);
        console.log(month);

        doGetAjaxRequestHandler(`${context}/brandWiseIncome?brand=${brand}&month=${month}`, function (
                response) {
                $('.imei-wise-income-container').html('');
                $('.brand-wise-income-container').html(response);
        });
}

function monthWiseIncome(month, domId) {
        console.log(month);
        doGetAjaxRequestHandler(context + "/monthWisePartnerIncome/" + month, function(response) {
                console.log(response);
                $('#' + domId).html(response);
        })
}

function imeiWiseIncome(catalogItemId, month) {
        console.log(catalogItemId);
        console.log(month);

        doGetAjaxRequestHandler(context + "/getLastMonthImeiWiseIncome?catalogItemId=" + catalogItemId + "&month=" + month, function(
                response) {
                $('.imei-wise-income-container').html(response);
        });
}

function toIsoDateTime(ddmmyyyy, endOfDay) {
        var parts = ddmmyyyy.split('/');
        if (parts.length !== 3) return ddmmyyyy;
        var isoDate = parts[2] + '-' + parts[1] + '-' + parts[0];
        return isoDate + (endOfDay ? 'T23:59:59' : 'T00:00:00');
}

function updateSingleScheme(schemeIds, catalogIds) {
        var payload = {
                "catalogIds": catalogIds.split(",").map(Number),
                "schemeIds": schemeIds.split(",").map(Number)
        };
        var startDate = $('#addItemStartDate').val();
        var endDate = $('#addItemEndDate').val();
        if (startDate) payload.startDate = toIsoDateTime(startDate, false);
        if (endDate) payload.endDate = toIsoDateTime(endDate, true);
        doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
                .stringify(payload), function(response) {
                        $('#newItemToSchemeModal').modal('hide');
                        alert("Item Added to scheme successfully");
                        loadSchemeDetails(schemeIds, SCHEME_DETAILS_CONTAINER);
                });
}

function updateSchemes(schemeIds, catalogIds) {
        doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
                .stringify({
                        "catalogIds": catalogIds.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 processSellin(purchaseInvoiceNumber) {
        doPostAjaxRequestWithJsonHandler(context + "/schemes/process-sellin",
        JSON.stringify(purchaseInvoiceNumber.split(",").map(x=>x.trim())), function(response) {
                        if (response) {
                                alert("Invoices Processed Successfully");
                                loadSchemeUpdatePage("main-content");
                        }
                });
}

function processSellout(fofoOrderInvoiceNumber) {
        doPostAjaxRequestWithJsonHandler(context + "/schemes/process-sellout",
        JSON.stringify(fofoOrderInvoiceNumber.split(",").map(x=>x.trim())), function(response) {
                        if (response) {
                                alert("Invoices Processed Successfully");
                                loadSchemeUpdatePage("main-content");
                        }
                });
}


function deleteScheme(schemeId, catalogId) {
        doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + schemeId
                + "&catalogId=" + catalogId, function(response) {
                        if (response == 'true') {
                                alert("Model Deleted successfully from Scheme");
                                loadSchemeDetails(schemeId, SCHEME_DETAILS_CONTAINER);
                        }
                });
}


function loadSearchItemScheme(domId, selectedModel, date) {
        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) {
                doGetAjaxRequestHandler(`${context}/getSchemes?searchModel=${selectedModel}&partnerType=${category}&date=${date}`, function(response) {
                        $('#' + domId).html(response);
                        $('#partner-category').val(category);
                });
        } else if (searchText) {
                doGetAjaxRequestHandler(`${context}/getSchemes?searchModel=${selectedModel}&date=${date}`, function(response) {
                        $('#' + domId).html(response);
                        $('#partner-category').val(category);
                });

        }

}

function loadSearchImeiScheme(domId, selected_imei, date) {
        var category = $('#partner-category').val();
        var searchText = $("#scheme-imei-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?searchImei="
                        + selected_imei + "&partnerType=" + category, function(
                                response) {
                        $('#' + domId).html(response);

                        $('#partner-category').val(category);
                        $('#scheme-imei-search-text').val(selected_imei);
                });
        } else if ((searchText)) {
                doGetAjaxRequestHandler(`${context}/getSchemes?searchImei=${selected_imei}&date=${date}`, function(response) {
                        $('#' + domId).html(response);
                        $('#scheme-imei-search-text').val(selected_imei);

                });
        }

}

function loadSchemeItemSearchInfo(selectedModel, date) {
        loadSearchItemScheme("main-content", selectedModel, date);
}

function loadSchemeImeiSearchInfo(selectedImei, date) {

        loadSearchImeiScheme("main-content", selectedImei, date);
}

$(document).on('click', ".mark-active", function() {
        let activeScheme=$("#activeSchemes").val();
        if (activeScheme.trim().length === 0) {
                alert("fields shouldn't be blank");
                return;
        }
        if (confirm("Are you sure you want to Active schemes?")) {
                console.log("activeScheme",activeScheme);
                doPutAjaxRequestHandler(context + "/activeSchemeByIds?schemeId=" + activeScheme, function(response) {
                        if (response){
                                $("#activeSchemes").val("");
                                alert("schemes activated")
                        }
                });
        }
});
$(document).on('click', ".mark-expire", function () {
        let expireSchemes = $("#expireSchemes").val();
        if (expireSchemes.trim().length === 0) {
                alert("fields shouldn't be blank");
                return;
        }
        if (confirm("Are you sure you want to expire schemes?")) {
                console.log("expireSchemes", expireSchemes);
                doPutAjaxRequestHandler(context + "/expireSchemeByIds?schemeId=" + expireSchemes, function (response) {
                        if (response) {
                                $("#expireSchemes").val("");
                                alert("schemes expired")
                        }
                });
        }
});