Subversion Repositories SmartDukaan

Rev

Rev 33879 | Rev 33909 | 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
    console.log("maritalStatus - " + maritalStatus);
12
    if (maritalStatus == 1) {
13
        $(".loiAnniversaryDate").removeClass('hide-model');
14
        $(".loiAnniversaryDate").addClass('show-model');
15
    } else {
16
        $(".loiAnniversaryDate").removeClass('show-model');
17
        $(".loiAnniversaryDate").addClass('hide-model');
18
    }
19
 
20
});
21
 
33578 tejus.loha 22
 
33885 tejus.loha 23
$(document).on('click', ".mk_submit_loi_form", function () {
33577 tejus.loha 24
    // Gather input values
25
    const referId = $('select[name="referId"]').val();
26
    const billingAddress = $('select[name="billingAddress"]').val();
33582 tejus.loha 27
    const acquiredDate = $('input[name="acquiredDate"]').val();
33577 tejus.loha 28
    const firstName = $('input[name="firstName"]').val();
29
    const lastName = $('input[name="lastName"]').val();
30
    const mobile = $('input[name="mobile"]').val();
33780 tejus.loha 31
 
32
    // validate email pattern
33
    const emailValue = $('input[name="email"]').val();
34
    var email;
35
    if (emailValue.length > 0) {
36
        if (isValidEmail(emailValue)) {
37
            email = emailValue;
38
        } else {
39
            alert("Please check your Email Address");
40
            return;
41
        }
42
    }
33577 tejus.loha 43
    const landline = $('input[name="landline"]').val();
44
    const dob = $('input[name="dob"]').val();
33624 tejus.loha 45
    var today = new Date();
46
    var birthDate = new Date(dob);
47
    var age = today.getFullYear() - birthDate.getFullYear();
48
    var monthDiff = today.getMonth() - birthDate.getMonth();
49
 
50
    if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
51
        age--;
52
    }
33577 tejus.loha 53
    var maritalStatus = $('select[name="maritalStatus"]').val();
54
    const anniversaryDate = $('input[name="anniversaryDate"]').val();
55
    const panNo = $('input[name="panNo"]').val();
56
    const adharNo = $('input[name="adharNo"]').val();
57
    const gstNo = $('input[name="gstNo"]').val();
58
    const bankName = $('input[name="bankName"]').val();
59
    const ifscCode = $('input[name="ifscCode"]').val();
60
    const accountNo = $('input[name="accountNo"]').val();
61
    const businessType = $('select[name="businessType"]').val();
62
    const companyName = $('input[name="companyName"]').val();
63
    const gstPin = $('input[name="gstPin"]').val();
64
    const gstState = $('input[name="gstState"]').val();
65
    const gstCity = $('input[name="gstCity"]').val();
66
    const gstDistrict = $('input[name="gstDistrict"]').val();
67
    const agreeWalletValue = $('select[name="agreeWalletValue"]').val();
68
    const storeArea = $('input[name="storeArea"]').val();
69
    const storePotential = $('input[name="storePotential"]').val();
33658 tejus.loha 70
    let brandCommitment = [];
71
    var brandCommitmentInputs = document.querySelectorAll(".brand-commitment");
72
    brandCommitmentInputs.forEach(function (input) {
73
        var commitmentValue = parseInt(input.value);
74
        if (!isNaN(commitmentValue)) {
75
            brandCommitment.push({
76
                brandName: input.getAttribute("name"),
77
                value: commitmentValue
78
            });
79
        }
80
    });
81
    let totalCommitment = brandCommitment.reduce((total, commitment) => total + commitment.value, 0);
82
    console.log("Total Commitment Amount:", totalCommitment);
33577 tejus.loha 83
    const lessCommitReason = $('input[name="lessCommitReason"]').val();
33658 tejus.loha 84
    let minCommit = totalCommitment >= storePotential * (70 / 100);
33577 tejus.loha 85
    const agreedBrandFees = $('select[name="agreedBrandFees"]').val();
86
    console.log("agreedBrandFees - ", agreedBrandFees);
33624 tejus.loha 87
    const values = agreedBrandFees.split(/[-]/); // Split the string
88
    const brandFee = parseFloat(values[1]);
33577 tejus.loha 89
    const brandFeesCollected = $('input[name="brandFeesCollected"]').val();
90
    const paymentMode = $('select[name="paymentMode"]').val();
91
    const paymentReferenceNo = $('input[name="paymentReferenceNo"]').val();
33578 tejus.loha 92
    const feeCollectingDate = $('input[name="feeCollectingDate"]').val();
33885 tejus.loha 93
    const paymentAttachment = $('input[name="paymentAttachment"]').val();
33577 tejus.loha 94
 
95
    let missingFields = [];
96
    if (!firstName) missingFields.push('First Name');
97
    if (!lastName) missingFields.push('Last Name');
98
    if (mobile.length < 10 || !mobile) {
99
        missingFields.push('Mobile number should be 10 digit');
100
    }
33658 tejus.loha 101
    if (!minCommit) {
33577 tejus.loha 102
        if (!lessCommitReason) missingFields.push('Less Commit Reason');
103
    }
104
    if (!maritalStatus) missingFields.push('Marital Status');
105
    if (maritalStatus == 1) {
106
        if (!anniversaryDate) missingFields.push('Anniversary Date');
107
    }
108
    if (!email) missingFields.push('Email');
33582 tejus.loha 109
    if (!acquiredDate) missingFields.push('Acquired date');
33577 tejus.loha 110
    if (!dob) missingFields.push('dob(Date of Birth)');
33624 tejus.loha 111
    if (age <= 18) missingFields.push('You must be at least 18 years old to Fill LOI FORM. ');
33577 tejus.loha 112
    if (!panNo) missingFields.push('Pan Number');
113
    if (!adharNo) missingFields.push('Aadhar Number');
114
    if (!gstNo) missingFields.push('GST Number');
115
    if (!bankName) missingFields.push('Bank Name');
116
    if (!ifscCode) missingFields.push('IFSC code');
117
    if (!accountNo) missingFields.push('Account Number');
118
    if (!businessType) missingFields.push('businessType');
119
    if (!companyName) missingFields.push('Company Name');
120
    if (!agreeWalletValue) missingFields.push('Agree Wallet Value');
121
    if (!storeArea) missingFields.push('storeArea');
122
    if (!storePotential) missingFields.push('Store Potential');
123
    if (!agreedBrandFees) missingFields.push('Agreed Brand Fees');
124
    if (!brandFeesCollected) missingFields.push('Brand Fees Collected');
33845 tejus.loha 125
    if (brandFeesCollected > brandFee) missingFields.push('The collected brand fee must not exceed the agreed brand fees.');
33577 tejus.loha 126
    if (!paymentMode) missingFields.push('Payment Mode');
127
    if (!paymentReferenceNo) missingFields.push('Payment Reference No');
33578 tejus.loha 128
    if (!feeCollectingDate) missingFields.push('Fee Collecting Date');
33885 tejus.loha 129
    if (!paymentAttachment) missingFields.push('Payment screenshot ');
33577 tejus.loha 130
    if (missingFields.length > 0) {
131
        alert('The following fields are required: ' + missingFields.join(', '));
132
        return;
133
    }
134
    const loiFormData = {
135
        referId: referId,
136
        businessType: businessType,
33582 tejus.loha 137
        acquiredDate: acquiredDate,
33577 tejus.loha 138
        firstName: firstName,
139
        lastName: lastName,
140
        mobile: mobile,
141
        email: email,
142
        landline: landline,
143
        dob: dob,
144
        anniversaryDate: anniversaryDate,
145
        panNo: panNo,
146
        adharNo: adharNo,
147
        gstNo: gstNo,
148
        bankName: bankName,
149
        ifscCode: ifscCode,
150
        accountNo: accountNo,
151
        companyName: companyName,
152
        gstPin: gstPin,
153
        gstState: gstState,
154
        gstCity: gstCity,
155
        gstDistrict: gstDistrict,
156
        agreeWalletValue: agreeWalletValue,
157
        storeArea: storeArea,
158
        storePotential: storePotential,
159
        lessCommitReason: lessCommitReason,
160
        agreedBrandFees: agreedBrandFees,
161
        brandFeesCollected: brandFeesCollected,
162
        paymentMode: paymentMode,
163
        paymentReferenceNo: paymentReferenceNo,
33578 tejus.loha 164
        feeCollectingTimeStamp: feeCollectingDate,
33885 tejus.loha 165
        paymentAttachment: paymentAttachment,
33658 tejus.loha 166
        billingAddress: billingAddress,
167
        brandCommitment: brandCommitment
33577 tejus.loha 168
    };
33658 tejus.loha 169
 
33577 tejus.loha 170
    console.log("form data - ", loiFormData);
171
    if (confirm("Are you sure to submit the form ?")) {
172
        doPostAjaxRequestWithJsonHandler(`${context}/submitLoiForm`, JSON.stringify(loiFormData), function (response) {
173
            console.log('responsee', response);
33507 tejus.loha 174
            if (response) {
175
                alert("Your LOI form Submitted successfully ");
176
                pendingLoiForm("main-content");
177
 
178
            } else {
179
                alert("Your LOI form not Submitted , try again ");
33845 tejus.loha 180
                doGetAjaxRequestHandler(`${context}/loiForm`,
33507 tejus.loha 181
                    function (response) {
182
                        $('#' + 'main-content').html(response);
183
                    });
184
            }
185
        });
186
    }
187
});
33578 tejus.loha 188
 
33658 tejus.loha 189
$(document).on('click', ".updateLoiForm", function () {
33507 tejus.loha 190
    let loiId = $(this).val();
191
    console.log("form id - ", loiId);
33658 tejus.loha 192
    doGetAjaxRequestHandler(context + "/updateLoiForm?loiId=" + loiId,
33507 tejus.loha 193
        function (response) {
194
            $('#' + 'main-content').html(response);
195
        });
196
});
33879 tejus.loha 197
 
33710 tejus.loha 198
$(document).on('click', ".save_agree_brand_fee", function () {
199
    let loiId = $(this).val();
200
    var $tr = $(this).closest('tr');
201
    var agreedBrandFee = $tr.find('input[name="brandFee"]').val();
202
    if (confirm("Are you sure to change Agreed brand fee")) {
203
        doPutAjaxRequestHandler(`${context}/updateAgreedBrandFee?loiId=${loiId}&brandFee=${agreedBrandFee}`, function (response) {
204
            pendingLoiForm("main-content");
205
        });
206
    } else {
207
        pendingLoiForm("main-content");
208
    }
209
});
33507 tejus.loha 210
 
33658 tejus.loha 211
$(document).on('click', ".updateLoiFormDataButton", function () {
212
    console.log("updateLoiFormDataButton clicked..");
213
    let loiId = $(this).data('loiid');
214
 
215
    const firstName = $('input[name="firstName"]').val();
216
    const lastName = $('input[name="lastName"]').val();
217
    const mobile = $('input[name="mobile"]').val();
218
    const email = $('input[name="email"]').val();
219
    const landline = $('input[name="landline"]').val();
220
    const dob = $('input[name="dob"]').val();
221
    const panNo = $('input[name="panNo"]').val();
222
    const adharNo = $('input[name="adharNo"]').val();
223
    let missingFields = [];
224
    if (!firstName) missingFields.push('First Name');
225
    if (!lastName) missingFields.push('Last Name');
226
    if (mobile.length < 10 || !mobile) {
227
        missingFields.push('Mobile number should be 10 digit');
228
    }
229
    if (!dob) missingFields.push('dob(Date of Birth)');
230
    if (!panNo) missingFields.push('Pan Number');
231
    if (!adharNo) missingFields.push('Aadhar Number');
232
    if (!email) missingFields.push('Email');
233
    if (missingFields.length > 0) {
234
        alert('The following fields are required: ' + missingFields.join(', '));
235
        return;
236
    }
237
    const loiFormData = {
238
        firstName: firstName,
239
        lastName: lastName,
240
        mobile: mobile,
241
        email: email,
242
        landline: landline,
243
        dob: dob,
244
        panNo: panNo,
245
        adharNo: adharNo
246
    };
247
    console.log("loiFormData - ", loiFormData);
248
    alert("you want update ..");
249
    doPostAjaxRequestWithJsonHandler(`${context}/updateLoiFormData?loiId=${loiId}`, JSON.stringify(loiFormData), function (response) {
33507 tejus.loha 250
        pendingLoiForm("main-content");
251
    });
252
 
253
});
254
 
255
$(document).on('click', ".pending-onboarding-form", function () {
33710 tejus.loha 256
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 257
        function (response) {
258
            $('#' + 'main-content').html(response);
259
        });
260
});
261
$(document).on('click', "#addBrandFeePayment", function () {
262
    let formData = objectifyForm($("form[name='brandFeeCollectionForm']").serializeArray());
263
    let loiId = $(this).val();
264
    console.log("form id -", loiId);
265
    for (var key in formData) {
266
        if (formData.hasOwnProperty(key) && formData[key].trim() === '') {
267
            alert("The (" + key + ") value is blank please fill this field !");
268
            return false;
269
        }
270
    }
271
    let jsonData = JSON.stringify(formData);
33658 tejus.loha 272
    if (confirm("Are you sure to add payment ?")) {
33525 tejus.loha 273
        doPostAjaxRequestWithJsonHandler(`${context}/brandfeeCollection?loiId=` + loiId, jsonData, function (response) {
274
            if (response) {
275
                alert("Payment add successfully...");
276
                pendingLoiForm("main-content");
33507 tejus.loha 277
 
33525 tejus.loha 278
            }
279
        });
280
    } else {
33658 tejus.loha 281
        alert("Payment is not add.");
282
 
33525 tejus.loha 283
    }
33507 tejus.loha 284
 
285
});
286
 
287
$(document).on('click', ".generateLoi", function () {
288
    let loiId = $(this).val();
289
    console.log("form id - ", loiId);
290
    doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
291
        function (response) {
292
            $('#' + 'main-content').html(response);
293
        });
294
});
295
 
33845 tejus.loha 296
$(document).on('click', ".mk-approve-loi", function () {
297
    let loiId = $(this).val();
298
    let companyName = $(this).data('company');
299
    let flag = $(this).data('flag');
300
    console.log("form id - ", loiId);
301
    if (flag === 1) {
302
        if (confirm(`Are you sure Approve Loi of  ${companyName} `)) {
303
            console.log("Approval");
304
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${true}`,
305
                function (response) {
306
                    alert("Loi Approved successfully");
307
                    pendingLoiForm("main-content");
308
                });
309
        }
310
    } else {
311
        if (confirm(`Are you sure to Reject "${companyName}" LOI`)) {
312
            console.log("reject");
313
            doPutAjaxRequestHandler(`${context}/approve-reject-Loi?loiId=${loiId}&flag=${false}`,
314
                function (response) {
315
                    pendingLoiForm("main-content");
316
                });
317
        }
318
    }
319
});
320
 
33507 tejus.loha 321
$(document).on('click', "#LOI_otp", function () {
322
    let loiId = $(this).val();
323
    console.log("loiId-", loiId);
33577 tejus.loha 324
    if (confirm("Are you sure to send OTP ?")) {
325
        doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
326
            function (response) {
327
                alert(response);
328
                doGetAjaxRequestHandler(context + "/generateLoi?loiId=" + loiId,
329
                    function (response) {
330
                        $('#' + 'main-content').html(response);
331
                    });
332
            });
333
    } else {
334
        alert("OTP not send .");
335
    }
336
 
33507 tejus.loha 337
});
338
 
339
//confirmPayment
33525 tejus.loha 340
$(document).on('click', ".paymentConfirmBtn", function () {
341
    let approval = $(this).data('approval');
33507 tejus.loha 342
    let bfcId = $(this).val();
33525 tejus.loha 343
    let description = "All details are correct";
344
    if (confirm("Are you sure to confirm this payment ?")) {
345
        doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
346
            function (response) {
33845 tejus.loha 347
                alert("Payment is confirm successfully");
33525 tejus.loha 348
                pendingLoiForm("main-content");
349
            });
350
    }
351
});
352
 
353
$(document).on('click', ".paymentRejectBtn", function () {
33507 tejus.loha 354
    let approval = $(this).data('approval');
33525 tejus.loha 355
    let bfcId = $(this).val();
356
    let description;
357
    description = prompt("Reason for rejection..");
358
    if (description !== null) {
359
        if (confirm("Are you sure to Reject this payment ?")) {
360
            doPutAjaxRequestHandler(`${context}/feePaymentApproval?bfcId=${bfcId}&feePaymentStatus=${approval}&description=${description}`,
361
                function (response) {
33845 tejus.loha 362
                    alert("Payment is rejected successfully");
33525 tejus.loha 363
                    pendingLoiForm("main-content");
364
                });
365
        }
366
    } else {
367
        alert("Please mention the reason as description and try again");
368
    }
33507 tejus.loha 369
});
370
$(document).on('click', ".upload-document-form", function () {
371
    let loiId = $(this).val();
33617 tejus.loha 372
    doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 373
        function (response) {
374
            $('#' + 'main-content').html(response);
375
        });
376
});
377
$(document).on('input', 'table#OnboardingDocumentTable input[type=file]', function () {
378
    if (confirm('Confirm file upload ?')) {
379
        var fileSelector = $(this)[0];
380
        if (fileSelector != undefined
381
            && fileSelector.files[0] != undefined) {
382
            var file = this.files[0];
383
            console.log("file", file);
384
            let fileInput = $(this);
385
            console.log("fileInput", file);
386
            uploadDocument(file, function (documentId) {
387
                console.log("documentIdzzz  : ", documentId);
388
                fileInput.closest('td').find(".documentId").val(documentId);
389
            });
390
        }
391
    }
392
});
33885 tejus.loha 393
 
394
$(document).on('input', 'table#OnboardingDocumentTable input[type=file],table#mk_brand-fee-collection-details input[type=file]', function () {
395
    if (confirm('Confirm file upload ?')) {
396
        var fileSelector = $(this)[0];
397
        if (fileSelector != undefined
398
            && fileSelector.files[0] != undefined) {
399
            var file = this.files[0];
400
            console.log("file", file);
401
            let fileInput = $(this);
402
            console.log("fileInput", file);
403
            uploadDocument(file, function (documentId) {
404
                console.log("documentIdzzz  : ", documentId);
405
                fileInput.closest('td').find(".documentId").val(documentId);
406
            });
407
        }
408
    }
409
});
410
 
411
$(document).on('input', '#payment-sc-doc', function () {
412
    if (confirm('Confirm file upload ?')) {
413
        var file = this.files[0];
414
        uploadDocument(file, function (documentId) {
415
            $('#payment-sc-docId').val(documentId);
416
        });
417
    }
418
});
419
 
420
 
33507 tejus.loha 421
$(document).on('click', ".mk_docApproval", function () {
422
    let loiId = $(this).data('form_id');
423
    let docMasterId = $(this).data('doc_master_id');
424
    let flag = $(this).data('flag');
425
    console.log("flag -", flag);
426
    doPutAjaxRequestHandler(`${context}/documentVerify?loiId=${loiId}&docMasterId=${docMasterId}&flag=${flag}`,
427
        function (response) {
428
            alert(response);
33617 tejus.loha 429
            doGetAjaxRequestHandler(`${context}/uploadDocumentForm?loiId=${loiId}`,
33507 tejus.loha 430
                function (response) {
431
                    $('#' + 'main-content').html(response);
432
                });
433
 
434
        });
435
});
436
$(document).on('click', "#uploadDocumentbtn1", function () {
437
    if (confirm("Are you sure to upload all documents ?")) {
438
        var loiId = $(this).val();
439
        var loiDocModels = [];
440
        console.log("loiId -", loiId);
441
        $("#OnboardingDocumentTable > tbody > tr").each(function (rowIndex) {
442
            var marsterId = $(this).find(".masterId").val();
443
            var docId = $(this).find(".documentId").val();
444
            var docName = $(this).find(".documentName").val();
445
            console.log("marsterId -", marsterId);
446
            var loiDocModel = {
447
                documentId: docId,
448
                documentName: docName,
449
                documentMasterId: marsterId
450
            };
451
            loiDocModels.push(loiDocModel);
452
        });
453
        console.log(loiDocModels);
454
        var loiDocModelData = JSON.stringify(loiDocModels);
455
        doPostAjaxRequestWithJsonHandler(`${context}/uploadOnboardingDocument?loiId=${loiId}`, loiDocModelData, function (response) {
456
            console.log('response-', response);
457
            pendingLoiForm("main-content");
458
        });
459
    } else {
460
        //Nothing to do
461
    }
462
 
463
 
464
});
465
 
466
$(document).on('click', ".CompletedLoiForm", function () {
33617 tejus.loha 467
    doGetAjaxRequestHandler(`${context}/completedLoiForms`,
33507 tejus.loha 468
        function (response) {
469
            $('#' + 'main-content').html(response);
470
        });
471
});
472
 
473
$(document).on('click', "#createNewOnboardingPanel", function () {
474
    let loiId = $(this).val();
33710 tejus.loha 475
    //let authId = $(this).closest('tr').find('.authId').val();
33507 tejus.loha 476
 
33710 tejus.loha 477
    if (true) {
478
 
479
        doPostAjaxRequestHandler(`${context}/createNewOnboardingPanel?loiId=${loiId}&authId=${0}`,
33507 tejus.loha 480
            function (response) {
481
                if (response) {
33710 tejus.loha 482
                    // doGetAjaxRequestHandler(`${context}/completedLoiForms`,
483
                    //     function (response) {
484
                    //         $('#' + 'main-content').html(response);
485
                    //     });
486
                    alert("it moved successfully ");
33507 tejus.loha 487
                } else {
488
                    //nothing
489
                }
490
 
491
            });
492
    } else {
493
        alert("Please choose RBM ");
494
    }
495
 
496
});
497
 
33617 tejus.loha 498
$(document).on('click', "#downloadAllLoiForm", function () {
499
    const from = $('input[name="from"]').val();
500
    const to = $('input[name="to"]').val();
501
    let missingFields = [];
502
    if (!from) missingFields.push('From date');
503
    if (!to) missingFields.push('To date');
504
    if (missingFields.length > 0) {
505
        alert('Please select : ' + missingFields.join(','));
506
        return;
507
    }
508
    console.log("From - ", from)
509
    console.log("To - ", to)
510
 
511
    window.location.href = `${context}/downloadLoiFromReport?from=${from}&to=${to}`;
512
});
33658 tejus.loha 513
$(document).on('click', ".brandFeePaymentEdit", function () {
514
    var bfcId = $(this).val();
515
    console.log("bfcId - ", bfcId);
516
    // Get the table row
517
    var $row = $(this).closest('tr');
518
    console.log("row - ", $row);
519
    var feeCollectingTimeStamp = $row.find('input[name="feeCollectingTimeStamp"]').val();
520
    var collectedAmount = $row.find('input[name="collectedAmount"]').val();
521
    var paymentReferenceNo = $row.find('input[name="paymentReferenceNo"]').val();
522
    var paymentMode = $row.find('select[name="paymentMode"]').val();
33885 tejus.loha 523
    var documentId = $row.find('input[name="documentId"]').val();
524
 
33658 tejus.loha 525
    const Data = {
526
        id: bfcId,
527
        feeCollectingTimeStamp: feeCollectingTimeStamp,
528
        collectedAmount: collectedAmount,
529
        paymentReferenceNo: paymentReferenceNo,
33885 tejus.loha 530
        attachment: documentId,
33658 tejus.loha 531
        paymentMode: paymentMode
532
    };
533
    var jsonData = JSON.stringify(Data);
534
    if (confirm("Are you sure to update details")) {
535
        doPostAjaxRequestWithJsonHandler(`${context}/updatePayment`, jsonData,
536
            function (response) {
33845 tejus.loha 537
                if (response) {
538
                    alert("Updated payment details are save successfully ")
539
                    pendingLoiForm('main-content');
540
                } else {
541
                    alert("Updated payment details are not save ")
542
                    pendingLoiForm('main-content');
543
                }
33658 tejus.loha 544
            });
545
    } else {
546
        pendingLoiForm('main-content');
547
    }
33617 tejus.loha 548
 
33658 tejus.loha 549
 
550
});
33879 tejus.loha 551
/*function validateOTP() {
552
    while (true) {
553
        let otp = prompt("Enter received OTP here");
554
        if (otp === null) {
555
            alert('OTP entry was cancelled. Try again.');
556
            return null;
557
        }
558
        let regex = /^[0-9]{5}$/;
559
        if (regex.test(otp)) {
560
            console.log('otp-flag-', otp);
561
            return otp;  // Return valid OTP
562
        } else {
563
            alert('Please enter a valid 5-digit numeric OTP');
564
        }
565
    }
566
}*/
33658 tejus.loha 567
 
33879 tejus.loha 568
$(document).on('click', "#confirmSign", function () {
569
    let loiId = $(this).val();
570
    // let otp = validateOTP();
571
    let otp = prompt("Enter received OTP here");
572
    console.log("loiId-", loiId, ",otp-", otp);
573
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
574
    if (otp != undefined || otp != null) {
33658 tejus.loha 575
 
33879 tejus.loha 576
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
577
            if (response) {
578
                const element = document.getElementById('loiPDF_content');
579
                console.log("element- ", element);
580
                const opt = {
581
                    margin: 0.5,
582
                    filename: 'document.pdf',
583
                    image: {type: 'jpeg', quality: 0.98},
584
                    html2canvas: {scale: 2, logging: true, useCORS: true},
585
                    jsPDF: {unit: 'in', format: 'letter', orientation: 'portrait'}
586
                };
587
                html2pdf().from(element).set(opt).outputPdf("arraybuffer").then(function (pdf) {
588
                    console.log("pdf- ", pdf);
589
                    const file = new Blob([pdf], {type: 'application/pdf'});
590
                    uploadDocument(file, function (documentId) {
591
                        console.log("documentIdddd-", documentId);
592
                        IdempotencyKey = uuidv4();
593
                        if (documentId > 0) {
594
                            saveLoiDoc(loiId, documentId);
595
                        } else {
596
                            alert("Something went wrong , please again to confirm otp")
597
                        }
598
                    });
599
                });
600
            }
601
        });
602
    } else {
603
        return false
604
    }
605
});
606
 
607
 
608
function saveLoiDoc(loiId, documentId) {
609
    let saveLoiDocUrl = `${context}/saveLoiDoc?loiId=` + loiId + `&loiDocId=` + documentId
610
    doPostAjaxRequestHandler(saveLoiDocUrl, function (response) {
611
        if (response) {
612
            alert("LOI has been signed successfully and sent to the registered email. Please check your email.");
613
            pendingLoiForm("main-content");
614
        } else {
615
            alert("Something went wrong , Please try again to generate Loi and Validate otp");
616
 
617
        }
618
    });
619
}
620
 
621
 
33507 tejus.loha 622
function pendingLoiForm(domId) {
33710 tejus.loha 623
    doGetAjaxRequestHandler(`${context}/pendingLoiForm`,
33507 tejus.loha 624
        function (response) {
625
            $('#' + domId).html(response);
626
        });
627
}