Subversion Repositories SmartDukaan

Rev

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