| 30725 |
amit.gupta |
1 |
$(function () {
|
| 31274 |
amit.gupta |
2 |
//Price change handler
|
| 33149 |
ranu |
3 |
$(document).on('change', "form#cd input.unitPrice, form#cd input.discount", function () {
|
|
|
4 |
var $row = $(this).closest('tr'); // Get the closest <tr> parent of the changed input
|
| 33437 |
ranu |
5 |
var unitPrice = parseFloat($row.find('input.unitPrice').val());
|
| 24440 |
amit.gupta |
6 |
|
| 31274 |
amit.gupta |
7 |
if (isNaN(unitPrice)) {
|
|
|
8 |
unitPrice = 0;
|
|
|
9 |
}
|
| 33149 |
ranu |
10 |
var discount = parseFloat($row.find('input.discount').val());
|
|
|
11 |
var maxDiscount = parseFloat($row.find('input.discount').data('maxdiscount'));
|
| 31274 |
amit.gupta |
12 |
if (isNaN(discount)) {
|
|
|
13 |
discount = 0;
|
|
|
14 |
}
|
|
|
15 |
if (isNaN(maxDiscount)) {
|
|
|
16 |
maxDiscount = 0;
|
|
|
17 |
}
|
|
|
18 |
if (discount > maxDiscount) {
|
| 33149 |
ranu |
19 |
alert("Discount can't be greater than max Discount");
|
|
|
20 |
$row.find('input.discount').val(maxDiscount);
|
| 31274 |
amit.gupta |
21 |
$(this).focus();
|
|
|
22 |
return;
|
|
|
23 |
}
|
|
|
24 |
if (unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)) {
|
|
|
25 |
alert("Invalid unit/discount price");
|
|
|
26 |
$(this).focus();
|
|
|
27 |
return;
|
|
|
28 |
}
|
| 32468 |
amit.gupta |
29 |
let lines = $("#order-items").find('tbody>tr:gt(0)').length;
|
|
|
30 |
if (lines > 3) {
|
| 33149 |
ranu |
31 |
calculateTotalAmount($row);
|
| 32469 |
amit.gupta |
32 |
} else {
|
|
|
33 |
calculateTotalAmount();
|
| 32468 |
amit.gupta |
34 |
}
|
| 33149 |
ranu |
35 |
$row.find('.mk_check_plans').trigger('click', ['manual']); // Trigger the button within the same row
|
| 31274 |
amit.gupta |
36 |
});
|
| 30725 |
amit.gupta |
37 |
|
| 33795 |
ranu |
38 |
$(document).on('click', ".upgrade-offer", function () {
|
|
|
39 |
var itemId = $(this).data('itemid');
|
|
|
40 |
doGetAjaxRequestHandler(`${context}/getItemWiseUpgradeOffer?itemId=` + itemId, function (response) {
|
|
|
41 |
$('#upgradeOfferModal .modal-content').html(response);
|
|
|
42 |
});
|
|
|
43 |
});
|
| 30725 |
amit.gupta |
44 |
|
| 33149 |
ranu |
45 |
|
| 31274 |
amit.gupta |
46 |
$(document).on('change', "form#cd input.insuranceamount", function () {
|
|
|
47 |
calculateTotalAmount();
|
|
|
48 |
});
|
| 30725 |
amit.gupta |
49 |
|
| 31274 |
amit.gupta |
50 |
$(document).on('click', ".create-order", function () {
|
|
|
51 |
checkout("main-content");
|
|
|
52 |
});
|
| 30725 |
amit.gupta |
53 |
|
| 31274 |
amit.gupta |
54 |
$(document).on('click', ".mk_check_plans", function (event, source) {
|
| 33149 |
ranu |
55 |
console.log("checkPlansssssss99999");
|
| 32434 |
amit.gupta |
56 |
let lines = $("#order-items").find('tbody>tr:gt(0)').length;
|
| 32414 |
amit.gupta |
57 |
if (lines > 3) {
|
|
|
58 |
//No need to check plans
|
|
|
59 |
return;
|
|
|
60 |
}
|
| 31274 |
amit.gupta |
61 |
$('div.itemdetails').find('input').val('');
|
|
|
62 |
let price = mop;
|
|
|
63 |
var mop = parseFloat($(this).data("mop"));
|
|
|
64 |
var sellingPrice = $(this).val();
|
|
|
65 |
var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
|
|
|
66 |
if (!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop) {
|
|
|
67 |
price = parseFloat(sellingPrice);
|
|
|
68 |
} else {
|
|
|
69 |
price = mop;
|
|
|
70 |
}
|
| 33437 |
ranu |
71 |
var poiId = parseFloat($(this).closest("tr").find("input.poiId").val());
|
| 31274 |
amit.gupta |
72 |
var discount = parseFloat($(this).closest("tr").find("input.discount").val());
|
|
|
73 |
if (!isNaN(discount)) {
|
|
|
74 |
price = price - discount;
|
|
|
75 |
}
|
|
|
76 |
let that = this;
|
| 33437 |
ranu |
77 |
doGetAjaxRequestHandler(`${context}/checkplans?price=${price}&itemId=${itemId}&poiId=${poiId}`, function (response) {
|
| 31274 |
amit.gupta |
78 |
var obj = JSON.parse(response);
|
|
|
79 |
if (obj != null) {
|
| 34798 |
ranu |
80 |
getInsurancePlansModal(obj, that, price, itemId);
|
| 31274 |
amit.gupta |
81 |
return;
|
|
|
82 |
} else {
|
|
|
83 |
if (typeof source === "undefined") {
|
|
|
84 |
alert("Product is not eligible for insurance");
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
});
|
|
|
88 |
});
|
| 30725 |
amit.gupta |
89 |
|
| 22245 |
ashik.ali |
90 |
});
|
| 23343 |
ashik.ali |
91 |
|
| 31274 |
amit.gupta |
92 |
class InsuranceElement extends React.Component {
|
|
|
93 |
planChecked;
|
| 23343 |
ashik.ali |
94 |
|
| 31274 |
amit.gupta |
95 |
constructor(props) {
|
|
|
96 |
super(props);
|
| 34798 |
ranu |
97 |
this.state = {
|
|
|
98 |
quotedPlans: {}
|
|
|
99 |
};
|
| 31274 |
amit.gupta |
100 |
}
|
| 24440 |
amit.gupta |
101 |
|
| 31274 |
amit.gupta |
102 |
render() {
|
|
|
103 |
console.log(this.props);
|
|
|
104 |
return <table className="table table-sm">
|
|
|
105 |
<thead>
|
|
|
106 |
<tr>
|
|
|
107 |
<th>Plan Name</th>
|
|
|
108 |
<th>Duration</th>
|
|
|
109 |
<th>DP</th>
|
|
|
110 |
<th>Selling Price</th>
|
|
|
111 |
<th>Action</th>
|
|
|
112 |
</tr>
|
|
|
113 |
</thead>
|
|
|
114 |
<tbody>
|
|
|
115 |
{Object.keys(this.props.plans).map((planName, i) =>
|
| 34798 |
ranu |
116 |
this.props.plans[planName].map((plan, j) => {
|
|
|
117 |
const quoted = this.state.quotedPlans[plan.productId];
|
|
|
118 |
const isQuoted = !!quoted;
|
|
|
119 |
const displayPremium = isQuoted ? quoted.premium : (plan.premium || 0);
|
| 34805 |
ranu |
120 |
const displayDP = isQuoted ? quoted.dp : (plan.dp || 0);
|
| 34798 |
ranu |
121 |
|
|
|
122 |
return (
|
|
|
123 |
<tr key={`${i}-${j}`}>
|
|
|
124 |
<td>{planName}</td>
|
|
|
125 |
<td>{plan.duration}</td>
|
|
|
126 |
<td>{displayDP ? displayDP.toFixed(2) : "-"}</td>
|
|
|
127 |
<td>{displayPremium ? displayPremium.toFixed(2) : "-"}</td>
|
|
|
128 |
|
|
|
129 |
<td>
|
|
|
130 |
{isQuoted || (plan.dp > 0 && plan.premium > 0) ? (
|
|
|
131 |
<button
|
|
|
132 |
className="btn btn-primary"
|
|
|
133 |
data-key={plan.productId}
|
|
|
134 |
data-amount={isQuoted ? quoted.premium.toFixed(2) : plan.premium.toFixed(2)}
|
|
|
135 |
data-correlationid={isQuoted ? quoted.correlationId : ''}
|
|
|
136 |
onClick={this.planChecked}
|
|
|
137 |
>
|
|
|
138 |
Add
|
|
|
139 |
</button>
|
|
|
140 |
) : (
|
| 35002 |
ranu |
141 |
<button className="btn btn-warning"
|
|
|
142 |
onClick={(e) => this.checkQuote(e, plan, planName)}>
|
| 34798 |
ranu |
143 |
Check Quote
|
|
|
144 |
</button>
|
|
|
145 |
)}
|
|
|
146 |
</td>
|
|
|
147 |
</tr>
|
|
|
148 |
);
|
|
|
149 |
})
|
|
|
150 |
)}
|
| 31274 |
amit.gupta |
151 |
</tbody>
|
| 34798 |
ranu |
152 |
|
| 31274 |
amit.gupta |
153 |
</table>;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
planChecked = (e) => {
|
| 34798 |
ranu |
157 |
//debugger;
|
| 31274 |
amit.gupta |
158 |
let $itemDetails = $('div.itemdetails');
|
|
|
159 |
if ($itemDetails.find('.dgram').val() === '') {
|
|
|
160 |
bootbox.alert('Mobile RAM is required');
|
|
|
161 |
return;
|
|
|
162 |
}
|
|
|
163 |
if ($itemDetails.find('.dgmemory').val() === '') {
|
|
|
164 |
bootbox.alert('Mobile Memory is required');
|
|
|
165 |
return;
|
|
|
166 |
}
|
|
|
167 |
if ($itemDetails.find('#dgmfgdate').val() === '') {
|
|
|
168 |
bootbox.alert('Mobile Mfg Date is required');
|
|
|
169 |
return;
|
|
|
170 |
}
|
|
|
171 |
let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');
|
|
|
172 |
$orderItemRow.find('.insuranceid').val($(e.target).data('key'));
|
| 34798 |
ranu |
173 |
$orderItemRow.find('.correlationid').val($(e.target).data('correlationid'));
|
| 31274 |
amit.gupta |
174 |
$orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));
|
|
|
175 |
$orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
|
|
|
176 |
$orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
|
| 34798 |
ranu |
177 |
// $orderItemRow.find('.mfgdate').val(window.mfgDate);
|
|
|
178 |
$orderItemRow.find('.mfgdate').val($itemDetails.find('.dgmfgdate').val());
|
| 31274 |
amit.gupta |
179 |
$('#mobilePlansModal').modal('hide');
|
|
|
180 |
calculateTotalAmount();
|
|
|
181 |
}
|
| 34798 |
ranu |
182 |
|
| 35002 |
ranu |
183 |
checkQuote = (e, plan, planName) => {
|
| 34798 |
ranu |
184 |
//debugger;
|
|
|
185 |
let $itemDetails = $('div.itemdetails');
|
|
|
186 |
if ($itemDetails.find('.dgram').val() === '') {
|
|
|
187 |
bootbox.alert('Mobile RAM is required');
|
|
|
188 |
return;
|
|
|
189 |
}
|
|
|
190 |
if ($itemDetails.find('.dgmemory').val() === '') {
|
|
|
191 |
bootbox.alert('Mobile Memory is required');
|
|
|
192 |
return;
|
|
|
193 |
}
|
|
|
194 |
if ($itemDetails.find('#dgmfgdate').val() === '') {
|
|
|
195 |
bootbox.alert('Mobile Mfg Date is required');
|
|
|
196 |
return;
|
|
|
197 |
}
|
|
|
198 |
let planCode = plan.productId;
|
|
|
199 |
let manuFacturedDate = $itemDetails.find('.dgmfgdate').val();
|
| 35002 |
ranu |
200 |
this.calculateQuote(planCode, this.props.itemId, this.props.devicePrice, manuFacturedDate, planName);
|
| 34798 |
ranu |
201 |
|
|
|
202 |
}
|
|
|
203 |
|
| 35002 |
ranu |
204 |
calculateQuote = (planCode, itemId, devicePrice, manuFacturedDate, planName) => {
|
| 34798 |
ranu |
205 |
doGetAjaxRequestHandler(
|
| 35002 |
ranu |
206 |
`${context}/getPlanQuote?planCode=${planCode}&itemId=${itemId}&sumInsured=${devicePrice}&manufacturedDate=${manuFacturedDate}&planName=${planName}`,
|
| 34798 |
ranu |
207 |
(responseText) => {
|
|
|
208 |
const response = JSON.parse(responseText);
|
|
|
209 |
console.log("quote call back", response);
|
|
|
210 |
|
| 35002 |
ranu |
211 |
if (response.afinityQuoteModel.policyStatus === "APPROVE" || response.afinityQuoteModel.message === "Success") {
|
| 34798 |
ranu |
212 |
const updatedPlan = {
|
| 34805 |
ranu |
213 |
premium: response.afinityQuoteModel.totalPremium,
|
|
|
214 |
dp: response.planDp,
|
|
|
215 |
correlationId: response.afinityQuoteModel.correlationId
|
| 34798 |
ranu |
216 |
};
|
|
|
217 |
|
|
|
218 |
this.setState((prevState) => ({
|
|
|
219 |
quotedPlans: {
|
|
|
220 |
...prevState.quotedPlans,
|
|
|
221 |
[planCode]: updatedPlan
|
|
|
222 |
}
|
|
|
223 |
}));
|
|
|
224 |
} else {
|
| 34805 |
ranu |
225 |
bootbox.alert("Quote failed: " + (response.afinityQuoteModel.message || "Unknown error"));
|
| 34798 |
ranu |
226 |
}
|
|
|
227 |
}
|
|
|
228 |
);
|
|
|
229 |
}
|
| 24440 |
amit.gupta |
230 |
}
|
|
|
231 |
|
| 31274 |
amit.gupta |
232 |
let reactRoot = null;
|
| 24440 |
amit.gupta |
233 |
|
| 34798 |
ranu |
234 |
function getInsurancePlansModal(insurancePlans, elePlanCheckedOn, devicePrice, itemId) {
|
| 31274 |
amit.gupta |
235 |
const domContainer = document.querySelector('.insurancedetails');
|
|
|
236 |
reactRoot = ReactDOM.createRoot(domContainer);
|
| 34798 |
ranu |
237 |
reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}
|
|
|
238 |
devicePrice={devicePrice} itemId={itemId}/>)
|
| 31274 |
amit.gupta |
239 |
$('#mobilePlansModal').modal({show: true});
|
|
|
240 |
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
|
| 32468 |
amit.gupta |
244 |
function calculateTotalAmount(inputEle) {
|
|
|
245 |
if (typeof inputEle !== "undefined") {
|
|
|
246 |
let itemId = $(inputEle).attr("itemid");
|
|
|
247 |
let unitPrice = inputEle.value;
|
|
|
248 |
$("#order-items").find(`input.unitPrice[itemid=${itemId}]`).each(function () {
|
|
|
249 |
this.value = unitPrice;
|
|
|
250 |
})
|
|
|
251 |
|
|
|
252 |
}
|
| 31274 |
amit.gupta |
253 |
var netPayableAmount = 0;
|
|
|
254 |
var totaInsuranceAmount = 0;
|
| 32329 |
amit.gupta |
255 |
$("#order-items").find('tbody>tr:gt(0)').each(function (index, el) {
|
| 31274 |
amit.gupta |
256 |
var rowTotal = 0;
|
|
|
257 |
let $tr = $(el);
|
|
|
258 |
var insuranceAmount = $tr.find('input.insuranceamount').val();
|
|
|
259 |
if (isNaN(insuranceAmount)) {
|
|
|
260 |
insuranceAmount = 0;
|
|
|
261 |
} else {
|
|
|
262 |
insuranceAmount = parseFloat(insuranceAmount);
|
|
|
263 |
}
|
| 30725 |
amit.gupta |
264 |
|
| 31274 |
amit.gupta |
265 |
var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
|
| 30725 |
amit.gupta |
266 |
|
| 31274 |
amit.gupta |
267 |
var unitPrice = parseFloat($(el).find('.unitPrice').val());
|
|
|
268 |
if (isNaN(unitPrice)) {
|
|
|
269 |
unitPrice = 0;
|
|
|
270 |
}
|
| 30725 |
amit.gupta |
271 |
|
| 31274 |
amit.gupta |
272 |
var discount = $(el).find('.discount').val();
|
|
|
273 |
if (isNaN(discount)) {
|
|
|
274 |
discount = 0;
|
|
|
275 |
}
|
| 23343 |
ashik.ali |
276 |
|
| 32329 |
amit.gupta |
277 |
rowTotal = (unitPrice - discount + insuranceAmount) * quantity;
|
| 31274 |
amit.gupta |
278 |
$tr.find('.totalPrice').val(rowTotal);
|
|
|
279 |
netPayableAmount += rowTotal;
|
|
|
280 |
totaInsuranceAmount += insuranceAmount;
|
|
|
281 |
});
|
|
|
282 |
if (totaInsuranceAmount > 0) {
|
|
|
283 |
$(".mk_insurance_row").show();
|
|
|
284 |
} else {
|
|
|
285 |
$(".mk_insurance_row").hide();
|
|
|
286 |
}
|
|
|
287 |
$('#cd').find('input.netPayableAmount').val(netPayableAmount);
|
| 23343 |
ashik.ali |
288 |
}
|
| 33795 |
ranu |
289 |
|
|
|
290 |
$(document).on('change', '.offerSelect', function () {
|
|
|
291 |
calculateAndUpdatePaymentOptions();
|
|
|
292 |
});
|
|
|
293 |
|
|
|
294 |
function calculateAndUpdatePaymentOptions() {
|
|
|
295 |
let totalSchemePayout = 0;
|
|
|
296 |
let totalPartnerPayout = 0;
|
|
|
297 |
|
|
|
298 |
// Loop through all selected options in each row
|
|
|
299 |
$('.offerSelect').each(function () {
|
|
|
300 |
let selectedOption = $(this).find('option:selected');
|
|
|
301 |
|
|
|
302 |
let schemePayout = parseFloat(selectedOption.data('scheme-payout')) || 0;
|
|
|
303 |
let partnerPayout = parseFloat(selectedOption.data('partner-payout')) || 0;
|
|
|
304 |
|
|
|
305 |
// Accumulate the payouts
|
|
|
306 |
totalSchemePayout += schemePayout;
|
|
|
307 |
totalPartnerPayout += partnerPayout;
|
|
|
308 |
});
|
|
|
309 |
|
|
|
310 |
// Now update the payment options with the accumulated values
|
|
|
311 |
updatePaymentOptions(totalSchemePayout, totalPartnerPayout);
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
function updatePaymentOptions(schemePayout, partnerPayout) {
|
|
|
315 |
$("#payment-option-id-amount-container").find('.paymentOptionAmount').each(function () {
|
|
|
316 |
let paymentOptionName = $(this).closest('.row').find('h5').text().trim();
|
|
|
317 |
|
|
|
318 |
if (paymentOptionName.includes('SAMSUNG UPGRADE')) {
|
|
|
319 |
$(this).val(schemePayout); // Set the total scheme payout
|
|
|
320 |
}
|
|
|
321 |
|
| 35055 |
ranu |
322 |
// if (paymentOptionName.includes('CASH DISCOUNT')) {
|
|
|
323 |
// $(this).val(partnerPayout); // Set the total partner payout
|
|
|
324 |
// }
|
| 33795 |
ranu |
325 |
});
|
|
|
326 |
}
|
|
|
327 |
|
| 34168 |
tejus.loha |
328 |
$(document).on('click', '.reset-irn-generated-panel', function () {
|
|
|
329 |
getResetIrnGeneratedPanel();
|
|
|
330 |
});
|
| 33795 |
ranu |
331 |
|
| 34168 |
tejus.loha |
332 |
$(document).on('click', '#search-invoice-for-irn-reset', function () {
|
|
|
333 |
var invoiceNumber = $("#search-invoice-number").val();
|
|
|
334 |
if (!invoiceNumber) {
|
|
|
335 |
alert("Please enter Invoice Number");
|
|
|
336 |
return;
|
|
|
337 |
}
|
|
|
338 |
doGetAjaxRequestHandler(`${context}/getTransactionForIrnReset?invoiceNumber=${invoiceNumber}`, function (response) {
|
|
|
339 |
$('#transaction-for-reset-irn-container').html(response);
|
|
|
340 |
});
|
|
|
341 |
});
|
| 33795 |
ranu |
342 |
|
| 34168 |
tejus.loha |
343 |
$(document).on('click', '#reset-irn-button', function () {
|
|
|
344 |
if (confirm("Are you sure to Reset IRN")) {
|
|
|
345 |
let invoices = [];
|
|
|
346 |
$('#eligible-irn-order tbody tr').each(function () {
|
|
|
347 |
const invoiceNumber = $(this).find('td:nth-child(3)').text();
|
|
|
348 |
invoices.push(invoiceNumber);
|
|
|
349 |
});
|
|
|
350 |
const invoiceNumbers = invoices.join(', ');
|
|
|
351 |
console.log('invoiceNumbersString - ', invoiceNumbers)
|
|
|
352 |
let url = `${context}/resetOrdersIrn?invoiceNumbers=${invoiceNumbers}`
|
|
|
353 |
doPutAjaxRequestHandler(url, function (response) {
|
|
|
354 |
if (response) {
|
|
|
355 |
alert(`IRN reset successfully for Invoice No - ${invoiceNumbers}`);
|
|
|
356 |
getResetIrnGeneratedPanel();
|
|
|
357 |
}
|
|
|
358 |
});
|
|
|
359 |
}
|
|
|
360 |
});
|
| 33795 |
ranu |
361 |
|
| 34168 |
tejus.loha |
362 |
function getResetIrnGeneratedPanel() {
|
|
|
363 |
doGetAjaxRequestHandler(`${context}/resetIrnGeneratedPanel`, function (response) {
|
|
|
364 |
$('#main-content').html(response);
|
|
|
365 |
});
|
|
|
366 |
}
|
| 33795 |
ranu |
367 |
|
|
|
368 |
|
|
|
369 |
|
| 34168 |
tejus.loha |
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|