Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
28903 amit.gupta 1
 
2
  $(document).on('change', "#selectPriceDropStatus", function() {
3
  	var  status = this.value;
4
  	if(status=='rejected') {
5
  		$('.mk_rejection_reason').val('').show();
6
  	} else {
7
  		$('.mk_rejection_reason').val('').hide();
8
	}  	
9
  });
10
  $(document).on('click', "#processPDButton", function() {
11
  	var  status = $("#selectPriceDropStatus").val();
12
  	updatePriceDropImeis(status);
13
  });
24406 amit.gupta 14
 
27754 amit.gupta 15
	$(document).on('click', "button.processPayout", function() {
24168 amit.gupta 16
		if($(".mk_pending")) {
17
 
18
		}
19
	}); 
24019 amit.gupta 20
 
27754 amit.gupta 21
	$(document).on('click', "button.add-pricing", function() {
24052 amit.gupta 22
		if($("#typeaheaditem1").val().trim().length == 0){
23
			alert("Please choose Item");
24
			return;
25
		}
26
		var mop = $("#mop").val();
27
		var dp = $("#dp").val();
28
		var mrp = $("#mrp").val();
24411 amit.gupta 29
		var tp = $("#tp").val();
24058 amit.gupta 30
		if(isNaN(dp) || isNaN(mop) || isNaN(mrp)) {
24052 amit.gupta 31
			alert("DP/MOP/MRP should be a number");
24058 amit.gupta 32
			return;
24052 amit.gupta 33
		}
24083 amit.gupta 34
		mop = parseFloat(mop),
35
		dp = parseFloat(dp),
36
		mrp = parseFloat(mrp)
24411 amit.gupta 37
		if(mrp !=0 && (mrp < mop || mrp < dp || mrp < tp)) {
38
			bootbox.alert("DP/MOP/TP should be lower than MRP");
24058 amit.gupta 39
			return;
24056 amit.gupta 40
		}
24410 amit.gupta 41
		getColorsForItems(0, currentItem.itemId, "Update prices for " + currentItem.itemDescription, function(itemIds){
42
			console.log(itemIds);
43
 
44
			if(itemIds!=null) {
45
				dataList = [];
46
				coloredItems.forEach(function(item){
47
					console.log(item);
48
					console.log(itemIds.indexOf(String(item.id)));
49
					if(itemIds.indexOf(String(item.id)) >= 0) {
50
						dataList.push(
51
						{
52
							id:item.id,
53
							mop:mop,
54
							dp:dp,
24411 amit.gupta 55
							mrp:mrp,
56
							tp:tp
24410 amit.gupta 57
						});
58
					}
59
				});
60
				bootbox.confirm("Confirm Update " + currentItem.itemDescription + "?", function(result){
61
					if(result) {
62
						doPostAjaxRequestWithJsonHandler(
63
								context+"/add-pricing", JSON.stringify(dataList),
64
								function(response) {
65
									if (response == 'true') {
24411 amit.gupta 66
										bootbox.alert("Prices Successfully Updated" );
24410 amit.gupta 67
									} else {
24411 amit.gupta 68
										bootbox.alert("Something went wrong pls try after sometime");
24410 amit.gupta 69
									}
70
								}
71
						);
72
					}
73
				});
24052 amit.gupta 74
			}
24410 amit.gupta 75
		});
24052 amit.gupta 76
 
77
	});
27754 amit.gupta 78
	$(document).on('click', "button.addPriceDrop", function() {
23884 amit.gupta 79
		if($("#typeaheaditem").val().trim().length == 0){
80
			alert("Please choose Item");
81
			return;
82
		}
24409 amit.gupta 83
		var newDp = $("#newDp").val();
23884 amit.gupta 84
		var newTp = $("#newTp").val();
85
		var newMop = $("#newMop").val();
86
		var affectedOn = $("#affectedDate").val();
87
		var allColors = $("#allColors").prop('checked');
24409 amit.gupta 88
 
89
		if(newDp.length == 0 || parseFloat(newDp) == 0) {
90
			alert("New Tp should not be empty");
23884 amit.gupta 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
 
102
		if(affectedOn.length == 0) {
103
			alert("Affected Date Should not be empty");
104
			return;
105
		}
28568 amit.gupta 106
		// as of now allColors is set to true. This means that all colors are
107
		// eligible for price drop
23884 amit.gupta 108
		if(confirm("Are you sure?")) {
109
			var obj = {
110
					itemId:currentItem.itemId,
24409 amit.gupta 111
					dp:parseFloat(newDp),
23884 amit.gupta 112
					tp:parseFloat(newTp),
113
					mop:parseFloat(newMop),
24409 amit.gupta 114
					allColors:true,
30599 amit.gupta 115
					affectedDate: getDatesFromPicker($('#affectedDate')).startDate
23884 amit.gupta 116
			}
117
			doPostAjaxRequestWithJsonHandler(
118
					context+"/priceDrop", JSON.stringify(obj),
119
					function(response) {
120
						if (response == 'true') {
24409 amit.gupta 121
							$('#newPriceDropModal').find('button.close').trigger('click');
23884 amit.gupta 122
							setTimeout(() => {
24406 amit.gupta 123
								alert("PriceDrop added successfully from " + $("#typeaheaditem").val());
23884 amit.gupta 124
								loadPriceDrop("main-content");
125
							}, 500);
126
						} else {
24410 amit.gupta 127
							alert("Invalid values provided could not update");
23884 amit.gupta 128
						}
129
					}
130
			);
131
		}
132
	});
27754 amit.gupta 133
	$(document).on('click', 'input.downloadtotalIMEI', function (){
23966 amit.gupta 134
		var priceDropId=$(this).closest('tr').data('pricedropid');
23819 govind 135
		doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
23971 amit.gupta 136
		"totalPriceDropIMEI"+priceDropId+".csv");
23819 govind 137
	});
138
 
27754 amit.gupta 139
	$(document).on('click', 'button.download-imeis', function(){
30609 amit.gupta 140
		let affectedDate = getDatesFromPicker('#affectedDate').startDate;
141
		doAjaxGetDownload(context + "/price-drop/imes/download/?affectedDate=" + affectedDate + "&itemId=" + currentItem.itemId, "pricedrop.csv")
23951 amit.gupta 142
	});
23819 govind 143
 
27754 amit.gupta 144
	$(document).on('click', 'button.mk_download_pricing', function(){
24060 amit.gupta 145
		doAjaxGetDownload(context+"/tagListing/download/4", "pricing.xlsx")
146
	});
23951 amit.gupta 147
 
27754 amit.gupta 148
	$(document).on('click', '.mk_auto_process', function (){
27071 amit.gupta 149
		var trElement=$(this).closest('tr');
150
		var payout = trElement.find('input.partner-payout').val();
151
		if(isNaN(parseInt(payout)) || parseInt(payout) <=0) {
152
			alert("Invalid payout amount");
153
		}
26355 amit.gupta 154
		if (confirm("Are you sure you want to Process Payout?")) {
155
			clickedPriceDrop = $(this);
156
			var priceDropId = trElement.data('pricedropid');
27071 amit.gupta 157
			autoProcess({priceDropId:priceDropId, partnerPayout:payout, activatedOnly:$(this).data('activatedonly')})
26355 amit.gupta 158
		}
26349 amit.gupta 159
	});
28568 amit.gupta 160
 
161
	function priceDropImeis(priceDropId){
24083 amit.gupta 162
 
28568 amit.gupta 163
 
24083 amit.gupta 164
		doAjaxRequestWithJsonHandler(context+"/priceDropImeis/"+ priceDropId, 'GET', null, function(response) {
165
			response = JSON.parse(response);
28568 amit.gupta 166
			holdArr=[];
167
			response.holdImeis.forEach(function(val,index){
168
				holdArr.push('<option>' +  val + '</option>')
169
			});
170
			$('select.mk_hold').html(holdArr.join('')).find('option');
171
			$('span.mk_hold_count').html(holdArr.length);
172
 
173
 
24083 amit.gupta 174
			pendingArr=[];
175
			response.pendingImeis.forEach(function(val,index){
28568 amit.gupta 176
				pendingArr.push('<option>' +  val + '</option>')
24083 amit.gupta 177
			});
26348 amit.gupta 178
			$('select.mk_pending').html(pendingArr.join('')).find('option');
24529 amit.gupta 179
			$('span.mk_pending_count').html(pendingArr.length);
24083 amit.gupta 180
 
181
			approvedArr=[];
182
			response.approvedImeis.forEach(function(val,index){
26348 amit.gupta 183
				approvedArr.push('<option>' +  val + '</option>')
24083 amit.gupta 184
			});
185
			$('select.mk_approved').html(approvedArr.join(''));
24529 amit.gupta 186
			$('span.mk_approved_count').html(approvedArr.length);
24083 amit.gupta 187
 
188
			rejectedArr=[];
189
			response.rejectedImeis.forEach(function(val,index){
190
				rejectedArr.push('<option>' +  val + '</option>')
191
			});
24529 amit.gupta 192
			$('span.mk_rejected_count').html(rejectedArr.length);
24083 amit.gupta 193
			$('select.mk_rejected').html(rejectedArr.join(''));
28568 amit.gupta 194
			// if(rejected) {}
24083 amit.gupta 195
		});
28568 amit.gupta 196
 
197
	}
198
 
199
	$(document).on('click', '.mk_view_imeis', function (){
200
		clickedPriceDrop = $(this);
201
		var trElement=$(this).closest('tr');
202
		var priceDropId = trElement.data('pricedropid');
203
		priceDropImeis(priceDropId);
204
 
24083 amit.gupta 205
	});
206
 
27754 amit.gupta 207
	$(document).on('click', '.mk_add_payout', function (){
24083 amit.gupta 208
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 209
			var trElement=$(this).closest('tr');
210
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 211
			var partnerPayout = trElement.find('.partner-payout').val();
212
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 213
 
214
			if(isNaN(partnerPayout) || partnerPayout == 0) {
215
				alert("Partner Payout can't be 0");
216
				return false;
217
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
218
				alert("Price Drop can't be 0");
219
				return false;
23819 govind 220
			}
23966 amit.gupta 221
			else {
222
				let priceDropObj = {
223
						priceDropIn:parseFloat(priceDropIn), 
224
						partnerPayout: parseFloat(partnerPayout), 
225
						priceDropId:parseInt(priceDropId)
226
				};
24083 amit.gupta 227
				addPayout(priceDropObj); 
23966 amit.gupta 228
			}
23819 govind 229
		}
23966 amit.gupta 230
		else {
231
			return false;
232
		}
23819 govind 233
	});
24083 amit.gupta 234
function addPayout(priceDropProcessObj){
235
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
236
		if (response == 'true') {
237
			alert("Payout added");
238
			loadPriceDrop("main-content");
239
		}
240
		else {
241
			alert("Some error occurred while adding payout.");
242
		}
243
	});
244
}
24406 amit.gupta 245
 
26355 amit.gupta 246
function autoProcess(priceDropObj){
247
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropObj), function(response) {
23966 amit.gupta 248
		if (response == 'true') {
249
			alert("PriceDrop sends successfully");
250
			loadPriceDrop("main-content");
251
		}
252
		else {
253
			alert("No IMEI is Eligible for PriceDrop");
254
			loadPriceDrop("main-content");
255
		}
23819 govind 256
	});
23966 amit.gupta 257
}
23819 govind 258
 
28568 amit.gupta 259
 
260
 
24083 amit.gupta 261
function updatePriceDropImeis(status){
28893 amit.gupta 262
	debugger;
24083 amit.gupta 263
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
264
	var imeis = [];
265
	imeis1.forEach(function(imei,i) {
266
		if(imei.trim()!='') {
267
			imeis.push(imei.trim()); 
268
		}
269
	});
28568 amit.gupta 270
 
271
	console.log("imeis"+imeis);
272
	console.log("imeis"+imeis.length);
273
 
274
	var arr = new Array();
275
	$('#pendingList option').each(function(){
276
	arr.push($(this).val());
277
	});
278
	console.log("arr"+arr);
279
	var holdarr = new Array();
280
	$('#holdList option').each(function(){
281
	holdarr.push($(this).val());
282
	});
283
	console.log("holdarr"+holdarr);;
284
	var lenArray = [];
285
 
26348 amit.gupta 286
	if(status=='rejected') {
28568 amit.gupta 287
 
26357 amit.gupta 288
		if($("#statusForm .mk_rejection_reason").val().trim()=="") {
26348 amit.gupta 289
			alert("Please enter rejection reason");
290
			return;
291
		}
28568 amit.gupta 292
		for ( const item of imeis)
293
		{ 
294
		if(arr.includes(item)){ 
295
 
296
			imeis = imeis.concat($('select.mk_rejected').val());
297
			lenArray=lenArray.concat(item);
26359 amit.gupta 298
		}
28568 amit.gupta 299
		else
300
		{
301
			imeis=[];
302
			lenArray=lenArray.concat(1);	
303
			if(imeis=="")
304
			{alert("All IMEIs Should be present in pending Status");}
305
					break;
306
		}
307
		}
308
 
26348 amit.gupta 309
	}
28568 amit.gupta 310
 
311
	else if(status=='approved') {
312
			for ( const item of imeis)
313
		{ 
314
		if(arr.includes(item)){
315
			imeis = imeis.concat($('select.mk_approved').val());
316
 
317
			lenArray=lenArray.concat(item);
318
 
319
		}
320
		else
321
		{
322
			imeis=[];
323
			lenArray=lenArray.concat(1);
324
			if(imeis=="")
325
			{alert("All IMEIs Should be present in pending Status");}
326
					break;
327
		}
328
		}
329
	}
330
   else if(status=='pending') {
331
	   for ( const item of imeis)
332
		{ 
333
		if(holdarr.includes(item)){
334
			imeis = imeis.concat($('select.mk_pending').val());
335
			lenArray=lenArray.concat(item);
336
		}
337
		else
338
		{
339
			imeis=[];
340
			if(imeis=="")
341
				lenArray=lenArray.concat(1);	
342
			{alert("All IMEIs Should be present in Hold Status");}
343
					break;
344
		}
345
		}
346
 
347
	} 
348
 
349
	else{
350
 
351
		for ( const item of imeis)
352
		{ 
353
		if(arr.includes(item)){
354
			imeis = imeis.concat($('select.mk_hold').val());
355
 
356
			lenArray=lenArray.concat(item);
357
		}
358
		else
359
		{
360
			imeis=[];
361
			lenArray=lenArray.concat(1);
362
			if(imeis=="")
363
			{alert("All IMEIs Should be present in pending Status");}
364
					break;
365
		}
366
		}
367
 
368
	}
26348 amit.gupta 369
 
28568 amit.gupta 370
	if(imeis.length == 0)  {
371
 
372
 
373
		if(lenArray.length != 0){
374
			return;
375
		}
376
		else{
24083 amit.gupta 377
		alert('Please choose imeis');
26359 amit.gupta 378
		return;
28568 amit.gupta 379
 
24083 amit.gupta 380
	}
28568 amit.gupta 381
	}
24176 amit.gupta 382
 
383
	if(!confirm("Move selected imeis to " + status + "?")) {
384
		return;
385
	}
24083 amit.gupta 386
	var trElement=clickedPriceDrop.closest('tr');
387
	var priceDropId = trElement.data('pricedropid');
388
 
28568 amit.gupta 389
	console.log("trElement"+trElement+"priceDropId"+priceDropId);
24083 amit.gupta 390
	priceDropImeisObj = {
391
			priceDropId: priceDropId,
392
			updatedStatus : status,
28568 amit.gupta 393
 
24083 amit.gupta 394
			updatedImeis : imeis
395
	};
396
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
397
		if (response == 'true') {
398
			alert('Imeis updated and processed successfully');
28568 amit.gupta 399
			priceDropImeis(priceDropId);
24083 amit.gupta 400
		}
401
		else {
402
			alert("Error occurred while updating.");
403
		}
404
	});
405
 
28568 amit.gupta 406
 
407
 
408
 
409
 
24410 amit.gupta 410
}