Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(".price_drop").live('click', function() {
                loadPriceDrop("main-content");
        });
        $("button.update-mop").live('click', function() {
                if($("#typeaheaditem").val().trim().length == 0){
                        alert("Please choose Item");
                        return;
                }
                var newMop = $("#newMop").val();
                var allColors = $("#allColors").prop('checked');

                if(newMop.length == 0 || parseFloat(newMop) == 0) {
                        alert("New Mop should not be empty");
                        return;
                }
                if(confirm("Are you sure?")) {
                        var obj = {
                                        itemId:currentItem.itemId,
                                        mop:parseFloat(newMop),
                                        allColors:allColors,
                        }
                        doPostAjaxRequestWithJsonHandler(
                                        context+"/updateMop", JSON.stringify(obj),
                                        function(response) {
                                                if (response == 'true') {
                                                        $('#newPriceDropModal').find('button.close').trigger('click');
                                                        setTimeout(() => {
                                                                alert("PriceDrop added successfully")
                                                                loadPriceDrop("main-content");
                                                        }, 500);
                                                } else {
                                                        alert("Something went wrong pls try after sometime");
                                                }
                                        }
                        );
                }
        });
        $("button.addPriceDrop").live('click', function() {
                if($("#typeaheaditem").val().trim().length == 0){
                        alert("Please choose Item");
                        return;
                }
                var priceDrop = $("#pd").val();
                var newTp = $("#newTp").val();
                var newMop = $("#newMop").val();
                var newNlc = $("#newNlc").val();
                var affectedOn = $("#affectedDate").val();
                var allColors = $("#allColors").prop('checked');
                if(priceDrop.length == 0 || parseFloat(priceDrop) == 0) {
                        alert("Price Drop should not be empty");
                        return;
                }
                if(newTp.length == 0 || parseFloat(newTp) == 0) {
                        alert("New Tp should not be empty");
                        return;
                }
                if(newMop.length == 0 || parseFloat(newMop) == 0) {
                        alert("New Mop should not be empty");
                        return;
                }
                if(newNlc.length == 0 || parseFloat(newNlc) == 0) {
                        alert("New Nlc should not be empty");
                        return;
                }

                if(affectedOn.length == 0) {
                        alert("Affected Date Should not be empty");
                        return;
                }
                if(confirm("Are you sure?")) {
                        var obj = {
                                        itemId:currentItem.itemId,
                                        tp:parseFloat(newTp),
                                        pd:parseFloat(priceDrop),
                                        mop:parseFloat(newMop),
                                        nlc:parseFloat(newNlc),
                                        allColors:allColors,
                                        affectedDate:startDate
                        }
                        doPostAjaxRequestWithJsonHandler(
                                        context+"/priceDrop", JSON.stringify(obj),
                                        function(response) {
                                                if (response == 'true') {
                                                        $('#newPriceDropModal').find('button.close').trigger('click');
                                                        setTimeout(() => {
                                                                alert("PriceDrop added successfully")
                                                                loadPriceDrop("main-content");
                                                        }, 500);
                                                } else {
                                                        alert("Something went wrong pls try after sometime");
                                                }
                                        }
                        );
                }
        });
        $('input.downloadtotalIMEI').live('click', function (){
                var priceDropId=$(this).closest('tr').data('pricedropid');
                doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
                "totalPriceDropIMEI"+priceDropId+".csv");
        });
        
        $('button.download-imeis').live('click', function(){
                doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
        });
        
        
        $('.mk_process_price_drop').live('click', function (){
                if (confirm("Are you sure you want to Process price Drop?")) {
                        var trElement=$(this).closest('tr');
                        var priceDropId = trElement.data('pricedropid');
                        var partnerPayout = trElement.find('.partner-payout').val();
                        var priceDropIn = trElement.find('.price-drop-in').val();
        
                        if(isNaN(partnerPayout) || partnerPayout == 0) {
                                alert("Partner Payout can't be 0");
                                return false;
                        } else if (isNaN(priceDropIn) || priceDropIn == 0) {
                                alert("Price Drop can't be 0");
                                return false;
                        }
                        else {
                                let priceDropObj = {
                                                priceDropIn:parseFloat(priceDropIn), 
                                                partnerPayout: parseFloat(partnerPayout), 
                                                priceDropId:parseInt(priceDropId)
                                };
                                processPayout(priceDropObj); 
                        }
                }
                else {
                        return false;
                }
        });
});

function loadPriceDrop(domId){
        doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
                $('#' + domId).html(response);
        });
}
function processPayout(priceDropProcessObj){
        doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
                if (response == 'true') {
                        alert("PriceDrop sends successfully");
                        loadPriceDrop("main-content");
                }
                else {
                        alert("No IMEI is Eligible for PriceDrop");
                        loadPriceDrop("main-content");
                }
        });
}