Subversion Repositories SmartDukaan

Rev

Rev 23966 | Rev 23971 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23819 govind 1
$(function() {
2
	$(".price_drop").live('click', function() {
3
		loadPriceDrop("main-content");
4
	});
23884 amit.gupta 5
	$("button.addPriceDrop").live('click', function() {
6
		if($("#typeaheaditem").val().trim().length == 0){
7
			alert("Please choose Item");
8
			return;
9
		}
10
		var priceDrop = $("#pd").val();
11
		var newTp = $("#newTp").val();
12
		var newMop = $("#newMop").val();
13
		var newNlc = $("#newNlc").val();
14
		var affectedOn = $("#affectedDate").val();
15
		var allColors = $("#allColors").prop('checked');
16
		if(priceDrop.length == 0 || parseFloat(priceDrop) == 0) {
17
			alert("Price Drop should not be empty");
18
			return;
19
		}
20
		if(newTp.length == 0 || parseFloat(newTp) == 0) {
21
			alert("New Tp should not be empty");
22
			return;
23
		}
24
		if(newMop.length == 0 || parseFloat(newMop) == 0) {
25
			alert("New Mop should not be empty");
26
			return;
27
		}
28
		if(newNlc.length == 0 || parseFloat(newNlc) == 0) {
29
			alert("New Nlc should not be empty");
30
			return;
31
		}
32
 
33
		if(affectedOn.length == 0) {
34
			alert("Affected Date Should not be empty");
35
			return;
36
		}
37
		if(confirm("Are you sure?")) {
38
			var obj = {
39
					itemId:currentItem.itemId,
40
					tp:parseFloat(newTp),
41
					pd:parseFloat(priceDrop),
42
					mop:parseFloat(newMop),
43
					nlc:parseFloat(newNlc),
44
					allColors:allColors,
45
					affectedDate:startDate
46
			}
47
			doPostAjaxRequestWithJsonHandler(
48
					context+"/priceDrop", JSON.stringify(obj),
49
					function(response) {
50
						if (response == 'true') {
51
							$('#newPriceDropModal').find('button.close').trigger('click');
52
							setTimeout(() => {
53
								alert("PriceDrop added successfully")
54
								loadPriceDrop("main-content");
55
							}, 500);
56
						} else {
57
							alert("Something went wrong pls try after sometime");
58
						}
59
					}
60
			);
61
		}
62
	});
63
	$('input.downloadtotalIMEI').live('click', function (){
23966 amit.gupta 64
		var priceDropId=$(this).closest('tr').data('pricedropid');
23819 govind 65
		doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
66
		"totalPriceDropIMEI"+priceDropId+".xlsx");
67
	});
68
 
23951 amit.gupta 69
	$('button.download-imeis').live('click', function(){
70
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
71
	});
23819 govind 72
 
23951 amit.gupta 73
 
23966 amit.gupta 74
	$('.mk_process_price_drop').live('click', function (){
75
		if (confirm("Are you sure you want to Process price Drop?")) {
76
			var trElement=$(this).closest('tr');
77
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 78
			var partnerPayout = trElement.find('.partner-payout').val();
79
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 80
 
81
			if(isNaN(partnerPayout) || partnerPayout == 0) {
82
				alert("Partner Payout can't be 0");
83
				return false;
84
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
85
				alert("Price Drop can't be 0");
86
				return false;
23819 govind 87
			}
23966 amit.gupta 88
			else {
89
				let priceDropObj = {
90
						priceDropIn:parseFloat(priceDropIn), 
91
						partnerPayout: parseFloat(partnerPayout), 
92
						priceDropId:parseInt(priceDropId)
93
				};
94
				processPayout(priceDropObj); 
95
			}
23819 govind 96
		}
23966 amit.gupta 97
		else {
98
			return false;
99
		}
23819 govind 100
	});
101
});
23966 amit.gupta 102
 
23819 govind 103
function loadPriceDrop(domId){
104
	doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
105
		$('#' + domId).html(response);
106
	});
107
}
23966 amit.gupta 108
function processPayout(priceDropProcessObj){
23968 amit.gupta 109
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
23966 amit.gupta 110
		if (response == 'true') {
111
			alert("PriceDrop sends successfully");
112
			loadPriceDrop("main-content");
113
		}
114
		else {
115
			alert("No IMEI is Eligible for PriceDrop");
116
			loadPriceDrop("main-content");
117
		}
23819 govind 118
	});
23966 amit.gupta 119
}
23819 govind 120