Subversion Repositories SmartDukaan

Rev

Rev 24529 | Rev 26349 | 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();
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
	});
23884 amit.gupta 65
	$("button.addPriceDrop").live('click', function() {
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
	});
119
	$('input.downloadtotalIMEI').live('click', 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
 
23951 amit.gupta 125
	$('button.download-imeis').live('click', function(){
126
		doAjaxGetDownload(context+"/price-drop/imes/download/?affectedDate="+startDate +"&itemId=" + currentItem.itemId, "pricedrop.csv")
127
	});
23819 govind 128
 
24060 amit.gupta 129
	$('button.mk_download_pricing').live('click', function(){
130
		doAjaxGetDownload(context+"/tagListing/download/4", "pricing.xlsx")
131
	});
23951 amit.gupta 132
 
26348 amit.gupta 133
	$('.mk_auto_process').live('click', function (){
134
 
135
	}
136
 
24083 amit.gupta 137
	$('.mk_view_imeis').live('click', function (){
138
		clickedPriceDrop = $(this);
139
		var trElement=$(this).closest('tr');
140
		var priceDropId = trElement.data('pricedropid');
141
 
142
		doAjaxRequestWithJsonHandler(context+"/priceDropImeis/"+ priceDropId, 'GET', null, function(response) {
143
			response = JSON.parse(response);
144
			pendingArr=[];
145
			response.pendingImeis.forEach(function(val,index){
26348 amit.gupta 146
				pendingArr.push('<option disabled>' +  val + '</option>')
24083 amit.gupta 147
			});
26348 amit.gupta 148
			$('select.mk_pending').html(pendingArr.join('')).find('option');
24529 amit.gupta 149
			$('span.mk_pending_count').html(pendingArr.length);
24083 amit.gupta 150
 
151
			approvedArr=[];
152
			response.approvedImeis.forEach(function(val,index){
26348 amit.gupta 153
				approvedArr.push('<option>' +  val + '</option>')
24083 amit.gupta 154
			});
155
			$('select.mk_approved').html(approvedArr.join(''));
24529 amit.gupta 156
			$('span.mk_approved_count').html(approvedArr.length);
24083 amit.gupta 157
 
158
			rejectedArr=[];
159
			response.rejectedImeis.forEach(function(val,index){
160
				rejectedArr.push('<option>' +  val + '</option>')
161
			});
24529 amit.gupta 162
			$('span.mk_rejected_count').html(rejectedArr.length);
24083 amit.gupta 163
			$('select.mk_rejected').html(rejectedArr.join(''));
24414 amit.gupta 164
			//if(rejected) {}
24083 amit.gupta 165
		});
166
	});
24060 amit.gupta 167
 
23966 amit.gupta 168
	$('.mk_process_price_drop').live('click', function (){
24083 amit.gupta 169
		if (confirm("Are you sure you want to Update Payout?")) {
170
			processPayout(priceDropProcessObj)
171
		}
172
	});
173
 
174
	$('.mk_add_payout').live('click', function (){
175
		if (confirm("Are you sure you want to add price Drop?")) {
23966 amit.gupta 176
			var trElement=$(this).closest('tr');
177
			var priceDropId = trElement.data('pricedropid');
23968 amit.gupta 178
			var partnerPayout = trElement.find('.partner-payout').val();
179
			var priceDropIn = trElement.find('.price-drop-in').val();
23966 amit.gupta 180
 
181
			if(isNaN(partnerPayout) || partnerPayout == 0) {
182
				alert("Partner Payout can't be 0");
183
				return false;
184
			} else if (isNaN(priceDropIn) || priceDropIn == 0) {
185
				alert("Price Drop can't be 0");
186
				return false;
23819 govind 187
			}
23966 amit.gupta 188
			else {
189
				let priceDropObj = {
190
						priceDropIn:parseFloat(priceDropIn), 
191
						partnerPayout: parseFloat(partnerPayout), 
192
						priceDropId:parseInt(priceDropId)
193
				};
24083 amit.gupta 194
				addPayout(priceDropObj); 
23966 amit.gupta 195
			}
23819 govind 196
		}
23966 amit.gupta 197
		else {
198
			return false;
199
		}
23819 govind 200
	});
24083 amit.gupta 201
function addPayout(priceDropProcessObj){
202
	doPostAjaxRequestWithJsonHandler(context+"/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function(response) {
203
		if (response == 'true') {
204
			alert("Payout added");
205
			loadPriceDrop("main-content");
206
		}
207
		else {
208
			alert("Some error occurred while adding payout.");
209
		}
210
	});
211
}
24406 amit.gupta 212
 
23966 amit.gupta 213
function processPayout(priceDropProcessObj){
23968 amit.gupta 214
	doPostAjaxRequestWithJsonHandler(context+"/processPriceDrop", JSON.stringify(priceDropProcessObj), function(response) {
23966 amit.gupta 215
		if (response == 'true') {
216
			alert("PriceDrop sends successfully");
217
			loadPriceDrop("main-content");
218
		}
219
		else {
220
			alert("No IMEI is Eligible for PriceDrop");
221
			loadPriceDrop("main-content");
222
		}
23819 govind 223
	});
23966 amit.gupta 224
}
23819 govind 225
 
24083 amit.gupta 226
function updatePriceDropImeis(status){
227
	var imeis1 = $('input.mk_imeis_text').val().trim().split(',');
228
	var imeis = [];
229
	imeis1.forEach(function(imei,i) {
230
		if(imei.trim()!='') {
231
			imeis.push(imei.trim()); 
232
		}
233
	});
26348 amit.gupta 234
	if(status=='rejected') {
235
		if(trim($("#pdForm .mk_rejection_reason").val())=="") {
236
			alert("Please enter rejection reason");
237
			return;
238
		}
239
		imeis.push($('select.mk_approved').val());
240
	} else {
241
		imeis.push($('select.mk_rejected').val());
242
	}
243
 
244
	if(imeis.length == 0) {
24083 amit.gupta 245
		alert('Please choose imeis');
246
	}
24176 amit.gupta 247
 
248
	if(!confirm("Move selected imeis to " + status + "?")) {
249
		return;
250
	}
24083 amit.gupta 251
	var trElement=clickedPriceDrop.closest('tr');
252
	var priceDropId = trElement.data('pricedropid');
253
 
254
	priceDropImeisObj = {
255
			priceDropId: priceDropId,
256
			updatedStatus : status,
257
			updatedImeis : imeis
258
	};
259
	doPostAjaxRequestWithJsonHandler(context+"/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function(response) {
260
		if (response == 'true') {
261
			alert('Imeis updated and processed successfully');
262
			clickedPriceDrop.click();
263
		}
264
		else {
265
			alert("Error occurred while updating.");
266
		}
267
	});
268
 
24410 amit.gupta 269
}