| 27875 |
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);
|
|
|
11 |
|
|
|
12 |
});
|
|
|
13 |
|
|
|
14 |
$(document).on('click', 'a.mk_offer_detail', function() {
|
|
|
15 |
let $offerTr = $(this).closest('tr');
|
|
|
16 |
let offerId = $offerTr.data('offerid');
|
|
|
17 |
doGetAjaxRequestHandler(`${context}\offer-details?offerId=${offerId}`, function(data) {
|
|
|
18 |
$('#offerDescription .modal-content').html(data);
|
|
|
19 |
$("#offerDescription").modal('show');
|
|
|
20 |
});
|
|
|
21 |
});
|
|
|
22 |
$(document).on('click', 'a.offer_history', function () {
|
|
|
23 |
let dt = new Date();
|
|
|
24 |
loadOfferHistory('#main-content', new Date().toISOString().slice(0,7));
|
|
|
25 |
});
|
|
|
26 |
$(document).on('click', 'input.create-offer', function () {
|
|
|
27 |
console.log("Click called");
|
|
|
28 |
createOfferNew();
|
|
|
29 |
});
|
|
|
30 |
|
|
|
31 |
$(document).on('click', 'a.download_offer', function () {
|
|
|
32 |
let $offerTr = $(this).closest('tr');
|
|
|
33 |
let offerId = $offerTr.data('offerid');
|
|
|
34 |
let fileName = `offer-${$offerTr.find('td:first')}.csv`;
|
|
|
35 |
doAjaxGetDownload(`${context}\offerDownload?offerId=${offerId}`, fileName);
|
|
|
36 |
});
|
|
|
37 |
|
|
|
38 |
$(document).on('change', 'input[name=schemeType]', function () {
|
|
|
39 |
if($('input[name=schemeType]:checked').val()=='ACTIVATION') {
|
|
|
40 |
$("div.activation-brands").show();
|
|
|
41 |
} else {
|
|
|
42 |
$("div.activation-brands").hide();
|
|
|
43 |
}
|
|
|
44 |
});
|
| 27879 |
amit.gupta |
45 |
$(document).on('change', 'input[name^=amountType]', function () {
|
| 27875 |
amit.gupta |
46 |
let holder1 = "Qty";
|
|
|
47 |
let holder2 = "pc(s) onwards, ";
|
|
|
48 |
let holder3 = "% of value";
|
|
|
49 |
if($(this).val()=="FIXED") {
|
|
|
50 |
holder3 = "per pc";
|
|
|
51 |
}
|
|
|
52 |
let slabHtml = `<div class="input-group slab">
|
|
|
53 |
<span class="input-group-addon">${holder1}</span>
|
|
|
54 |
<input type="text" class="slabOnwardsAmount form-control" value="0"/>
|
|
|
55 |
<span class="input-group-addon">${holder2}</span>
|
|
|
56 |
<input type="text" class="form-control payoutValue" value="0"/>
|
|
|
57 |
<span class="input-group-addon">${holder3}</span>
|
|
|
58 |
</div>`;
|
|
|
59 |
$(this).closest('.itemcriteriapayout').find('div.slab-container').html(slabHtml.repeat(4));
|
|
|
60 |
//targetSlabTemplate = $('div.targetslabs').get(0).outerHTML;
|
|
|
61 |
});
|
|
|
62 |
});
|
|
|
63 |
function changeTargetType() {
|
|
|
64 |
let holder1 = "Rs.";
|
|
|
65 |
let holder2 = "onwards,";
|
| 27895 |
amit.gupta |
66 |
if ($(this).val() == "QUANTITY") {
|
|
|
67 |
holder1 = "Qty";
|
|
|
68 |
holder2 = "pc(s) onwards, ";
|
|
|
69 |
}
|
|
|
70 |
let targetHtml = `<span class="input-group-addon">${holder1}</span>
|
|
|
71 |
<input type="text" style="width:100px" class="form-control payoutTarget" value="0">
|
|
|
72 |
<span class="input-group-addon">${holder2}</span>
|
|
|
73 |
<input type="text" class="form-control targetDescription" placeholder="Description">`;
|
|
|
74 |
$('div.targetContainer').html(targetHtml);
|
|
|
75 |
}
|
|
|
76 |
function changePayoutType() {
|
|
|
77 |
let holder1 = "Rs.";
|
|
|
78 |
let holder2 = "onwards,";
|
| 27875 |
amit.gupta |
79 |
let holder3 = "% of value";
|
|
|
80 |
$allSlabContainers = $('div.slab-container');
|
|
|
81 |
$('div.slab-payout input:radio[value="PERCENTAGE"]').prop('checked',true);
|
|
|
82 |
if ($(this).val() == "QUANTITY") {
|
|
|
83 |
holder1 = "Qty";
|
|
|
84 |
holder2 = "pc(s) onwards, ";
|
|
|
85 |
$('div.slab-payout input:radio[value="FIXED"]').prop('checked',false).prop('disabled',false);
|
|
|
86 |
} else {
|
|
|
87 |
$('div.slab-payout input:radio[value="FIXED"]').prop('checked',false).prop('disabled',true);
|
|
|
88 |
}
|
|
|
89 |
let slabHtml = `<div class="input-group slab">
|
|
|
90 |
<span class="input-group-addon">${holder1}</span>
|
|
|
91 |
<input type="text" class="slabOnwardsAmount form-control" value="0"/>
|
|
|
92 |
<span class="input-group-addon">${holder2}</span>
|
|
|
93 |
<input type="text" class="form-control payoutValue" value="0"/>
|
|
|
94 |
<span class="input-group-addon">${holder3}</span>
|
|
|
95 |
</div>`;
|
|
|
96 |
$allSlabContainers.html(slabHtml.repeat(4));
|
|
|
97 |
}
|
|
|
98 |
$(document).on('click', 'a.mk_offer_active', function(){
|
|
|
99 |
let spanContainer = $(this).closest('span.mk_active');
|
|
|
100 |
let offerId = spanContainer.data("id");
|
|
|
101 |
doGetAjaxRequestHandler(`${context}/offer/active/${offerId}`, function (response) {
|
|
|
102 |
alert("Offer is now active");
|
|
|
103 |
spanContainer.html("Now Active");
|
|
|
104 |
});
|
|
|
105 |
});
|
|
|
106 |
$(document).on('click', 'button.slab-add', function(){
|
|
|
107 |
newTargetSlab = $(targetSlabTemplate);
|
|
|
108 |
$('div.targetslabscontainer').append(newTargetSlab);
|
|
|
109 |
newTargetSlab.find("select.criteria-brands").toggle().next().remove();
|
|
|
110 |
newTargetSlab.find("select.criteria-brands").chosen({no_results_text: "Oops, nothing found!"});
|
|
|
111 |
});
|
|
|
112 |
$(document).on('click', 'button.slab-remove', function(){
|
|
|
113 |
targetSlabContainer = $('div.targetslabscontainer');
|
|
|
114 |
if(targetSlabContainer.find(".targetslabs").length > 1) {
|
|
|
115 |
targetSlabContainer.find(".targetslabs:last").remove();
|
|
|
116 |
} else {
|
|
|
117 |
alert("Cant remove single Slab");
|
|
|
118 |
}
|
|
|
119 |
});
|
|
|
120 |
$(document).on('click', 'button.slab-copy', function(){
|
|
|
121 |
newTargetSlab = $('div.targetslabs').eq(0).clone().appendTo('div.targetslabscontainer');
|
| 27975 |
amit.gupta |
122 |
catalogIdSelectContainers = $('div.targetslabs').eq(0).find('select.criteria-catalogids');
|
|
|
123 |
newCatalogIdSelectContainers = newTargetSlab.find('select.criteria-catalogids');
|
|
|
124 |
for(let i=0;i<4;i++) {
|
|
|
125 |
let selectContainer = catalogIdSelectContainers.get(i);
|
|
|
126 |
let newSelectContainer = newCatalogIdSelectContainers.get(i);
|
|
|
127 |
for(let j=0;j<selectContainer.options.length;j++) {
|
|
|
128 |
newSelectContainer.options[j].selected = selectContainer.options[j].selected;
|
|
|
129 |
}
|
|
|
130 |
newSelectContainer.closest('span').replaceWith(newSelectContainer);
|
|
|
131 |
$(newSelectContainer).multiselect({
|
|
|
132 |
includeSelectAllOption : true,
|
|
|
133 |
maxHeight : 400,
|
|
|
134 |
buttonWidth : '240px',
|
|
|
135 |
numberDisplayed : 1,
|
|
|
136 |
nonSelectedText : 'Items',
|
|
|
137 |
nSelectedText : ' - Items Selected',
|
|
|
138 |
allSelectedText : 'All Items Selected',
|
|
|
139 |
enableFiltering : true,
|
|
|
140 |
enableCaseInsensitiveFiltering : true,
|
|
|
141 |
});
|
|
|
142 |
}
|
| 27875 |
amit.gupta |
143 |
selectContainers = newTargetSlab.find("select.criteria-brands");
|
|
|
144 |
selectContainers.each((y,x)=>{
|
|
|
145 |
$next = $(x).toggle().next();
|
|
|
146 |
$next.find("a.search-choice-close").each(function(index,ele){
|
|
|
147 |
x.options[$(ele).data('option-array-index') + 0].selected=true;
|
|
|
148 |
});
|
|
|
149 |
$next.remove();
|
|
|
150 |
});
|
|
|
151 |
newTargetSlab.find("select.criteria-brands").chosen({no_results_text: "Oops, nothing found!"});
|
|
|
152 |
//createSlabFrom(currentHtml);
|
|
|
153 |
});
|
|
|
154 |
|
| 27916 |
amit.gupta |
155 |
$(document).on('click', 'select.criteria-catalogids+div > button', function(){
|
| 27875 |
amit.gupta |
156 |
if(changed) {
|
| 27916 |
amit.gupta |
157 |
let brands = $(this).closest('.item-criteria').find('select').val();
|
|
|
158 |
$brandsContainer = $(this);
|
| 27875 |
amit.gupta |
159 |
var url = `${context}/entity?brands=${brands.join(",")}&categoryId=3&limit=0`;
|
|
|
160 |
$select = $brandsContainer.closest('.item-criteria').find('.criteria-catalogids');
|
|
|
161 |
$select.html('');
|
|
|
162 |
if(brands.length > 0) {
|
|
|
163 |
doGetAjaxRequestHandler(url, function(response) {
|
|
|
164 |
data = JSON.parse(response);
|
|
|
165 |
for(i = 0; i < data.length; i++) {
|
|
|
166 |
$select.append(`<option value="${data[i].catalogId_i}">${data[i].title_s}</option>`);
|
|
|
167 |
}
|
|
|
168 |
$select.multiselect('rebuild');
|
|
|
169 |
});
|
|
|
170 |
} else {
|
|
|
171 |
$select.html('');
|
|
|
172 |
$select.multiselect('rebuild');
|
|
|
173 |
}
|
|
|
174 |
changed = !changed;
|
|
|
175 |
}
|
|
|
176 |
});
|
|
|
177 |
|
|
|
178 |
function createOfferNew() {
|
|
|
179 |
let validated = true;
|
|
|
180 |
let createOfferRequest = {};
|
|
|
181 |
createOfferRequest['name'] = $("#offer_name").val();
|
|
|
182 |
createOfferRequest['startDate'] = startDate;
|
|
|
183 |
createOfferRequest['endDate'] = endDate;
|
|
|
184 |
createOfferRequest['offerNotes'] = $("#offer_notes").val();
|
| 28018 |
amit.gupta |
185 |
createOfferRequest['incrementalTarget'] = $("input[name=incremental_target]").is(":checked");
|
| 27875 |
amit.gupta |
186 |
createOfferRequest['terms'] = $("#offer_terms").val();
|
|
|
187 |
createOfferRequest['targetType'] = $("input[name=targetType]:checked").val();
|
| 27895 |
amit.gupta |
188 |
createOfferRequest['payoutType'] = $("input[name=payoutType]:checked").val();
|
| 27875 |
amit.gupta |
189 |
createOfferRequest['schemeType'] = $("input[name=schemeType]:checked").val();
|
|
|
190 |
if(createOfferRequest['schemeType']=='ACTIVATION') {
|
|
|
191 |
createOfferRequest['activationBrands'] = $("div.activation-brands select").val().join(",") || null;
|
|
|
192 |
} else {
|
|
|
193 |
createOfferRequest['activationBrands'] = null;
|
|
|
194 |
|
|
|
195 |
}
|
|
|
196 |
createOfferRequest['sellinPercentage'] = $("#sellinPercentage").val();
|
|
|
197 |
createOfferRequest['brandShareTerms'] = $('#brandShare').val();
|
|
|
198 |
createOfferRequest['partnerCriteria'] = {};
|
|
|
199 |
createOfferRequest['partnerCriteria']['fofoIds'] = ($("#partners").val() || []).map(Number);
|
|
|
200 |
createOfferRequest['partnerCriteria']['partnerTypes'] = ($("select.criteria-partner-type").val() || []);
|
|
|
201 |
createOfferRequest['partnerCriteria']['regionIds'] = ($("select.criteria-warehouseregion").val() || []).map(Number);
|
|
|
202 |
|
|
|
203 |
createOfferRequest['itemCriteria'] = itemCriteria($('div.itemCriteria'));
|
|
|
204 |
let targetSlabs = [];
|
|
|
205 |
$('div.targetslabs').each(function (index, ele) {
|
|
|
206 |
let $targetSlab = $(ele);
|
|
|
207 |
let targetOnwardsValue = $targetSlab.find('.payoutTarget').val();
|
|
|
208 |
let targetDescription = $targetSlab.find('.targetDescription').val();
|
|
|
209 |
let itemCriteriaPayouts = [];
|
|
|
210 |
if (isNaN(targetOnwardsValue) || targetOnwardsValue < 0) {
|
|
|
211 |
validated = false;
|
|
|
212 |
alert(`Invalid Number - ${targetOnwardsValue}`);
|
|
|
213 |
} else {
|
|
|
214 |
if (index == 0 || targetOnwardsValue > 0) {
|
|
|
215 |
let $itemCriteriaPayoutContainers = $targetSlab.find('.itemcriteriapayout');
|
|
|
216 |
$itemCriteriaPayoutContainers.each(function (index, itemCriteriaPayoutContainer) {
|
|
|
217 |
let $itemCriteriaPayoutContainer = $(itemCriteriaPayoutContainer);
|
|
|
218 |
let amountType = $itemCriteriaPayoutContainer.find('input[name^=amountType]:checked').val();
|
|
|
219 |
let payoutSlabs = [];
|
|
|
220 |
let itemCriteria1 = itemCriteria($itemCriteriaPayoutContainer);
|
|
|
221 |
let $payoutSlabContainers = $itemCriteriaPayoutContainer.find('.slab');
|
| 28018 |
amit.gupta |
222 |
let itemCriteriaChanged = itemCriteria1['smartPhone'] || itemCriteria1['featuredPhone']
|
| 27951 |
amit.gupta |
223 |
|| itemCriteria1['catalogIds'].length > 0 || itemCriteria1['brands'].length > 0
|
| 27952 |
amit.gupta |
224 |
|| itemCriteria1['excludeCatalogIds'].length > 0
|
| 27955 |
amit.gupta |
225 |
|| itemCriteria1['startPrice'] > 0 || itemCriteria1['endPrice'] > itemCriteria1['startPrice'] > 0;
|
| 27875 |
amit.gupta |
226 |
if (itemCriteriaChanged || index == 0) {
|
|
|
227 |
$payoutSlabContainers.each(function (slabContainerIndex, slabContainer) {
|
|
|
228 |
let $slab = $(slabContainer);
|
|
|
229 |
|
|
|
230 |
let slabOnwardsAmount = $slab.find('.slabOnwardsAmount').val();
|
|
|
231 |
if (isNaN(slabOnwardsAmount) || slabOnwardsAmount < 0) {
|
|
|
232 |
validated = false;
|
|
|
233 |
alert(`Invalid Payout Slab Amount - ${slabOnwardsAmount}`);
|
|
|
234 |
} else {
|
|
|
235 |
if (slabContainerIndex == 0 || slabOnwardsAmount > 0) {
|
|
|
236 |
let payoutAmount = $slab.find('.payoutValue').val();
|
|
|
237 |
if (isNaN(payoutAmount) || payoutAmount <= 0) {
|
|
|
238 |
validated = false;
|
|
|
239 |
alert(`Invalid Payout Slab Amount - ${slabOnwardsAmount}`);
|
|
|
240 |
}
|
|
|
241 |
let payoutSlab = {
|
|
|
242 |
onwardsAmount: Number(slabOnwardsAmount),
|
|
|
243 |
payoutAmount: Number(payoutAmount)
|
|
|
244 |
}
|
|
|
245 |
payoutSlabs.push(payoutSlab);
|
|
|
246 |
}
|
|
|
247 |
}
|
|
|
248 |
});
|
|
|
249 |
let itemCriteriaPayout = {
|
|
|
250 |
itemCriteria: itemCriteria1,
|
|
|
251 |
payoutSlabs: payoutSlabs,
|
|
|
252 |
amountType: amountType
|
|
|
253 |
};
|
|
|
254 |
itemCriteriaPayouts.push(itemCriteriaPayout);
|
|
|
255 |
}
|
|
|
256 |
});
|
|
|
257 |
targetSlabs.push({
|
|
|
258 |
onwardsAmount: targetOnwardsValue,
|
|
|
259 |
targetDescription : targetDescription,
|
|
|
260 |
itemCriteriaPayouts: itemCriteriaPayouts
|
|
|
261 |
});
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
});
|
|
|
265 |
createOfferRequest['targetSlabs'] = targetSlabs;
|
|
|
266 |
if (validated && confirm("Confirm creating scheme offer")) {
|
|
|
267 |
console.log("Validated");
|
|
|
268 |
console.log(createOfferRequest);
|
|
|
269 |
doPostAjaxRequestWithJsonHandler(`${context}/createOffer`, JSON.stringify(createOfferRequest), function (response) {
|
|
|
270 |
alert("Offer created successfully");
|
|
|
271 |
let dt = new Date();
|
|
|
272 |
loadOfferHistory('#main-content', new Date().toISOString().slice(0,7));
|
|
|
273 |
});
|
|
|
274 |
} else {
|
|
|
275 |
console.log("Invalid Offer");
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
function itemCriteria($container) {
|
| 28018 |
amit.gupta |
280 |
let smartPhone = $container.find("input[name=smartphone]").is(":checked");
|
|
|
281 |
let featuredPhone = $container.find("input[name=featuredphone]").is(":checked");
|
| 27875 |
amit.gupta |
282 |
let catalogIds = $container.find('.criteria-catalogids').val() || [];
|
|
|
283 |
let excludeCatalogIds = [];
|
|
|
284 |
let excludeChecked = $container.find('input.exclude').is(':checked');
|
|
|
285 |
if(excludeChecked) {
|
|
|
286 |
excludeCatalogIds = catalogIds;
|
|
|
287 |
catalogIds = [];
|
|
|
288 |
}
|
|
|
289 |
let brands = $container.find('.criteria-brands').val() || [];
|
|
|
290 |
return {
|
|
|
291 |
startPrice: Number($container.find('.startValue').val()),
|
|
|
292 |
endPrice: Number($container.find('.endValue').val()),
|
|
|
293 |
catalogIds: catalogIds.map(Number),
|
|
|
294 |
excludeCatalogIds : excludeCatalogIds.map(Number),
|
|
|
295 |
brands: brands,
|
| 28018 |
amit.gupta |
296 |
smartPhone: smartPhone,
|
|
|
297 |
featuredPhone: featuredPhone
|
| 27875 |
amit.gupta |
298 |
};
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
function loadOffer(domId) {
|
|
|
302 |
console.log(domId);
|
|
|
303 |
doGetAjaxRequestHandler(context + "/getCreateOffer", function (response) {
|
|
|
304 |
$('#' + domId).html(response);
|
|
|
305 |
});
|
|
|
306 |
}
|
|
|
307 |
function loadOfferHistory(domId, yearMonth) {
|
|
|
308 |
doGetAjaxRequestHandler(`${context}/offerHistory?yearMonth=${yearMonth}`, function (response) {
|
|
|
309 |
$(domId).html(response);
|
|
|
310 |
$(domId).find("#yearmonth").val(yearMonth);
|
|
|
311 |
});
|
|
|
312 |
}
|
|
|
313 |
|