Subversion Repositories SmartDukaan

Rev

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