Subversion Repositories SmartDukaan

Rev

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