Subversion Repositories SmartDukaan

Rev

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

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