| 26588 |
tejbeer |
1 |
$(function() {
|
|
|
2 |
$(".scheme_offer").live('click', function() {
|
|
|
3 |
loadOffer("main-content");
|
|
|
4 |
});
|
| 26674 |
tejbeer |
5 |
|
|
|
6 |
$(".marginDetail").live(
|
|
|
7 |
'click',
|
|
|
8 |
function() {
|
|
|
9 |
|
|
|
10 |
var offerid = $(this).data('offerid');
|
|
|
11 |
console.log(offerid);
|
|
|
12 |
doGetAjaxRequestHandler(context + "/getOfferMargin?offerId="
|
|
|
13 |
+ offerid, function(response) {
|
|
|
14 |
$('.offer-container .modal-content').html(response);
|
|
|
15 |
});
|
|
|
16 |
});
|
|
|
17 |
|
|
|
18 |
$(".offer_history").live('click', function() {
|
|
|
19 |
loadOfferHistory("main-content");
|
|
|
20 |
});
|
| 26719 |
tejbeer |
21 |
|
| 27171 |
tejbeer |
22 |
|
| 26719 |
tejbeer |
23 |
$("#offer-history-paginated .next").live(
|
|
|
24 |
'click',
|
|
|
25 |
function() {
|
|
|
26 |
|
|
|
27 |
loadPaginatedNextItems('/getPaginatedOffers', null,
|
|
|
28 |
'offer-history-paginated', 'offer-listings-table',
|
|
|
29 |
'offer-details-container');
|
|
|
30 |
|
|
|
31 |
$(this).blur();
|
|
|
32 |
});
|
|
|
33 |
|
|
|
34 |
$("#offer-history-paginated .previous").live(
|
|
|
35 |
'click',
|
|
|
36 |
function() {
|
|
|
37 |
|
|
|
38 |
loadPaginatedPreviousItems('/getPaginatedOffers', null,
|
|
|
39 |
'offer-history-paginated', 'offer-listings-table',
|
|
|
40 |
'offer-details-container');
|
|
|
41 |
|
|
|
42 |
$(this).blur();
|
|
|
43 |
});
|
|
|
44 |
|
| 26588 |
tejbeer |
45 |
$(".new-offer").live("click", function(e) {
|
|
|
46 |
createOffer();
|
|
|
47 |
});
|
| 26694 |
tejbeer |
48 |
|
| 26719 |
tejbeer |
49 |
$("#offer-search-button").live('click', function() {
|
|
|
50 |
var searchText = $("#offer-search-text").val();
|
|
|
51 |
if (typeof (searchText) == "undefined" || !searchText) {
|
|
|
52 |
searchText = "";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
console.log(searchText)
|
|
|
56 |
loadOfferSearchInfo(searchText);
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
$(".offer-listing-details").live('click', function() {
|
|
|
60 |
var offerId = $(this).attr('data');
|
| 27171 |
tejbeer |
61 |
console.log("offerId = " + offerId);
|
| 26719 |
tejbeer |
62 |
loadOfferDetails(offerId, "offer-details-container");
|
|
|
63 |
});
|
|
|
64 |
|
|
|
65 |
$("#extendOffer-button")
|
|
|
66 |
.live(
|
|
|
67 |
'click',
|
|
|
68 |
function() {
|
|
|
69 |
console.log("extend button click");
|
|
|
70 |
var extendDatetime = $('input[name="extendOffer"]')
|
|
|
71 |
.val();
|
|
|
72 |
var offerId = $('#offerId').val()
|
|
|
73 |
console.log("extendDatetime : " + extendDatetime);
|
|
|
74 |
console.log(offerId);
|
|
|
75 |
if (extendDatetime) {
|
|
|
76 |
if (confirm("Are you sure you want to Extend expireDateTime for Scheme!") == true) {
|
|
|
77 |
extendOfferById(offerId)
|
|
|
78 |
}
|
|
|
79 |
} else {
|
|
|
80 |
alert("feild can't be blank");
|
|
|
81 |
}
|
|
|
82 |
});
|
|
|
83 |
|
| 26694 |
tejbeer |
84 |
$(".change-status")
|
|
|
85 |
.live(
|
|
|
86 |
'click',
|
|
|
87 |
function() {
|
|
|
88 |
var id = $(this).data('offid');
|
|
|
89 |
if (confirm("Are you sure you want to update the offer!") == true) {
|
|
|
90 |
doPostAjaxRequestHandler(context
|
|
|
91 |
+ "/updateOfferStatus?id=" + id, function(
|
|
|
92 |
response) {
|
|
|
93 |
if (response == 'true') {
|
|
|
94 |
alert("successfully update");
|
|
|
95 |
loadOfferHistory("main-content");
|
|
|
96 |
|
|
|
97 |
}
|
|
|
98 |
});
|
| 26719 |
tejbeer |
99 |
|
| 26694 |
tejbeer |
100 |
return false;
|
|
|
101 |
}
|
|
|
102 |
});
|
| 26588 |
tejbeer |
103 |
});
|
|
|
104 |
|
|
|
105 |
function loadOffer(domId) {
|
|
|
106 |
console.log(domId);
|
|
|
107 |
doGetAjaxRequestHandler(context + "/getCreateOffer", function(response) {
|
|
|
108 |
$('#' + domId).html(response);
|
|
|
109 |
$('#qtyMargin').hide();
|
|
|
110 |
$('#qtyPercentageMargin').hide();
|
|
|
111 |
$('#valueMargin').hide();
|
|
|
112 |
$('#oneBrandMarginOffer').hide();
|
|
|
113 |
$('#itemModelMarginOffer').hide();
|
|
|
114 |
$('#itemModelOffer').hide();
|
|
|
115 |
|
|
|
116 |
});
|
|
|
117 |
|
|
|
118 |
}
|
|
|
119 |
|
| 26674 |
tejbeer |
120 |
function loadOfferHistory(domId) {
|
|
|
121 |
doGetAjaxRequestHandler(context + "/getOffers", function(response) {
|
|
|
122 |
$('#' + domId).html(response);
|
|
|
123 |
|
|
|
124 |
});
|
|
|
125 |
}
|
|
|
126 |
|
| 26588 |
tejbeer |
127 |
function selecteditemCriteria() {
|
|
|
128 |
var itemCriteria = $('#itemCriteria').val();
|
|
|
129 |
console.log(itemCriteria);
|
|
|
130 |
if (itemCriteria == "All_Brands") {
|
|
|
131 |
$('#oneBrandMarginOffer').hide();
|
|
|
132 |
$('#itemModelMarginOffer').hide();
|
|
|
133 |
$('#itemModelOffer').hide();
|
|
|
134 |
} else if (itemCriteria == "Multiple_Brand") {
|
|
|
135 |
$('#oneBrandMarginOffer').show();
|
|
|
136 |
$('#itemModelMarginOffer').hide();
|
|
|
137 |
$('#itemModelOffer').hide();
|
|
|
138 |
} else if (itemCriteria == "Item_Model") {
|
|
|
139 |
$('#oneBrandMarginOffer').hide();
|
|
|
140 |
$('#itemModelMarginOffer').show();
|
|
|
141 |
$('#itemModelOffer').show();
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
function selectedTargetType() {
|
|
|
147 |
|
|
|
148 |
var targetType = $('#targetType').val();
|
|
|
149 |
selectedAmountType()
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
function selectedAmountType() {
|
|
|
154 |
var targetType = $('#targetType').val();
|
|
|
155 |
var amountType = $('#amountType').val();
|
|
|
156 |
console.log(amountType);
|
|
|
157 |
if (targetType == "value" && amountType == "percentage") {
|
|
|
158 |
$('#valueMargin').show();
|
|
|
159 |
$('#qtyMargin').hide();
|
|
|
160 |
$('#qtyPercentageMargin').hide();
|
|
|
161 |
|
|
|
162 |
} else if (targetType == "quantity" && amountType == "percentage") {
|
|
|
163 |
$('#qtyPercentageMargin').show();
|
|
|
164 |
$('#qtyMargin').hide();
|
|
|
165 |
$('#valueMargin').hide();
|
|
|
166 |
|
|
|
167 |
} else if (targetType == "quantity" && amountType == "amount") {
|
|
|
168 |
$('#qtyMargin').show();
|
|
|
169 |
$('#qtyPercentageMargin').hide();
|
|
|
170 |
$('#valueMargin').hide();
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
function createOffer() {
|
|
|
176 |
var offerDetailData = {}
|
|
|
177 |
var amountOffer;
|
|
|
178 |
var amountOfferJson = [];
|
|
|
179 |
var offerName = $('#offerName').val();
|
|
|
180 |
var description = $('#description').val();
|
|
|
181 |
var itemCriteria = $('#itemCriteria').val();
|
|
|
182 |
var targetType = $('#targetType').val();
|
|
|
183 |
var amountType = $('#amountType').val();
|
|
|
184 |
var fofoIds = $('#fofo-users').val();
|
| 26674 |
tejbeer |
185 |
var criteria = $('#criteria').val();
|
|
|
186 |
var partnerCategory = $('#partner-category').val();
|
| 26694 |
tejbeer |
187 |
var schemeType = $('#schemeType').val();
|
| 26588 |
tejbeer |
188 |
|
|
|
189 |
if (offerName === "" && description === "" && itemCriteria === ""
|
|
|
190 |
&& targetType === "" && amountType === "" && fofoIds === "") {
|
|
|
191 |
alert("Field can't be empty");
|
|
|
192 |
return;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
if (offerName === "") {
|
|
|
196 |
alert("Offer Name is required");
|
|
|
197 |
return;
|
|
|
198 |
}
|
| 26674 |
tejbeer |
199 |
|
| 26588 |
tejbeer |
200 |
if (itemCriteria === "") {
|
|
|
201 |
alert("Item Criteria is required");
|
|
|
202 |
return;
|
|
|
203 |
}
|
|
|
204 |
if (targetType === "") {
|
|
|
205 |
alert("Target Type Number is required");
|
|
|
206 |
return;
|
|
|
207 |
}
|
|
|
208 |
if (amountType === "") {
|
|
|
209 |
alert("Amount Type is required");
|
|
|
210 |
return;
|
|
|
211 |
}
|
| 26694 |
tejbeer |
212 |
|
|
|
213 |
if (partnerCategory === "") {
|
|
|
214 |
alert("category is required");
|
|
|
215 |
return;
|
|
|
216 |
} else if (fofoIds === "") {
|
| 26588 |
tejbeer |
217 |
alert("Minimum One Partner is required");
|
| 26674 |
tejbeer |
218 |
|
| 26588 |
tejbeer |
219 |
return;
|
|
|
220 |
}
|
|
|
221 |
if (description === "") {
|
|
|
222 |
alert("Description is required");
|
|
|
223 |
return;
|
|
|
224 |
}
|
|
|
225 |
|
| 26694 |
tejbeer |
226 |
if (schemeType === "") {
|
|
|
227 |
alert("Scheme Type is required");
|
|
|
228 |
return;
|
|
|
229 |
}
|
|
|
230 |
|
| 26588 |
tejbeer |
231 |
console.log(itemCriteria);
|
|
|
232 |
if (itemCriteria == "Multiple_Brand") {
|
|
|
233 |
var brand = $('#brand').val();
|
|
|
234 |
|
|
|
235 |
if (brand === "") {
|
|
|
236 |
alert("brand is required");
|
|
|
237 |
return;
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
if (targetType == "value" && amountType == "percentage") {
|
|
|
241 |
for (i = 0; i < 6; i++) {
|
|
|
242 |
var value = $('#value' + i).val();
|
|
|
243 |
var margin = $('#margin' + i).val();
|
|
|
244 |
if (value != "") {
|
|
|
245 |
amountOffer = {
|
|
|
246 |
"value" : value,
|
|
|
247 |
"margin" : margin
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
amountOfferJson.push(amountOffer)
|
|
|
251 |
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
} else if (targetType == "quantity" && amountType == "percentage") {
|
|
|
256 |
for (i = 0; i < 6; i++) {
|
|
|
257 |
var value = $('#qtyPer' + i).val();
|
|
|
258 |
var margin = $('#qtyPermargin' + i).val();
|
|
|
259 |
if (value != "") {
|
|
|
260 |
amountOffer = {
|
|
|
261 |
"value" : value,
|
|
|
262 |
"margin" : margin
|
|
|
263 |
}
|
|
|
264 |
amountOfferJson.push(amountOffer)
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
} else if (targetType == "quantity" && amountType == "amount") {
|
|
|
269 |
for (i = 0; i < 6; i++) {
|
|
|
270 |
var value = $('#qty' + i).val();
|
|
|
271 |
var margin = $('#qtymargin' + i).val();
|
|
|
272 |
if (value != "") {
|
|
|
273 |
amountOffer = {
|
|
|
274 |
"value" : value,
|
|
|
275 |
"margin" : margin
|
|
|
276 |
}
|
|
|
277 |
amountOfferJson.push(amountOffer)
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
if (amountOfferJson.length === 0) {
|
|
|
282 |
alert("value and margin is required");
|
|
|
283 |
return;
|
|
|
284 |
}
|
|
|
285 |
offerDetailData['name'] = $('#offerName').val();
|
|
|
286 |
offerDetailData['description'] = $('#description').val();
|
|
|
287 |
offerDetailData['fofoIds'] = $('#fofo-users').val();
|
|
|
288 |
offerDetailData['price'] = $('#price').val();
|
|
|
289 |
offerDetailData['amountOffer'] = amountOfferJson;
|
|
|
290 |
if (itemCriteria == "Item_Model") {
|
|
|
291 |
offerDetailData['catalogIds'] = $('#item_catalog_id').val();
|
|
|
292 |
}
|
|
|
293 |
if (itemCriteria == "Multiple_Brand") {
|
|
|
294 |
offerDetailData['brands'] = $('#brand').val();
|
|
|
295 |
}
|
|
|
296 |
offerDetailData['amountType'] = $('#amountType').val();
|
|
|
297 |
offerDetailData['itemCriteria'] = $('#itemCriteria').val();
|
|
|
298 |
offerDetailData['targetType'] = $('#targetType').val();
|
| 26674 |
tejbeer |
299 |
offerDetailData['criteria'] = $('#criteria').val();
|
|
|
300 |
offerDetailData['partnerType'] = $('#partner-category').val();
|
| 26694 |
tejbeer |
301 |
|
|
|
302 |
offerDetailData['schemeType'] = $('#schemeType').val();
|
| 26588 |
tejbeer |
303 |
offerDetailData['startDate'] = startDate;
|
|
|
304 |
offerDetailData['endDate'] = endDate;
|
|
|
305 |
console.log(offerDetailData);
|
|
|
306 |
|
|
|
307 |
if (confirm("Are you sure you want to add offer!") == true) {
|
|
|
308 |
doPostAjaxRequestWithJsonHandler(context + "/createOffer", JSON
|
|
|
309 |
.stringify(offerDetailData), function(response) {
|
|
|
310 |
if (response == 'true') {
|
|
|
311 |
alert("successfully create");
|
|
|
312 |
loadOffer("main-content");
|
|
|
313 |
}
|
|
|
314 |
});
|
|
|
315 |
|
|
|
316 |
return false;
|
|
|
317 |
}
|
|
|
318 |
}
|
| 26719 |
tejbeer |
319 |
|
|
|
320 |
function loadOfferSearchInfo(searchText) {
|
|
|
321 |
loadSearchOffer("main-content", searchText);
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
function extendOfferById(offerId) {
|
|
|
325 |
doPostAjaxRequestWithJsonHandler(context + "/extendByOfferId?offerId="
|
|
|
326 |
+ offerId, JSON.stringify(startDate), function(response) {
|
|
|
327 |
if (response == 'true') {
|
|
|
328 |
alert("Offer extended successfully");
|
|
|
329 |
loadOfferHistory("main-content");
|
| 27171 |
tejbeer |
330 |
} else {
|
|
|
331 |
extendOffer - button
|
| 26719 |
tejbeer |
332 |
alert("Offer already Expired");
|
|
|
333 |
loadOfferHistory("main-content");
|
|
|
334 |
}
|
|
|
335 |
});
|
|
|
336 |
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
function loadSearchOffer(domId, search_text) {
|
|
|
340 |
doGetAjaxRequestHandler(
|
|
|
341 |
context + "/searchOffer/?searchTerm=" + search_text, function(
|
|
|
342 |
response) {
|
|
|
343 |
$('#' + domId).html(response);
|
|
|
344 |
});
|
|
|
345 |
|
|
|
346 |
}
|
|
|
347 |
function loadOfferDetails(offerId, domId) {
|
|
|
348 |
doGetAjaxRequestHandler(context + "/offerById?offerId=" + offerId,
|
|
|
349 |
function(response) {
|
|
|
350 |
$('#' + domId).html(response);
|
|
|
351 |
window.dispatchEvent(new Event('resize'));
|
|
|
352 |
});
|
|
|
353 |
}
|