| 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) {
|
|
|
80 |
getInsurancePlansModal(obj, that);
|
|
|
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);
|
|
|
97 |
}
|
| 24440 |
amit.gupta |
98 |
|
| 31274 |
amit.gupta |
99 |
render() {
|
|
|
100 |
console.log(this.props);
|
|
|
101 |
return <table className="table table-sm">
|
|
|
102 |
<thead>
|
|
|
103 |
<tr>
|
|
|
104 |
<th>Plan Name</th>
|
|
|
105 |
<th>Duration</th>
|
|
|
106 |
<th>DP</th>
|
|
|
107 |
<th>Selling Price</th>
|
|
|
108 |
<th>Action</th>
|
|
|
109 |
</tr>
|
|
|
110 |
</thead>
|
|
|
111 |
<tbody>
|
|
|
112 |
{Object.keys(this.props.plans).map((planName, i) =>
|
|
|
113 |
this.props.plans[planName].map((plan, i) =>
|
|
|
114 |
<tr key={i}>
|
|
|
115 |
<td>{planName}</td>
|
|
|
116 |
<td>{plan.duration}</td>
|
|
|
117 |
<td>{plan.dp}</td>
|
|
|
118 |
<td>{plan.premium}</td>
|
|
|
119 |
<td>
|
|
|
120 |
<button className="btn btn-primary" data-key={plan.productId}
|
|
|
121 |
data-amount={plan.premium} onClick={this.planChecked}>Add
|
|
|
122 |
</button>
|
|
|
123 |
</td>
|
|
|
124 |
</tr>))}
|
|
|
125 |
</tbody>
|
|
|
126 |
</table>;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
planChecked = (e) => {
|
|
|
130 |
debugger;
|
|
|
131 |
let $itemDetails = $('div.itemdetails');
|
|
|
132 |
if ($itemDetails.find('.dgram').val() === '') {
|
|
|
133 |
bootbox.alert('Mobile RAM is required');
|
|
|
134 |
return;
|
|
|
135 |
}
|
|
|
136 |
if ($itemDetails.find('.dgmemory').val() === '') {
|
|
|
137 |
bootbox.alert('Mobile Memory is required');
|
|
|
138 |
return;
|
|
|
139 |
}
|
|
|
140 |
if ($itemDetails.find('#dgmfgdate').val() === '') {
|
|
|
141 |
bootbox.alert('Mobile Mfg Date is required');
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');
|
|
|
145 |
$orderItemRow.find('.insuranceid').val($(e.target).data('key'));
|
|
|
146 |
$orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));
|
|
|
147 |
$orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
|
|
|
148 |
$orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
|
|
|
149 |
$orderItemRow.find('.mfgdate').val(window.mfgDate);
|
|
|
150 |
$('#mobilePlansModal').modal('hide');
|
|
|
151 |
calculateTotalAmount();
|
|
|
152 |
}
|
| 24440 |
amit.gupta |
153 |
}
|
|
|
154 |
|
| 31274 |
amit.gupta |
155 |
let reactRoot = null;
|
| 24440 |
amit.gupta |
156 |
|
| 31274 |
amit.gupta |
157 |
function getInsurancePlansModal(insurancePlans, elePlanCheckedOn) {
|
|
|
158 |
const domContainer = document.querySelector('.insurancedetails');
|
|
|
159 |
reactRoot = ReactDOM.createRoot(domContainer);
|
|
|
160 |
reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}/>)
|
|
|
161 |
$('#mobilePlansModal').modal({show: true});
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
|
| 32468 |
amit.gupta |
166 |
function calculateTotalAmount(inputEle) {
|
|
|
167 |
if (typeof inputEle !== "undefined") {
|
|
|
168 |
let itemId = $(inputEle).attr("itemid");
|
|
|
169 |
let unitPrice = inputEle.value;
|
|
|
170 |
$("#order-items").find(`input.unitPrice[itemid=${itemId}]`).each(function () {
|
|
|
171 |
this.value = unitPrice;
|
|
|
172 |
})
|
|
|
173 |
|
|
|
174 |
}
|
| 31274 |
amit.gupta |
175 |
var netPayableAmount = 0;
|
|
|
176 |
var totaInsuranceAmount = 0;
|
| 32329 |
amit.gupta |
177 |
$("#order-items").find('tbody>tr:gt(0)').each(function (index, el) {
|
| 31274 |
amit.gupta |
178 |
var rowTotal = 0;
|
|
|
179 |
let $tr = $(el);
|
|
|
180 |
var insuranceAmount = $tr.find('input.insuranceamount').val();
|
|
|
181 |
if (isNaN(insuranceAmount)) {
|
|
|
182 |
insuranceAmount = 0;
|
|
|
183 |
} else {
|
|
|
184 |
insuranceAmount = parseFloat(insuranceAmount);
|
|
|
185 |
}
|
| 30725 |
amit.gupta |
186 |
|
| 31274 |
amit.gupta |
187 |
var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
|
| 30725 |
amit.gupta |
188 |
|
| 31274 |
amit.gupta |
189 |
var unitPrice = parseFloat($(el).find('.unitPrice').val());
|
|
|
190 |
if (isNaN(unitPrice)) {
|
|
|
191 |
unitPrice = 0;
|
|
|
192 |
}
|
| 30725 |
amit.gupta |
193 |
|
| 31274 |
amit.gupta |
194 |
var discount = $(el).find('.discount').val();
|
|
|
195 |
if (isNaN(discount)) {
|
|
|
196 |
discount = 0;
|
|
|
197 |
}
|
| 23343 |
ashik.ali |
198 |
|
| 32329 |
amit.gupta |
199 |
rowTotal = (unitPrice - discount + insuranceAmount) * quantity;
|
| 31274 |
amit.gupta |
200 |
$tr.find('.totalPrice').val(rowTotal);
|
|
|
201 |
netPayableAmount += rowTotal;
|
|
|
202 |
totaInsuranceAmount += insuranceAmount;
|
|
|
203 |
});
|
|
|
204 |
if (totaInsuranceAmount > 0) {
|
|
|
205 |
$(".mk_insurance_row").show();
|
|
|
206 |
} else {
|
|
|
207 |
$(".mk_insurance_row").hide();
|
|
|
208 |
}
|
|
|
209 |
$('#cd').find('input.netPayableAmount').val(netPayableAmount);
|
| 23343 |
ashik.ali |
210 |
}
|
| 33795 |
ranu |
211 |
|
|
|
212 |
$(document).on('change', '.offerSelect', function () {
|
|
|
213 |
calculateAndUpdatePaymentOptions();
|
|
|
214 |
});
|
|
|
215 |
|
|
|
216 |
function calculateAndUpdatePaymentOptions() {
|
|
|
217 |
let totalSchemePayout = 0;
|
|
|
218 |
let totalPartnerPayout = 0;
|
|
|
219 |
|
|
|
220 |
// Loop through all selected options in each row
|
|
|
221 |
$('.offerSelect').each(function () {
|
|
|
222 |
let selectedOption = $(this).find('option:selected');
|
|
|
223 |
|
|
|
224 |
let schemePayout = parseFloat(selectedOption.data('scheme-payout')) || 0;
|
|
|
225 |
let partnerPayout = parseFloat(selectedOption.data('partner-payout')) || 0;
|
|
|
226 |
|
|
|
227 |
// Accumulate the payouts
|
|
|
228 |
totalSchemePayout += schemePayout;
|
|
|
229 |
totalPartnerPayout += partnerPayout;
|
|
|
230 |
});
|
|
|
231 |
|
|
|
232 |
// Now update the payment options with the accumulated values
|
|
|
233 |
updatePaymentOptions(totalSchemePayout, totalPartnerPayout);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
function updatePaymentOptions(schemePayout, partnerPayout) {
|
|
|
237 |
$("#payment-option-id-amount-container").find('.paymentOptionAmount').each(function () {
|
|
|
238 |
let paymentOptionName = $(this).closest('.row').find('h5').text().trim();
|
|
|
239 |
|
|
|
240 |
if (paymentOptionName.includes('SAMSUNG UPGRADE')) {
|
|
|
241 |
$(this).val(schemePayout); // Set the total scheme payout
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
if (paymentOptionName.includes('CASH DISCOUNT')) {
|
|
|
245 |
$(this).val(partnerPayout); // Set the total partner payout
|
|
|
246 |
}
|
|
|
247 |
});
|
|
|
248 |
}
|
|
|
249 |
|
| 34168 |
tejus.loha |
250 |
$(document).on('click', '.reset-irn-generated-panel', function () {
|
|
|
251 |
getResetIrnGeneratedPanel();
|
|
|
252 |
});
|
| 33795 |
ranu |
253 |
|
| 34168 |
tejus.loha |
254 |
$(document).on('click', '#search-invoice-for-irn-reset', function () {
|
|
|
255 |
var invoiceNumber = $("#search-invoice-number").val();
|
|
|
256 |
if (!invoiceNumber) {
|
|
|
257 |
alert("Please enter Invoice Number");
|
|
|
258 |
return;
|
|
|
259 |
}
|
|
|
260 |
doGetAjaxRequestHandler(`${context}/getTransactionForIrnReset?invoiceNumber=${invoiceNumber}`, function (response) {
|
|
|
261 |
$('#transaction-for-reset-irn-container').html(response);
|
|
|
262 |
});
|
|
|
263 |
});
|
| 33795 |
ranu |
264 |
|
| 34168 |
tejus.loha |
265 |
$(document).on('click', '#reset-irn-button', function () {
|
|
|
266 |
if (confirm("Are you sure to Reset IRN")) {
|
|
|
267 |
let invoices = [];
|
|
|
268 |
$('#eligible-irn-order tbody tr').each(function () {
|
|
|
269 |
const invoiceNumber = $(this).find('td:nth-child(3)').text();
|
|
|
270 |
invoices.push(invoiceNumber);
|
|
|
271 |
});
|
|
|
272 |
const invoiceNumbers = invoices.join(', ');
|
|
|
273 |
console.log('invoiceNumbersString - ', invoiceNumbers)
|
|
|
274 |
let url = `${context}/resetOrdersIrn?invoiceNumbers=${invoiceNumbers}`
|
|
|
275 |
doPutAjaxRequestHandler(url, function (response) {
|
|
|
276 |
if (response) {
|
|
|
277 |
alert(`IRN reset successfully for Invoice No - ${invoiceNumbers}`);
|
|
|
278 |
getResetIrnGeneratedPanel();
|
|
|
279 |
}
|
|
|
280 |
});
|
|
|
281 |
}
|
|
|
282 |
});
|
| 33795 |
ranu |
283 |
|
| 34168 |
tejus.loha |
284 |
function getResetIrnGeneratedPanel() {
|
|
|
285 |
doGetAjaxRequestHandler(`${context}/resetIrnGeneratedPanel`, function (response) {
|
|
|
286 |
$('#main-content').html(response);
|
|
|
287 |
});
|
|
|
288 |
}
|
| 33795 |
ranu |
289 |
|
|
|
290 |
|
|
|
291 |
|
| 34168 |
tejus.loha |
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|