Subversion Repositories SmartDukaan

Rev

Rev 24083 | Rev 24176 | 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 = {
66
					itemId:currentItem1.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(''));
185
		});
186
	});
24060 amit.gupta 187
 
23966 amit.gupta 188
	$('.mk_process_price_drop').live('click', function (){
24083 amit.gupta 189
		if (confirm("Are you sure you want to Update Payout?")) {
190
			processPayout(priceDropProcessObj)
191
		}
192
	});
193
 
194
	$('.mk_add_payout').live('click', function (){
195
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 196
			var trElement=$(this).closest('tr');
197
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 198
			var partnerPayout = trElement.find('.partner-payout').val();
199
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 200
 
201
			if(isNaN(partnerPayout) || partnerPayout == 0) {
202
				alert("Partner Payout can't be 0");
203
				return false;
204
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
205
				alert("Price Drop can't be 0");
206
				return false;
23819 govind 207
			}
23966 amit.gupta 208
			else {
209
				let priceDropObj = {
210
						priceDropIn:parseFloat(priceDropIn), 
211
						partnerPayout: parseFloat(partnerPayout), 
212
						priceDropId:parseInt(priceDropId)
213
				};
24083 amit.gupta 214
				addPayout(priceDropObj); 
23966 amit.gupta 215
			}
23819 govind 216
		}
23966 amit.gupta 217
		else {
218
			return false;
219
		}
23819 govind 220
	});
221
});
24083 amit.gupta 222
function addPayout(priceDropProcessObj){
223
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
224
		if (response == 'true') {
225
			alert("Payout added");
226
			loadPriceDrop("main-content");
227
		}
228
		else {
229
			alert("Some error occurred while adding payout.");
230
		}
231
	});
232
}
23819 govind 233
function loadPriceDrop(domId){
234
	doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
235
		$('#' + domId).html(response);
236
	});
237
}
23966 amit.gupta 238
function processPayout(priceDropProcessObj){
23968 amit.gupta 239
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
23966 amit.gupta 240
		if (response == 'true') {
241
			alert("PriceDrop sends successfully");
242
			loadPriceDrop("main-content");
243
		}
244
		else {
245
			alert("No IMEI is Eligible for PriceDrop");
246
			loadPriceDrop("main-content");
247
		}
23819 govind 248
	});
23966 amit.gupta 249
}
23819 govind 250
 
24083 amit.gupta 251
function updatePriceDropImeis(status){
252
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
253
	var imeis = [];
254
	imeis1.forEach(function(imei,i) {
255
		if(imei.trim()!='') {
256
			imeis.push(imei.trim()); 
257
		}
258
	});
259
	imeis = imeis.concat($('select.mk_pending').val())
260
	.concat($('select.mk_approved').val())
261
	.concat($('select.mk_rejected').val());
262
 
263
	if(imeis.length < 0) {
264
		alert('Please choose imeis');
265
	}
266
 
267
	var trElement=clickedPriceDrop.closest('tr');
268
	var priceDropId = trElement.data('pricedropid');
269
 
270
	priceDropImeisObj = {
271
			priceDropId: priceDropId,
272
			updatedStatus : status,
273
			updatedImeis : imeis
274
	};
275
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
276
		if (response == 'true') {
277
			alert('Imeis updated and processed successfully');
278
			clickedPriceDrop.click();
279
		}
280
		else {
281
			alert("Error occurred while updating.");
282
		}
283
	});
284
 
285
}