Subversion Repositories SmartDukaan

Rev

Rev 34745 | Rev 35971 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34745 Rev 35038
Line 588... Line 588...
588
    }
588
    }
589
}*/
589
}*/
590
 
590
 
591
$(document).on('click', "#confirmSign", function () {
591
$(document).on('click', "#confirmSign", function () {
592
    let loiId = $(this).val();
592
    let loiId = $(this).val();
593
    // let otp = validateOTP();
-
 
594
    let otp = prompt("Enter received OTP here");
593
    let otp = prompt("Enter received OTP here");
595
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
594
    let validateOtpUrl = `${context}/validateLoiOtp?loiId=${loiId}&provideOtp=${otp}`;
596
    if (otp != undefined || otp != null) {
-
 
597
 
595
 
-
 
596
    if (otp !== undefined && otp !== null) {
598
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
597
        doPutAjaxRequestHandler(validateOtpUrl, function (response) {
-
 
598
            console.log('OTP validation response:', response);
-
 
599
 
-
 
600
            if (response && response.response && response.response.success) {
-
 
601
                const docHash = (response.response.documentHash || "");
-
 
602
                const ip = response.response.ipAddress || "";
-
 
603
                const createdAt = response.response.createdAt || new Date().toLocaleString();
599
            if (response) {
604
                const watermarkText =
-
 
605
                    `OTP VERIFIED\n` +
-
 
606
                    `DOCUMENT HASH:\n ${docHash}\n` +
-
 
607
                    `IP ADDRESS: ${ip}\n` +
-
 
608
                    `CREATED ON: ${createdAt}`;
600
                const element = document.getElementById('loiPDF_content');
609
                const originalElement = document.getElementById('loiPDF_content');
-
 
610
                const clonedElement = originalElement.cloneNode(true);
-
 
611
                const existingStyles = clonedElement.querySelectorAll('style');
-
 
612
                existingStyles.forEach(style => style.remove());
-
 
613
                $(clonedElement).find('.pending-badge, .pending-indicator').remove();
-
 
614
                $(clonedElement).find('.signature-section').each(function () {
-
 
615
                    this.style.setProperty('position', 'relative', 'important');
-
 
616
                    this.style.setProperty('padding', '20px', 'important');
-
 
617
                });
-
 
618
 
-
 
619
                const signatureSections = clonedElement.querySelectorAll('.signature-section');
-
 
620
                signatureSections.forEach(section => {
-
 
621
                    const oldWatermarks = section.querySelectorAll('.watermark-overlay');
-
 
622
                    oldWatermarks.forEach(w => w.remove());
-
 
623
 
-
 
624
                    const watermarkDiv = document.createElement('div');
-
 
625
                    watermarkDiv.className = 'watermark-overlay';
-
 
626
                    watermarkDiv.textContent = watermarkText;
-
 
627
                    watermarkDiv.style.position = 'absolute';
-
 
628
                    watermarkDiv.style.fontSize = '7px';
-
 
629
                    watermarkDiv.style.top = '30px';
-
 
630
                    watermarkDiv.style.left = '1%';
-
 
631
                    watermarkDiv.style.color = 'rgb(4,97,225)';
-
 
632
                    watermarkDiv.style.fontWeight = 'bold';
-
 
633
                    watermarkDiv.style.fontFamily = 'Arial,sans-serif';
-
 
634
                    watermarkDiv.style.whiteSpace = 'pre-line';
-
 
635
                    watermarkDiv.style.textAlign = 'center';
-
 
636
                    watermarkDiv.style.pointerEvents = 'none';
-
 
637
                    watermarkDiv.style.width = '90%';
-
 
638
                    watermarkDiv.style.lineHeight = '1.7';
-
 
639
                    watermarkDiv.style.zIndex = '1';
-
 
640
                    watermarkDiv.style.userSelect = 'none';
-
 
641
 
-
 
642
                    section.style.position = 'relative';
-
 
643
                    section.appendChild(watermarkDiv);
-
 
644
                });
-
 
645
 
-
 
646
                const tempContainer = document.createElement('div');
-
 
647
                tempContainer.style.position = 'absolute';
-
 
648
                tempContainer.style.left = '-9999px';
-
 
649
                tempContainer.style.width = '800px';
-
 
650
                tempContainer.appendChild(clonedElement);
-
 
651
                document.body.appendChild(tempContainer);
-
 
652
 
601
                const opt = {
653
                const opt = {
-
 
654
                    margin: [0.5, 0.5, 0.5, 0.5],
-
 
655
                    filename: `LOI_${loiId}_${new Date().getTime()}.pdf`,
602
                    margin: 0.5,
656
                    image: {
603
                    filename: 'document.pdf',
657
                        type: 'jpeg',
604
                    image: {type: 'jpeg', quality: 0.98},
658
                        quality: 0.98
-
 
659
                    },
-
 
660
                    html2canvas: {
-
 
661
                        scale: 1.2,
-
 
662
                        logging: false,
605
                    html2canvas: {scale: 2, logging: true, useCORS: true},
663
                        useCORS: true,
-
 
664
                        allowTaint: false,
-
 
665
                        backgroundColor: '#ffffff'
-
 
666
                    },
-
 
667
                    jsPDF: {
-
 
668
                        unit: 'in',
-
 
669
                        format: 'letter',
606
                    jsPDF: {unit: 'in', format: 'letter', orientation: 'portrait'}
670
                        orientation: 'portrait'
-
 
671
                    }
607
                };
672
                };
-
 
673
 
608
                html2pdf().from(element).set(opt).outputPdf("arraybuffer").then(function (pdf) {
674
                html2pdf().from(clonedElement).set(opt).outputPdf("arraybuffer")
-
 
675
                    .then(function (pdf) {
-
 
676
                        document.body.removeChild(tempContainer);
-
 
677
 
609
                    const file = new Blob([pdf], {type: 'application/pdf'});
678
                        const file = new Blob([pdf], {type: 'application/pdf'});
-
 
679
 
610
                    uploadDocument(file, function (documentId) {
680
                        uploadDocument(file, function (documentId) {
611
                        IdempotencyKey = uuidv4();
681
                            IdempotencyKey = uuidv4();
612
                        if (documentId > 0) {
682
                            if (documentId > 0) {
613
                            saveLoiDoc(loiId, documentId);
683
                                saveLoiDoc(loiId, documentId);
-
 
684
                                alert("Document signed and saved successfully!");
614
                        } else {
685
                            } else {
615
                            alert("Something went wrong , please again to confirm otp")
686
                                alert("Something went wrong, please try again to confirm OTP");
-
 
687
                            }
616
                        }
688
                        });
-
 
689
                    })
-
 
690
                    .catch(function (error) {
-
 
691
                        console.error('PDF generation failed:', error);
-
 
692
                        document.body.removeChild(tempContainer);
-
 
693
                        alert("PDF generation failed. Please try again.");
617
                    });
694
                    });
618
                });
695
            } else {
-
 
696
                console.error('OTP validation failed:', response);
-
 
697
                alert("OTP validation failed: " + (response.response?.message || "Please try again."));
619
            }
698
            }
-
 
699
        }, function (error) {
-
 
700
            console.error('AJAX request failed:', error);
-
 
701
            alert("Request failed. Please check your connection and try again.");
620
        });
702
        });
621
    } else {
703
    } else {
622
        return false;
704
        return false;
623
    }
705
    }
624
});
706
});