Subversion Repositories SmartDukaan

Rev

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

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