Subversion Repositories SmartDukaan

Rev

Rev 28725 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
24107 govind 1
var targetSlab = [];
2
var slabmonth;
3
var slabInputs = {};
4
$(function() {
5
 
27754 amit.gupta 6
	$(document).on('click', ".upload-target", function() {
24107 govind 7
		console.log("upload target Button Clicked...")
8
		uploadTarget("main-content");
9
	});
27755 amit.gupta 10
	$(document).on('click', ".create-partner-target-button",
25501 tejbeer 11
					function() {
12
						var targetId = $("#partnerTargetdetailsforAddTarget")
13
								.val();
14
						var fofoId = $("#partnerNameForTarget").val();
15
						var targetValue = $(".targetValue").val();
16
						if (fofoId == "" || fofoId == undefined
17
								|| fofoId == null) {
18
							alert("select partner");
19
							return false;
20
						}
21
						if (targetValue == "" || targetValue == undefined
22
								|| targetValue == null) {
23
							alert("Target value input field can't be empty");
24
							return false;
25
						}
26
						if (confirm("Are you sure you want to create partner target") == true) {
27
							createPartnerTarget(targetId, fofoId, targetValue);
28
						}
29
					});
24833 govind 30
 
27754 amit.gupta 31
	$(document).on('click', "#add-single-partner-target", function() {
24833 govind 32
		var id = $(this).data('id');
33
		addPartnerTarget(id);
34
	});
27754 amit.gupta 35
	$(document).on('click', "#edit-partner-target", function() {
24833 govind 36
		var partnerTargetId = $(this).data('targetid');
37
		getEditPartnerTarget(partnerTargetId);
38
	});
27755 amit.gupta 39
	$(document).on('click', ".modify-partner-target-button",
24833 govind 40
					function() {
41
						var partnerTargetId = $(this).data('id');
42
						var partnerTargetDetailsId = $("#partnerTargetdetails")
43
								.val();
44
						var targetValue = $(".partnerTargetValue").val();
45
						console.log(partnerTargetId);
46
						if (confirm("Are you sure you want to modify partner target") == true) {
47
							modifyPartnerTarget(partnerTargetId,
48
									partnerTargetDetailsId, targetValue);
49
						}
50
					});
51
 
27754 amit.gupta 52
	$(document).on('click', ".partner-target", function() {
24107 govind 53
		console.log("partner target Button Clicked...")
24171 govind 54
		partnerTarget("main-content");
24107 govind 55
	});
27755 amit.gupta 56
	$(document).on('click', "#partner-target-details-paginated .next",
24171 govind 57
			function() {
58
				loadPaginatedNextItems('/getAllPartnerTargetPaginated', null,
59
						'partner-target-details-paginated',
60
						'partner-target-details-table',
61
						'partner-target-details-container');
62
				$(this).blur();
63
			});
24107 govind 64
 
27755 amit.gupta 65
	$(document).on('click', "#partner-target-details-paginated .previous",
24171 govind 66
			function() {
67
				loadPaginatedPreviousItems('/getAllPartnerTargetPaginated',
68
						null, 'partner-target-details-paginated',
69
						'partner-target-details-table',
70
						'partner-target-details-container');
71
				$(this).blur();
72
			});
27754 amit.gupta 73
	$(document).on('click', ".partner-target-details", function() {
24171 govind 74
		var targetId = $(this).attr('data');
75
		console.log("targetId = " + targetId);
76
		loadPartnerTargetDetails(targetId, "partner-target-details-container");
24107 govind 77
	});
25501 tejbeer 78
 
28725 amit.gupta 79
 
25501 tejbeer 80
 
27754 amit.gupta 81
	$(document).on('click', ".deleteslab", function() {
24107 govind 82
		console.log("delete slab button clicked");
83
		var index = $(this).data('index');
84
		console.log(index);
85
		targetSlab.splice(-1, 1);
86
		$(".div-" + index).remove();
87
		$("#index-" + (index - 1)).show();
88
		console.log(targetSlab);
24171 govind 89
		if (targetSlab.length == 0) {
90
			$("#uploadfile").prop('disabled', false);
91
			$("#targetName").prop('disabled', false);
92
			$("#targetDuration").prop('disabled', false);
93
			$('#target-brands').prop('disabled', false);
94
		}
24107 govind 95
 
96
	});
97
 
27755 amit.gupta 98
	$(document).on('click', "#addSlab",
24107 govind 99
					function() {
100
						console.log("Add slab Button Clicked...");
101
						var labelName = $("#label").val();
102
						var slabpercentage = $("#slabpercentage").val();
103
						var rewardPercentage = $("#rewardPercentage").val();
24171 govind 104
						var slabName = $("#slabNameId").val();
105
						$("#uploadfile").prop('disabled', true);
106
						$("#targetName").prop('disabled', true);
107
						$("#targetDuration").prop('disabled', true);
108
						$('#target-brands').prop('disabled', true);
109
						if (slabpercentage == "" || rewardPercentage == ""
110
								|| slabName === "") {
24107 govind 111
							alert("Input field can't be empty");
112
							return;
113
						}
114
						console.log(targetSlab.length);
115
 
116
						if (targetSlab.length > 0) {
117
							console.log("#index-"
118
									+ parseFloat(targetSlab.length - 1));
119
 
120
							if (parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) < parseFloat(slabpercentage)) {
121
								$("#index-" + parseFloat(targetSlab.length - 1))
122
										.hide();
123
								slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
124
								slabInputs['maxSlabPercentage'] = slabpercentage;
125
								slabInputs['rewardPercentage'] = rewardPercentage;
24171 govind 126
								slabInputs['slabName'] = slabName;
24107 govind 127
								console.log(slabInputs);
128
								targetSlab.push(slabInputs);
129
								console.log(slabInputs)
130
								$("#slab-input")
131
										.html(
24171 govind 132
												"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
133
														+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
134
														+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
24107 govind 135
														+ "<input type=button class=btn-primary  value=+ id=addSlab>"
136
 
137
										);
138
 
139
								var htmlString = $("<div class=div-"
140
										+ parseFloat(targetSlab.length - 1)
141
										+ ">"
142
										+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
143
										+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
144
										+ slabpercentage
24171 govind 145
										+ ">  "
24107 govind 146
										+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
147
										+ rewardPercentage
24171 govind 148
										+ ">  "
149
										+ "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
150
										+ slabName
151
										+ ">"
24107 govind 152
										+ "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
153
										+ parseFloat(targetSlab.length - 1)
154
										+ "\"id=index-"
155
										+ parseFloat(targetSlab.length - 1)
24171 govind 156
										+ ">" + "  <div><br>");
24107 govind 157
								$("#slab-order").append(htmlString);
158
								slabInputs = {};
159
							} else {
160
								alert("Slab Percentage is not less than previous Slab Percentage");
161
								return false;
162
							}
163
						} else {
164
							slabInputs['minSlabPercentage'] = 0;
165
							slabInputs['maxSlabPercentage'] = slabpercentage;
166
							slabInputs['rewardPercentage'] = rewardPercentage;
24171 govind 167
							slabInputs['slabName'] = slabName;
24107 govind 168
							console.log(slabInputs);
169
							targetSlab.push(slabInputs);
170
							console.log(slabInputs)
171
							$("#slab-input")
172
									.html(
24171 govind 173
											"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
174
													+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
175
													+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
24107 govind 176
													+ "<input type=button class=btn-primary  value=+ id=addSlab>"
177
 
178
									);
179
 
180
							var htmlString = $("<div class=div-"
181
									+ parseFloat(targetSlab.length - 1)
182
									+ ">"
183
									+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
184
									+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
185
									+ slabpercentage
24171 govind 186
									+ ">  "
24107 govind 187
									+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
188
									+ rewardPercentage
24171 govind 189
									+ ">  "
190
									+ "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
191
									+ slabName
192
									+ ">"
24107 govind 193
									+ "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
194
									+ parseFloat(targetSlab.length - 1)
195
									+ "\" id=index-"
196
									+ parseFloat(targetSlab.length - 1) + ">"
24171 govind 197
									+ "  <div><br><div>");
24107 govind 198
							$("#slab-order").append(htmlString);
199
							$("#slabdate").prop('disabled', true);
200
							slabInputs = {};
201
						}
202
 
203
					});
204
 
27755 amit.gupta 205
	$(document).on('click', "#uploadExcel",
24107 govind 206
					function() {
207
						var excelfile = $('#uploadfile')[0].files[0];
24171 govind 208
						var targetName = $('#targetName').val();
209
						var slabName = $("#slabNameId").val();
210
						console.log(excelfile);
211
						console.log(targetName);
212
						if (!excelfile) {
213
							alert("choose excel file for upload");
214
							return;
215
						}
216
						var ext = $('#uploadfile').val().split('.').pop()
217
								.toLowerCase();
218
						if ($.inArray(ext, [ 'xlsx' ]) == -1) {
219
							alert('invalid extension!');
220
							return;
221
						}
24833 govind 222
						if (targetName === null || targetName === "") {
24171 govind 223
							alert("targetName Field is not empty");
224
							return;
225
						}
24833 govind 226
						if (slabName === null || slabName === "") {
24171 govind 227
							alert("slabName Field is not empty");
228
							return;
229
						}
230
						var brandName = $('#target-brands').val();
231
						console.log(brandName);
232
						if (brandName == "") {
233
							brandName = null;
234
						}
24107 govind 235
						console.log("excelfile" + excelfile);
24171 govind 236
						var labelName = $("#label").val();
237
						var rewardPercentage = $("#rewardPercentage").val();
238
						if (rewardPercentage == "" || slabName === "") {
239
							alert("Input field can't be empty");
240
							return;
241
						}
242
						slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
243
						slabInputs['maxSlabPercentage'] = -1;
244
						slabInputs['rewardPercentage'] = rewardPercentage;
245
						slabInputs['slabName'] = slabName;
246
						console.log(slabInputs);
247
						targetSlab.push(slabInputs);
248
						slabInputs = {};
249
						console.log(targetSlab);
24107 govind 250
						if (confirm("Are you sure you want to upload excel file!") == true) {
24171 govind 251
							var data = {
30599 amit.gupta 252
								targetName: targetName,
253
								startDate: getDatesFromPicker($('input[name="targetDuration"]')).startDate,
254
								endDate: getDatesFromPicker($('input[name="targetDurarion"]')).endDate,
255
								brandName: brandName,
256
								targetSlabs: targetSlab
24107 govind 257
							}
258
 
24171 govind 259
							doAjaxUploadRequestJsonHandler(context
260
									+ "/uploadPartnersTarget", 'POST',
261
									excelfile, JSON.stringify(data), function(
262
											response) {
263
										if (response == "true") {
264
											alert("successfully uploaded");
265
											targetSlab = [];
266
											uploadTarget("main-content");
267
										}
268
										targetSlab = [];
269
 
270
									});
24107 govind 271
						}
272
					});
273
 
274
});
275
 
276
function labelChange() {
277
	var labelName = $("#label").val();
278
	console.log(labelName);
24171 govind 279
	if (labelName == "upto") {
24107 govind 280
 
24171 govind 281
		$("#slab-input")
282
				.html(
283
						"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
284
								+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
285
								+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
286
								+ "<input type=button class=btn-primary  value=+ id=addSlab>"
24107 govind 287
 
24171 govind 288
				);
24107 govind 289
 
24171 govind 290
	} else {
291
		$("#slab-input")
292
				.html(
24107 govind 293
 
24171 govind 294
						"<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">"
24833 govind 295
								+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
296
								+ "<input class=\"btn btn-primary\" type=button value=upload id=uploadExcel>");
24107 govind 297
	}
298
}
299
 
300
function uploadTarget(domId) {
301
	doGetAjaxRequestHandler(context + "/uploadPartnerTargetPage", function(
302
			response) {
303
		$('#' + domId).html(response);
304
	});
305
}
24171 govind 306
function partnerTarget(domId) {
307
	doGetAjaxRequestHandler(context + "/getAllPartnerTarget",
308
			function(response) {
309
				$('#' + domId).html(response);
310
			});
24107 govind 311
}
24171 govind 312
function loadPartnerTargetDetails(targetId, domId) {
313
	doGetAjaxRequestHandler(context + "/getPartnerTarget?targetId=" + targetId,
314
			function(response) {
315
				$('#' + domId).html(response);
316
				window.dispatchEvent(new Event('resize'));
317
			});
24107 govind 318
}
24833 govind 319
function getEditPartnerTarget(partnerTargetId) {
320
	doGetAjaxRequestHandler(context + "/getAllPartnerRelatedTarget?id="
321
			+ partnerTargetId, function(response) {
322
		$(".edit-partner-target-container .modal-content").html(response);
323
	});
324
}
325
function modifyPartnerTarget(partnerTargetId, partnerTargetDetailsId,
326
		targetValue) {
327
	var params = {
328
		"partnerTargetId" : partnerTargetId,
329
		"partnerTargetDetailsId" : partnerTargetDetailsId,
330
		"targetValue" : targetValue,
331
	}
332
	doPostAjaxRequestWithParamsHandler(context + "/updatePartnerTarget",
333
			params, function(response) {
334
				if (response == "true") {
335
					alert("Target successfully modified");
336
					getEditPartnerTarget(partnerTargetId)
337
				} else {
338
					alert("Target already defined");
339
				}
340
			});
341
}
342
function addPartnerTarget(id) {
343
	doGetAjaxRequestHandler(context + "/addPartnerTarget?id=" + id, function(
344
			response) {
345
		$(".add-partner-target-container .modal-content").html(response);
346
	});
347
}
25501 tejbeer 348
 
349
function loadTargetInfoPage(domId) {
350
	doGetAjaxRequestHandler(context + "/getTargetInfo", function(response) {
351
		$('#' + domId).html(response);
352
	});
353
}
354
 
24833 govind 355
function createPartnerTarget(targetId, fofoId, targetValue) {
356
	var params = {
357
		"fofoId" : fofoId,
358
		"partnerTargetDetailsId" : targetId,
359
		"targetValue" : targetValue,
360
	}
361
	console.log(targetValue);
362
	doPostAjaxRequestWithParamsHandler(context + "/addPartnerTarget", params,
363
			function(response) {
364
				if (response == "true") {
365
					alert("successfully created!");
25501 tejbeer 366
				} else {
367
					alert("You are not authorized to create partner target");
24833 govind 368
				}
369
			});
370
}