Subversion Repositories SmartDukaan

Rev

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