Subversion Repositories SmartDukaan

Rev

Rev 34739 | Rev 35038 | 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();
33909 tejus.loha 91
    const finCode = $('input[name="finCode"]').val();
33658 tejus.loha 92
    let brandCommitment = [];
93
    var brandCommitmentInputs = document.querySelectorAll(".brand-commitment");
94
    brandCommitmentInputs.forEach(function (input) {
95
        var commitmentValue = parseInt(input.value);
96
        if (!isNaN(commitmentValue)) {
97
            brandCommitment.push({
98
                brandName: input.getAttribute("name"),
99
                value: commitmentValue
100
            });
101
        }
102
    });
103
    let totalCommitment = brandCommitment.reduce((total, commitment) => total + commitment.value, 0);
33577 tejus.loha 104
    const lessCommitReason = $('input[name="lessCommitReason"]').val();
33658 tejus.loha 105
    let minCommit = totalCommitment >= storePotential * (70 / 100);
33577 tejus.loha 106
    const agreedBrandFees = $('select[name="agreedBrandFees"]').val();
33624 tejus.loha 107
    const values = agreedBrandFees.split(/[-]/); // Split the string
108
    const brandFee = parseFloat(values[1]);
33577 tejus.loha 109
    const brandFeesCollected = $('input[name="brandFeesCollected"]').val();
110
    const paymentMode = $('select[name="paymentMode"]').val();
111
    const paymentReferenceNo = $('input[name="paymentReferenceNo"]').val();
33578 tejus.loha 112
    const feeCollectingDate = $('input[name="feeCollectingDate"]').val();
33885 tejus.loha 113
    const paymentAttachment = $('input[name="paymentAttachment"]').val();
33577 tejus.loha 114
 
115
    let missingFields = [];
116
    if (!firstName) missingFields.push('First Name');
117
    if (!lastName) missingFields.push('Last Name');
118
    if (mobile.length < 10 || !mobile) {
119
        missingFields.push('Mobile number should be 10 digit');
120
    }
33658 tejus.loha 121
    if (!minCommit) {
33577 tejus.loha 122
        if (!lessCommitReason) missingFields.push('Less Commit Reason');
123
    }
124
    if (!maritalStatus) missingFields.push('Marital Status');
125
    if (maritalStatus == 1) {
126
        if (!anniversaryDate) missingFields.push('Anniversary Date');
127
    }
128
    if (!email) missingFields.push('Email');
34107 tejus.loha 129
    if (!referId) missingFields.push('Refer By');
130
    if (!bdm) missingFields.push('Bdm');
131
    if (!stateHead) missingFields.push('State head');
33582 tejus.loha 132
    if (!acquiredDate) missingFields.push('Acquired date');
33577 tejus.loha 133
    if (!dob) missingFields.push('dob(Date of Birth)');
33624 tejus.loha 134
    if (age <= 18) missingFields.push('You must be at least 18 years old to Fill LOI FORM. ');
33577 tejus.loha 135
    if (!panNo) missingFields.push('Pan Number');
136
    if (!adharNo) missingFields.push('Aadhar Number');
137
    if (!gstNo) missingFields.push('GST Number');
138
    if (!bankName) missingFields.push('Bank Name');
139
    if (!ifscCode) missingFields.push('IFSC code');
140
    if (!accountNo) missingFields.push('Account Number');
141
    if (!businessType) missingFields.push('businessType');
142
    if (!companyName) missingFields.push('Company Name');
143
    if (!agreeWalletValue) missingFields.push('Agree Wallet Value');
144
    if (!storeArea) missingFields.push('storeArea');
145
    if (!storePotential) missingFields.push('Store Potential');
146
    if (!agreedBrandFees) missingFields.push('Agreed Brand Fees');
147
    if (!brandFeesCollected) missingFields.push('Brand Fees Collected');
33845 tejus.loha 148
    if (brandFeesCollected > brandFee) missingFields.push('The collected brand fee must not exceed the agreed brand fees.');
33577 tejus.loha 149
    if (!paymentMode) missingFields.push('Payment Mode');
150
    if (!paymentReferenceNo) missingFields.push('Payment Reference No');
33578 tejus.loha 151
    if (!feeCollectingDate) missingFields.push('Fee Collecting Date');
33885 tejus.loha 152
    if (!paymentAttachment) missingFields.push('Payment screenshot ');
33577 tejus.loha 153
    if (missingFields.length > 0) {
154
        alert('The following fields are required: ' + missingFields.join(', '));
155
        return;
156
    }
157
    const loiFormData = {
158
        referId: referId,
34107 tejus.loha 159
        stateHead: stateHead,
160
        bdm: bdm,
33577 tejus.loha 161
        businessType: businessType,
33582 tejus.loha 162
        acquiredDate: acquiredDate,
33577 tejus.loha 163
        firstName: firstName,
164
        lastName: lastName,
165
        mobile: mobile,
166
        email: email,
167
        landline: landline,
168
        dob: dob,
169
        anniversaryDate: anniversaryDate,
170
        panNo: panNo,
171
        adharNo: adharNo,
172
        gstNo: gstNo,
173
        bankName: bankName,
174
        ifscCode: ifscCode,
175
        accountNo: accountNo,
176
        companyName: companyName,
177
        gstPin: gstPin,
178
        gstState: gstState,
179
        gstCity: gstCity,
180
        gstDistrict: gstDistrict,
181
        agreeWalletValue: agreeWalletValue,
182
        storeArea: storeArea,
183
        storePotential: storePotential,
33909 tejus.loha 184
        financeCode: finCode,
33577 tejus.loha 185
        lessCommitReason: lessCommitReason,
186
        agreedBrandFees: agreedBrandFees,
187
        brandFeesCollected: brandFeesCollected,
188
        paymentMode: paymentMode,
189
        paymentReferenceNo: paymentReferenceNo,
33578 tejus.loha 190
        feeCollectingTimeStamp: feeCollectingDate,
33885 tejus.loha 191
        paymentAttachment: paymentAttachment,
33658 tejus.loha 192
        billingAddress: billingAddress,
193
        brandCommitment: brandCommitment
33577 tejus.loha 194
    };
33658 tejus.loha 195
 
33577 tejus.loha 196
    if (confirm("Are you sure to submit the form ?")) {
197
        doPostAjaxRequestWithJsonHandler(`${context}/submitLoiForm`, JSON.stringify(loiFormData), function (response) {
198
            console.log('responsee', response);
33507 tejus.loha 199
            if (response) {
200
                alert("Your LOI form Submitted successfully ");
201
                pendingLoiForm("main-content");
202
 
203
            } else {
204
                alert("Your LOI form not Submitted , try again ");
33845 tejus.loha 205
                doGetAjaxRequestHandler(`${context}/loiForm`,
33507 tejus.loha 206
                    function (response) {
207
                        $('#' + 'main-content').html(response);
208
                    });
209
            }
210
        });
211
    }
212
});
33578 tejus.loha 213
 
33658 tejus.loha 214
$(document).on('click', ".updateLoiForm", function () {
33507 tejus.loha 215
    let loiId = $(this).val();
33658 tejus.loha 216
    doGetAjaxRequestHandler(context + "/updateLoiForm?loiId=" + loiId,
33507 tejus.loha 217
        function (response) {
218
            $('#' + 'main-content').html(response);
219
        });
220
});
33879 tejus.loha 221
 
33710 tejus.loha 222
$(document).on('click', ".save_agree_brand_fee", function () {
223
    let loiId = $(this).val();
224
    var $tr = $(this).closest('tr');
225
    var agreedBrandFee = $tr.find('input[name="brandFee"]').val();
34085 tejus.loha 226
    var brandType = $tr.find('select[name="brandType"]').val();
33710 tejus.loha 227
    if (confirm("Are you sure to change Agreed brand fee")) {
34085 tejus.loha 228
        doPutAjaxRequestHandler(`${context}/updateAgreedBrandFee?loiId=${loiId}&brandFee=${agreedBrandFee}&storeType=${brandType}`, function (response) {
33710 tejus.loha 229
            pendingLoiForm("main-content");
230
        });
231
    } else {
232
        pendingLoiForm("main-content");
233
    }
234
});
33507 tejus.loha 235
 
33658 tejus.loha 236
$(document).on('click', ".updateLoiFormDataButton", function () {
237
    let loiId = $(this).data('loiid');
238
    const firstName = $('input[name="firstName"]').val();
239
    const lastName = $('input[name="lastName"]').val();
240
    const mobile = $('input[name="mobile"]').val();
241
    const email = $('input[name="email"]').val();
242
    const landline = $('input[name="landline"]').val();
243
    const dob = $('input[name="dob"]').val();
244
    const panNo = $('input[name="panNo"]').val();
245
    const adharNo = $('input[name="adharNo"]').val();
246
    let missingFields = [];
247
    if (!firstName) missingFields.push('First Name');
248
    if (!lastName) missingFields.push('Last Name');
249
    if (mobile.length < 10 || !mobile) {
250
        missingFields.push('Mobile number should be 10 digit');
251
    }
252
    if (!dob) missingFields.push('dob(Date of Birth)');
253
    if (!panNo) missingFields.push('Pan Number');
254
    if (!adharNo) missingFields.push('Aadhar Number');
255
    if (!email) missingFields.push('Email');
256
    if (missingFields.length > 0) {
257
        alert('The following fields are required: ' + missingFields.join(', '));
258
        return;
259
    }
260
    const loiFormData = {
261
        firstName: firstName,
262
        lastName: lastName,
263
        mobile: mobile,
264
        email: email,
265
        landline: landline,
266
        dob: dob,
267
        panNo: panNo,
268
        adharNo: adharNo
269
    };
270
    alert("you want update ..");
271
    doPostAjaxRequestWithJsonHandler(`${context}/updateLoiFormData?loiId=${loiId}`, JSON.stringify(loiFormData), function (response) {
33507 tejus.loha 272
        pendingLoiForm("main-content");
273
    });
274
 
275
});
276
 
277
$(document).on('click', ".pending-onboarding-form", function () {
33710 tejus.loha 278
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 279
        function (response) {
280
            $('#' + 'main-content').html(response);
281
        });
282
});
283
$(document).on('click', "#addBrandFeePayment", function () {
284
    let formData = objectifyForm($("form[name='brandFeeCollectionForm']").serializeArray());
285
    let loiId = $(this).val();
286
    for (var key in formData) {
287
        if (formData.hasOwnProperty(key) && formData[key].trim() === '') {
288
            alert("The (" + key + ") value is blank please fill this field !");
289
            return false;
290
        }
291
    }
292
    let jsonData = JSON.stringify(formData);
33658 tejus.loha 293
    if (confirm("Are you sure to add payment ?")) {
33525 tejus.loha 294
        doPostAjaxRequestWithJsonHandler(`${context}/brandfeeCollection?loiId=` + loiId, jsonData, function (response) {
295
            if (response) {
296
                alert("Payment add successfully...");
297
                pendingLoiForm("main-content");
33507 tejus.loha 298
 
33525 tejus.loha 299
            }
300
        });
301
    } else {
33658 tejus.loha 302
        alert("Payment is not add.");
303
 
33525 tejus.loha 304
    }
33507 tejus.loha 305
 
306
});
307
 
308
$(document).on('click', ".generateLoi", function () {
309
    let loiId = $(this).val();
310
    doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
311
        function (response) {
312
            $('#' + 'main-content').html(response);
313
        });
314
});
315
 
34085 tejus.loha 316
// $(document).on('change', 'select[name="pageSize"]', function () {
317
//     let pageSize = $(this).val();
318
//     console.log("pageSize - ", pageSize);
319
//     doGetAjaxRequestHandler(`${context}/pendingLoiForm?pageSize=${pageSize}&pageNumber=${1}`,
320
//         function (response) {
321
//             $('#' + 'main-content').html(response);
322
//         });
323
// });
324
 
33845 tejus.loha 325
$(document).on('click', ".mk-approve-loi", function () {
326
    let loiId = $(this).val();
327
    let companyName = $(this).data('company');
328
    let flag = $(this).data('flag');
329
    if (flag === 1) {
330
        if (confirm(`Are you sure Approve Loi of  ${companyName} `)) {
331
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${true}`,
332
                function (response) {
333
                    alert("Loi Approved successfully");
334
                    pendingLoiForm("main-content");
335
                });
336
        }
337
    } else {
338
        if (confirm(`Are you sure to Reject "${companyName}" LOI`)) {
339
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${false}`,
340
                function (response) {
341
                    pendingLoiForm("main-content");
342
                });
343
        }
344
    }
345
});
346
 
33507 tejus.loha 347
$(document).on('click', "#LOI_otp", function () {
348
    let loiId = $(this).val();
33577 tejus.loha 349
    if (confirm("Are you sure to send OTP ?")) {
350
        doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
351
            function (response) {
352
                alert(response);
353
                doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
354
                    function (response) {
355
                        $('#' + 'main-content').html(response);
356
                    });
357
            });
358
    } else {
359
        alert("OTP not send .");
360
    }
361
 
33507 tejus.loha 362
});
363
 
364
//confirmPayment
33525 tejus.loha 365
$(document).on('click', ".paymentConfirmBtn", function () {
366
    let approval = $(this).data('approval');
33507 tejus.loha 367
    let bfcId = $(this).val();
33525 tejus.loha 368
    let description = "All details are correct";
369
    if (confirm("Are you sure to confirm this payment ?")) {
370
        doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
371
            function (response) {
33845 tejus.loha 372
                alert("Payment is confirm successfully");
33525 tejus.loha 373
                pendingLoiForm("main-content");
374
            });
375
    }
376
});
377
 
378
$(document).on('click', ".paymentRejectBtn", function () {
33507 tejus.loha 379
    let approval = $(this).data('approval');
33525 tejus.loha 380
    let bfcId = $(this).val();
381
    let description;
382
    description = prompt("Reason for rejection..");
383
    if (description !== null) {
384
        if (confirm("Are you sure to Reject this payment ?")) {
385
            doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
386
                function (response) {
33845 tejus.loha 387
                    alert("Payment is rejected successfully");
33525 tejus.loha 388
                    pendingLoiForm("main-content");
389
                });
390
        }
391
    } else {
392
        alert("Please mention the reason as description and try again");
393
    }
33507 tejus.loha 394
});
34739 aman.kumar 395
$(document).on('click', ".deleteFeeCollection", function () {
396
    let bfcId = $(this).val();
397
    if (confirm("Are you sure you want to delete this payment entry?")) {
398
        doPutAjaxRequestHandler(
399
            `${context}/feePaymentDeletion?bfcId=${bfcId}`,
400
            function (response) {
401
                alert("Payment entry has been deleted successfully.");
402
                pendingLoiForm("main-content");
403
            }
404
        );
405
    }
406
});
407
 
33507 tejus.loha 408
$(document).on('click', ".upload-document-form", function () {
409
    let loiId = $(this).val();
33617 tejus.loha 410
    doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 411
        function (response) {
412
            $('#' + 'main-content').html(response);
413
        });
414
});
415
$(document).on('input', 'table#OnboardingDocumentTable input[type=file]', function () {
416
    if (confirm('Confirm file upload ?')) {
417
        var fileSelector = $(this)[0];
418
        if (fileSelector != undefined
419
            && fileSelector.files[0] != undefined) {
420
            var file = this.files[0];
421
            let fileInput = $(this);
422
            uploadDocument(file, function (documentId) {
423
                fileInput.closest('td').find(".documentId").val(documentId);
424
            });
425
        }
426
    }
427
});
33885 tejus.loha 428
 
429
$(document).on('input', 'table#OnboardingDocumentTable input[type=file],table#mk_brand-fee-collection-details input[type=file]', function () {
430
    if (confirm('Confirm file upload ?')) {
431
        var fileSelector = $(this)[0];
432
        if (fileSelector != undefined
433
            && fileSelector.files[0] != undefined) {
434
            var file = this.files[0];
435
            let fileInput = $(this);
436
            uploadDocument(file, function (documentId) {
437
                fileInput.closest('td').find(".documentId").val(documentId);
438
            });
439
        }
440
    }
441
});
442
 
443
$(document).on('input', '#payment-sc-doc', function () {
444
    if (confirm('Confirm file upload ?')) {
445
        var file = this.files[0];
446
        uploadDocument(file, function (documentId) {
447
            $('#payment-sc-docId').val(documentId);
448
        });
449
    }
450
});
451
 
452
 
33507 tejus.loha 453
$(document).on('click', ".mk_docApproval", function () {
454
    let loiId = $(this).data('form_id');
455
    let docMasterId = $(this).data('doc_master_id');
456
    let flag = $(this).data('flag');
457
    doPutAjaxRequestHandler(`${context}/documentVerify?loiId=${loiId}&docMasterId=${docMasterId}&flag=${flag}`,
458
        function (response) {
459
            alert(response);
33617 tejus.loha 460
            doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 461
                function (response) {
462
                    $('#' + 'main-content').html(response);
463
                });
464
 
465
        });
466
});
467
$(document).on('click', "#uploadDocumentbtn1", function () {
468
    if (confirm("Are you sure to upload all documents ?")) {
469
        var loiId = $(this).val();
470
        var loiDocModels = [];
471
        $("#OnboardingDocumentTable > tbody > tr").each(function (rowIndex) {
472
            var marsterId = $(this).find(".masterId").val();
473
            var docId = $(this).find(".documentId").val();
474
            var docName = $(this).find(".documentName").val();
475
            var loiDocModel = {
476
                documentId: docId,
477
                documentName: docName,
478
                documentMasterId: marsterId
479
            };
480
            loiDocModels.push(loiDocModel);
481
        });
482
        var loiDocModelData = JSON.stringify(loiDocModels);
483
        doPostAjaxRequestWithJsonHandler(`${context}/uploadOnboardingDocument?loiId=${loiId}`, loiDocModelData, function (response) {
484
            pendingLoiForm("main-content");
485
        });
486
    } else {
487
        //Nothing to do
488
    }
489
 
490
 
491
});
492
 
493
$(document).on('click', ".CompletedLoiForm", function () {
33617 tejus.loha 494
    doGetAjaxRequestHandler(`${context}/completedLoiForms`,
33507 tejus.loha 495
        function (response) {
496
            $('#' + 'main-content').html(response);
497
        });
498
});
499
 
500
$(document).on('click', "#createNewOnboardingPanel", function () {
501
    let loiId = $(this).val();
33710 tejus.loha 502
    //let authId = $(this).closest('tr').find('.authId').val();
33507 tejus.loha 503
 
33710 tejus.loha 504
    if (true) {
505
 
506
        doPostAjaxRequestHandler(`${context}/createNewOnboardingPanel?loiId=${loiId}&authId=${0}`,
33507 tejus.loha 507
            function (response) {
508
                if (response) {
33710 tejus.loha 509
                    // doGetAjaxRequestHandler(`${context}/completedLoiForms`,
510
                    //     function (response) {
511
                    //         $('#' + 'main-content').html(response);
512
                    //     });
513
                    alert("it moved successfully ");
33507 tejus.loha 514
                } else {
515
                    //nothing
516
                }
517
 
518
            });
519
    } else {
520
        alert("Please choose RBM ");
521
    }
522
 
523
});
524
 
33617 tejus.loha 525
$(document).on('click', "#downloadAllLoiForm", function () {
526
    const from = $('input[name="from"]').val();
527
    const to = $('input[name="to"]').val();
528
    let missingFields = [];
529
    if (!from) missingFields.push('From date');
530
    if (!to) missingFields.push('To date');
531
    if (missingFields.length > 0) {
532
        alert('Please select : ' + missingFields.join(','));
533
        return;
534
    }
535
    window.location.href = `${context}/downloadLoiFromReport?from=${from}&to=${to}`;
536
});
33658 tejus.loha 537
$(document).on('click', ".brandFeePaymentEdit", function () {
538
    var bfcId = $(this).val();
34310 tejus.loha 539
 
33658 tejus.loha 540
    // Get the table row
541
    var $row = $(this).closest('tr');
542
    var feeCollectingTimeStamp = $row.find('input[name="feeCollectingTimeStamp"]').val();
543
    var collectedAmount = $row.find('input[name="collectedAmount"]').val();
544
    var paymentReferenceNo = $row.find('input[name="paymentReferenceNo"]').val();
545
    var paymentMode = $row.find('select[name="paymentMode"]').val();
33885 tejus.loha 546
    var documentId = $row.find('input[name="documentId"]').val();
547
 
33658 tejus.loha 548
    const Data = {
549
        id: bfcId,
550
        feeCollectingTimeStamp: feeCollectingTimeStamp,
551
        collectedAmount: collectedAmount,
552
        paymentReferenceNo: paymentReferenceNo,
34745 aman.kumar 553
        paymentAttachment: documentId,
33658 tejus.loha 554
        paymentMode: paymentMode
555
    };
556
    var jsonData = JSON.stringify(Data);
557
    if (confirm("Are you sure to update details")) {
558
        doPostAjaxRequestWithJsonHandler(`${context}/updatePayment`, jsonData,
559
            function (response) {
33845 tejus.loha 560
                if (response) {
561
                    alert("Updated payment details are save successfully ")
562
                    pendingLoiForm('main-content');
563
                } else {
564
                    alert("Updated payment details are not save ")
565
                    pendingLoiForm('main-content');
566
                }
33658 tejus.loha 567
            });
568
    } else {
569
        pendingLoiForm('main-content');
570
    }
33617 tejus.loha 571
 
33658 tejus.loha 572
 
573
});
33879 tejus.loha 574
/*function validateOTP() {
575
    while (true) {
576
        let otp = prompt("Enter received OTP here");
577
        if (otp === null) {
578
            alert('OTP entry was cancelled. Try again.');
579
            return null;
580
        }
581
        let regex = /^[0-9]{5}$/;
582
        if (regex.test(otp)) {
583
            console.log('otp-flag-', otp);
584
            return otp;  // Return valid OTP
585
        } else {
586
            alert('Please enter a valid 5-digit numeric OTP');
587
        }
588
    }
589
}*/
33658 tejus.loha 590
 
33879 tejus.loha 591
$(document).on('click', "#confirmSign", function () {
592
    let loiId = $(this).val();
593
    // let otp = validateOTP();
594
    let otp = prompt("Enter received OTP here");
595
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
596
    if (otp != undefined || otp != null) {
33658 tejus.loha 597
 
33879 tejus.loha 598
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
599
            if (response) {
600
                const element = document.getElementById('loiPDF_content');
601
                const opt = {
602
                    margin: 0.5,
603
                    filename: 'document.pdf',
604
                    image: {type: 'jpeg', quality: 0.98},
605
                    html2canvas: {scale: 2, logging: true, useCORS: true},
606
                    jsPDF: {unit: 'in', format: 'letter', orientation: 'portrait'}
607
                };
608
                html2pdf().from(element).set(opt).outputPdf("arraybuffer").then(function (pdf) {
609
                    const file = new Blob([pdf], {type: 'application/pdf'});
610
                    uploadDocument(file, function (documentId) {
611
                        IdempotencyKey = uuidv4();
612
                        if (documentId > 0) {
613
                            saveLoiDoc(loiId, documentId);
614
                        } else {
615
                            alert("Something went wrong , please again to confirm otp")
616
                        }
617
                    });
618
                });
619
            }
620
        });
621
    } else {
34310 tejus.loha 622
        return false;
33879 tejus.loha 623
    }
624
});
625
 
626
 
627
function saveLoiDoc(loiId, documentId) {
628
    let saveLoiDocUrl = `${context}/saveLoiDoc?loiId=` + loiId + `&loiDocId=` + documentId
629
    doPostAjaxRequestHandler(saveLoiDocUrl, function (response) {
630
        if (response) {
631
            alert("LOI has been signed successfully and sent to the registered email. Please check your email.");
632
            pendingLoiForm("main-content");
633
        } else {
634
            alert("Something went wrong , Please try again to generate Loi and Validate otp");
635
        }
636
    });
637
}
638
 
639
 
33507 tejus.loha 640
function pendingLoiForm(domId) {
33710 tejus.loha 641
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 642
        function (response) {
643
            $('#' + domId).html(response);
644
        });
645
}
34085 tejus.loha 646
 
647
/*
648
function createPagination(containerId, totalPages, currentPage = 1, onPageChange = null) {
649
    const $container = $('#' + containerId);
650
    $container.empty(); // Clear the container
651
 
652
    // Helper Function to Render Pagination
653
    function renderPagination(currentPage) {
654
        $container.empty();
655
 
656
        // Previous Button
657
        const $prevButton = $('<button>')
658
            .text('Previous')
659
            .click(() => handlePageChange(currentPage > 1 ? currentPage - 1 : totalPages)); // Loop to last page if on the first page
660
        $container.append($prevButton);
661
 
662
        // First Page
663
        const $firstPageButton = $('<button>')
664
            .text('1')
665
            .addClass(currentPage === 1 ? 'active' : '')
666
            .click(() => handlePageChange(1));
667
        $container.append($firstPageButton);
668
 
669
        // Ellipsis Before Current Pages
670
        if (currentPage > 3) {
671
            $container.append($('<span>').text('...'));
672
        }
673
 
674
        // Dynamic Pages Around Current Page
675
        for (let i = Math.max(2, currentPage - 1); i <= Math.min(totalPages - 1, currentPage + 1); i++) {
676
            const $pageButton = $('<button>')
677
                .text(i)
678
                .addClass(currentPage === i ? 'active' : '')
679
                .click(() => handlePageChange(i));
680
            $container.append($pageButton);
681
        }
682
 
683
        // Ellipsis Before Last Page
684
        if (currentPage < totalPages - 2) {
685
            $container.append($('<span>').text('...'));
686
        }
687
 
688
        // Last Page
689
        if (totalPages > 1) {
690
            const $lastPageButton = $('<button>')
691
                .text(totalPages)
692
                .addClass(currentPage === totalPages ? 'active' : '')
693
                .click(() => handlePageChange(totalPages));
694
            $container.append($lastPageButton);
695
        }
696
 
697
        // Next Button
698
        const $nextButton = $('<button>')
699
            .text('Next')
700
            .click(() => handlePageChange(currentPage < totalPages ? currentPage + 1 : 1)); // Loop to first page if on the last page
701
        $container.append($nextButton);
702
    }
703
 
704
    // Handle Page Change
705
    function handlePageChange(selectedPage) {
706
        if (onPageChange) {
707
            onPageChange(selectedPage); // Trigger the callback with the selected page
708
        }
709
        renderPagination(selectedPage); // Re-render pagination
710
    }
711
 
712
    // Initial Render
713
    renderPagination(currentPage);
714
}*/