Subversion Repositories SmartDukaan

Rev

Rev 34107 | Rev 34739 | 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
});
395
$(document).on('click', ".upload-document-form", function () {
396
    let loiId = $(this).val();
33617 tejus.loha 397
    doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 398
        function (response) {
399
            $('#' + 'main-content').html(response);
400
        });
401
});
402
$(document).on('input', 'table#OnboardingDocumentTable input[type=file]', function () {
403
    if (confirm('Confirm file upload ?')) {
404
        var fileSelector = $(this)[0];
405
        if (fileSelector != undefined
406
            && fileSelector.files[0] != undefined) {
407
            var file = this.files[0];
408
            let fileInput = $(this);
409
            uploadDocument(file, function (documentId) {
410
                fileInput.closest('td').find(".documentId").val(documentId);
411
            });
412
        }
413
    }
414
});
33885 tejus.loha 415
 
416
$(document).on('input', 'table#OnboardingDocumentTable input[type=file],table#mk_brand-fee-collection-details input[type=file]', function () {
417
    if (confirm('Confirm file upload ?')) {
418
        var fileSelector = $(this)[0];
419
        if (fileSelector != undefined
420
            && fileSelector.files[0] != undefined) {
421
            var file = this.files[0];
422
            let fileInput = $(this);
423
            uploadDocument(file, function (documentId) {
424
                fileInput.closest('td').find(".documentId").val(documentId);
425
            });
426
        }
427
    }
428
});
429
 
430
$(document).on('input', '#payment-sc-doc', function () {
431
    if (confirm('Confirm file upload ?')) {
432
        var file = this.files[0];
433
        uploadDocument(file, function (documentId) {
434
            $('#payment-sc-docId').val(documentId);
435
        });
436
    }
437
});
438
 
439
 
33507 tejus.loha 440
$(document).on('click', ".mk_docApproval", function () {
441
    let loiId = $(this).data('form_id');
442
    let docMasterId = $(this).data('doc_master_id');
443
    let flag = $(this).data('flag');
444
    doPutAjaxRequestHandler(`${context}/documentVerify?loiId=${loiId}&docMasterId=${docMasterId}&flag=${flag}`,
445
        function (response) {
446
            alert(response);
33617 tejus.loha 447
            doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 448
                function (response) {
449
                    $('#' + 'main-content').html(response);
450
                });
451
 
452
        });
453
});
454
$(document).on('click', "#uploadDocumentbtn1", function () {
455
    if (confirm("Are you sure to upload all documents ?")) {
456
        var loiId = $(this).val();
457
        var loiDocModels = [];
458
        $("#OnboardingDocumentTable > tbody > tr").each(function (rowIndex) {
459
            var marsterId = $(this).find(".masterId").val();
460
            var docId = $(this).find(".documentId").val();
461
            var docName = $(this).find(".documentName").val();
462
            var loiDocModel = {
463
                documentId: docId,
464
                documentName: docName,
465
                documentMasterId: marsterId
466
            };
467
            loiDocModels.push(loiDocModel);
468
        });
469
        var loiDocModelData = JSON.stringify(loiDocModels);
470
        doPostAjaxRequestWithJsonHandler(`${context}/uploadOnboardingDocument?loiId=${loiId}`, loiDocModelData, function (response) {
471
            pendingLoiForm("main-content");
472
        });
473
    } else {
474
        //Nothing to do
475
    }
476
 
477
 
478
});
479
 
480
$(document).on('click', ".CompletedLoiForm", function () {
33617 tejus.loha 481
    doGetAjaxRequestHandler(`${context}/completedLoiForms`,
33507 tejus.loha 482
        function (response) {
483
            $('#' + 'main-content').html(response);
484
        });
485
});
486
 
487
$(document).on('click', "#createNewOnboardingPanel", function () {
488
    let loiId = $(this).val();
33710 tejus.loha 489
    //let authId = $(this).closest('tr').find('.authId').val();
33507 tejus.loha 490
 
33710 tejus.loha 491
    if (true) {
492
 
493
        doPostAjaxRequestHandler(`${context}/createNewOnboardingPanel?loiId=${loiId}&authId=${0}`,
33507 tejus.loha 494
            function (response) {
495
                if (response) {
33710 tejus.loha 496
                    // doGetAjaxRequestHandler(`${context}/completedLoiForms`,
497
                    //     function (response) {
498
                    //         $('#' + 'main-content').html(response);
499
                    //     });
500
                    alert("it moved successfully ");
33507 tejus.loha 501
                } else {
502
                    //nothing
503
                }
504
 
505
            });
506
    } else {
507
        alert("Please choose RBM ");
508
    }
509
 
510
});
511
 
33617 tejus.loha 512
$(document).on('click', "#downloadAllLoiForm", function () {
513
    const from = $('input[name="from"]').val();
514
    const to = $('input[name="to"]').val();
515
    let missingFields = [];
516
    if (!from) missingFields.push('From date');
517
    if (!to) missingFields.push('To date');
518
    if (missingFields.length > 0) {
519
        alert('Please select : ' + missingFields.join(','));
520
        return;
521
    }
522
    window.location.href = `${context}/downloadLoiFromReport?from=${from}&to=${to}`;
523
});
33658 tejus.loha 524
$(document).on('click', ".brandFeePaymentEdit", function () {
525
    var bfcId = $(this).val();
34310 tejus.loha 526
 
33658 tejus.loha 527
    // Get the table row
528
    var $row = $(this).closest('tr');
529
    var feeCollectingTimeStamp = $row.find('input[name="feeCollectingTimeStamp"]').val();
530
    var collectedAmount = $row.find('input[name="collectedAmount"]').val();
531
    var paymentReferenceNo = $row.find('input[name="paymentReferenceNo"]').val();
532
    var paymentMode = $row.find('select[name="paymentMode"]').val();
33885 tejus.loha 533
    var documentId = $row.find('input[name="documentId"]').val();
534
 
33658 tejus.loha 535
    const Data = {
536
        id: bfcId,
537
        feeCollectingTimeStamp: feeCollectingTimeStamp,
538
        collectedAmount: collectedAmount,
539
        paymentReferenceNo: paymentReferenceNo,
33885 tejus.loha 540
        attachment: documentId,
33658 tejus.loha 541
        paymentMode: paymentMode
542
    };
543
    var jsonData = JSON.stringify(Data);
544
    if (confirm("Are you sure to update details")) {
545
        doPostAjaxRequestWithJsonHandler(`${context}/updatePayment`, jsonData,
546
            function (response) {
33845 tejus.loha 547
                if (response) {
548
                    alert("Updated payment details are save successfully ")
549
                    pendingLoiForm('main-content');
550
                } else {
551
                    alert("Updated payment details are not save ")
552
                    pendingLoiForm('main-content');
553
                }
33658 tejus.loha 554
            });
555
    } else {
556
        pendingLoiForm('main-content');
557
    }
33617 tejus.loha 558
 
33658 tejus.loha 559
 
560
});
33879 tejus.loha 561
/*function validateOTP() {
562
    while (true) {
563
        let otp = prompt("Enter received OTP here");
564
        if (otp === null) {
565
            alert('OTP entry was cancelled. Try again.');
566
            return null;
567
        }
568
        let regex = /^[0-9]{5}$/;
569
        if (regex.test(otp)) {
570
            console.log('otp-flag-', otp);
571
            return otp;  // Return valid OTP
572
        } else {
573
            alert('Please enter a valid 5-digit numeric OTP');
574
        }
575
    }
576
}*/
33658 tejus.loha 577
 
33879 tejus.loha 578
$(document).on('click', "#confirmSign", function () {
579
    let loiId = $(this).val();
580
    // let otp = validateOTP();
581
    let otp = prompt("Enter received OTP here");
582
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
583
    if (otp != undefined || otp != null) {
33658 tejus.loha 584
 
33879 tejus.loha 585
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
586
            if (response) {
587
                const element = document.getElementById('loiPDF_content');
588
                const opt = {
589
                    margin: 0.5,
590
                    filename: 'document.pdf',
591
                    image: {type: 'jpeg', quality: 0.98},
592
                    html2canvas: {scale: 2, logging: true, useCORS: true},
593
                    jsPDF: {unit: 'in', format: 'letter', orientation: 'portrait'}
594
                };
595
                html2pdf().from(element).set(opt).outputPdf("arraybuffer").then(function (pdf) {
596
                    const file = new Blob([pdf], {type: 'application/pdf'});
597
                    uploadDocument(file, function (documentId) {
598
                        IdempotencyKey = uuidv4();
599
                        if (documentId > 0) {
600
                            saveLoiDoc(loiId, documentId);
601
                        } else {
602
                            alert("Something went wrong , please again to confirm otp")
603
                        }
604
                    });
605
                });
606
            }
607
        });
608
    } else {
34310 tejus.loha 609
        return false;
33879 tejus.loha 610
    }
611
});
612
 
613
 
614
function saveLoiDoc(loiId, documentId) {
615
    let saveLoiDocUrl = `${context}/saveLoiDoc?loiId=` + loiId + `&loiDocId=` + documentId
616
    doPostAjaxRequestHandler(saveLoiDocUrl, function (response) {
617
        if (response) {
618
            alert("LOI has been signed successfully and sent to the registered email. Please check your email.");
619
            pendingLoiForm("main-content");
620
        } else {
621
            alert("Something went wrong , Please try again to generate Loi and Validate otp");
622
        }
623
    });
624
}
625
 
626
 
33507 tejus.loha 627
function pendingLoiForm(domId) {
33710 tejus.loha 628
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 629
        function (response) {
630
            $('#' + domId).html(response);
631
        });
632
}
34085 tejus.loha 633
 
634
/*
635
function createPagination(containerId, totalPages, currentPage = 1, onPageChange = null) {
636
    const $container = $('#' + containerId);
637
    $container.empty(); // Clear the container
638
 
639
    // Helper Function to Render Pagination
640
    function renderPagination(currentPage) {
641
        $container.empty();
642
 
643
        // Previous Button
644
        const $prevButton = $('<button>')
645
            .text('Previous')
646
            .click(() => handlePageChange(currentPage > 1 ? currentPage - 1 : totalPages)); // Loop to last page if on the first page
647
        $container.append($prevButton);
648
 
649
        // First Page
650
        const $firstPageButton = $('<button>')
651
            .text('1')
652
            .addClass(currentPage === 1 ? 'active' : '')
653
            .click(() => handlePageChange(1));
654
        $container.append($firstPageButton);
655
 
656
        // Ellipsis Before Current Pages
657
        if (currentPage > 3) {
658
            $container.append($('<span>').text('...'));
659
        }
660
 
661
        // Dynamic Pages Around Current Page
662
        for (let i = Math.max(2, currentPage - 1); i <= Math.min(totalPages - 1, currentPage + 1); i++) {
663
            const $pageButton = $('<button>')
664
                .text(i)
665
                .addClass(currentPage === i ? 'active' : '')
666
                .click(() => handlePageChange(i));
667
            $container.append($pageButton);
668
        }
669
 
670
        // Ellipsis Before Last Page
671
        if (currentPage < totalPages - 2) {
672
            $container.append($('<span>').text('...'));
673
        }
674
 
675
        // Last Page
676
        if (totalPages > 1) {
677
            const $lastPageButton = $('<button>')
678
                .text(totalPages)
679
                .addClass(currentPage === totalPages ? 'active' : '')
680
                .click(() => handlePageChange(totalPages));
681
            $container.append($lastPageButton);
682
        }
683
 
684
        // Next Button
685
        const $nextButton = $('<button>')
686
            .text('Next')
687
            .click(() => handlePageChange(currentPage < totalPages ? currentPage + 1 : 1)); // Loop to first page if on the last page
688
        $container.append($nextButton);
689
    }
690
 
691
    // Handle Page Change
692
    function handlePageChange(selectedPage) {
693
        if (onPageChange) {
694
            onPageChange(selectedPage); // Trigger the callback with the selected page
695
        }
696
        renderPagination(selectedPage); // Re-render pagination
697
    }
698
 
699
    // Initial Render
700
    renderPagination(currentPage);
701
}*/