| 29951 |
amit.gupta |
1 |
$(function () {
|
| 30252 |
amit.gupta |
2 |
$(document).on('click', ".price-circular", function () {
|
|
|
3 |
loadPriceCircular("main-content");
|
|
|
4 |
});
|
| 28102 |
tejbeer |
5 |
|
| 30252 |
amit.gupta |
6 |
$(document).on('click', ".partner-price-circular", function () {
|
| 28134 |
tejbeer |
7 |
|
| 30252 |
amit.gupta |
8 |
bootbox.confirm({
|
|
|
9 |
message: "<div class = 'disclosurehindata'> <img src='resources/images/disclosure.png' style='width:100%'> </div>"
|
|
|
10 |
,
|
|
|
11 |
buttons: {
|
|
|
12 |
confirm: {
|
|
|
13 |
label: 'I agree',
|
|
|
14 |
className: 'btn-success'
|
|
|
15 |
},
|
|
|
16 |
cancel: {
|
|
|
17 |
label: 'I disagree',
|
|
|
18 |
className: 'btn-danger'
|
|
|
19 |
}
|
|
|
20 |
},
|
|
|
21 |
callback: function (result) {
|
|
|
22 |
if (result == true) {
|
|
|
23 |
loadPartnerPriceCircular("main-content");
|
|
|
24 |
}
|
|
|
25 |
}
|
|
|
26 |
});
|
| 28134 |
tejbeer |
27 |
|
| 30252 |
amit.gupta |
28 |
});
|
| 28102 |
tejbeer |
29 |
|
| 30252 |
amit.gupta |
30 |
$(document).on('click', ".submit-circular-request", function () {
|
|
|
31 |
let brand = $("#brands").val();
|
|
|
32 |
let priceCircularUrl = `${context}/priceCircularByBrand?brand=${brand}`;
|
|
|
33 |
if (typeof partnerId == "number") {
|
|
|
34 |
priceCircularUrl = `${priceCircularUrl}&fofoId=${partnerId}`;
|
|
|
35 |
}
|
|
|
36 |
doGetAjaxRequestHandler(priceCircularUrl,
|
|
|
37 |
function (response) {
|
|
|
38 |
console.log(response)
|
|
|
39 |
$('.price-circular-container').html(response);
|
|
|
40 |
});
|
|
|
41 |
});
|
| 28102 |
tejbeer |
42 |
|
| 30252 |
amit.gupta |
43 |
$(document).on('click', ".download-nlc", function () {
|
|
|
44 |
let brand = $("#brands").val();
|
|
|
45 |
let downloadNlcUrl = `${context}/downloadNlcByBrand?brand=${brand}`;
|
|
|
46 |
if (typeof partnerId == "number") {
|
|
|
47 |
downloadNlcUrl = `${downloadNlcUrl}&fofoId=${partnerId}`;
|
|
|
48 |
}
|
|
|
49 |
doAjaxGetDownload(downloadNlcUrl, `${brand}-nlc.csv`);
|
|
|
50 |
});
|
| 28102 |
tejbeer |
51 |
|
| 30252 |
amit.gupta |
52 |
|
| 28102 |
tejbeer |
53 |
});
|
|
|
54 |
|
|
|
55 |
function loadPriceCircular(domId) {
|
| 30252 |
amit.gupta |
56 |
doGetAjaxRequestHandler(context + "/priceCircular",
|
|
|
57 |
function (response) {
|
|
|
58 |
$('#' + domId).html(response);
|
|
|
59 |
});
|
| 28102 |
tejbeer |
60 |
}
|
|
|
61 |
|
|
|
62 |
function loadPartnerPriceCircular(domId) {
|
| 30252 |
amit.gupta |
63 |
doGetAjaxRequestHandler(context + "/partnerPriceCircular",
|
|
|
64 |
function (response) {
|
|
|
65 |
$('#' + domId).html(response);
|
|
|
66 |
});
|
| 35501 |
ranu |
67 |
}
|
|
|
68 |
|
|
|
69 |
$(document).on('click', ".today-offer", function () {
|
| 35505 |
ranu |
70 |
loadTodayOfferVM("main-content");
|
| 35501 |
ranu |
71 |
});
|
|
|
72 |
|
|
|
73 |
// Main function called to load the shell
|
| 35505 |
ranu |
74 |
function loadTodayOfferVM(domId) {
|
|
|
75 |
doGetAjaxRequestHandler(context + `/todayOffer`, function (response) {
|
| 35501 |
ranu |
76 |
// Load the brand tabs
|
|
|
77 |
$('#' + domId).html(response);
|
|
|
78 |
|
|
|
79 |
// AUTO-LOAD Samsung immediately after tabs are ready
|
| 35505 |
ranu |
80 |
loadBrandOffers("Motorola", 0);
|
| 35501 |
ranu |
81 |
});
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
// Click listener for tabs
|
|
|
86 |
$(document).on('click', ".brand-tab", function () {
|
|
|
87 |
let fofoId = $(this).data('fofoid');
|
|
|
88 |
let brand = $(this).data("brand");
|
|
|
89 |
loadBrandOffers(brand, fofoId);
|
|
|
90 |
});
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
// Function to handle the actual data loading
|
|
|
94 |
function loadBrandOffers(brandName, fofoId) {
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
// 1. Show the loader immediately
|
|
|
98 |
const loaderHtml = `
|
|
|
99 |
<center><div class="loader-wrapper">
|
|
|
100 |
<i class="fa fa-spinner fa-spin fa-4x"></i>
|
|
|
101 |
<span class="loader-text">Loading offers for ${brandName}...</span>
|
|
|
102 |
</div></center>`;
|
|
|
103 |
|
|
|
104 |
$('.today-offer-container').html(loaderHtml);
|
|
|
105 |
|
|
|
106 |
// 2. Prepare the URL
|
|
|
107 |
let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
|
|
|
108 |
if (typeof partnerId == "number") {
|
|
|
109 |
todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
// 3. Hit the API
|
|
|
113 |
doGetAjaxRequestHandler(todayOfferUrl, function (response) {
|
|
|
114 |
// Success: The loader is replaced by the actual table response
|
|
|
115 |
$('.today-offer-container').html(response);
|
|
|
116 |
|
|
|
117 |
// Update Active Tab UI
|
|
|
118 |
$(".brand-tabs li").removeClass("active");
|
|
|
119 |
$(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
|
|
|
120 |
});
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
$(document).on('click', '.today-offer-view', function () {
|
|
|
125 |
let offerId = $(this).data("offerid");
|
|
|
126 |
doGetAjaxRequestHandler(`${context}/getOfferMargins?offerId=${offerId}`, function (data) {
|
|
|
127 |
$('#todayOfferDescription .modal-content').html(data);
|
|
|
128 |
$("#todayOfferDescription").modal('show');
|
|
|
129 |
});
|
|
|
130 |
});
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
$(document).on('click', '.today-fofo-offer', function () {
|
|
|
134 |
let fofoId = $(this).data("fofoid");
|
|
|
135 |
doGetAjaxRequestHandler(`${context}/todayFofoOffer?fofoId=${fofoId}`, function (data) {
|
|
|
136 |
$(".today-fofo-offer-view").show();
|
|
|
137 |
$(".fofo-summry-view").hide();
|
| 35838 |
ranu |
138 |
$(".scheme-imei-history-view").hide();
|
|
|
139 |
$(".partner-wallet-view").hide();
|
| 35501 |
ranu |
140 |
$('.today-fofo-offer-view').html(data);
|
|
|
141 |
// AUTO-LOAD Samsung immediately after tabs are ready
|
|
|
142 |
loadFofoBrandOffers("Motorola", fofoId);
|
|
|
143 |
});
|
|
|
144 |
});
|
|
|
145 |
|
|
|
146 |
|
| 35502 |
ranu |
147 |
$(document).on('click', '.fofo-stock-info', function () {
|
|
|
148 |
|
|
|
149 |
$(".today-fofo-offer-view").hide();
|
| 35771 |
ranu |
150 |
$(".scheme-imei-history-view").hide();
|
| 35838 |
ranu |
151 |
$(".partner-wallet-view").hide();
|
| 35502 |
ranu |
152 |
$(".fofo-summry-view").show();
|
|
|
153 |
});
|
|
|
154 |
|
|
|
155 |
|
| 35775 |
ranu |
156 |
// Variables for modal search
|
|
|
157 |
var modalCurrentItem = null;
|
|
|
158 |
var modalFofoId = null;
|
|
|
159 |
|
| 35771 |
ranu |
160 |
// IMEI Margin (Scheme IMEI History) handlers
|
|
|
161 |
$(document).on('click', '.scheme-imei-history-btn', function () {
|
| 35775 |
ranu |
162 |
modalFofoId = $(this).data("fofoid");
|
| 35771 |
ranu |
163 |
|
|
|
164 |
// Load the scheme-imei-history view (empty initially, user will search)
|
| 35775 |
ranu |
165 |
doGetAjaxRequestHandler(`${context}/getImeiMarginModal?searchImei=&fofoId=${modalFofoId}`, function (response) {
|
| 35771 |
ranu |
166 |
$(".today-fofo-offer-view").hide();
|
|
|
167 |
$(".fofo-summry-view").hide();
|
| 35838 |
ranu |
168 |
$(".partner-wallet-view").hide();
|
| 35771 |
ranu |
169 |
$(".scheme-imei-history-view").show();
|
|
|
170 |
$('.scheme-imei-history-view').html(response);
|
|
|
171 |
|
|
|
172 |
// Initialize IMEI autocomplete if available
|
|
|
173 |
if (typeof getAllImeiAheadOptions === 'function') {
|
| 35775 |
ranu |
174 |
getImeiAheadOptions($("#modal-imei-search-text"), modalFofoId, function (inventoryItem) {
|
| 35771 |
ranu |
175 |
// Trigger search when item selected from autocomplete
|
|
|
176 |
});
|
|
|
177 |
}
|
| 35775 |
ranu |
178 |
|
|
|
179 |
// Initialize model autocomplete for modal
|
|
|
180 |
initModalModelAutocomplete();
|
| 35771 |
ranu |
181 |
});
|
|
|
182 |
});
|
|
|
183 |
|
| 35838 |
ranu |
184 |
// Partner Wallet handlers
|
|
|
185 |
$(document).on('click', '.partner-wallet-btn', function () {
|
|
|
186 |
let fofoId = $(this).data("fofoid");
|
|
|
187 |
|
|
|
188 |
// Load the partner wallet history view
|
|
|
189 |
doGetAjaxRequestHandler(`${context}/getWalletHistoryByPartner?fofoId=${fofoId}`, function (response) {
|
|
|
190 |
$(".today-fofo-offer-view").hide();
|
|
|
191 |
$(".fofo-summry-view").hide();
|
|
|
192 |
$(".scheme-imei-history-view").hide();
|
|
|
193 |
$(".partner-wallet-view").show();
|
|
|
194 |
$('.partner-wallet-view').html(response);
|
|
|
195 |
});
|
|
|
196 |
});
|
|
|
197 |
|
| 35775 |
ranu |
198 |
// Initialize model autocomplete in modal
|
|
|
199 |
function initModalModelAutocomplete() {
|
|
|
200 |
modalCurrentItem = null;
|
|
|
201 |
if (typeof getEntityAheadOptions === 'function') {
|
|
|
202 |
getEntityAheadOptions($("#modal-model-search-text"), function (selectedItem) {
|
|
|
203 |
modalCurrentItem = selectedItem.catalogId_i;
|
|
|
204 |
});
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
|
| 35771 |
ranu |
208 |
// Search IMEI margin on button click within modal
|
| 35775 |
ranu |
209 |
$(document).on('click', '#modal-imei-search-button', function () {
|
|
|
210 |
let imei = $("#modal-imei-search-text").val().trim();
|
| 35771 |
ranu |
211 |
if (imei) {
|
|
|
212 |
searchImeiMarginInModal(imei);
|
|
|
213 |
} else {
|
|
|
214 |
alert("Please enter IMEI number");
|
|
|
215 |
}
|
|
|
216 |
});
|
|
|
217 |
|
| 35775 |
ranu |
218 |
// Search Model margin on button click within modal
|
|
|
219 |
$(document).on('click', '#modal-model-search-button', function () {
|
|
|
220 |
let searchText = $("#modal-model-search-text").val().trim();
|
|
|
221 |
let date = $(".modal-schemes-date").val();
|
|
|
222 |
|
|
|
223 |
if (!searchText) {
|
|
|
224 |
alert("Please select a model");
|
|
|
225 |
return;
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
if (modalCurrentItem) {
|
|
|
229 |
searchModelMarginInModal(modalCurrentItem, date);
|
|
|
230 |
} else {
|
|
|
231 |
alert("Please select a valid model from suggestions");
|
|
|
232 |
}
|
|
|
233 |
});
|
|
|
234 |
|
|
|
235 |
// Function to search and load model-wise margin details in modal
|
|
|
236 |
function searchModelMarginInModal(catalogId, date) {
|
|
|
237 |
const loaderHtml = `
|
|
|
238 |
<center><div class="loader-wrapper" style="padding: 50px;">
|
|
|
239 |
<i class="fa fa-spinner fa-spin fa-3x"></i>
|
|
|
240 |
<p style="margin-top: 15px;">Loading model margin details...</p>
|
|
|
241 |
</div></center>`;
|
|
|
242 |
|
|
|
243 |
// Hide IMEI results, show Model results container
|
|
|
244 |
$('.modal-imei-margin-container').hide();
|
|
|
245 |
$('.modal-model-margin-container').show().html(loaderHtml);
|
|
|
246 |
|
|
|
247 |
// Use new endpoint with fofoId
|
|
|
248 |
doGetAjaxRequestHandler(`${context}/getModelMarginModal?searchModel=${catalogId}&date=${date}&fofoId=${modalFofoId}`, function (response) {
|
|
|
249 |
$('.modal-model-margin-container').html(response);
|
|
|
250 |
});
|
|
|
251 |
}
|
|
|
252 |
|
| 35771 |
ranu |
253 |
// Function to search and load IMEI margin details in modal
|
|
|
254 |
function searchImeiMarginInModal(imei) {
|
|
|
255 |
const loaderHtml = `
|
|
|
256 |
<center><div class="loader-wrapper" style="padding: 50px;">
|
|
|
257 |
<i class="fa fa-spinner fa-spin fa-3x"></i>
|
|
|
258 |
<p style="margin-top: 15px;">Loading margin details for ${imei}...</p>
|
|
|
259 |
</div></center>`;
|
|
|
260 |
|
| 35775 |
ranu |
261 |
// Hide Model results, show IMEI results container
|
|
|
262 |
$('.modal-model-margin-container').hide();
|
|
|
263 |
$('.modal-imei-margin-container').show().html(loaderHtml);
|
| 35771 |
ranu |
264 |
|
| 35775 |
ranu |
265 |
// Use new endpoint with fofoId
|
|
|
266 |
doGetAjaxRequestHandler(`${context}/getImeiMarginModal?searchImei=${imei}&fofoId=${modalFofoId}`, function (response) {
|
|
|
267 |
$('.modal-imei-margin-container').html(response);
|
| 35771 |
ranu |
268 |
});
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
|
| 35501 |
ranu |
272 |
$(document).on('click', ".fofo-brand-tab", function () {
|
|
|
273 |
let fofoId = $(this).data('fofoid');
|
|
|
274 |
let brand = $(this).data("brand");
|
|
|
275 |
loadFofoBrandOffers(brand, fofoId);
|
|
|
276 |
});
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
// Function to handle the actual data loading
|
|
|
280 |
function loadFofoBrandOffers(brandName, fofoId) {
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
// 1. Show the loader immediately
|
|
|
284 |
const loaderHtml = `
|
|
|
285 |
<center><div class="loader-wrapper">
|
|
|
286 |
<i class="fa fa-spinner fa-spin fa-4x"></i>
|
|
|
287 |
<span class="loader-text">Loading offers for ${brandName}...</span>
|
|
|
288 |
</div></center>`;
|
|
|
289 |
|
|
|
290 |
$('.today-fofo-offer-container').html(loaderHtml);
|
|
|
291 |
|
|
|
292 |
// 2. Prepare the URL
|
|
|
293 |
let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
|
|
|
294 |
if (typeof partnerId == "number") {
|
|
|
295 |
todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
// 3. Hit the API
|
|
|
299 |
doGetAjaxRequestHandler(todayOfferUrl, function (response) {
|
|
|
300 |
// Success: The loader is replaced by the actual table response
|
|
|
301 |
$('.today-fofo-offer-container').html(response);
|
|
|
302 |
|
|
|
303 |
// Update Active Tab UI
|
|
|
304 |
$(".brand-tabs li").removeClass("active");
|
|
|
305 |
$(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
|
|
|
306 |
});
|
| 28102 |
tejbeer |
307 |
}
|