Subversion Repositories SmartDukaan

Rev

Rev 24052 | Rev 24058 | 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
	});
24019 amit.gupta 5
	$("button.update-mop").live('click', function() {
6
		if($("#typeaheaditem").val().trim().length == 0){
7
			alert("Please choose Item");
8
			return;
9
		}
10
		var newMop = $("#newMop").val();
11
		var allColors = $("#allColors").prop('checked');
12
 
13
		if(newMop.length == 0 || parseFloat(newMop) == 0) {
14
			alert("New Mop should not be empty");
15
			return;
16
		}
17
		if(confirm("Are you sure?")) {
18
			var obj = {
19
					itemId:currentItem.itemId,
20
					mop:parseFloat(newMop),
21
					allColors:allColors,
22
			}
23
			doPostAjaxRequestWithJsonHandler(
24
					context+"/updateMop", JSON.stringify(obj),
25
					function(response) {
26
						if (response == 'true') {
27
							$('#newPriceDropModal').find('button.close').trigger('click');
28
							setTimeout(() => {
29
								alert("PriceDrop added successfully")
30
								loadPriceDrop("main-content");
31
							}, 500);
32
						} else {
33
							alert("Something went wrong pls try after sometime");
34
						}
35
					}
36
			);
37
		}
38
	});
24052 amit.gupta 39
	$("button.add-pricing").live('click', function() {
40
		if($("#typeaheaditem1").val().trim().length == 0){
41
			alert("Please choose Item");
42
			return;
43
		}
44
		var mop = $("#mop").val();
45
		var dp = $("#dp").val();
46
		var mrp = $("#mrp").val();
24056 amit.gupta 47
		if(isNaN(dp) || isNaN(mop) || isNan(mrp)) {
24052 amit.gupta 48
			alert("DP/MOP/MRP should be a number");
49
		}
24056 amit.gupta 50
		if(mrp < mop || mrp < dp) {
51
			alert("DP/MOP should be lower than MRP");
52
		}
24052 amit.gupta 53
		if(confirm("Are you sure?")) {
54
			var obj = {
55
					itemId:currentItem1.itemId,
56
					mop:parseFloat(mop),
57
					dp:parseFloat(dp),
58
					mrp:parseFloat(mrp)
59
			}
60
			doPostAjaxRequestWithJsonHandler(
61
					context+"/add-pricing", JSON.stringify(obj),
62
					function(response) {
63
						if (response == 'true') {
64
							$('#newPriceDropModal').find('button.close').trigger('click');
65
							setTimeout(() => {
66
								alert("PriceDrop added successfully")
67
								loadPriceDrop("main-content");
68
							}, 500);
69
						} else {
70
							alert("Something went wrong pls try after sometime");
71
						}
72
					}
73
			);
74
		}
75
 
76
	});
23884 amit.gupta 77
	$("button.addPriceDrop").live('click', function() {
78
		if($("#typeaheaditem").val().trim().length == 0){
79
			alert("Please choose Item");
80
			return;
81
		}
24052 amit.gupta 82
 
23884 amit.gupta 83
		var priceDrop = $("#pd").val();
84
		var newTp = $("#newTp").val();
85
		var newMop = $("#newMop").val();
86
		var newNlc = $("#newNlc").val();
87
		var affectedOn = $("#affectedDate").val();
88
		var allColors = $("#allColors").prop('checked');
89
		if(priceDrop.length == 0 || parseFloat(priceDrop) == 0) {
90
			alert("Price Drop should not be empty");
91
			return;
92
		}
93
		if(newTp.length == 0 || parseFloat(newTp) == 0) {
94
			alert("New Tp should not be empty");
95
			return;
96
		}
97
		if(newMop.length == 0 || parseFloat(newMop) == 0) {
98
			alert("New Mop should not be empty");
99
			return;
100
		}
101
		if(newNlc.length == 0 || parseFloat(newNlc) == 0) {
102
			alert("New Nlc should not be empty");
103
			return;
104
		}
105
 
106
		if(affectedOn.length == 0) {
107
			alert("Affected Date Should not be empty");
108
			return;
109
		}
110
		if(confirm("Are you sure?")) {
111
			var obj = {
112
					itemId:currentItem.itemId,
113
					tp:parseFloat(newTp),
114
					pd:parseFloat(priceDrop),
115
					mop:parseFloat(newMop),
116
					nlc:parseFloat(newNlc),
117
					allColors:allColors,
118
					affectedDate:startDate
119
			}
120
			doPostAjaxRequestWithJsonHandler(
121
					context+"/priceDrop", JSON.stringify(obj),
122
					function(response) {
123
						if (response == 'true') {
124
							$('#newPriceDropModal').find('button.close').trigger('click');
125
							setTimeout(() => {
126
								alert("PriceDrop added successfully")
127
								loadPriceDrop("main-content");
128
							}, 500);
129
						} else {
130
							alert("Something went wrong pls try after sometime");
131
						}
132
					}
133
			);
134
		}
135
	});
136
	$('input.downloadtotalIMEI').live('click', function (){
23966 amit.gupta 137
		var priceDropId=$(this).closest('tr').data('pricedropid');
23819 govind 138
		doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
23971 amit.gupta 139
		"totalPriceDropIMEI"+priceDropId+".csv");
23819 govind 140
	});
141
 
23951 amit.gupta 142
	$('button.download-imeis').live('click', function(){
143
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
144
	});
23819 govind 145
 
23951 amit.gupta 146
 
23966 amit.gupta 147
	$('.mk_process_price_drop').live('click', function (){
148
		if (confirm("Are you sure you want to Process price Drop?")) {
149
			var trElement=$(this).closest('tr');
150
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 151
			var partnerPayout = trElement.find('.partner-payout').val();
152
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 153
 
154
			if(isNaN(partnerPayout) || partnerPayout == 0) {
155
				alert("Partner Payout can't be 0");
156
				return false;
157
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
158
				alert("Price Drop can't be 0");
159
				return false;
23819 govind 160
			}
23966 amit.gupta 161
			else {
162
				let priceDropObj = {
163
						priceDropIn:parseFloat(priceDropIn), 
164
						partnerPayout: parseFloat(partnerPayout), 
165
						priceDropId:parseInt(priceDropId)
166
				};
167
				processPayout(priceDropObj); 
168
			}
23819 govind 169
		}
23966 amit.gupta 170
		else {
171
			return false;
172
		}
23819 govind 173
	});
174
});
23966 amit.gupta 175
 
23819 govind 176
function loadPriceDrop(domId){
177
	doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
178
		$('#' + domId).html(response);
179
	});
180
}
23966 amit.gupta 181
function processPayout(priceDropProcessObj){
23968 amit.gupta 182
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
23966 amit.gupta 183
		if (response == 'true') {
184
			alert("PriceDrop sends successfully");
185
			loadPriceDrop("main-content");
186
		}
187
		else {
188
			alert("No IMEI is Eligible for PriceDrop");
189
			loadPriceDrop("main-content");
190
		}
23819 govind 191
	});
23966 amit.gupta 192
}
23819 govind 193