Subversion Repositories SmartDukaan

Rev

Rev 35098 | Rev 35232 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 {
35098 ranu 93
 
31274 amit.gupta 94
    planChecked;
23343 ashik.ali 95
 
31274 amit.gupta 96
    constructor(props) {
97
        super(props);
34798 ranu 98
        this.state = {
99
            quotedPlans: {}
100
        };
31274 amit.gupta 101
    }
24440 amit.gupta 102
 
31274 amit.gupta 103
    render() {
104
        console.log(this.props);
105
        return <table className="table table-sm">
106
            <thead>
107
            <tr>
108
                <th>Plan Name</th>
109
                <th>Duration</th>
110
                <th>DP</th>
111
                <th>Selling Price</th>
112
                <th>Action</th>
113
            </tr>
114
            </thead>
115
            <tbody>
116
            {Object.keys(this.props.plans).map((planName, i) =>
34798 ranu 117
                this.props.plans[planName].map((plan, j) => {
118
                    const quoted = this.state.quotedPlans[plan.productId];
119
                    const isQuoted = !!quoted;
120
                    const displayPremium = isQuoted ? quoted.premium : (plan.premium || 0);
34805 ranu 121
                    const displayDP = isQuoted ? quoted.dp : (plan.dp || 0);
34798 ranu 122
 
123
                    return (
124
                        <tr key={`${i}-${j}`}>
35098 ranu 125
                            <td>
126
                                {plan.providerId == 6 ? (
35192 ranu 127
                                    <div style={{textAlign: "center"}}>
128
                                        <img
129
                                            src="/resources/images/ProtectPlusLogo2.jpg"
130
                                            style={{height: "70px"}}
131
                                            alt="ProtectPlus"
132
                                        />
133
                                        <div style={{fontSize: "13px", marginTop: "4px", color: "#666"}}>
134
                                            4% margin
135
                                        </div>
136
                                    </div>
35098 ranu 137
                                ) : (
138
                                    planName
139
                                )}
140
 
141
                            </td>
142
 
34798 ranu 143
                            <td>{plan.duration}</td>
144
                            <td>{displayDP ? displayDP.toFixed(2) : "-"}</td>
145
                            <td>{displayPremium ? displayPremium.toFixed(2) : "-"}</td>
146
 
147
                            <td>
148
                                {isQuoted || (plan.dp > 0 && plan.premium > 0) ? (
149
                                    <button
150
                                        className="btn btn-primary"
151
                                        data-key={plan.productId}
152
                                        data-amount={isQuoted ? quoted.premium.toFixed(2) : plan.premium.toFixed(2)}
35067 ranu 153
                                        data-correlationid={isQuoted ? quoted.correlationId : plan.correlationId}
34798 ranu 154
                                        onClick={this.planChecked}
155
                                    >
156
                                        Add
157
                                    </button>
158
                                ) : (
35002 ranu 159
                                    <button className="btn btn-warning"
160
                                            onClick={(e) => this.checkQuote(e, plan, planName)}>
34798 ranu 161
                                        Check Quote
162
                                    </button>
163
                                )}
164
                            </td>
165
                        </tr>
166
                    );
167
                })
168
            )}
31274 amit.gupta 169
            </tbody>
34798 ranu 170
 
31274 amit.gupta 171
        </table>;
172
    }
173
 
174
    planChecked = (e) => {
34798 ranu 175
        //debugger;
31274 amit.gupta 176
        let $itemDetails = $('div.itemdetails');
177
        if ($itemDetails.find('.dgram').val() === '') {
178
            bootbox.alert('Mobile RAM is required');
179
            return;
180
        }
181
        if ($itemDetails.find('.dgmemory').val() === '') {
182
            bootbox.alert('Mobile Memory is required');
183
            return;
184
        }
185
        if ($itemDetails.find('#dgmfgdate').val() === '') {
186
            bootbox.alert('Mobile Mfg Date is required');
187
            return;
188
        }
189
        let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');
190
        $orderItemRow.find('.insuranceid').val($(e.target).data('key'));
34798 ranu 191
        $orderItemRow.find('.correlationid').val($(e.target).data('correlationid'));
31274 amit.gupta 192
        $orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));
193
        $orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
194
        $orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
34798 ranu 195
        // $orderItemRow.find('.mfgdate').val(window.mfgDate);
196
        $orderItemRow.find('.mfgdate').val($itemDetails.find('.dgmfgdate').val());
31274 amit.gupta 197
        $('#mobilePlansModal').modal('hide');
198
        calculateTotalAmount();
199
    }
34798 ranu 200
 
35002 ranu 201
    checkQuote = (e, plan, planName) => {
34798 ranu 202
        //debugger;
203
        let $itemDetails = $('div.itemdetails');
204
        if ($itemDetails.find('.dgram').val() === '') {
205
            bootbox.alert('Mobile RAM is required');
206
            return;
207
        }
208
        if ($itemDetails.find('.dgmemory').val() === '') {
209
            bootbox.alert('Mobile Memory is required');
210
            return;
211
        }
212
        if ($itemDetails.find('#dgmfgdate').val() === '') {
213
            bootbox.alert('Mobile Mfg Date is required');
214
            return;
215
        }
216
        let planCode = plan.productId;
217
        let manuFacturedDate = $itemDetails.find('.dgmfgdate').val();
35002 ranu 218
        this.calculateQuote(planCode, this.props.itemId, this.props.devicePrice, manuFacturedDate, planName);
34798 ranu 219
 
220
    }
221
 
35002 ranu 222
    calculateQuote = (planCode, itemId, devicePrice, manuFacturedDate, planName) => {
34798 ranu 223
        doGetAjaxRequestHandler(
35002 ranu 224
            `${context}/getPlanQuote?planCode=${planCode}&itemId=${itemId}&sumInsured=${devicePrice}&manufacturedDate=${manuFacturedDate}&planName=${planName}`,
34798 ranu 225
            (responseText) => {
226
                const response = JSON.parse(responseText);
227
                console.log("quote call back", response);
228
 
35002 ranu 229
                if (response.afinityQuoteModel.policyStatus === "APPROVE" || response.afinityQuoteModel.message === "Success") {
34798 ranu 230
                    const updatedPlan = {
34805 ranu 231
                        premium: response.afinityQuoteModel.totalPremium,
232
                        dp: response.planDp,
233
                        correlationId: response.afinityQuoteModel.correlationId
34798 ranu 234
                    };
235
 
236
                    this.setState((prevState) => ({
237
                        quotedPlans: {
238
                            ...prevState.quotedPlans,
239
                            [planCode]: updatedPlan
240
                        }
241
                    }));
242
                } else {
34805 ranu 243
                    bootbox.alert("Quote failed: " + (response.afinityQuoteModel.message || "Unknown error"));
34798 ranu 244
                }
245
            }
246
        );
247
    }
24440 amit.gupta 248
}
249
 
31274 amit.gupta 250
let reactRoot = null;
24440 amit.gupta 251
 
34798 ranu 252
function getInsurancePlansModal(insurancePlans, elePlanCheckedOn, devicePrice, itemId) {
31274 amit.gupta 253
    const domContainer = document.querySelector('.insurancedetails');
254
    reactRoot = ReactDOM.createRoot(domContainer);
34798 ranu 255
    reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}
256
                                       devicePrice={devicePrice} itemId={itemId}/>)
31274 amit.gupta 257
    $('#mobilePlansModal').modal({show: true});
258
 
259
}
260
 
261
 
32468 amit.gupta 262
function calculateTotalAmount(inputEle) {
263
    if (typeof inputEle !== "undefined") {
264
        let itemId = $(inputEle).attr("itemid");
265
        let unitPrice = inputEle.value;
266
        $("#order-items").find(`input.unitPrice[itemid=${itemId}]`).each(function () {
267
            this.value = unitPrice;
268
        })
269
 
270
    }
31274 amit.gupta 271
    var netPayableAmount = 0;
272
    var totaInsuranceAmount = 0;
32329 amit.gupta 273
    $("#order-items").find('tbody>tr:gt(0)').each(function (index, el) {
31274 amit.gupta 274
        var rowTotal = 0;
275
        let $tr = $(el);
276
        var insuranceAmount = $tr.find('input.insuranceamount').val();
277
        if (isNaN(insuranceAmount)) {
278
            insuranceAmount = 0;
279
        } else {
280
            insuranceAmount = parseFloat(insuranceAmount);
281
        }
30725 amit.gupta 282
 
31274 amit.gupta 283
        var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
30725 amit.gupta 284
 
31274 amit.gupta 285
        var unitPrice = parseFloat($(el).find('.unitPrice').val());
286
        if (isNaN(unitPrice)) {
287
            unitPrice = 0;
288
        }
30725 amit.gupta 289
 
31274 amit.gupta 290
        var discount = $(el).find('.discount').val();
291
        if (isNaN(discount)) {
292
            discount = 0;
293
        }
23343 ashik.ali 294
 
32329 amit.gupta 295
        rowTotal = (unitPrice - discount + insuranceAmount) * quantity;
31274 amit.gupta 296
        $tr.find('.totalPrice').val(rowTotal);
297
        netPayableAmount += rowTotal;
298
        totaInsuranceAmount += insuranceAmount;
299
    });
300
    if (totaInsuranceAmount > 0) {
301
        $(".mk_insurance_row").show();
302
    } else {
303
        $(".mk_insurance_row").hide();
304
    }
305
    $('#cd').find('input.netPayableAmount').val(netPayableAmount);
23343 ashik.ali 306
}
33795 ranu 307
 
308
$(document).on('change', '.offerSelect', function () {
309
    calculateAndUpdatePaymentOptions();
310
});
311
 
312
function calculateAndUpdatePaymentOptions() {
313
    let totalSchemePayout = 0;
314
    let totalPartnerPayout = 0;
315
 
316
    // Loop through all selected options in each row
317
    $('.offerSelect').each(function () {
318
        let selectedOption = $(this).find('option:selected');
319
 
320
        let schemePayout = parseFloat(selectedOption.data('scheme-payout')) || 0;
321
        let partnerPayout = parseFloat(selectedOption.data('partner-payout')) || 0;
322
 
323
        // Accumulate the payouts
324
        totalSchemePayout += schemePayout;
325
        totalPartnerPayout += partnerPayout;
326
    });
327
 
328
    // Now update the payment options with the accumulated values
329
    updatePaymentOptions(totalSchemePayout, totalPartnerPayout);
330
}
331
 
332
function updatePaymentOptions(schemePayout, partnerPayout) {
333
    $("#payment-option-id-amount-container").find('.paymentOptionAmount').each(function () {
334
        let paymentOptionName = $(this).closest('.row').find('h5').text().trim();
335
 
336
        if (paymentOptionName.includes('SAMSUNG UPGRADE')) {
337
            $(this).val(schemePayout);  // Set the total scheme payout
338
        }
339
 
35055 ranu 340
        // if (paymentOptionName.includes('CASH DISCOUNT')) {
341
        //     $(this).val(partnerPayout);  // Set the total partner payout
342
        // }
33795 ranu 343
    });
344
}
345
 
34168 tejus.loha 346
$(document).on('click', '.reset-irn-generated-panel', function () {
347
    getResetIrnGeneratedPanel();
348
});
33795 ranu 349
 
34168 tejus.loha 350
$(document).on('click', '#search-invoice-for-irn-reset', function () {
351
    var invoiceNumber = $("#search-invoice-number").val();
352
    if (!invoiceNumber) {
353
        alert("Please enter Invoice Number");
354
        return;
355
    }
356
    doGetAjaxRequestHandler(`${context}/getTransactionForIrnReset?invoiceNumber=${invoiceNumber}`, function (response) {
357
        $('#transaction-for-reset-irn-container').html(response);
358
    });
359
});
33795 ranu 360
 
34168 tejus.loha 361
$(document).on('click', '#reset-irn-button', function () {
362
    if (confirm("Are you sure to Reset IRN")) {
363
        let invoices = [];
364
        $('#eligible-irn-order tbody tr').each(function () {
365
            const invoiceNumber = $(this).find('td:nth-child(3)').text();
366
            invoices.push(invoiceNumber);
367
        });
368
        const invoiceNumbers = invoices.join(', ');
369
        console.log('invoiceNumbersString - ', invoiceNumbers)
370
        let url = `${context}/resetOrdersIrn?invoiceNumbers=${invoiceNumbers}`
371
        doPutAjaxRequestHandler(url, function (response) {
372
            if (response) {
373
                alert(`IRN reset successfully for Invoice No - ${invoiceNumbers}`);
374
                getResetIrnGeneratedPanel();
375
            }
376
        });
377
    }
378
});
33795 ranu 379
 
34168 tejus.loha 380
function getResetIrnGeneratedPanel() {
381
    doGetAjaxRequestHandler(`${context}/resetIrnGeneratedPanel`, function (response) {
382
        $('#main-content').html(response);
383
    });
384
}
33795 ranu 385
 
386
 
387
 
34168 tejus.loha 388
 
389
 
390
 
391