Subversion Repositories SmartDukaan

Rev

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