| 24107 |
govind |
1 |
var targetSlab = [];
|
|
|
2 |
var slabmonth;
|
|
|
3 |
var slabInputs = {};
|
|
|
4 |
$(function() {
|
|
|
5 |
|
|
|
6 |
$(".upload-target").live('click', function() {
|
|
|
7 |
console.log("upload target Button Clicked...")
|
|
|
8 |
uploadTarget("main-content");
|
|
|
9 |
});
|
|
|
10 |
$(".partner-target").live('click', function() {
|
|
|
11 |
console.log("partner target Button Clicked...")
|
|
|
12 |
partnerTarget("main-content", startDate);
|
|
|
13 |
});
|
|
|
14 |
|
|
|
15 |
$(".create-slab").live('click', function() {
|
|
|
16 |
console.log("create slab Button Clicked...");
|
|
|
17 |
createSlab("main-content");
|
|
|
18 |
});
|
|
|
19 |
$(".deleteslab").live('click', function() {
|
|
|
20 |
console.log("delete slab button clicked");
|
|
|
21 |
var index = $(this).data('index');
|
|
|
22 |
console.log(index);
|
|
|
23 |
targetSlab.splice(-1, 1);
|
|
|
24 |
$(".div-" + index).remove();
|
|
|
25 |
$("#index-" + (index - 1)).show();
|
|
|
26 |
console.log(targetSlab);
|
|
|
27 |
|
|
|
28 |
});
|
|
|
29 |
|
|
|
30 |
$("#saveSlab")
|
|
|
31 |
.live(
|
|
|
32 |
'click',
|
|
|
33 |
function() {
|
|
|
34 |
console.log("save slab Button Clicked...");
|
|
|
35 |
console.log(targetSlab);
|
|
|
36 |
var labelName = $("#label").val();
|
|
|
37 |
var rewardPercentage = $("#rewardPercentage").val();
|
|
|
38 |
if (rewardPercentage == "") {
|
|
|
39 |
alert("Input field can't be empty");
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
|
|
|
43 |
slabInputs['maxSlabPercentage'] = -1;
|
|
|
44 |
slabInputs['rewardPercentage'] = rewardPercentage;
|
|
|
45 |
console.log(slabInputs);
|
|
|
46 |
targetSlab.push(slabInputs);
|
|
|
47 |
slabInputs = {};
|
|
|
48 |
console.log(targetSlab);
|
|
|
49 |
if (confirm("Are you sure you want to save slab!") == true) {
|
|
|
50 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
51 |
+ "/createSlab?slabMonth=" + slabmonth,
|
|
|
52 |
JSON.stringify(targetSlab), function(
|
|
|
53 |
response) {
|
|
|
54 |
if (response === 'true') {
|
|
|
55 |
alert("Slab created successfully");
|
|
|
56 |
targetSlab = [];
|
|
|
57 |
createSlab("main-content");
|
|
|
58 |
|
|
|
59 |
} else {
|
|
|
60 |
alert("slab already created");
|
|
|
61 |
targetSlab = [];
|
|
|
62 |
createSlab("main-content");
|
|
|
63 |
|
|
|
64 |
}
|
|
|
65 |
});
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
$("#addSlab")
|
|
|
71 |
.live(
|
|
|
72 |
'click',
|
|
|
73 |
function() {
|
|
|
74 |
console.log("Add slab Button Clicked...");
|
|
|
75 |
var labelName = $("#label").val();
|
|
|
76 |
var slabpercentage = $("#slabpercentage").val();
|
|
|
77 |
var rewardPercentage = $("#rewardPercentage").val();
|
|
|
78 |
|
|
|
79 |
if (slabpercentage == "" || rewardPercentage == "") {
|
|
|
80 |
alert("Input field can't be empty");
|
|
|
81 |
return;
|
|
|
82 |
}
|
|
|
83 |
console.log(targetSlab.length);
|
|
|
84 |
|
|
|
85 |
if (targetSlab.length > 0) {
|
|
|
86 |
console.log("#index-"
|
|
|
87 |
+ parseFloat(targetSlab.length - 1));
|
|
|
88 |
|
|
|
89 |
if (parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) < parseFloat(slabpercentage)) {
|
|
|
90 |
$("#index-" + parseFloat(targetSlab.length - 1))
|
|
|
91 |
.hide();
|
|
|
92 |
slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
|
|
|
93 |
slabInputs['maxSlabPercentage'] = slabpercentage;
|
|
|
94 |
slabInputs['rewardPercentage'] = rewardPercentage;
|
|
|
95 |
console.log(slabInputs);
|
|
|
96 |
targetSlab.push(slabInputs);
|
|
|
97 |
console.log(slabInputs)
|
|
|
98 |
$("#slab-input")
|
|
|
99 |
.html(
|
|
|
100 |
" <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
|
|
|
101 |
+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
|
|
|
102 |
+ "<input type=button class=btn-primary value=+ id=addSlab>"
|
|
|
103 |
|
|
|
104 |
);
|
|
|
105 |
|
|
|
106 |
var htmlString = $("<div class=div-"
|
|
|
107 |
+ parseFloat(targetSlab.length - 1)
|
|
|
108 |
+ ">"
|
|
|
109 |
+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
|
|
|
110 |
+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
|
|
|
111 |
+ slabpercentage
|
|
|
112 |
+ ">  "
|
|
|
113 |
+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
|
|
|
114 |
+ rewardPercentage
|
|
|
115 |
+ "> "
|
|
|
116 |
+ "<input type=button value=x class=\"btn btn-primary deleteslab\" data-index=\""
|
|
|
117 |
+ parseFloat(targetSlab.length - 1)
|
|
|
118 |
+ "\"id=index-"
|
|
|
119 |
+ parseFloat(targetSlab.length - 1)
|
|
|
120 |
+ ">" + "  <div><br>");
|
|
|
121 |
$("#slab-order").append(htmlString);
|
|
|
122 |
|
|
|
123 |
$("#slabdate").prop('disabled', true);
|
|
|
124 |
slabInputs = {};
|
|
|
125 |
} else {
|
|
|
126 |
alert("Slab Percentage is not less than previous Slab Percentage");
|
|
|
127 |
return false;
|
|
|
128 |
}
|
|
|
129 |
} else {
|
|
|
130 |
slabInputs['minSlabPercentage'] = 0;
|
|
|
131 |
slabInputs['maxSlabPercentage'] = slabpercentage;
|
|
|
132 |
slabInputs['rewardPercentage'] = rewardPercentage;
|
|
|
133 |
console.log(slabInputs);
|
|
|
134 |
targetSlab.push(slabInputs);
|
|
|
135 |
console.log(slabInputs)
|
|
|
136 |
$("#slab-input")
|
|
|
137 |
.html(
|
|
|
138 |
" <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
|
|
|
139 |
+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
|
|
|
140 |
+ "<input type=button class=btn-primary value=+ id=addSlab>"
|
|
|
141 |
|
|
|
142 |
);
|
|
|
143 |
|
|
|
144 |
var htmlString = $("<div class=div-"
|
|
|
145 |
+ parseFloat(targetSlab.length - 1)
|
|
|
146 |
+ ">"
|
|
|
147 |
+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
|
|
|
148 |
+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
|
|
|
149 |
+ slabpercentage
|
|
|
150 |
+ ">  "
|
|
|
151 |
+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
|
|
|
152 |
+ rewardPercentage
|
|
|
153 |
+ "> "
|
|
|
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) + ">"
|
|
|
158 |
+ "  <div><br><div>");
|
|
|
159 |
$("#slab-order").append(htmlString);
|
|
|
160 |
$("#slabdate").prop('disabled', true);
|
|
|
161 |
slabInputs = {};
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
});
|
|
|
165 |
|
|
|
166 |
$("#uploadExcel")
|
|
|
167 |
.live(
|
|
|
168 |
'click',
|
|
|
169 |
function() {
|
|
|
170 |
var excelfile = $('#uploadfile')[0].files[0];
|
|
|
171 |
var targetdate = $('#targetDateTime').val();
|
|
|
172 |
console.log("excelfile" + excelfile);
|
|
|
173 |
if (confirm("Are you sure you want to upload excel file!") == true) {
|
|
|
174 |
if (!excelfile) {
|
|
|
175 |
alert("choose excel file for upload");
|
|
|
176 |
return;
|
|
|
177 |
}
|
|
|
178 |
var ext = $('#uploadfile').val().split('.').pop()
|
|
|
179 |
.toLowerCase();
|
|
|
180 |
if ($.inArray(ext, [ 'xlsx' ]) == -1) {
|
|
|
181 |
alert('invalid extension!');
|
|
|
182 |
return;
|
|
|
183 |
}
|
|
|
184 |
if (targetdate === null) {
|
|
|
185 |
alert("Target Month Field is not empty");
|
|
|
186 |
return;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
console.log(targetdate);
|
|
|
190 |
doAjaxUploadRequestHandler(context
|
|
|
191 |
+ "/uploadPartnersTarget?targetDate="
|
|
|
192 |
+ targetdate, 'POST', excelfile, function(
|
|
|
193 |
response) {
|
|
|
194 |
if (response == true) {
|
|
|
195 |
alert("successfully uploaded");
|
|
|
196 |
doGetAjaxRequestHandler(context
|
|
|
197 |
+ "/uploadPartnerTargetPage",
|
|
|
198 |
function(response) {
|
|
|
199 |
$('#' + "main-content").html(
|
|
|
200 |
response);
|
|
|
201 |
});
|
|
|
202 |
}
|
|
|
203 |
});
|
|
|
204 |
}
|
|
|
205 |
});
|
|
|
206 |
|
|
|
207 |
});
|
|
|
208 |
|
|
|
209 |
function labelChange() {
|
|
|
210 |
var labelName = $("#label").val();
|
|
|
211 |
console.log(labelName);
|
|
|
212 |
var month = $("#slabdate").val();
|
|
|
213 |
console.log(month);
|
|
|
214 |
if (month) {
|
|
|
215 |
slabmonth = month;
|
|
|
216 |
console.log(slabmonth);
|
|
|
217 |
if (labelName == "upto") {
|
|
|
218 |
|
|
|
219 |
$("#slab-input")
|
|
|
220 |
.html(
|
|
|
221 |
" <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
|
|
|
222 |
+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
|
|
|
223 |
+ "<input type=button class=btn-primary value=+ id=addSlab>"
|
|
|
224 |
|
|
|
225 |
);
|
|
|
226 |
|
|
|
227 |
} else {
|
|
|
228 |
$("#slab-input")
|
|
|
229 |
.html(
|
|
|
230 |
|
|
|
231 |
"<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
|
|
|
232 |
+ "<button type=button class=\"btn btn-primary\" value=\"save slab\" id=saveSlab>save</button>");
|
|
|
233 |
}
|
|
|
234 |
} else {
|
|
|
235 |
alert("Month field can't be empty");
|
|
|
236 |
return;
|
|
|
237 |
}
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
function uploadTarget(domId) {
|
|
|
241 |
doGetAjaxRequestHandler(context + "/uploadPartnerTargetPage", function(
|
|
|
242 |
response) {
|
|
|
243 |
$('#' + domId).html(response);
|
|
|
244 |
});
|
|
|
245 |
}
|
|
|
246 |
function createSlab(domId) {
|
|
|
247 |
doGetAjaxRequestHandler(context + "/createTargetSlab", function(response) {
|
|
|
248 |
$('#' + domId).html(response);
|
|
|
249 |
});
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
function partnerTarget(domId, slabMonth) {
|
|
|
253 |
console.log(slabMonth);
|
|
|
254 |
doGetAjaxRequestHandler(context + "/getPartnerTarget?slabMonth="
|
|
|
255 |
+ slabMonth, function(response) {
|
|
|
256 |
$('#' + domId).html(response);
|
|
|
257 |
});
|
|
|
258 |
}
|
|
|
259 |
function getSlabTarget() {
|
|
|
260 |
var slabMonth = $("#partnerTargetDatetime").val();
|
|
|
261 |
console.log(slabMonth);
|
|
|
262 |
doGetAjaxRequestHandler(context + "/getPartnerTarget?slabMonth="
|
|
|
263 |
+ slabMonth, function(response) {
|
|
|
264 |
$('#main-content').html(response);
|
|
|
265 |
});
|
|
|
266 |
}
|