| 33660 |
amit.gupta |
1 |
$(document).ready(function () {
|
|
|
2 |
$(document).on('change', 'select.criteria-brands', function () {
|
|
|
3 |
changed = true;
|
|
|
4 |
});
|
|
|
5 |
$(document).on('click', ".scheme_offer", function () {
|
|
|
6 |
loadOffer("main-content");
|
|
|
7 |
});
|
|
|
8 |
$(document).on('click', '#yearmonth-submit', function () {
|
|
|
9 |
let yearMonth = $("#yearmonth").val();
|
|
|
10 |
loadOfferHistory('#main-content', yearMonth);
|
| 27875 |
amit.gupta |
11 |
|
| 33660 |
amit.gupta |
12 |
});
|
| 27875 |
amit.gupta |
13 |
|
| 33660 |
amit.gupta |
14 |
$(document).on('click', 'a.mk_partner_view', function () {
|
|
|
15 |
let $offerTr = $(this).closest('tr');
|
|
|
16 |
let offerId = $offerTr.data('offerid');
|
|
|
17 |
if (typeof (offerId) == "undefined") {
|
|
|
18 |
offerId = $(this).closest('th').data('offerid');
|
|
|
19 |
let idx = $(this).closest('th').data('idx');
|
|
|
20 |
priceCircularTable.order([[parseInt(idx), 'desc']]).draw();
|
|
|
21 |
}
|
|
|
22 |
doGetAjaxRequestHandler(`${context}/getOfferMargins?offerId=${offerId}`, function (data) {
|
|
|
23 |
$('#offerDescription .modal-content').html(data);
|
|
|
24 |
$("#offerDescription").modal('show');
|
|
|
25 |
});
|
|
|
26 |
});
|
| 30485 |
tejbeer |
27 |
|
| 33660 |
amit.gupta |
28 |
$(document).on('click', 'a.mk_offer_detail', function () {
|
|
|
29 |
let $offerTr = $(this).closest('tr');
|
|
|
30 |
let offerId = $offerTr.data('offerid');
|
|
|
31 |
doGetAjaxRequestHandler(`${context}\getOfferMargins?offerId=${offerId}`, function (data) {
|
|
|
32 |
$('#offerDescription .modal-content').html(data);
|
|
|
33 |
$("#offerDescription").modal('show');
|
|
|
34 |
});
|
|
|
35 |
});
|
|
|
36 |
$(document).on('click', 'a.offer_history', function () {
|
|
|
37 |
let dt = new Date();
|
|
|
38 |
loadOfferHistory('#main-content', new Date().toISOString().slice(0, 7));
|
|
|
39 |
});
|
|
|
40 |
$(document).on('click', 'input.create-offer', function () {
|
|
|
41 |
console.log("Click called");
|
|
|
42 |
createOfferNew();
|
|
|
43 |
});
|
| 30485 |
tejbeer |
44 |
|
| 33660 |
amit.gupta |
45 |
$(document).on('click', 'a.process_offer', function () {
|
|
|
46 |
let $offerTr = $(this).closest('tr');
|
|
|
47 |
let offerId = $offerTr.data('offerid');
|
|
|
48 |
$clicked = $(this);
|
|
|
49 |
if (confirm("Are your sure you want to process?")) {
|
|
|
50 |
$clicked.hide();
|
|
|
51 |
doGetAjaxRequestHandler(`${context}/offer/process/${offerId}`, function () {
|
|
|
52 |
alert("Offer Processed successfully");
|
|
|
53 |
$clicked.show();
|
|
|
54 |
});
|
|
|
55 |
}
|
|
|
56 |
});
|
| 30485 |
tejbeer |
57 |
|
| 33660 |
amit.gupta |
58 |
$(document).on('change', 'input[name=schemeType]', function () {
|
|
|
59 |
if ($('input[name=schemeType]').val() == 'ACTIVATION') {
|
|
|
60 |
$("div.activation-brands").show();
|
|
|
61 |
} else {
|
|
|
62 |
$("div.activation-brands").hide();
|
|
|
63 |
}
|
|
|
64 |
});
|
|
|
65 |
$(document).on('change', 'input[name^=amountType]', function () {
|
|
|
66 |
let holder1 = "Qty";
|
|
|
67 |
let holder2 = "pc(s) onwards, ";
|
|
|
68 |
let holder3 = "% of value";
|
|
|
69 |
if ($(this).val() == "FIXED") {
|
|
|
70 |
holder3 = "per pc";
|
|
|
71 |
} else if ($(this).val() == "SLAB_FIXED") {
|
|
|
72 |
holder3 = "";
|
|
|
73 |
}
|
|
|
74 |
let slabHtml = `<div class="input-group slab">
|
| 27875 |
amit.gupta |
75 |
<span class="input-group-addon">${holder1}</span>
|
|
|
76 |
<input type="text" class="slabOnwardsAmount form-control" value="0"/>
|
|
|
77 |
<span class="input-group-addon">${holder2}</span>
|
|
|
78 |
<input type="text" class="form-control payoutValue" value="0"/>
|
|
|
79 |
<span class="input-group-addon">${holder3}</span>
|
|
|
80 |
</div>`;
|
| 35219 |
amit |
81 |
$(this).closest('.itemcriteriapayout').find('div.slab-container').html(slabHtml.repeat(15));
|
| 33660 |
amit.gupta |
82 |
//targetSlabTemplate = $('div.targetslabs').get(0).outerHTML;
|
|
|
83 |
});
|
| 27875 |
amit.gupta |
84 |
});
|
| 33660 |
amit.gupta |
85 |
|
| 27875 |
amit.gupta |
86 |
function changeTargetType() {
|
| 33660 |
amit.gupta |
87 |
let holder1 = "Rs.";
|
|
|
88 |
let holder2 = "onwards,";
|
|
|
89 |
if ($(this).val() == "QUANTITY") {
|
|
|
90 |
holder1 = "Qty";
|
|
|
91 |
holder2 = "pc(s) onwards, ";
|
|
|
92 |
}
|
|
|
93 |
let targetHtml = `<span class="input-group-addon">${holder1}</span>
|
| 27895 |
amit.gupta |
94 |
<input type="text" style="width:100px" class="form-control payoutTarget" value="0">
|
|
|
95 |
<span class="input-group-addon">${holder2}</span>
|
|
|
96 |
<input type="text" class="form-control targetDescription" placeholder="Description">`;
|
| 33660 |
amit.gupta |
97 |
$('div.targetContainer').html(targetHtml);
|
| 27895 |
amit.gupta |
98 |
}
|
| 33660 |
amit.gupta |
99 |
|
| 27895 |
amit.gupta |
100 |
function changePayoutType() {
|
| 33660 |
amit.gupta |
101 |
let holder1 = "Rs.";
|
|
|
102 |
let holder2 = "onwards,";
|
|
|
103 |
let holder3 = "% of value";
|
|
|
104 |
$allSlabContainers = $('div.slab-container');
|
|
|
105 |
$('div.slab-payout input:radio[value="PERCENTAGE"]').prop('checked', true);
|
|
|
106 |
if ($(this).val() == "QUANTITY") {
|
|
|
107 |
holder1 = "Qty";
|
|
|
108 |
holder2 = "pc(s) onwards, ";
|
|
|
109 |
$('div.slab-payout input:radio[value!="PERCENTAGE"]').prop('checked', false).prop('disabled', false);
|
|
|
110 |
} else {
|
|
|
111 |
$('div.slab-payout input:radio[value!="PERCENTAGE"]').prop('checked', false).prop('disabled', true);
|
|
|
112 |
}
|
|
|
113 |
let slabHtml = `<div class="input-group slab">
|
| 27875 |
amit.gupta |
114 |
<span class="input-group-addon">${holder1}</span>
|
|
|
115 |
<input type="text" class="slabOnwardsAmount form-control" value="0"/>
|
|
|
116 |
<span class="input-group-addon">${holder2}</span>
|
|
|
117 |
<input type="text" class="form-control payoutValue" value="0"/>
|
|
|
118 |
<span class="input-group-addon">${holder3}</span>
|
|
|
119 |
</div>`;
|
| 35218 |
amit |
120 |
$allSlabContainers.html(slabHtml.repeat(15));
|
| 27875 |
amit.gupta |
121 |
}
|
| 33660 |
amit.gupta |
122 |
|
|
|
123 |
$(document).on('click', 'a.mk_offer_active', function () {
|
|
|
124 |
$clicked = $(this);
|
|
|
125 |
let offerId = $clicked.closest('tr').data("offerid");
|
|
|
126 |
if (confirm(`Are you sure want to activate ${offerId}?`)) {
|
|
|
127 |
doGetAjaxRequestHandler(`${context}/offer/active/${offerId}`, function (response) {
|
|
|
128 |
alert("Offer is now active");
|
|
|
129 |
$clicked.closest("li").html(`<a class="mk_offer_inactive" href="javascript:void(0)">Mark Inactive</a>`);
|
|
|
130 |
});
|
|
|
131 |
}
|
| 27875 |
amit.gupta |
132 |
});
|
| 33660 |
amit.gupta |
133 |
$(document).on('click', 'a.mk_offer_inactive', function () {
|
|
|
134 |
$clicked = $(this);
|
|
|
135 |
let offerId = $clicked.closest('tr').data("offerid");
|
|
|
136 |
if (confirm(`Are you sure want to activate ${offerId}?`)) {
|
|
|
137 |
doGetAjaxRequestHandler(`${context}/offer/active/${offerId}?active=false`, function (response) {
|
|
|
138 |
alert("Offer is now inactive");
|
|
|
139 |
$clicked.closest("li").html(`<a class="mk_offer_active" href="javascript:void(0)">Mark Active</a>`);
|
|
|
140 |
});
|
|
|
141 |
}
|
| 29907 |
amit.gupta |
142 |
});
|
| 33660 |
amit.gupta |
143 |
$(document).on('click', 'button.slab-add', function () {
|
|
|
144 |
newTargetSlab = $(targetSlabTemplate);
|
|
|
145 |
$('div.targetslabscontainer').append(newTargetSlab);
|
|
|
146 |
newTargetSlab.find("select.criteria-brands").toggle().next().remove();
|
|
|
147 |
newTargetSlab.find("select.criteria-brands").chosen({no_results_text: "Oops, nothing found!"});
|
| 27875 |
amit.gupta |
148 |
});
|
| 33660 |
amit.gupta |
149 |
$(document).on('click', 'button.slab-remove', function () {
|
|
|
150 |
targetSlabContainer = $('div.targetslabscontainer');
|
|
|
151 |
if (targetSlabContainer.find(".targetslabs").length > 1) {
|
|
|
152 |
targetSlabContainer.find(".targetslabs:last").remove();
|
|
|
153 |
} else {
|
|
|
154 |
alert("Cant remove single Slab");
|
|
|
155 |
}
|
| 27875 |
amit.gupta |
156 |
});
|
| 33660 |
amit.gupta |
157 |
$(document).on('click', 'button.slab-copy', function () {
|
|
|
158 |
newTargetSlab = $('div.targetslabs').eq(0).clone().appendTo('div.targetslabscontainer');
|
|
|
159 |
catalogIdSelectContainers = $('div.targetslabs').eq(0).find('select.criteria-catalogids');
|
|
|
160 |
newCatalogIdSelectContainers = newTargetSlab.find('select.criteria-catalogids');
|
| 35219 |
amit |
161 |
for (let i = 0; i < 15; i++) {
|
| 33660 |
amit.gupta |
162 |
let selectContainer = catalogIdSelectContainers.get(i);
|
|
|
163 |
let newSelectContainer = newCatalogIdSelectContainers.get(i);
|
|
|
164 |
for (let j = 0; j < selectContainer.options.length; j++) {
|
|
|
165 |
newSelectContainer.options[j].selected = selectContainer.options[j].selected;
|
|
|
166 |
}
|
|
|
167 |
newSelectContainer.closest('span').replaceWith(newSelectContainer);
|
|
|
168 |
$(newSelectContainer).multiselect({
|
|
|
169 |
includeSelectAllOption: true,
|
|
|
170 |
maxHeight: 400,
|
|
|
171 |
buttonWidth: '240px',
|
|
|
172 |
numberDisplayed: 1,
|
|
|
173 |
nonSelectedText: 'Items',
|
|
|
174 |
nSelectedText: ' - Items Selected',
|
|
|
175 |
allSelectedText: 'All Items Selected',
|
|
|
176 |
enableFiltering: true,
|
|
|
177 |
enableCaseInsensitiveFiltering: true,
|
|
|
178 |
});
|
|
|
179 |
}
|
|
|
180 |
selectContainers = newTargetSlab.find("select.criteria-brands");
|
|
|
181 |
selectContainers.each((y, x) => {
|
|
|
182 |
$next = $(x).toggle().next();
|
|
|
183 |
$next.find("a.search-choice-close").each(function (index, ele) {
|
|
|
184 |
x.options[$(ele).data('option-array-index') + 0].selected = true;
|
|
|
185 |
});
|
|
|
186 |
$next.remove();
|
|
|
187 |
});
|
|
|
188 |
newTargetSlab.find("select.criteria-brands").chosen({no_results_text: "Oops, nothing found!"});
|
|
|
189 |
//createSlabFrom(currentHtml);
|
| 27875 |
amit.gupta |
190 |
});
|
|
|
191 |
|
| 34210 |
tejus.loha |
192 |
$(document).on('click', '.scheme_block_imeis_panel', function () {
|
|
|
193 |
reloadBlockImeiPanel();
|
|
|
194 |
$('div.modal-backdrop.fade').remove();
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
});
|
|
|
198 |
|
|
|
199 |
$(document).on('click', '.eligible_offer_imeis_panel', function () {
|
| 34216 |
tejus.loha |
200 |
doGetAjaxRequestHandler(`${context}/offerEligibleImeis/panel`, function (response) {
|
| 34210 |
tejus.loha |
201 |
$('#main-content').html(response);
|
|
|
202 |
});
|
|
|
203 |
$('div.modal-backdrop.fade').remove();
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
});
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
$(document).on('click', '#submit_scheme_block_imeis', function () {
|
|
|
210 |
let blockImei = $('#block_imei_scheme').val();
|
|
|
211 |
console.log("blockImei - ", blockImei);
|
|
|
212 |
if (!blockImei) {
|
|
|
213 |
alert("Please enter Imei");
|
|
|
214 |
return;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
let url = `${context}/createBlockImei?imeiNumbers=${blockImei}`;
|
|
|
218 |
if (confirm('Are you sure to block all enter Imei numbers')) {
|
|
|
219 |
doPostAjaxRequestHandler(url, function (response) {
|
|
|
220 |
if (response) {
|
|
|
221 |
alert("Imei blocked successfully");
|
|
|
222 |
reloadBlockImeiList();
|
|
|
223 |
}
|
|
|
224 |
});
|
|
|
225 |
} else {
|
|
|
226 |
return;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
});
|
|
|
230 |
$(document).on('click', '#submit_offer_eligible_imeis', function () {
|
| 34216 |
tejus.loha |
231 |
let eligibleImeis = $('#offer_eligible_imeis').val();
|
| 34210 |
tejus.loha |
232 |
let offerId = $('#offerId').val();
|
| 34216 |
tejus.loha |
233 |
console.log("Eligible Imeeis - ", eligibleImeis);
|
| 34210 |
tejus.loha |
234 |
console.log("offer id - ", offerId);
|
|
|
235 |
if (!offerId) {
|
|
|
236 |
alert("Please enter Offer Id");
|
|
|
237 |
return;
|
|
|
238 |
}
|
| 34216 |
tejus.loha |
239 |
if (!eligibleImeis) {
|
|
|
240 |
alert("Please enter Imei");
|
|
|
241 |
return;
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
let url = `${context}/offerEligibleImeis/create?imeis=${eligibleImeis}&offerId=${offerId}`;
|
|
|
245 |
if (confirm('Are you sure to submit')) {
|
| 34210 |
tejus.loha |
246 |
doPostAjaxRequestHandler(url, function (response) {
|
|
|
247 |
if (response) {
|
|
|
248 |
reloadOfferEligibleImeisList();
|
|
|
249 |
alert("submited successfully");
|
|
|
250 |
}
|
|
|
251 |
});
|
|
|
252 |
} else {
|
|
|
253 |
return;
|
|
|
254 |
}
|
|
|
255 |
});
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
$(document).on('click', '.scheme_imei_block_unblock_button', function () {
|
|
|
259 |
let blockedImeiId = $(this).val();
|
|
|
260 |
if (confirm("Are you sure to change status")) {
|
|
|
261 |
doPutAjaxRequestHandler(`${context}/blockUnblockImei?id=${blockedImeiId}`, function (response) {
|
|
|
262 |
reloadBlockImeiList();
|
|
|
263 |
});
|
|
|
264 |
} else {
|
|
|
265 |
return;
|
|
|
266 |
}
|
|
|
267 |
});
|
|
|
268 |
|
|
|
269 |
$(document).on('click', '.offer_eligible_imeis_EligibilityChange_button', function () {
|
|
|
270 |
let blockedImeiId = $(this).val();
|
|
|
271 |
if (confirm("Are you sure to change status")) {
|
| 34216 |
tejus.loha |
272 |
doPutAjaxRequestHandler(`${context}/offerEligibleImeis/changeStatus?id=${blockedImeiId}`, function (response) {
|
| 34210 |
tejus.loha |
273 |
reloadOfferEligibleImeisList();
|
|
|
274 |
alert("Status changed successfully");
|
|
|
275 |
});
|
|
|
276 |
} else {
|
|
|
277 |
return;
|
|
|
278 |
}
|
|
|
279 |
});
|
|
|
280 |
|
|
|
281 |
$(document).on('click', '.scheme_blocked_imei_remove_button', function () {
|
|
|
282 |
let blockedImeiId = $(this).val();
|
|
|
283 |
if (confirm("Are you sure to remove")) {
|
|
|
284 |
doDeleteAjaxRequestHandler(`${context}/removeBlockedImei?id=${blockedImeiId}`, function (response) {
|
|
|
285 |
if (response) {
|
|
|
286 |
reloadBlockImeiList();
|
|
|
287 |
}
|
|
|
288 |
});
|
|
|
289 |
} else {
|
|
|
290 |
return;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
});
|
|
|
295 |
$(document).on('click', '.offer_eligible_imei_remove_button', function () {
|
|
|
296 |
let offerId = $(this).val();
|
|
|
297 |
if (confirm("Are you sure to remove")) {
|
| 34216 |
tejus.loha |
298 |
doDeleteAjaxRequestHandler(`${context}/offerEligibleImeis/deleteByOfferId?offerId=${offerId}`, function (response) {
|
| 34210 |
tejus.loha |
299 |
if (response) {
|
|
|
300 |
reloadOfferEligibleImeisList();
|
|
|
301 |
alert("Removed successfully");
|
|
|
302 |
}
|
|
|
303 |
});
|
|
|
304 |
} else {
|
|
|
305 |
return;
|
|
|
306 |
}
|
|
|
307 |
});
|
|
|
308 |
|
|
|
309 |
function reloadBlockImeiPanel() {
|
|
|
310 |
doGetAjaxRequestHandler(`${context}/blockImeiPanel`, function (response) {
|
|
|
311 |
$('#main-content').html(response);
|
|
|
312 |
});
|
|
|
313 |
// $('div.modal-backdrop.fade').remove();
|
|
|
314 |
}
|
|
|
315 |
function reloadBlockImeiOfferPanel() {
|
|
|
316 |
doGetAjaxRequestHandler(`${context}/blockImeiOfferPanel`, function (response) {
|
|
|
317 |
$('#main-content').html(response);
|
|
|
318 |
});
|
|
|
319 |
$('div.modal-backdrop.fade').remove();
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
function reloadBlockImeiList() {
|
|
|
323 |
doGetAjaxRequestHandler(`${context}/blockImeiList`, function (response) {
|
|
|
324 |
$('#scheme_blocked_imeis_div').empty();
|
|
|
325 |
$('#scheme_blocked_imeis_div').html(response);
|
|
|
326 |
});
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
function reloadOfferEligibleImeisList() {
|
| 34216 |
tejus.loha |
330 |
doGetAjaxRequestHandler(`${context}/offerEligibleImeis/allList`, function (response) {
|
| 34210 |
tejus.loha |
331 |
$('#offer_eligible_imeis_div').empty();
|
|
|
332 |
$('#offer_eligible_imeis_div').html(response);
|
|
|
333 |
|
|
|
334 |
});
|
|
|
335 |
}
|
|
|
336 |
|
| 33660 |
amit.gupta |
337 |
$(document).on('click', 'select.criteria-catalogids+div > button', function () {
|
|
|
338 |
if (changed) {
|
|
|
339 |
let brands = $(this).closest('.item-criteria').find('select').val();
|
|
|
340 |
let led = $(this).closest('.item-criteria').find('input[name=led]').is(":checked");
|
|
|
341 |
let tablet = $(this).closest('.item-criteria').find('input[name=tablet]').is(":checked");
|
|
|
342 |
let smartWatch = $(this).closest('.item-criteria').find('input[name=smartwatch]').is(":checked");
|
|
|
343 |
$brandsContainer = $(this);
|
|
|
344 |
let categoryId = 3;
|
|
|
345 |
if (led) {
|
|
|
346 |
categoryId = 14202;
|
|
|
347 |
}
|
|
|
348 |
if (tablet) {
|
|
|
349 |
categoryId = 10010;
|
|
|
350 |
}
|
|
|
351 |
if (smartWatch) {
|
|
|
352 |
categoryId = 6;
|
|
|
353 |
}
|
|
|
354 |
var url = `${context}/entity?brands=${brands.join(",")}&categoryId=${categoryId}&limit=0`;
|
|
|
355 |
$select = $brandsContainer.closest('.item-criteria').find('.criteria-catalogids');
|
|
|
356 |
$select.html('');
|
|
|
357 |
if (brands.length > 0) {
|
|
|
358 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
359 |
data = JSON.parse(response);
|
|
|
360 |
for (i = 0; i < data.length; i++) {
|
|
|
361 |
$select.append(`<option value="${data[i].catalogId_i}">${data[i].title_s}</option>`);
|
|
|
362 |
}
|
|
|
363 |
$select.multiselect('rebuild');
|
|
|
364 |
});
|
|
|
365 |
} else {
|
|
|
366 |
$select.html('');
|
|
|
367 |
$select.multiselect('rebuild');
|
|
|
368 |
}
|
|
|
369 |
changed = !changed;
|
|
|
370 |
}
|
| 27875 |
amit.gupta |
371 |
});
|
|
|
372 |
|
| 30485 |
tejbeer |
373 |
var ckEditor;
|
|
|
374 |
|
| 27875 |
amit.gupta |
375 |
function createOfferNew() {
|
| 33660 |
amit.gupta |
376 |
let validated = true;
|
|
|
377 |
let rangePicker = getDatesFromPicker('input[name="dateRange"]');
|
|
|
378 |
let createOfferRequest = {};
|
|
|
379 |
createOfferRequest['name'] = $("#offer_name").val();
|
|
|
380 |
createOfferRequest['startDate'] = rangePicker.startDate;
|
|
|
381 |
createOfferRequest['endDate'] = rangePicker.endDate;
|
|
|
382 |
createOfferRequest['offerNotes'] = $("#offer_notes").val();
|
|
|
383 |
createOfferRequest['baseCriteria'] = $("input[name=base_criteria]").is(":checked");
|
|
|
384 |
createOfferRequest['terms'] = ckEditor.getData() //$("#offer_terms").val();
|
|
|
385 |
createOfferRequest['targetType'] = $("input[name=targetType]:checked").val();
|
|
|
386 |
createOfferRequest['payoutType'] = $("input[name=payoutType]:checked").val();
|
|
|
387 |
createOfferRequest['schemeType'] = $("select[name=schemeType]").val();
|
|
|
388 |
createOfferRequest['booster'] = false;
|
|
|
389 |
createOfferRequest['activationBrands'] = null;
|
| 32065 |
amit.gupta |
390 |
createOfferRequest['discount'] = $("input[name=discount]").is(':checked');
|
| 33660 |
amit.gupta |
391 |
if (createOfferRequest['schemeType'] == 'ACTIVATION') {
|
|
|
392 |
createOfferRequest['activationBrands'] = $("div.activation-brands select").val().join(",") || null;
|
|
|
393 |
} else if (createOfferRequest['schemeType'] == 'SELLINBOOSTER') {
|
|
|
394 |
createOfferRequest['schemeType'] = 'SELLIN';
|
|
|
395 |
createOfferRequest['booster'] = true;
|
|
|
396 |
}
|
|
|
397 |
createOfferRequest['sellinPercentage'] = $("#sellinPercentage").val();
|
|
|
398 |
createOfferRequest['brandShareTerms'] = $('#brandShare').val();
|
|
|
399 |
createOfferRequest['partnerCriteria'] = {};
|
|
|
400 |
createOfferRequest['partnerCriteria']['fofoIds'] = ($("#partners").val() || []).map(Number);
|
|
|
401 |
createOfferRequest['partnerCriteria']['excludeFofoIds'] = [];
|
|
|
402 |
let excludeFofoIdChecked = $('input.excludeFofoId').is(':checked');
|
|
|
403 |
if (excludeFofoIdChecked) {
|
|
|
404 |
createOfferRequest['partnerCriteria']['excludeFofoIds'] = createOfferRequest['partnerCriteria']['fofoIds'];
|
|
|
405 |
createOfferRequest['partnerCriteria']['fofoIds'] = [];
|
|
|
406 |
}
|
|
|
407 |
createOfferRequest['partnerCriteria']['partnerTypes'] = ($("select.criteria-partner-type").val() || []);
|
|
|
408 |
createOfferRequest['partnerCriteria']['regionIds'] = ($("select.criteria-warehouseregion").val() || []).map(Number);
|
| 27875 |
amit.gupta |
409 |
|
| 33660 |
amit.gupta |
410 |
createOfferRequest['itemCriteria'] = itemCriteria($('div.itemCriteria'));
|
|
|
411 |
let targetSlabs = [];
|
|
|
412 |
$('div.targetslabs').each(function (index, ele) {
|
|
|
413 |
let $targetSlab = $(ele);
|
|
|
414 |
let targetOnwardsValue = $targetSlab.find('.payoutTarget').val();
|
|
|
415 |
let targetDescription = $targetSlab.find('.targetDescription').val();
|
|
|
416 |
let itemCriteriaPayouts = [];
|
|
|
417 |
if (isNaN(targetOnwardsValue) || targetOnwardsValue < 0) {
|
|
|
418 |
validated = false;
|
|
|
419 |
alert(`Invalid Number - ${targetOnwardsValue}`);
|
|
|
420 |
} else {
|
|
|
421 |
if (index == 0 || targetOnwardsValue > 0) {
|
|
|
422 |
let $itemCriteriaPayoutContainers = $targetSlab.find('.itemcriteriapayout');
|
|
|
423 |
$itemCriteriaPayoutContainers.each(function (index, itemCriteriaPayoutContainer) {
|
|
|
424 |
let $itemCriteriaPayoutContainer = $(itemCriteriaPayoutContainer);
|
|
|
425 |
let amountType = $itemCriteriaPayoutContainer.find('input[name^=amountType]:checked').val();
|
|
|
426 |
let startDate = $itemCriteriaPayoutContainer.find('input.startDate').val();
|
|
|
427 |
let endDate = $itemCriteriaPayoutContainer.find('input.endDate').val();
|
|
|
428 |
if ((startDate == "" && endDate != "") && (startDate != "" && endDate == "")) {
|
|
|
429 |
alert("Criteria specific date is required");
|
|
|
430 |
return false;
|
|
|
431 |
}
|
|
|
432 |
let payoutSlabs = [];
|
|
|
433 |
let itemCriteria1 = itemCriteria($itemCriteriaPayoutContainer);
|
|
|
434 |
let $payoutSlabContainers = $itemCriteriaPayoutContainer.find('.slab');
|
|
|
435 |
let itemCriteriaChanged = itemCriteria1['smartPhone'] || itemCriteria1['featuredPhone']
|
|
|
436 |
|| itemCriteria1['catalogIds'].length > 0 || itemCriteria1['brands'].length > 0
|
|
|
437 |
|| itemCriteria1['excludeCatalogIds'].length > 0
|
|
|
438 |
|| itemCriteria1['startPrice'] > 0 || itemCriteria1['endPrice'] > itemCriteria1['startPrice'] > 0;
|
|
|
439 |
if (itemCriteriaChanged || index == 0) {
|
|
|
440 |
$payoutSlabContainers.each(function (slabContainerIndex, slabContainer) {
|
|
|
441 |
let $slab = $(slabContainer);
|
| 30485 |
tejbeer |
442 |
|
| 33660 |
amit.gupta |
443 |
let slabOnwardsAmount = $slab.find('.slabOnwardsAmount').val();
|
|
|
444 |
if (isNaN(slabOnwardsAmount) || slabOnwardsAmount < 0) {
|
|
|
445 |
validated = false;
|
|
|
446 |
alert(`Invalid Payout Slab Amount - ${slabOnwardsAmount}`);
|
|
|
447 |
} else {
|
|
|
448 |
if (slabContainerIndex == 0 || slabOnwardsAmount > 0) {
|
|
|
449 |
let payoutAmount = $slab.find('.payoutValue').val();
|
|
|
450 |
if (isNaN(payoutAmount) || payoutAmount <= 0) {
|
|
|
451 |
validated = false;
|
|
|
452 |
alert(`Invalid Payout Slab Amount - ${slabOnwardsAmount}`);
|
|
|
453 |
}
|
|
|
454 |
let payoutSlab = {
|
|
|
455 |
onwardsAmount: Number(slabOnwardsAmount),
|
|
|
456 |
payoutAmount: Number(payoutAmount)
|
|
|
457 |
}
|
|
|
458 |
payoutSlabs.push(payoutSlab);
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
});
|
|
|
462 |
let itemCriteriaPayout = {
|
|
|
463 |
itemCriteria: itemCriteria1,
|
|
|
464 |
payoutSlabs: payoutSlabs,
|
|
|
465 |
amountType: amountType,
|
|
|
466 |
startDate: jsonStartDate(startDate),
|
|
|
467 |
endDate: jsonEndDate(endDate)
|
|
|
468 |
};
|
|
|
469 |
itemCriteriaPayouts.push(itemCriteriaPayout);
|
|
|
470 |
}
|
|
|
471 |
});
|
|
|
472 |
targetSlabs.push({
|
|
|
473 |
onwardsAmount: targetOnwardsValue,
|
|
|
474 |
targetDescription: targetDescription,
|
|
|
475 |
itemCriteriaPayouts: itemCriteriaPayouts
|
|
|
476 |
});
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
});
|
|
|
480 |
createOfferRequest['targetSlabs'] = targetSlabs;
|
|
|
481 |
if (validated && confirm("Confirm creating scheme offer")) {
|
|
|
482 |
console.log("Validated");
|
|
|
483 |
console.log(createOfferRequest);
|
|
|
484 |
doPostAjaxRequestWithJsonHandler(`${context}/createOffer`, JSON.stringify(createOfferRequest), function (response) {
|
|
|
485 |
alert("Offer created successfully");
|
|
|
486 |
let dt = new Date();
|
|
|
487 |
loadOfferHistory('#main-content', new Date().toISOString().slice(0, 7));
|
|
|
488 |
});
|
|
|
489 |
} else {
|
|
|
490 |
console.log("Invalid Offer");
|
|
|
491 |
}
|
| 27875 |
amit.gupta |
492 |
}
|
|
|
493 |
|
|
|
494 |
function itemCriteria($container) {
|
| 33660 |
amit.gupta |
495 |
let smartPhone = $container.find("input[name=smartphone]").is(":checked");
|
|
|
496 |
let featuredPhone = $container.find("input[name=featuredphone]").is(":checked");
|
|
|
497 |
let led = $container.find("input[name=led]").is(":checked");
|
|
|
498 |
let smartWatch = $container.find("input[name=smartwatch]").is(":checked");
|
|
|
499 |
let catalogIds = $container.find('.criteria-catalogids').val() || [];
|
|
|
500 |
let excludeCatalogIds = [];
|
|
|
501 |
let excludeChecked = $container.find('input.exclude').is(':checked');
|
|
|
502 |
if (excludeChecked) {
|
|
|
503 |
excludeCatalogIds = catalogIds;
|
|
|
504 |
catalogIds = [];
|
|
|
505 |
}
|
|
|
506 |
let brands = $container.find('.criteria-brands').val() || [];
|
|
|
507 |
return {
|
|
|
508 |
startPrice: Number($container.find('.startValue').val()),
|
|
|
509 |
endPrice: Number($container.find('.endValue').val()),
|
|
|
510 |
catalogIds: catalogIds.map(Number),
|
|
|
511 |
excludeCatalogIds: excludeCatalogIds.map(Number),
|
|
|
512 |
brands: brands,
|
|
|
513 |
smartPhone: smartPhone,
|
|
|
514 |
featuredPhone: featuredPhone,
|
|
|
515 |
smartWatch: smartWatch,
|
|
|
516 |
led: led
|
|
|
517 |
};
|
| 27875 |
amit.gupta |
518 |
}
|
|
|
519 |
|
|
|
520 |
function loadOffer(domId) {
|
| 33660 |
amit.gupta |
521 |
console.log(domId);
|
|
|
522 |
doGetAjaxRequestHandler(context + "/getCreateOffer", function (response) {
|
|
|
523 |
$('#' + domId).html(response);
|
| 30485 |
tejbeer |
524 |
|
| 33660 |
amit.gupta |
525 |
DecoupledEditor
|
|
|
526 |
.create(document.querySelector('#offer_terms'))
|
| 30485 |
tejbeer |
527 |
|
|
|
528 |
|
| 33660 |
amit.gupta |
529 |
.then(newEditor => {
|
|
|
530 |
const toolbarContainer = document.querySelector('#toolbar-container');
|
| 30485 |
tejbeer |
531 |
|
| 33660 |
amit.gupta |
532 |
toolbarContainer.appendChild(newEditor.ui.view.toolbar.element);
|
| 30485 |
tejbeer |
533 |
|
| 33660 |
amit.gupta |
534 |
ckEditor = newEditor
|
|
|
535 |
})
|
|
|
536 |
.catch(error => {
|
|
|
537 |
console.error(error);
|
|
|
538 |
});
|
| 30485 |
tejbeer |
539 |
|
| 33660 |
amit.gupta |
540 |
});
|
|
|
541 |
}
|
| 30485 |
tejbeer |
542 |
|
| 27875 |
amit.gupta |
543 |
function loadOfferHistory(domId, yearMonth) {
|
| 33660 |
amit.gupta |
544 |
doGetAjaxRequestHandler(`${context}/offerHistory?yearMonth=${yearMonth}`, function (response) {
|
|
|
545 |
$(domId).html(response);
|
|
|
546 |
$(domId).find("#yearmonth").val(yearMonth);
|
|
|
547 |
});
|
| 27875 |
amit.gupta |
548 |
}
|
|
|
549 |
|