Subversion Repositories SmartDukaan

Rev

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

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