Subversion Repositories SmartDukaan

Rev

Rev 28903 | Rev 30609 | 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(){
23951 amit.gupta 140
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
141
	});
23819 govind 142
 
27754 amit.gupta 143
	$(document).on('click', 'button.mk_download_pricing', function(){
24060 amit.gupta 144
		doAjaxGetDownload(context+"/tagListing/download/4", "pricing.xlsx")
145
	});
23951 amit.gupta 146
 
27754 amit.gupta 147
	$(document).on('click', '.mk_auto_process', function (){
27071 amit.gupta 148
		var trElement=$(this).closest('tr');
149
		var payout = trElement.find('input.partner-payout').val();
150
		if(isNaN(parseInt(payout)) || parseInt(payout) <=0) {
151
			alert("Invalid payout amount");
152
		}
26355 amit.gupta 153
		if (confirm("Are you sure you want to Process Payout?")) {
154
			clickedPriceDrop = $(this);
155
			var priceDropId = trElement.data('pricedropid');
27071 amit.gupta 156
			autoProcess({priceDropId:priceDropId, partnerPayout:payout, activatedOnly:$(this).data('activatedonly')})
26355 amit.gupta 157
		}
26349 amit.gupta 158
	});
28568 amit.gupta 159
 
160
	function priceDropImeis(priceDropId){
24083 amit.gupta 161
 
28568 amit.gupta 162
 
24083 amit.gupta 163
		doAjaxRequestWithJsonHandler(context+"/priceDropImeis/"+ priceDropId, 'GET', null, function(response) {
164
			response = JSON.parse(response);
28568 amit.gupta 165
			holdArr=[];
166
			response.holdImeis.forEach(function(val,index){
167
				holdArr.push('<option>' +  val + '</option>')
168
			});
169
			$('select.mk_hold').html(holdArr.join('')).find('option');
170
			$('span.mk_hold_count').html(holdArr.length);
171
 
172
 
24083 amit.gupta 173
			pendingArr=[];
174
			response.pendingImeis.forEach(function(val,index){
28568 amit.gupta 175
				pendingArr.push('<option>' +  val + '</option>')
24083 amit.gupta 176
			});
26348 amit.gupta 177
			$('select.mk_pending').html(pendingArr.join('')).find('option');
24529 amit.gupta 178
			$('span.mk_pending_count').html(pendingArr.length);
24083 amit.gupta 179
 
180
			approvedArr=[];
181
			response.approvedImeis.forEach(function(val,index){
26348 amit.gupta 182
				approvedArr.push('<option>' +  val + '</option>')
24083 amit.gupta 183
			});
184
			$('select.mk_approved').html(approvedArr.join(''));
24529 amit.gupta 185
			$('span.mk_approved_count').html(approvedArr.length);
24083 amit.gupta 186
 
187
			rejectedArr=[];
188
			response.rejectedImeis.forEach(function(val,index){
189
				rejectedArr.push('<option>' +  val + '</option>')
190
			});
24529 amit.gupta 191
			$('span.mk_rejected_count').html(rejectedArr.length);
24083 amit.gupta 192
			$('select.mk_rejected').html(rejectedArr.join(''));
28568 amit.gupta 193
			// if(rejected) {}
24083 amit.gupta 194
		});
28568 amit.gupta 195
 
196
	}
197
 
198
	$(document).on('click', '.mk_view_imeis', function (){
199
		clickedPriceDrop = $(this);
200
		var trElement=$(this).closest('tr');
201
		var priceDropId = trElement.data('pricedropid');
202
		priceDropImeis(priceDropId);
203
 
24083 amit.gupta 204
	});
205
 
27754 amit.gupta 206
	$(document).on('click', '.mk_add_payout', function (){
24083 amit.gupta 207
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 208
			var trElement=$(this).closest('tr');
209
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 210
			var partnerPayout = trElement.find('.partner-payout').val();
211
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 212
 
213
			if(isNaN(partnerPayout) || partnerPayout == 0) {
214
				alert("Partner Payout can't be 0");
215
				return false;
216
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
217
				alert("Price Drop can't be 0");
218
				return false;
23819 govind 219
			}
23966 amit.gupta 220
			else {
221
				let priceDropObj = {
222
						priceDropIn:parseFloat(priceDropIn), 
223
						partnerPayout: parseFloat(partnerPayout), 
224
						priceDropId:parseInt(priceDropId)
225
				};
24083 amit.gupta 226
				addPayout(priceDropObj); 
23966 amit.gupta 227
			}
23819 govind 228
		}
23966 amit.gupta 229
		else {
230
			return false;
231
		}
23819 govind 232
	});
24083 amit.gupta 233
function addPayout(priceDropProcessObj){
234
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
235
		if (response == 'true') {
236
			alert("Payout added");
237
			loadPriceDrop("main-content");
238
		}
239
		else {
240
			alert("Some error occurred while adding payout.");
241
		}
242
	});
243
}
24406 amit.gupta 244
 
26355 amit.gupta 245
function autoProcess(priceDropObj){
246
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropObj), function(response) {
23966 amit.gupta 247
		if (response == 'true') {
248
			alert("PriceDrop sends successfully");
249
			loadPriceDrop("main-content");
250
		}
251
		else {
252
			alert("No IMEI is Eligible for PriceDrop");
253
			loadPriceDrop("main-content");
254
		}
23819 govind 255
	});
23966 amit.gupta 256
}
23819 govind 257
 
28568 amit.gupta 258
 
259
 
24083 amit.gupta 260
function updatePriceDropImeis(status){
28893 amit.gupta 261
	debugger;
24083 amit.gupta 262
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
263
	var imeis = [];
264
	imeis1.forEach(function(imei,i) {
265
		if(imei.trim()!='') {
266
			imeis.push(imei.trim()); 
267
		}
268
	});
28568 amit.gupta 269
 
270
	console.log("imeis"+imeis);
271
	console.log("imeis"+imeis.length);
272
 
273
	var arr = new Array();
274
	$('#pendingList option').each(function(){
275
	arr.push($(this).val());
276
	});
277
	console.log("arr"+arr);
278
	var holdarr = new Array();
279
	$('#holdList option').each(function(){
280
	holdarr.push($(this).val());
281
	});
282
	console.log("holdarr"+holdarr);;
283
	var lenArray = [];
284
 
26348 amit.gupta 285
	if(status=='rejected') {
28568 amit.gupta 286
 
26357 amit.gupta 287
		if($("#statusForm .mk_rejection_reason").val().trim()=="") {
26348 amit.gupta 288
			alert("Please enter rejection reason");
289
			return;
290
		}
28568 amit.gupta 291
		for ( const item of imeis)
292
		{ 
293
		if(arr.includes(item)){ 
294
 
295
			imeis = imeis.concat($('select.mk_rejected').val());
296
			lenArray=lenArray.concat(item);
26359 amit.gupta 297
		}
28568 amit.gupta 298
		else
299
		{
300
			imeis=[];
301
			lenArray=lenArray.concat(1);	
302
			if(imeis=="")
303
			{alert("All IMEIs Should be present in pending Status");}
304
					break;
305
		}
306
		}
307
 
26348 amit.gupta 308
	}
28568 amit.gupta 309
 
310
	else if(status=='approved') {
311
			for ( const item of imeis)
312
		{ 
313
		if(arr.includes(item)){
314
			imeis = imeis.concat($('select.mk_approved').val());
315
 
316
			lenArray=lenArray.concat(item);
317
 
318
		}
319
		else
320
		{
321
			imeis=[];
322
			lenArray=lenArray.concat(1);
323
			if(imeis=="")
324
			{alert("All IMEIs Should be present in pending Status");}
325
					break;
326
		}
327
		}
328
	}
329
   else if(status=='pending') {
330
	   for ( const item of imeis)
331
		{ 
332
		if(holdarr.includes(item)){
333
			imeis = imeis.concat($('select.mk_pending').val());
334
			lenArray=lenArray.concat(item);
335
		}
336
		else
337
		{
338
			imeis=[];
339
			if(imeis=="")
340
				lenArray=lenArray.concat(1);	
341
			{alert("All IMEIs Should be present in Hold Status");}
342
					break;
343
		}
344
		}
345
 
346
	} 
347
 
348
	else{
349
 
350
		for ( const item of imeis)
351
		{ 
352
		if(arr.includes(item)){
353
			imeis = imeis.concat($('select.mk_hold').val());
354
 
355
			lenArray=lenArray.concat(item);
356
		}
357
		else
358
		{
359
			imeis=[];
360
			lenArray=lenArray.concat(1);
361
			if(imeis=="")
362
			{alert("All IMEIs Should be present in pending Status");}
363
					break;
364
		}
365
		}
366
 
367
	}
26348 amit.gupta 368
 
28568 amit.gupta 369
	if(imeis.length == 0)  {
370
 
371
 
372
		if(lenArray.length != 0){
373
			return;
374
		}
375
		else{
24083 amit.gupta 376
		alert('Please choose imeis');
26359 amit.gupta 377
		return;
28568 amit.gupta 378
 
24083 amit.gupta 379
	}
28568 amit.gupta 380
	}
24176 amit.gupta 381
 
382
	if(!confirm("Move selected imeis to " + status + "?")) {
383
		return;
384
	}
24083 amit.gupta 385
	var trElement=clickedPriceDrop.closest('tr');
386
	var priceDropId = trElement.data('pricedropid');
387
 
28568 amit.gupta 388
	console.log("trElement"+trElement+"priceDropId"+priceDropId);
24083 amit.gupta 389
	priceDropImeisObj = {
390
			priceDropId: priceDropId,
391
			updatedStatus : status,
28568 amit.gupta 392
 
24083 amit.gupta 393
			updatedImeis : imeis
394
	};
395
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
396
		if (response == 'true') {
397
			alert('Imeis updated and processed successfully');
28568 amit.gupta 398
			priceDropImeis(priceDropId);
24083 amit.gupta 399
		}
400
		else {
401
			alert("Error occurred while updating.");
402
		}
403
	});
404
 
28568 amit.gupta 405
 
406
 
407
 
408
 
24410 amit.gupta 409
}