Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
33507 tejus.loha 1
$(document).on('click', ".onboarding-form1", function () {
33845 tejus.loha 2
    doGetAjaxRequestHandler(`${context}/loiForm`,
33507 tejus.loha 3
        function (response) {
4
            $('#' + 'main-content').html(response);
5
        });
6
});
7
 
33577 tejus.loha 8
 
9
$(document).on('change', "#maritalStatus", function () {
10
    let maritalStatus = $(this).val();
11
    if (maritalStatus == 1) {
12
        $(".loiAnniversaryDate").removeClass('hide-model');
13
        $(".loiAnniversaryDate").addClass('show-model');
14
    } else {
15
        $(".loiAnniversaryDate").removeClass('show-model');
16
        $(".loiAnniversaryDate").addClass('hide-model');
17
    }
18
 
19
});
20
 
33578 tejus.loha 21
 
33885 tejus.loha 22
$(document).on('click', ".mk_submit_loi_form", function () {
33577 tejus.loha 23
    // Gather input values
24
    const referId = $('select[name="referId"]').val();
34107 tejus.loha 25
    const stateHead = $('select[name="stateHead"]').val();
26
    const bdm = $('select[name="bdm"]').val();
34310 tejus.loha 27
    let billingAddress = $('select[name="billingAddress"]').val();
28
    if(!billingAddress){
29
        const addrFieldData = {
30
            "bno": "",
31
            "bnm": "",
32
            "st": "",
33
            "locality": "",
34
            "loc": "",
35
            "dst": "",
36
            "pncd": "",
37
            "stcd": ""
38
        };
39
 
40
        // Dynamically create input fields
41
        let address = [];
42
        Object.keys(addrFieldData).forEach(function (field) {
43
             addrFieldData[field] = $('input[name="'+field+'"]').val();
44
        });
45
        billingAddress = JSON.stringify(addrFieldData);
46
 
47
    }
33582 tejus.loha 48
    const acquiredDate = $('input[name="acquiredDate"]').val();
33577 tejus.loha 49
    const firstName = $('input[name="firstName"]').val();
50
    const lastName = $('input[name="lastName"]').val();
51
    const mobile = $('input[name="mobile"]').val();
33780 tejus.loha 52
 
53
    // validate email pattern
54
    const emailValue = $('input[name="email"]').val();
55
    var email;
56
    if (emailValue.length > 0) {
57
        if (isValidEmail(emailValue)) {
58
            email = emailValue;
59
        } else {
60
            alert("Please check your Email Address");
61
            return;
62
        }
63
    }
33577 tejus.loha 64
    const landline = $('input[name="landline"]').val();
65
    const dob = $('input[name="dob"]').val();
33624 tejus.loha 66
    var today = new Date();
67
    var birthDate = new Date(dob);
68
    var age = today.getFullYear() - birthDate.getFullYear();
69
    var monthDiff = today.getMonth() - birthDate.getMonth();
70
 
71
    if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
72
        age--;
73
    }
33577 tejus.loha 74
    var maritalStatus = $('select[name="maritalStatus"]').val();
75
    const anniversaryDate = $('input[name="anniversaryDate"]').val();
76
    const panNo = $('input[name="panNo"]').val();
77
    const adharNo = $('input[name="adharNo"]').val();
78
    const gstNo = $('input[name="gstNo"]').val();
79
    const bankName = $('input[name="bankName"]').val();
80
    const ifscCode = $('input[name="ifscCode"]').val();
81
    const accountNo = $('input[name="accountNo"]').val();
82
    const businessType = $('select[name="businessType"]').val();
83
    const companyName = $('input[name="companyName"]').val();
84
    const gstPin = $('input[name="gstPin"]').val();
85
    const gstState = $('input[name="gstState"]').val();
86
    const gstCity = $('input[name="gstCity"]').val();
87
    const gstDistrict = $('input[name="gstDistrict"]').val();
88
    const agreeWalletValue = $('select[name="agreeWalletValue"]').val();
89
    const storeArea = $('input[name="storeArea"]').val();
90
    const storePotential = $('input[name="storePotential"]').val();
35971 aman 91
    let financeOptions = [];
92
    document.querySelectorAll(".finance-code-input").forEach(function (input) {
93
        var code = input.value.trim();
94
        if (code) {
95
            financeOptions.push({
96
                paymentOptionId: parseInt(input.getAttribute("data-payment-option-id")),
97
                financeCode: code
98
            });
99
        }
100
    });
33658 tejus.loha 101
    let brandCommitment = [];
102
    var brandCommitmentInputs = document.querySelectorAll(".brand-commitment");
35971 aman 103
    var hasInvalidQty = false;
33658 tejus.loha 104
    brandCommitmentInputs.forEach(function (input) {
105
        var commitmentValue = parseInt(input.value);
106
        if (!isNaN(commitmentValue)) {
35971 aman 107
            if (commitmentValue > 1000) {
108
                hasInvalidQty = true;
109
            }
33658 tejus.loha 110
            brandCommitment.push({
111
                brandName: input.getAttribute("name"),
112
                value: commitmentValue
113
            });
114
        }
115
    });
35971 aman 116
    if (hasInvalidQty) {
117
        alert("Quantity per brand cannot exceed 1000. Please enter valid quantities.");
118
        return;
119
    }
33658 tejus.loha 120
    let totalCommitment = brandCommitment.reduce((total, commitment) => total + commitment.value, 0);
35971 aman 121
    // Calculate estimated value: total qty × 20000 (average smartphone value)
122
    let estimatedValue = totalCommitment * 20000;
123
    let minCommit = estimatedValue >= (0.7 * storePotential);
124
    const lessCommitReason = $('textarea[name="lessCommitReason"]').val();
33577 tejus.loha 125
    const agreedBrandFees = $('select[name="agreedBrandFees"]').val();
33624 tejus.loha 126
    const values = agreedBrandFees.split(/[-]/); // Split the string
127
    const brandFee = parseFloat(values[1]);
33577 tejus.loha 128
    const brandFeesCollected = $('input[name="brandFeesCollected"]').val();
129
    const paymentMode = $('select[name="paymentMode"]').val();
130
    const paymentReferenceNo = $('input[name="paymentReferenceNo"]').val();
33578 tejus.loha 131
    const feeCollectingDate = $('input[name="feeCollectingDate"]').val();
33885 tejus.loha 132
    const paymentAttachment = $('input[name="paymentAttachment"]').val();
33577 tejus.loha 133
 
134
    let missingFields = [];
135
    if (!firstName) missingFields.push('First Name');
136
    if (!lastName) missingFields.push('Last Name');
137
    if (mobile.length < 10 || !mobile) {
138
        missingFields.push('Mobile number should be 10 digit');
139
    }
33658 tejus.loha 140
    if (!minCommit) {
33577 tejus.loha 141
        if (!lessCommitReason) missingFields.push('Less Commit Reason');
142
    }
143
    if (!maritalStatus) missingFields.push('Marital Status');
144
    if (maritalStatus == 1) {
145
        if (!anniversaryDate) missingFields.push('Anniversary Date');
146
    }
147
    if (!email) missingFields.push('Email');
34107 tejus.loha 148
    if (!referId) missingFields.push('Refer By');
149
    if (!bdm) missingFields.push('Bdm');
150
    if (!stateHead) missingFields.push('State head');
33582 tejus.loha 151
    if (!acquiredDate) missingFields.push('Acquired date');
33577 tejus.loha 152
    if (!dob) missingFields.push('dob(Date of Birth)');
33624 tejus.loha 153
    if (age <= 18) missingFields.push('You must be at least 18 years old to Fill LOI FORM. ');
33577 tejus.loha 154
    if (!panNo) missingFields.push('Pan Number');
155
    if (!adharNo) missingFields.push('Aadhar Number');
156
    if (!gstNo) missingFields.push('GST Number');
157
    if (!bankName) missingFields.push('Bank Name');
158
    if (!ifscCode) missingFields.push('IFSC code');
159
    if (!accountNo) missingFields.push('Account Number');
160
    if (!businessType) missingFields.push('businessType');
161
    if (!companyName) missingFields.push('Company Name');
162
    if (!agreeWalletValue) missingFields.push('Agree Wallet Value');
163
    if (!storeArea) missingFields.push('storeArea');
164
    if (!storePotential) missingFields.push('Store Potential');
165
    if (!agreedBrandFees) missingFields.push('Agreed Brand Fees');
166
    if (!brandFeesCollected) missingFields.push('Brand Fees Collected');
33845 tejus.loha 167
    if (brandFeesCollected > brandFee) missingFields.push('The collected brand fee must not exceed the agreed brand fees.');
33577 tejus.loha 168
    if (!paymentMode) missingFields.push('Payment Mode');
169
    if (!paymentReferenceNo) missingFields.push('Payment Reference No');
33578 tejus.loha 170
    if (!feeCollectingDate) missingFields.push('Fee Collecting Date');
33885 tejus.loha 171
    if (!paymentAttachment) missingFields.push('Payment screenshot ');
33577 tejus.loha 172
    if (missingFields.length > 0) {
173
        alert('The following fields are required: ' + missingFields.join(', '));
174
        return;
175
    }
176
    const loiFormData = {
177
        referId: referId,
34107 tejus.loha 178
        stateHead: stateHead,
179
        bdm: bdm,
33577 tejus.loha 180
        businessType: businessType,
33582 tejus.loha 181
        acquiredDate: acquiredDate,
33577 tejus.loha 182
        firstName: firstName,
183
        lastName: lastName,
184
        mobile: mobile,
185
        email: email,
186
        landline: landline,
187
        dob: dob,
188
        anniversaryDate: anniversaryDate,
189
        panNo: panNo,
190
        adharNo: adharNo,
191
        gstNo: gstNo,
192
        bankName: bankName,
193
        ifscCode: ifscCode,
194
        accountNo: accountNo,
195
        companyName: companyName,
196
        gstPin: gstPin,
197
        gstState: gstState,
198
        gstCity: gstCity,
199
        gstDistrict: gstDistrict,
200
        agreeWalletValue: agreeWalletValue,
201
        storeArea: storeArea,
202
        storePotential: storePotential,
35971 aman 203
        financeOptions: financeOptions,
33577 tejus.loha 204
        lessCommitReason: lessCommitReason,
205
        agreedBrandFees: agreedBrandFees,
206
        brandFeesCollected: brandFeesCollected,
207
        paymentMode: paymentMode,
208
        paymentReferenceNo: paymentReferenceNo,
33578 tejus.loha 209
        feeCollectingTimeStamp: feeCollectingDate,
33885 tejus.loha 210
        paymentAttachment: paymentAttachment,
33658 tejus.loha 211
        billingAddress: billingAddress,
212
        brandCommitment: brandCommitment
33577 tejus.loha 213
    };
33658 tejus.loha 214
 
33577 tejus.loha 215
    if (confirm("Are you sure to submit the form ?")) {
216
        doPostAjaxRequestWithJsonHandler(`${context}/submitLoiForm`, JSON.stringify(loiFormData), function (response) {
217
            console.log('responsee', response);
33507 tejus.loha 218
            if (response) {
219
                alert("Your LOI form Submitted successfully ");
220
                pendingLoiForm("main-content");
221
 
222
            } else {
223
                alert("Your LOI form not Submitted , try again ");
33845 tejus.loha 224
                doGetAjaxRequestHandler(`${context}/loiForm`,
33507 tejus.loha 225
                    function (response) {
226
                        $('#' + 'main-content').html(response);
227
                    });
228
            }
229
        });
230
    }
231
});
33578 tejus.loha 232
 
33658 tejus.loha 233
$(document).on('click', ".updateLoiForm", function () {
33507 tejus.loha 234
    let loiId = $(this).val();
33658 tejus.loha 235
    doGetAjaxRequestHandler(context + "/updateLoiForm?loiId=" + loiId,
33507 tejus.loha 236
        function (response) {
237
            $('#' + 'main-content').html(response);
238
        });
239
});
33879 tejus.loha 240
 
33710 tejus.loha 241
$(document).on('click', ".save_agree_brand_fee", function () {
242
    let loiId = $(this).val();
243
    var $tr = $(this).closest('tr');
244
    var agreedBrandFee = $tr.find('input[name="brandFee"]').val();
34085 tejus.loha 245
    var brandType = $tr.find('select[name="brandType"]').val();
33710 tejus.loha 246
    if (confirm("Are you sure to change Agreed brand fee")) {
34085 tejus.loha 247
        doPutAjaxRequestHandler(`${context}/updateAgreedBrandFee?loiId=${loiId}&brandFee=${agreedBrandFee}&storeType=${brandType}`, function (response) {
33710 tejus.loha 248
            pendingLoiForm("main-content");
249
        });
250
    } else {
251
        pendingLoiForm("main-content");
252
    }
253
});
33507 tejus.loha 254
 
33658 tejus.loha 255
$(document).on('click', ".updateLoiFormDataButton", function () {
256
    let loiId = $(this).data('loiid');
257
    const firstName = $('input[name="firstName"]').val();
258
    const lastName = $('input[name="lastName"]').val();
259
    const mobile = $('input[name="mobile"]').val();
260
    const email = $('input[name="email"]').val();
261
    const landline = $('input[name="landline"]').val();
262
    const dob = $('input[name="dob"]').val();
263
    const panNo = $('input[name="panNo"]').val();
264
    const adharNo = $('input[name="adharNo"]').val();
265
    let missingFields = [];
266
    if (!firstName) missingFields.push('First Name');
267
    if (!lastName) missingFields.push('Last Name');
268
    if (mobile.length < 10 || !mobile) {
269
        missingFields.push('Mobile number should be 10 digit');
270
    }
271
    if (!dob) missingFields.push('dob(Date of Birth)');
272
    if (!panNo) missingFields.push('Pan Number');
273
    if (!adharNo) missingFields.push('Aadhar Number');
274
    if (!email) missingFields.push('Email');
275
    if (missingFields.length > 0) {
276
        alert('The following fields are required: ' + missingFields.join(', '));
277
        return;
278
    }
279
    const loiFormData = {
280
        firstName: firstName,
281
        lastName: lastName,
282
        mobile: mobile,
283
        email: email,
284
        landline: landline,
285
        dob: dob,
286
        panNo: panNo,
287
        adharNo: adharNo
288
    };
289
    alert("you want update ..");
290
    doPostAjaxRequestWithJsonHandler(`${context}/updateLoiFormData?loiId=${loiId}`, JSON.stringify(loiFormData), function (response) {
33507 tejus.loha 291
        pendingLoiForm("main-content");
292
    });
293
 
294
});
295
 
296
$(document).on('click', ".pending-onboarding-form", function () {
33710 tejus.loha 297
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 298
        function (response) {
299
            $('#' + 'main-content').html(response);
300
        });
301
});
302
$(document).on('click', "#addBrandFeePayment", function () {
35971 aman 303
    var $btn = $(this);
304
    if ($btn.prop('disabled')) return false;
33507 tejus.loha 305
    let formData = objectifyForm($("form[name='brandFeeCollectionForm']").serializeArray());
35971 aman 306
    let loiId = $btn.val();
33507 tejus.loha 307
    for (var key in formData) {
308
        if (formData.hasOwnProperty(key) && formData[key].trim() === '') {
309
            alert("The (" + key + ") value is blank please fill this field !");
310
            return false;
311
        }
312
    }
313
    let jsonData = JSON.stringify(formData);
33658 tejus.loha 314
    if (confirm("Are you sure to add payment ?")) {
35971 aman 315
        $btn.prop('disabled', true);
33525 tejus.loha 316
        doPostAjaxRequestWithJsonHandler(`${context}/brandfeeCollection?loiId=` + loiId, jsonData, function (response) {
317
            if (response) {
318
                alert("Payment add successfully...");
35971 aman 319
                $('#brandFeeCollectionModel').modal('hide');
33525 tejus.loha 320
                pendingLoiForm("main-content");
321
            }
35971 aman 322
            $btn.prop('disabled', false);
33525 tejus.loha 323
        });
324
    } else {
33658 tejus.loha 325
        alert("Payment is not add.");
33525 tejus.loha 326
    }
33507 tejus.loha 327
});
328
 
329
$(document).on('click', ".generateLoi", function () {
330
    let loiId = $(this).val();
331
    doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
332
        function (response) {
333
            $('#' + 'main-content').html(response);
334
        });
335
});
336
 
34085 tejus.loha 337
// $(document).on('change', 'select[name="pageSize"]', function () {
338
//     let pageSize = $(this).val();
339
//     console.log("pageSize - ", pageSize);
340
//     doGetAjaxRequestHandler(`${context}/pendingLoiForm?pageSize=${pageSize}&pageNumber=${1}`,
341
//         function (response) {
342
//             $('#' + 'main-content').html(response);
343
//         });
344
// });
345
 
33845 tejus.loha 346
$(document).on('click', ".mk-approve-loi", function () {
347
    let loiId = $(this).val();
348
    let companyName = $(this).data('company');
349
    let flag = $(this).data('flag');
350
    if (flag === 1) {
351
        if (confirm(`Are you sure Approve Loi of  ${companyName} `)) {
352
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${true}`,
353
                function (response) {
354
                    alert("Loi Approved successfully");
355
                    pendingLoiForm("main-content");
356
                });
357
        }
358
    } else {
359
        if (confirm(`Are you sure to Reject "${companyName}" LOI`)) {
360
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${false}`,
361
                function (response) {
362
                    pendingLoiForm("main-content");
363
                });
364
        }
365
    }
366
});
367
 
35977 aman 368
var otpCountdownTimer = null;
369
 
370
function startResendCountdown(btn) {
371
    var remaining = 30;
372
    btn.prop('disabled', true).removeClass('btn-success').addClass('btn-warning');
373
    btn.text('Resend OTP (' + remaining + 's)');
374
    otpCountdownTimer = setInterval(function () {
375
        remaining--;
376
        if (remaining <= 0) {
377
            clearInterval(otpCountdownTimer);
378
            otpCountdownTimer = null;
379
            btn.text('Resend OTP').prop('disabled', false);
380
        } else {
381
            btn.text('Resend OTP (' + remaining + 's)');
382
        }
383
    }, 1000);
384
}
385
 
33507 tejus.loha 386
$(document).on('click', "#LOI_otp", function () {
35977 aman 387
    let btn = $(this);
388
    let loiId = btn.val();
389
    if (otpCountdownTimer) return;
390
    let isResend = btn.text().indexOf('Resend') >= 0;
391
    if (!isResend && !confirm("Are you sure to send OTP ?")) return;
392
    btn.prop('disabled', true).text('Sending...');
393
    doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
394
        function (response) {
395
            $('#otp_status').show().text('OTP Sent Successfully!');
396
            startResendCountdown(btn);
397
        });
33507 tejus.loha 398
});
399
 
400
//confirmPayment
33525 tejus.loha 401
$(document).on('click', ".paymentConfirmBtn", function () {
402
    let approval = $(this).data('approval');
33507 tejus.loha 403
    let bfcId = $(this).val();
33525 tejus.loha 404
    let description = "All details are correct";
405
    if (confirm("Are you sure to confirm this payment ?")) {
406
        doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
407
            function (response) {
33845 tejus.loha 408
                alert("Payment is confirm successfully");
33525 tejus.loha 409
                pendingLoiForm("main-content");
410
            });
411
    }
412
});
413
 
414
$(document).on('click', ".paymentRejectBtn", function () {
33507 tejus.loha 415
    let approval = $(this).data('approval');
33525 tejus.loha 416
    let bfcId = $(this).val();
417
    let description;
418
    description = prompt("Reason for rejection..");
419
    if (description !== null) {
420
        if (confirm("Are you sure to Reject this payment ?")) {
421
            doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
422
                function (response) {
33845 tejus.loha 423
                    alert("Payment is rejected successfully");
33525 tejus.loha 424
                    pendingLoiForm("main-content");
425
                });
426
        }
427
    } else {
428
        alert("Please mention the reason as description and try again");
429
    }
33507 tejus.loha 430
});
34739 aman.kumar 431
$(document).on('click', ".deleteFeeCollection", function () {
432
    let bfcId = $(this).val();
433
    if (confirm("Are you sure you want to delete this payment entry?")) {
434
        doPutAjaxRequestHandler(
435
            `${context}/feePaymentDeletion?bfcId=${bfcId}`,
436
            function (response) {
437
                alert("Payment entry has been deleted successfully.");
438
                pendingLoiForm("main-content");
439
            }
440
        );
441
    }
442
});
443
 
33507 tejus.loha 444
$(document).on('click', ".upload-document-form", function () {
445
    let loiId = $(this).val();
33617 tejus.loha 446
    doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 447
        function (response) {
448
            $('#' + 'main-content').html(response);
449
        });
450
});
33885 tejus.loha 451
$(document).on('input', 'table#OnboardingDocumentTable input[type=file],table#mk_brand-fee-collection-details input[type=file]', function () {
452
    if (confirm('Confirm file upload ?')) {
453
        var fileSelector = $(this)[0];
454
        if (fileSelector != undefined
455
            && fileSelector.files[0] != undefined) {
456
            var file = this.files[0];
457
            let fileInput = $(this);
458
            uploadDocument(file, function (documentId) {
459
                fileInput.closest('td').find(".documentId").val(documentId);
460
            });
461
        }
462
    }
463
});
464
 
465
$(document).on('input', '#payment-sc-doc', function () {
466
    if (confirm('Confirm file upload ?')) {
467
        var file = this.files[0];
468
        uploadDocument(file, function (documentId) {
469
            $('#payment-sc-docId').val(documentId);
470
        });
471
    }
472
});
473
 
474
 
33507 tejus.loha 475
$(document).on('click', ".mk_docApproval", function () {
476
    let loiId = $(this).data('form_id');
477
    let docMasterId = $(this).data('doc_master_id');
478
    let flag = $(this).data('flag');
479
    doPutAjaxRequestHandler(`${context}/documentVerify?loiId=${loiId}&docMasterId=${docMasterId}&flag=${flag}`,
480
        function (response) {
481
            alert(response);
33617 tejus.loha 482
            doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 483
                function (response) {
484
                    $('#' + 'main-content').html(response);
485
                });
486
 
487
        });
488
});
489
$(document).on('click', "#uploadDocumentbtn1", function () {
490
    if (confirm("Are you sure to upload all documents ?")) {
491
        var loiId = $(this).val();
492
        var loiDocModels = [];
493
        $("#OnboardingDocumentTable > tbody > tr").each(function (rowIndex) {
494
            var marsterId = $(this).find(".masterId").val();
495
            var docId = $(this).find(".documentId").val();
496
            var docName = $(this).find(".documentName").val();
497
            var loiDocModel = {
498
                documentId: docId,
499
                documentName: docName,
500
                documentMasterId: marsterId
501
            };
502
            loiDocModels.push(loiDocModel);
503
        });
504
        var loiDocModelData = JSON.stringify(loiDocModels);
505
        doPostAjaxRequestWithJsonHandler(`${context}/uploadOnboardingDocument?loiId=${loiId}`, loiDocModelData, function (response) {
506
            pendingLoiForm("main-content");
507
        });
508
    } else {
509
        //Nothing to do
510
    }
511
 
512
 
513
});
514
 
515
$(document).on('click', ".CompletedLoiForm", function () {
33617 tejus.loha 516
    doGetAjaxRequestHandler(`${context}/completedLoiForms`,
33507 tejus.loha 517
        function (response) {
518
            $('#' + 'main-content').html(response);
519
        });
520
});
521
 
522
$(document).on('click', "#createNewOnboardingPanel", function () {
523
    let loiId = $(this).val();
33710 tejus.loha 524
    //let authId = $(this).closest('tr').find('.authId').val();
33507 tejus.loha 525
 
33710 tejus.loha 526
    if (true) {
527
 
528
        doPostAjaxRequestHandler(`${context}/createNewOnboardingPanel?loiId=${loiId}&authId=${0}`,
33507 tejus.loha 529
            function (response) {
530
                if (response) {
33710 tejus.loha 531
                    // doGetAjaxRequestHandler(`${context}/completedLoiForms`,
532
                    //     function (response) {
533
                    //         $('#' + 'main-content').html(response);
534
                    //     });
535
                    alert("it moved successfully ");
33507 tejus.loha 536
                } else {
537
                    //nothing
538
                }
539
 
540
            });
541
    } else {
542
        alert("Please choose RBM ");
543
    }
544
 
545
});
546
 
33617 tejus.loha 547
$(document).on('click', "#downloadAllLoiForm", function () {
548
    const from = $('input[name="from"]').val();
549
    const to = $('input[name="to"]').val();
550
    let missingFields = [];
551
    if (!from) missingFields.push('From date');
552
    if (!to) missingFields.push('To date');
553
    if (missingFields.length > 0) {
554
        alert('Please select : ' + missingFields.join(','));
555
        return;
556
    }
557
    window.location.href = `${context}/downloadLoiFromReport?from=${from}&to=${to}`;
558
});
33658 tejus.loha 559
$(document).on('click', ".brandFeePaymentEdit", function () {
560
    var bfcId = $(this).val();
34310 tejus.loha 561
 
33658 tejus.loha 562
    // Get the table row
563
    var $row = $(this).closest('tr');
564
    var feeCollectingTimeStamp = $row.find('input[name="feeCollectingTimeStamp"]').val();
565
    var collectedAmount = $row.find('input[name="collectedAmount"]').val();
566
    var paymentReferenceNo = $row.find('input[name="paymentReferenceNo"]').val();
567
    var paymentMode = $row.find('select[name="paymentMode"]').val();
33885 tejus.loha 568
    var documentId = $row.find('input[name="documentId"]').val();
569
 
33658 tejus.loha 570
    const Data = {
571
        id: bfcId,
572
        feeCollectingTimeStamp: feeCollectingTimeStamp,
573
        collectedAmount: collectedAmount,
574
        paymentReferenceNo: paymentReferenceNo,
34745 aman.kumar 575
        paymentAttachment: documentId,
33658 tejus.loha 576
        paymentMode: paymentMode
577
    };
578
    var jsonData = JSON.stringify(Data);
579
    if (confirm("Are you sure to update details")) {
580
        doPostAjaxRequestWithJsonHandler(`${context}/updatePayment`, jsonData,
581
            function (response) {
33845 tejus.loha 582
                if (response) {
583
                    alert("Updated payment details are save successfully ")
584
                    pendingLoiForm('main-content');
585
                } else {
586
                    alert("Updated payment details are not save ")
587
                    pendingLoiForm('main-content');
588
                }
33658 tejus.loha 589
            });
590
    } else {
591
        pendingLoiForm('main-content');
592
    }
33617 tejus.loha 593
 
33658 tejus.loha 594
 
595
});
33879 tejus.loha 596
/*function validateOTP() {
597
    while (true) {
598
        let otp = prompt("Enter received OTP here");
599
        if (otp === null) {
600
            alert('OTP entry was cancelled. Try again.');
601
            return null;
602
        }
603
        let regex = /^[0-9]{5}$/;
604
        if (regex.test(otp)) {
605
            console.log('otp-flag-', otp);
606
            return otp;  // Return valid OTP
607
        } else {
608
            alert('Please enter a valid 5-digit numeric OTP');
609
        }
610
    }
611
}*/
33658 tejus.loha 612
 
33879 tejus.loha 613
$(document).on('click', "#confirmSign", function () {
614
    let loiId = $(this).val();
615
    let otp = prompt("Enter received OTP here");
616
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
33658 tejus.loha 617
 
35038 aman 618
    if (otp !== undefined && otp !== null) {
33879 tejus.loha 619
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
35038 aman 620
            console.log('OTP validation response:', response);
621
 
622
            if (response && response.response && response.response.success) {
623
                const docHash = (response.response.documentHash || "");
624
                const ip = response.response.ipAddress || "";
625
                const createdAt = response.response.createdAt || new Date().toLocaleString();
626
                const watermarkText =
627
                    `OTP VERIFIED\n` +
628
                    `DOCUMENT HASH:\n ${docHash}\n` +
629
                    `IP ADDRESS: ${ip}\n` +
630
                    `CREATED ON: ${createdAt}`;
631
                const originalElement = document.getElementById('loiPDF_content');
632
                const clonedElement = originalElement.cloneNode(true);
633
                const existingStyles = clonedElement.querySelectorAll('style');
634
                existingStyles.forEach(style => style.remove());
635
                $(clonedElement).find('.pending-badge, .pending-indicator').remove();
636
                $(clonedElement).find('.signature-section').each(function () {
637
                    this.style.setProperty('position', 'relative', 'important');
638
                    this.style.setProperty('padding', '20px', 'important');
639
                });
640
 
641
                const signatureSections = clonedElement.querySelectorAll('.signature-section');
642
                signatureSections.forEach(section => {
643
                    const oldWatermarks = section.querySelectorAll('.watermark-overlay');
644
                    oldWatermarks.forEach(w => w.remove());
645
 
646
                    const watermarkDiv = document.createElement('div');
647
                    watermarkDiv.className = 'watermark-overlay';
648
                    watermarkDiv.textContent = watermarkText;
649
                    watermarkDiv.style.position = 'absolute';
650
                    watermarkDiv.style.fontSize = '7px';
651
                    watermarkDiv.style.top = '30px';
652
                    watermarkDiv.style.left = '1%';
653
                    watermarkDiv.style.color = 'rgb(4,97,225)';
654
                    watermarkDiv.style.fontWeight = 'bold';
655
                    watermarkDiv.style.fontFamily = 'Arial,sans-serif';
656
                    watermarkDiv.style.whiteSpace = 'pre-line';
657
                    watermarkDiv.style.textAlign = 'center';
658
                    watermarkDiv.style.pointerEvents = 'none';
659
                    watermarkDiv.style.width = '90%';
660
                    watermarkDiv.style.lineHeight = '1.7';
661
                    watermarkDiv.style.zIndex = '1';
662
                    watermarkDiv.style.userSelect = 'none';
663
 
664
                    section.style.position = 'relative';
665
                    section.appendChild(watermarkDiv);
666
                });
667
 
668
                const tempContainer = document.createElement('div');
669
                tempContainer.style.position = 'absolute';
670
                tempContainer.style.left = '-9999px';
671
                tempContainer.style.width = '800px';
672
                tempContainer.appendChild(clonedElement);
673
                document.body.appendChild(tempContainer);
674
 
33879 tejus.loha 675
                const opt = {
35038 aman 676
                    margin: [0.5, 0.5, 0.5, 0.5],
677
                    filename: `LOI_${loiId}_${new Date().getTime()}.pdf`,
678
                    image: {
679
                        type: 'jpeg',
680
                        quality: 0.98
681
                    },
682
                    html2canvas: {
683
                        scale: 1.2,
684
                        logging: false,
685
                        useCORS: true,
686
                        allowTaint: false,
687
                        backgroundColor: '#ffffff'
688
                    },
689
                    jsPDF: {
690
                        unit: 'in',
691
                        format: 'letter',
692
                        orientation: 'portrait'
693
                    }
33879 tejus.loha 694
                };
35038 aman 695
 
696
                html2pdf().from(clonedElement).set(opt).outputPdf("arraybuffer")
697
                    .then(function (pdf) {
698
                        document.body.removeChild(tempContainer);
699
 
700
                        const file = new Blob([pdf], {type: 'application/pdf'});
701
 
702
                        uploadDocument(file, function (documentId) {
703
                            IdempotencyKey = uuidv4();
704
                            if (documentId > 0) {
705
                                saveLoiDoc(loiId, documentId);
706
                                alert("Document signed and saved successfully!");
707
                            } else {
708
                                alert("Something went wrong, please try again to confirm OTP");
709
                            }
710
                        });
711
                    })
712
                    .catch(function (error) {
713
                        console.error('PDF generation failed:', error);
714
                        document.body.removeChild(tempContainer);
715
                        alert("PDF generation failed. Please try again.");
33879 tejus.loha 716
                    });
35038 aman 717
            } else {
718
                console.error('OTP validation failed:', response);
719
                alert("OTP validation failed: " + (response.response?.message || "Please try again."));
33879 tejus.loha 720
            }
35038 aman 721
        }, function (error) {
722
            console.error('AJAX request failed:', error);
723
            alert("Request failed. Please check your connection and try again.");
33879 tejus.loha 724
        });
725
    } else {
34310 tejus.loha 726
        return false;
33879 tejus.loha 727
    }
728
});
729
 
730
 
731
function saveLoiDoc(loiId, documentId) {
732
    let saveLoiDocUrl = `${context}/saveLoiDoc?loiId=` + loiId + `&loiDocId=` + documentId
733
    doPostAjaxRequestHandler(saveLoiDocUrl, function (response) {
734
        if (response) {
735
            alert("LOI has been signed successfully and sent to the registered email. Please check your email.");
736
            pendingLoiForm("main-content");
737
        } else {
738
            alert("Something went wrong , Please try again to generate Loi and Validate otp");
739
        }
740
    });
741
}
742
 
743
 
33507 tejus.loha 744
function pendingLoiForm(domId) {
33710 tejus.loha 745
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 746
        function (response) {
747
            $('#' + domId).html(response);
748
        });
749
}
34085 tejus.loha 750
 
751
/*
752
function createPagination(containerId, totalPages, currentPage = 1, onPageChange = null) {
753
    const $container = $('#' + containerId);
754
    $container.empty(); // Clear the container
755
 
756
    // Helper Function to Render Pagination
757
    function renderPagination(currentPage) {
758
        $container.empty();
759
 
760
        // Previous Button
761
        const $prevButton = $('<button>')
762
            .text('Previous')
763
            .click(() => handlePageChange(currentPage > 1 ? currentPage - 1 : totalPages)); // Loop to last page if on the first page
764
        $container.append($prevButton);
765
 
766
        // First Page
767
        const $firstPageButton = $('<button>')
768
            .text('1')
769
            .addClass(currentPage === 1 ? 'active' : '')
770
            .click(() => handlePageChange(1));
771
        $container.append($firstPageButton);
772
 
773
        // Ellipsis Before Current Pages
774
        if (currentPage > 3) {
775
            $container.append($('<span>').text('...'));
776
        }
777
 
778
        // Dynamic Pages Around Current Page
779
        for (let i = Math.max(2, currentPage - 1); i <= Math.min(totalPages - 1, currentPage + 1); i++) {
780
            const $pageButton = $('<button>')
781
                .text(i)
782
                .addClass(currentPage === i ? 'active' : '')
783
                .click(() => handlePageChange(i));
784
            $container.append($pageButton);
785
        }
786
 
787
        // Ellipsis Before Last Page
788
        if (currentPage < totalPages - 2) {
789
            $container.append($('<span>').text('...'));
790
        }
791
 
792
        // Last Page
793
        if (totalPages > 1) {
794
            const $lastPageButton = $('<button>')
795
                .text(totalPages)
796
                .addClass(currentPage === totalPages ? 'active' : '')
797
                .click(() => handlePageChange(totalPages));
798
            $container.append($lastPageButton);
799
        }
800
 
801
        // Next Button
802
        const $nextButton = $('<button>')
803
            .text('Next')
804
            .click(() => handlePageChange(currentPage < totalPages ? currentPage + 1 : 1)); // Loop to first page if on the last page
805
        $container.append($nextButton);
806
    }
807
 
808
    // Handle Page Change
809
    function handlePageChange(selectedPage) {
810
        if (onPageChange) {
811
            onPageChange(selectedPage); // Trigger the callback with the selected page
812
        }
813
        renderPagination(selectedPage); // Re-render pagination
814
    }
815
 
816
    // Initial Render
817
    renderPagination(currentPage);
818
}*/