Subversion Repositories SmartDukaan

Rev

Rev 35038 | Rev 35977 | 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
 
33507 tejus.loha 368
$(document).on('click', "#LOI_otp", function () {
369
    let loiId = $(this).val();
33577 tejus.loha 370
    if (confirm("Are you sure to send OTP ?")) {
371
        doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
372
            function (response) {
373
                alert(response);
374
                doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
375
                    function (response) {
376
                        $('#' + 'main-content').html(response);
377
                    });
378
            });
379
    } else {
380
        alert("OTP not send .");
381
    }
382
 
33507 tejus.loha 383
});
384
 
385
//confirmPayment
33525 tejus.loha 386
$(document).on('click', ".paymentConfirmBtn", function () {
387
    let approval = $(this).data('approval');
33507 tejus.loha 388
    let bfcId = $(this).val();
33525 tejus.loha 389
    let description = "All details are correct";
390
    if (confirm("Are you sure to confirm this payment ?")) {
391
        doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
392
            function (response) {
33845 tejus.loha 393
                alert("Payment is confirm successfully");
33525 tejus.loha 394
                pendingLoiForm("main-content");
395
            });
396
    }
397
});
398
 
399
$(document).on('click', ".paymentRejectBtn", function () {
33507 tejus.loha 400
    let approval = $(this).data('approval');
33525 tejus.loha 401
    let bfcId = $(this).val();
402
    let description;
403
    description = prompt("Reason for rejection..");
404
    if (description !== null) {
405
        if (confirm("Are you sure to Reject this payment ?")) {
406
            doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
407
                function (response) {
33845 tejus.loha 408
                    alert("Payment is rejected successfully");
33525 tejus.loha 409
                    pendingLoiForm("main-content");
410
                });
411
        }
412
    } else {
413
        alert("Please mention the reason as description and try again");
414
    }
33507 tejus.loha 415
});
34739 aman.kumar 416
$(document).on('click', ".deleteFeeCollection", function () {
417
    let bfcId = $(this).val();
418
    if (confirm("Are you sure you want to delete this payment entry?")) {
419
        doPutAjaxRequestHandler(
420
            `${context}/feePaymentDeletion?bfcId=${bfcId}`,
421
            function (response) {
422
                alert("Payment entry has been deleted successfully.");
423
                pendingLoiForm("main-content");
424
            }
425
        );
426
    }
427
});
428
 
33507 tejus.loha 429
$(document).on('click', ".upload-document-form", function () {
430
    let loiId = $(this).val();
33617 tejus.loha 431
    doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 432
        function (response) {
433
            $('#' + 'main-content').html(response);
434
        });
435
});
33885 tejus.loha 436
$(document).on('input', 'table#OnboardingDocumentTable input[type=file],table#mk_brand-fee-collection-details input[type=file]', function () {
437
    if (confirm('Confirm file upload ?')) {
438
        var fileSelector = $(this)[0];
439
        if (fileSelector != undefined
440
            && fileSelector.files[0] != undefined) {
441
            var file = this.files[0];
442
            let fileInput = $(this);
443
            uploadDocument(file, function (documentId) {
444
                fileInput.closest('td').find(".documentId").val(documentId);
445
            });
446
        }
447
    }
448
});
449
 
450
$(document).on('input', '#payment-sc-doc', function () {
451
    if (confirm('Confirm file upload ?')) {
452
        var file = this.files[0];
453
        uploadDocument(file, function (documentId) {
454
            $('#payment-sc-docId').val(documentId);
455
        });
456
    }
457
});
458
 
459
 
33507 tejus.loha 460
$(document).on('click', ".mk_docApproval", function () {
461
    let loiId = $(this).data('form_id');
462
    let docMasterId = $(this).data('doc_master_id');
463
    let flag = $(this).data('flag');
464
    doPutAjaxRequestHandler(`${context}/documentVerify?loiId=${loiId}&docMasterId=${docMasterId}&flag=${flag}`,
465
        function (response) {
466
            alert(response);
33617 tejus.loha 467
            doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 468
                function (response) {
469
                    $('#' + 'main-content').html(response);
470
                });
471
 
472
        });
473
});
474
$(document).on('click', "#uploadDocumentbtn1", function () {
475
    if (confirm("Are you sure to upload all documents ?")) {
476
        var loiId = $(this).val();
477
        var loiDocModels = [];
478
        $("#OnboardingDocumentTable > tbody > tr").each(function (rowIndex) {
479
            var marsterId = $(this).find(".masterId").val();
480
            var docId = $(this).find(".documentId").val();
481
            var docName = $(this).find(".documentName").val();
482
            var loiDocModel = {
483
                documentId: docId,
484
                documentName: docName,
485
                documentMasterId: marsterId
486
            };
487
            loiDocModels.push(loiDocModel);
488
        });
489
        var loiDocModelData = JSON.stringify(loiDocModels);
490
        doPostAjaxRequestWithJsonHandler(`${context}/uploadOnboardingDocument?loiId=${loiId}`, loiDocModelData, function (response) {
491
            pendingLoiForm("main-content");
492
        });
493
    } else {
494
        //Nothing to do
495
    }
496
 
497
 
498
});
499
 
500
$(document).on('click', ".CompletedLoiForm", function () {
33617 tejus.loha 501
    doGetAjaxRequestHandler(`${context}/completedLoiForms`,
33507 tejus.loha 502
        function (response) {
503
            $('#' + 'main-content').html(response);
504
        });
505
});
506
 
507
$(document).on('click', "#createNewOnboardingPanel", function () {
508
    let loiId = $(this).val();
33710 tejus.loha 509
    //let authId = $(this).closest('tr').find('.authId').val();
33507 tejus.loha 510
 
33710 tejus.loha 511
    if (true) {
512
 
513
        doPostAjaxRequestHandler(`${context}/createNewOnboardingPanel?loiId=${loiId}&authId=${0}`,
33507 tejus.loha 514
            function (response) {
515
                if (response) {
33710 tejus.loha 516
                    // doGetAjaxRequestHandler(`${context}/completedLoiForms`,
517
                    //     function (response) {
518
                    //         $('#' + 'main-content').html(response);
519
                    //     });
520
                    alert("it moved successfully ");
33507 tejus.loha 521
                } else {
522
                    //nothing
523
                }
524
 
525
            });
526
    } else {
527
        alert("Please choose RBM ");
528
    }
529
 
530
});
531
 
33617 tejus.loha 532
$(document).on('click', "#downloadAllLoiForm", function () {
533
    const from = $('input[name="from"]').val();
534
    const to = $('input[name="to"]').val();
535
    let missingFields = [];
536
    if (!from) missingFields.push('From date');
537
    if (!to) missingFields.push('To date');
538
    if (missingFields.length > 0) {
539
        alert('Please select : ' + missingFields.join(','));
540
        return;
541
    }
542
    window.location.href = `${context}/downloadLoiFromReport?from=${from}&to=${to}`;
543
});
33658 tejus.loha 544
$(document).on('click', ".brandFeePaymentEdit", function () {
545
    var bfcId = $(this).val();
34310 tejus.loha 546
 
33658 tejus.loha 547
    // Get the table row
548
    var $row = $(this).closest('tr');
549
    var feeCollectingTimeStamp = $row.find('input[name="feeCollectingTimeStamp"]').val();
550
    var collectedAmount = $row.find('input[name="collectedAmount"]').val();
551
    var paymentReferenceNo = $row.find('input[name="paymentReferenceNo"]').val();
552
    var paymentMode = $row.find('select[name="paymentMode"]').val();
33885 tejus.loha 553
    var documentId = $row.find('input[name="documentId"]').val();
554
 
33658 tejus.loha 555
    const Data = {
556
        id: bfcId,
557
        feeCollectingTimeStamp: feeCollectingTimeStamp,
558
        collectedAmount: collectedAmount,
559
        paymentReferenceNo: paymentReferenceNo,
34745 aman.kumar 560
        paymentAttachment: documentId,
33658 tejus.loha 561
        paymentMode: paymentMode
562
    };
563
    var jsonData = JSON.stringify(Data);
564
    if (confirm("Are you sure to update details")) {
565
        doPostAjaxRequestWithJsonHandler(`${context}/updatePayment`, jsonData,
566
            function (response) {
33845 tejus.loha 567
                if (response) {
568
                    alert("Updated payment details are save successfully ")
569
                    pendingLoiForm('main-content');
570
                } else {
571
                    alert("Updated payment details are not save ")
572
                    pendingLoiForm('main-content');
573
                }
33658 tejus.loha 574
            });
575
    } else {
576
        pendingLoiForm('main-content');
577
    }
33617 tejus.loha 578
 
33658 tejus.loha 579
 
580
});
33879 tejus.loha 581
/*function validateOTP() {
582
    while (true) {
583
        let otp = prompt("Enter received OTP here");
584
        if (otp === null) {
585
            alert('OTP entry was cancelled. Try again.');
586
            return null;
587
        }
588
        let regex = /^[0-9]{5}$/;
589
        if (regex.test(otp)) {
590
            console.log('otp-flag-', otp);
591
            return otp;  // Return valid OTP
592
        } else {
593
            alert('Please enter a valid 5-digit numeric OTP');
594
        }
595
    }
596
}*/
33658 tejus.loha 597
 
33879 tejus.loha 598
$(document).on('click', "#confirmSign", function () {
599
    let loiId = $(this).val();
600
    let otp = prompt("Enter received OTP here");
601
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
33658 tejus.loha 602
 
35038 aman 603
    if (otp !== undefined && otp !== null) {
33879 tejus.loha 604
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
35038 aman 605
            console.log('OTP validation response:', response);
606
 
607
            if (response && response.response && response.response.success) {
608
                const docHash = (response.response.documentHash || "");
609
                const ip = response.response.ipAddress || "";
610
                const createdAt = response.response.createdAt || new Date().toLocaleString();
611
                const watermarkText =
612
                    `OTP VERIFIED\n` +
613
                    `DOCUMENT HASH:\n ${docHash}\n` +
614
                    `IP ADDRESS: ${ip}\n` +
615
                    `CREATED ON: ${createdAt}`;
616
                const originalElement = document.getElementById('loiPDF_content');
617
                const clonedElement = originalElement.cloneNode(true);
618
                const existingStyles = clonedElement.querySelectorAll('style');
619
                existingStyles.forEach(style => style.remove());
620
                $(clonedElement).find('.pending-badge, .pending-indicator').remove();
621
                $(clonedElement).find('.signature-section').each(function () {
622
                    this.style.setProperty('position', 'relative', 'important');
623
                    this.style.setProperty('padding', '20px', 'important');
624
                });
625
 
626
                const signatureSections = clonedElement.querySelectorAll('.signature-section');
627
                signatureSections.forEach(section => {
628
                    const oldWatermarks = section.querySelectorAll('.watermark-overlay');
629
                    oldWatermarks.forEach(w => w.remove());
630
 
631
                    const watermarkDiv = document.createElement('div');
632
                    watermarkDiv.className = 'watermark-overlay';
633
                    watermarkDiv.textContent = watermarkText;
634
                    watermarkDiv.style.position = 'absolute';
635
                    watermarkDiv.style.fontSize = '7px';
636
                    watermarkDiv.style.top = '30px';
637
                    watermarkDiv.style.left = '1%';
638
                    watermarkDiv.style.color = 'rgb(4,97,225)';
639
                    watermarkDiv.style.fontWeight = 'bold';
640
                    watermarkDiv.style.fontFamily = 'Arial,sans-serif';
641
                    watermarkDiv.style.whiteSpace = 'pre-line';
642
                    watermarkDiv.style.textAlign = 'center';
643
                    watermarkDiv.style.pointerEvents = 'none';
644
                    watermarkDiv.style.width = '90%';
645
                    watermarkDiv.style.lineHeight = '1.7';
646
                    watermarkDiv.style.zIndex = '1';
647
                    watermarkDiv.style.userSelect = 'none';
648
 
649
                    section.style.position = 'relative';
650
                    section.appendChild(watermarkDiv);
651
                });
652
 
653
                const tempContainer = document.createElement('div');
654
                tempContainer.style.position = 'absolute';
655
                tempContainer.style.left = '-9999px';
656
                tempContainer.style.width = '800px';
657
                tempContainer.appendChild(clonedElement);
658
                document.body.appendChild(tempContainer);
659
 
33879 tejus.loha 660
                const opt = {
35038 aman 661
                    margin: [0.5, 0.5, 0.5, 0.5],
662
                    filename: `LOI_${loiId}_${new Date().getTime()}.pdf`,
663
                    image: {
664
                        type: 'jpeg',
665
                        quality: 0.98
666
                    },
667
                    html2canvas: {
668
                        scale: 1.2,
669
                        logging: false,
670
                        useCORS: true,
671
                        allowTaint: false,
672
                        backgroundColor: '#ffffff'
673
                    },
674
                    jsPDF: {
675
                        unit: 'in',
676
                        format: 'letter',
677
                        orientation: 'portrait'
678
                    }
33879 tejus.loha 679
                };
35038 aman 680
 
681
                html2pdf().from(clonedElement).set(opt).outputPdf("arraybuffer")
682
                    .then(function (pdf) {
683
                        document.body.removeChild(tempContainer);
684
 
685
                        const file = new Blob([pdf], {type: 'application/pdf'});
686
 
687
                        uploadDocument(file, function (documentId) {
688
                            IdempotencyKey = uuidv4();
689
                            if (documentId > 0) {
690
                                saveLoiDoc(loiId, documentId);
691
                                alert("Document signed and saved successfully!");
692
                            } else {
693
                                alert("Something went wrong, please try again to confirm OTP");
694
                            }
695
                        });
696
                    })
697
                    .catch(function (error) {
698
                        console.error('PDF generation failed:', error);
699
                        document.body.removeChild(tempContainer);
700
                        alert("PDF generation failed. Please try again.");
33879 tejus.loha 701
                    });
35038 aman 702
            } else {
703
                console.error('OTP validation failed:', response);
704
                alert("OTP validation failed: " + (response.response?.message || "Please try again."));
33879 tejus.loha 705
            }
35038 aman 706
        }, function (error) {
707
            console.error('AJAX request failed:', error);
708
            alert("Request failed. Please check your connection and try again.");
33879 tejus.loha 709
        });
710
    } else {
34310 tejus.loha 711
        return false;
33879 tejus.loha 712
    }
713
});
714
 
715
 
716
function saveLoiDoc(loiId, documentId) {
717
    let saveLoiDocUrl = `${context}/saveLoiDoc?loiId=` + loiId + `&loiDocId=` + documentId
718
    doPostAjaxRequestHandler(saveLoiDocUrl, function (response) {
719
        if (response) {
720
            alert("LOI has been signed successfully and sent to the registered email. Please check your email.");
721
            pendingLoiForm("main-content");
722
        } else {
723
            alert("Something went wrong , Please try again to generate Loi and Validate otp");
724
        }
725
    });
726
}
727
 
728
 
33507 tejus.loha 729
function pendingLoiForm(domId) {
33710 tejus.loha 730
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 731
        function (response) {
732
            $('#' + domId).html(response);
733
        });
734
}
34085 tejus.loha 735
 
736
/*
737
function createPagination(containerId, totalPages, currentPage = 1, onPageChange = null) {
738
    const $container = $('#' + containerId);
739
    $container.empty(); // Clear the container
740
 
741
    // Helper Function to Render Pagination
742
    function renderPagination(currentPage) {
743
        $container.empty();
744
 
745
        // Previous Button
746
        const $prevButton = $('<button>')
747
            .text('Previous')
748
            .click(() => handlePageChange(currentPage > 1 ? currentPage - 1 : totalPages)); // Loop to last page if on the first page
749
        $container.append($prevButton);
750
 
751
        // First Page
752
        const $firstPageButton = $('<button>')
753
            .text('1')
754
            .addClass(currentPage === 1 ? 'active' : '')
755
            .click(() => handlePageChange(1));
756
        $container.append($firstPageButton);
757
 
758
        // Ellipsis Before Current Pages
759
        if (currentPage > 3) {
760
            $container.append($('<span>').text('...'));
761
        }
762
 
763
        // Dynamic Pages Around Current Page
764
        for (let i = Math.max(2, currentPage - 1); i <= Math.min(totalPages - 1, currentPage + 1); i++) {
765
            const $pageButton = $('<button>')
766
                .text(i)
767
                .addClass(currentPage === i ? 'active' : '')
768
                .click(() => handlePageChange(i));
769
            $container.append($pageButton);
770
        }
771
 
772
        // Ellipsis Before Last Page
773
        if (currentPage < totalPages - 2) {
774
            $container.append($('<span>').text('...'));
775
        }
776
 
777
        // Last Page
778
        if (totalPages > 1) {
779
            const $lastPageButton = $('<button>')
780
                .text(totalPages)
781
                .addClass(currentPage === totalPages ? 'active' : '')
782
                .click(() => handlePageChange(totalPages));
783
            $container.append($lastPageButton);
784
        }
785
 
786
        // Next Button
787
        const $nextButton = $('<button>')
788
            .text('Next')
789
            .click(() => handlePageChange(currentPage < totalPages ? currentPage + 1 : 1)); // Loop to first page if on the last page
790
        $container.append($nextButton);
791
    }
792
 
793
    // Handle Page Change
794
    function handlePageChange(selectedPage) {
795
        if (onPageChange) {
796
            onPageChange(selectedPage); // Trigger the callback with the selected page
797
        }
798
        renderPagination(selectedPage); // Re-render pagination
799
    }
800
 
801
    // Initial Render
802
    renderPagination(currentPage);
803
}*/