Subversion Repositories SmartDukaan

Rev

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