Subversion Repositories SmartDukaan

Rev

Rev 27071 | Rev 28568 | 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
		}
24409 amit.gupta 93
		//as of now allColors is set to true. This means that all colors are eligible for price drop
23884 amit.gupta 94
		if(confirm("Are you sure?")) {
95
			var obj = {
96
					itemId:currentItem.itemId,
24409 amit.gupta 97
					dp:parseFloat(newDp),
23884 amit.gupta 98
					tp:parseFloat(newTp),
99
					mop:parseFloat(newMop),
24409 amit.gupta 100
					allColors:true,
23884 amit.gupta 101
					affectedDate:startDate
102
			}
103
			doPostAjaxRequestWithJsonHandler(
104
					context+"/priceDrop", JSON.stringify(obj),
105
					function(response) {
106
						if (response == 'true') {
24409 amit.gupta 107
							$('#newPriceDropModal').find('button.close').trigger('click');
23884 amit.gupta 108
							setTimeout(() => {
24406 amit.gupta 109
								alert("PriceDrop added successfully from " + $("#typeaheaditem").val());
23884 amit.gupta 110
								loadPriceDrop("main-content");
111
							}, 500);
112
						} else {
24410 amit.gupta 113
							alert("Invalid values provided could not update");
23884 amit.gupta 114
						}
115
					}
116
			);
117
		}
118
	});
27754 amit.gupta 119
	$(document).on('click', 'input.downloadtotalIMEI', function (){
23966 amit.gupta 120
		var priceDropId=$(this).closest('tr').data('pricedropid');
23819 govind 121
		doAjaxGetDownload(context+"/downloadtotalPriceDropIMEI/"+priceDropId,
23971 amit.gupta 122
		"totalPriceDropIMEI"+priceDropId+".csv");
23819 govind 123
	});
124
 
27754 amit.gupta 125
	$(document).on('click', 'button.download-imeis', function(){
23951 amit.gupta 126
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
127
	});
23819 govind 128
 
27754 amit.gupta 129
	$(document).on('click', 'button.mk_download_pricing', function(){
24060 amit.gupta 130
		doAjaxGetDownload(context+"/tagListing/download/4", "pricing.xlsx")
131
	});
23951 amit.gupta 132
 
27754 amit.gupta 133
	$(document).on('click', '.mk_auto_process', function (){
27071 amit.gupta 134
		var trElement=$(this).closest('tr');
135
		var payout = trElement.find('input.partner-payout').val();
136
		if(isNaN(parseInt(payout)) || parseInt(payout) <=0) {
137
			alert("Invalid payout amount");
138
		}
26355 amit.gupta 139
		if (confirm("Are you sure you want to Process Payout?")) {
140
			clickedPriceDrop = $(this);
141
			var priceDropId = trElement.data('pricedropid');
27071 amit.gupta 142
			autoProcess({priceDropId:priceDropId, partnerPayout:payout, activatedOnly:$(this).data('activatedonly')})
26355 amit.gupta 143
		}
26349 amit.gupta 144
	});
26348 amit.gupta 145
 
27754 amit.gupta 146
	$(document).on('click', '.mk_view_imeis', function (){
24083 amit.gupta 147
		clickedPriceDrop = $(this);
148
		var trElement=$(this).closest('tr');
149
		var priceDropId = trElement.data('pricedropid');
150
 
151
		doAjaxRequestWithJsonHandler(context+"/priceDropImeis/"+ priceDropId, 'GET', null, function(response) {
152
			response = JSON.parse(response);
153
			pendingArr=[];
154
			response.pendingImeis.forEach(function(val,index){
26348 amit.gupta 155
				pendingArr.push('<option disabled>' +  val + '</option>')
24083 amit.gupta 156
			});
26348 amit.gupta 157
			$('select.mk_pending').html(pendingArr.join('')).find('option');
24529 amit.gupta 158
			$('span.mk_pending_count').html(pendingArr.length);
24083 amit.gupta 159
 
160
			approvedArr=[];
161
			response.approvedImeis.forEach(function(val,index){
26348 amit.gupta 162
				approvedArr.push('<option>' +  val + '</option>')
24083 amit.gupta 163
			});
164
			$('select.mk_approved').html(approvedArr.join(''));
24529 amit.gupta 165
			$('span.mk_approved_count').html(approvedArr.length);
24083 amit.gupta 166
 
167
			rejectedArr=[];
168
			response.rejectedImeis.forEach(function(val,index){
169
				rejectedArr.push('<option>' +  val + '</option>')
170
			});
24529 amit.gupta 171
			$('span.mk_rejected_count').html(rejectedArr.length);
24083 amit.gupta 172
			$('select.mk_rejected').html(rejectedArr.join(''));
24414 amit.gupta 173
			//if(rejected) {}
24083 amit.gupta 174
		});
175
	});
176
 
27754 amit.gupta 177
	$(document).on('click', '.mk_add_payout', function (){
24083 amit.gupta 178
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 179
			var trElement=$(this).closest('tr');
180
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 181
			var partnerPayout = trElement.find('.partner-payout').val();
182
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 183
 
184
			if(isNaN(partnerPayout) || partnerPayout == 0) {
185
				alert("Partner Payout can't be 0");
186
				return false;
187
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
188
				alert("Price Drop can't be 0");
189
				return false;
23819 govind 190
			}
23966 amit.gupta 191
			else {
192
				let priceDropObj = {
193
						priceDropIn:parseFloat(priceDropIn), 
194
						partnerPayout: parseFloat(partnerPayout), 
195
						priceDropId:parseInt(priceDropId)
196
				};
24083 amit.gupta 197
				addPayout(priceDropObj); 
23966 amit.gupta 198
			}
23819 govind 199
		}
23966 amit.gupta 200
		else {
201
			return false;
202
		}
23819 govind 203
	});
24083 amit.gupta 204
function addPayout(priceDropProcessObj){
205
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
206
		if (response == 'true') {
207
			alert("Payout added");
208
			loadPriceDrop("main-content");
209
		}
210
		else {
211
			alert("Some error occurred while adding payout.");
212
		}
213
	});
214
}
24406 amit.gupta 215
 
26355 amit.gupta 216
function autoProcess(priceDropObj){
217
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropObj), function(response) {
23966 amit.gupta 218
		if (response == 'true') {
219
			alert("PriceDrop sends successfully");
220
			loadPriceDrop("main-content");
221
		}
222
		else {
223
			alert("No IMEI is Eligible for PriceDrop");
224
			loadPriceDrop("main-content");
225
		}
23819 govind 226
	});
23966 amit.gupta 227
}
23819 govind 228
 
24083 amit.gupta 229
function updatePriceDropImeis(status){
230
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
231
	var imeis = [];
232
	imeis1.forEach(function(imei,i) {
233
		if(imei.trim()!='') {
234
			imeis.push(imei.trim()); 
235
		}
236
	});
26348 amit.gupta 237
	if(status=='rejected') {
26357 amit.gupta 238
		if($("#statusForm .mk_rejection_reason").val().trim()=="") {
26348 amit.gupta 239
			alert("Please enter rejection reason");
240
			return;
241
		}
26362 amit.gupta 242
		imeis = imeis.concat($('select.mk_approved').val());
26359 amit.gupta 243
	} else {
244
		if($("#statusForm .mk_rejection_reason").val().trim()!="") {
245
			alert("Rejection reason should be empty during approval.");
26360 amit.gupta 246
			return;
26359 amit.gupta 247
		}
26362 amit.gupta 248
		imeis = imeis.concat($('select.mk_rejected').val());
26348 amit.gupta 249
	}
250
 
251
	if(imeis.length == 0) {
24083 amit.gupta 252
		alert('Please choose imeis');
26359 amit.gupta 253
		return;
24083 amit.gupta 254
	}
24176 amit.gupta 255
 
256
	if(!confirm("Move selected imeis to " + status + "?")) {
257
		return;
258
	}
24083 amit.gupta 259
	var trElement=clickedPriceDrop.closest('tr');
260
	var priceDropId = trElement.data('pricedropid');
261
 
262
	priceDropImeisObj = {
263
			priceDropId: priceDropId,
264
			updatedStatus : status,
265
			updatedImeis : imeis
266
	};
267
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
268
		if (response == 'true') {
269
			alert('Imeis updated and processed successfully');
270
			clickedPriceDrop.click();
271
		}
272
		else {
273
			alert("Error occurred while updating.");
274
		}
275
	});
276
 
24410 amit.gupta 277
}