Subversion Repositories SmartDukaan

Rev

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