Subversion Repositories SmartDukaan

Rev

Rev 24066 | Rev 24168 | 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(() => {
24062 amit.gupta 29
								alert("Pricing added successfully")
24019 amit.gupta 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();
24058 amit.gupta 47
		if(isNaN(dp) || isNaN(mop) || isNaN(mrp)) {
24052 amit.gupta 48
			alert("DP/MOP/MRP should be a number");
24058 amit.gupta 49
			return;
24052 amit.gupta 50
		}
24083 amit.gupta 51
		mop = parseFloat(mop),
52
		dp = parseFloat(dp),
53
		mrp = parseFloat(mrp)
24056 amit.gupta 54
		if(mrp < mop || mrp < dp) {
55
			alert("DP/MOP should be lower than MRP");
24058 amit.gupta 56
			return;
24056 amit.gupta 57
		}
24052 amit.gupta 58
		if(confirm("Are you sure?")) {
59
			var obj = {
60
					itemId:currentItem1.itemId,
24083 amit.gupta 61
					mop:mop,
62
					dp:dp,
63
					mrp:mrp
24052 amit.gupta 64
			}
65
			doPostAjaxRequestWithJsonHandler(
66
					context+"/add-pricing", JSON.stringify(obj),
67
					function(response) {
68
						if (response == 'true') {
24066 amit.gupta 69
							$('#addPriceModal').find('button.close').trigger('click');
24052 amit.gupta 70
							setTimeout(() => {
71
								alert("PriceDrop added successfully")
72
								loadPriceDrop("main-content");
73
							}, 500);
74
						} else {
75
							alert("Something went wrong pls try after sometime");
76
						}
77
					}
78
			);
79
		}
80
 
81
	});
23884 amit.gupta 82
	$("button.addPriceDrop").live('click', function() {
83
		if($("#typeaheaditem").val().trim().length == 0){
84
			alert("Please choose Item");
85
			return;
86
		}
24052 amit.gupta 87
 
23884 amit.gupta 88
		var priceDrop = $("#pd").val();
89
		var newTp = $("#newTp").val();
90
		var newMop = $("#newMop").val();
91
		var newNlc = $("#newNlc").val();
92
		var affectedOn = $("#affectedDate").val();
93
		var allColors = $("#allColors").prop('checked');
94
		if(priceDrop.length == 0 || parseFloat(priceDrop) == 0) {
95
			alert("Price Drop should not be empty");
96
			return;
97
		}
98
		if(newTp.length == 0 || parseFloat(newTp) == 0) {
99
			alert("New Tp should not be empty");
100
			return;
101
		}
102
		if(newMop.length == 0 || parseFloat(newMop) == 0) {
103
			alert("New Mop should not be empty");
104
			return;
105
		}
106
		if(newNlc.length == 0 || parseFloat(newNlc) == 0) {
107
			alert("New Nlc should not be empty");
108
			return;
109
		}
110
 
111
		if(affectedOn.length == 0) {
112
			alert("Affected Date Should not be empty");
113
			return;
114
		}
115
		if(confirm("Are you sure?")) {
116
			var obj = {
117
					itemId:currentItem.itemId,
118
					tp:parseFloat(newTp),
119
					pd:parseFloat(priceDrop),
120
					mop:parseFloat(newMop),
121
					nlc:parseFloat(newNlc),
122
					allColors:allColors,
123
					affectedDate:startDate
124
			}
125
			doPostAjaxRequestWithJsonHandler(
126
					context+"/priceDrop", JSON.stringify(obj),
127
					function(response) {
128
						if (response == 'true') {
129
							$('#newPriceDropModal').find('button.close').trigger('click');
130
							setTimeout(() => {
131
								alert("PriceDrop added successfully")
132
								loadPriceDrop("main-content");
133
							}, 500);
134
						} else {
135
							alert("Something went wrong pls try after sometime");
136
						}
137
					}
138
			);
139
		}
140
	});
141
	$('input.downloadtotalIMEI').live('click', function (){
23966 amit.gupta 142
		var priceDropId=$(this).closest('tr').data('pricedropid');
23819 govind 143
		doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
23971 amit.gupta 144
		"totalPriceDropIMEI"+priceDropId+".csv");
23819 govind 145
	});
146
 
23951 amit.gupta 147
	$('button.download-imeis').live('click', function(){
148
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
149
	});
23819 govind 150
 
24060 amit.gupta 151
	$('button.mk_download_pricing').live('click', function(){
152
		doAjaxGetDownload(context+"/tagListing/download/4", "pricing.xlsx")
153
	});
23951 amit.gupta 154
 
24083 amit.gupta 155
	$('.mk_view_imeis').live('click', function (){
156
		clickedPriceDrop = $(this);
157
		var trElement=$(this).closest('tr');
158
		var priceDropId = trElement.data('pricedropid');
159
 
160
		doAjaxRequestWithJsonHandler(context+"/priceDropImeis/"+ priceDropId, 'GET', null, function(response) {
161
			response = JSON.parse(response);
162
			pendingArr=[];
163
			response.pendingImeis.forEach(function(val,index){
164
				pendingArr.push('<option>' +  val + '</option>')
165
			});
166
			$('select.mk_pending').html(pendingArr.join(''));
167
 
168
			approvedArr=[];
169
			response.approvedImeis.forEach(function(val,index){
170
				approvedArr.push('<option disabled>' +  val + '</option>')
171
			});
172
			$('select.mk_approved').html(approvedArr.join(''));
173
 
174
			rejectedArr=[];
175
			response.rejectedImeis.forEach(function(val,index){
176
				rejectedArr.push('<option>' +  val + '</option>')
177
			});
178
			$('select.mk_rejected').html(rejectedArr.join(''));
179
		});
180
	});
24060 amit.gupta 181
 
23966 amit.gupta 182
	$('.mk_process_price_drop').live('click', function (){
24083 amit.gupta 183
		if (confirm("Are you sure you want to Update Payout?")) {
184
			processPayout(priceDropProcessObj)
185
		}
186
	});
187
 
188
	$('.mk_add_payout').live('click', function (){
189
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 190
			var trElement=$(this).closest('tr');
191
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 192
			var partnerPayout = trElement.find('.partner-payout').val();
193
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 194
 
195
			if(isNaN(partnerPayout) || partnerPayout == 0) {
196
				alert("Partner Payout can't be 0");
197
				return false;
198
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
199
				alert("Price Drop can't be 0");
200
				return false;
23819 govind 201
			}
23966 amit.gupta 202
			else {
203
				let priceDropObj = {
204
						priceDropIn:parseFloat(priceDropIn), 
205
						partnerPayout: parseFloat(partnerPayout), 
206
						priceDropId:parseInt(priceDropId)
207
				};
24083 amit.gupta 208
				addPayout(priceDropObj); 
23966 amit.gupta 209
			}
23819 govind 210
		}
23966 amit.gupta 211
		else {
212
			return false;
213
		}
23819 govind 214
	});
215
});
24083 amit.gupta 216
function addPayout(priceDropProcessObj){
217
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
218
		if (response == 'true') {
219
			alert("Payout added");
220
			loadPriceDrop("main-content");
221
		}
222
		else {
223
			alert("Some error occurred while adding payout.");
224
		}
225
	});
226
}
23819 govind 227
function loadPriceDrop(domId){
228
	doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
229
		$('#' + domId).html(response);
230
	});
231
}
23966 amit.gupta 232
function processPayout(priceDropProcessObj){
23968 amit.gupta 233
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
23966 amit.gupta 234
		if (response == 'true') {
235
			alert("PriceDrop sends successfully");
236
			loadPriceDrop("main-content");
237
		}
238
		else {
239
			alert("No IMEI is Eligible for PriceDrop");
240
			loadPriceDrop("main-content");
241
		}
23819 govind 242
	});
23966 amit.gupta 243
}
23819 govind 244
 
24083 amit.gupta 245
function updatePriceDropImeis(status){
246
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
247
	var imeis = [];
248
	imeis1.forEach(function(imei,i) {
249
		if(imei.trim()!='') {
250
			imeis.push(imei.trim()); 
251
		}
252
	});
253
	imeis = imeis.concat($('select.mk_pending').val())
254
	.concat($('select.mk_approved').val())
255
	.concat($('select.mk_rejected').val());
256
 
257
	if(imeis.length < 0) {
258
		alert('Please choose imeis');
259
	}
260
 
261
	var trElement=clickedPriceDrop.closest('tr');
262
	var priceDropId = trElement.data('pricedropid');
263
 
264
	priceDropImeisObj = {
265
			priceDropId: priceDropId,
266
			updatedStatus : status,
267
			updatedImeis : imeis
268
	};
269
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
270
		if (response == 'true') {
271
			alert('Imeis updated and processed successfully');
272
			clickedPriceDrop.click();
273
		}
274
		else {
275
			alert("Error occurred while updating.");
276
		}
277
	});
278
 
279
}