You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
  3. <head th:replace="~{fragments/head :: head}">
  4. <style>
  5. @media print {
  6. /* Hide buttons when printing */
  7. .button-container {
  8. display: none !important;
  9. }
  10. .nav-display {
  11. display: none !important;
  12. }
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div th:replace="~{fragments/collectionpendingdetails :: div}"></div>
  18. <script th:replace="~{fragments/script :: script}"></script>
  19. <script>
  20. function printTables(bookingId) {
  21. $.ajax({
  22. type: "GET",
  23. url: '/communityhall/user/collectionpendingacknowledgement',
  24. data: {bookingId: bookingId},
  25. success: function (bodyMessage) {
  26. exportLicToPDF(bodyMessage, bookingId);
  27. // console.log(bodyMessage);
  28. },
  29. error: function (xhr, status, error) {
  30. console.error("Failed to fetch booking details:", error);
  31. alert("Error fetching booking details. Please try again.");
  32. }
  33. });
  34. }
  35. function exportLicToPDF(details, bookingId, format = 'a4', orientation = 'portrait') {
  36. var parser = new DOMParser();
  37. var doc = parser.parseFromString(details, 'text/html');
  38. // Select the entire container element
  39. var element = document.querySelector('#pcoded');
  40. // Hide unwanted elements
  41. document.querySelector('.button-container').style.display = 'none'; // Hide the button container
  42. // Generate PDF
  43. html2pdf().from(element).set({
  44. margin: [0.1, 0.1, 0.1, 0.1], // Adjust margins to fit content better
  45. filename: `BookingAck-${bookingId}.pdf`, // Construct the filename with bookingId
  46. html2canvas: {
  47. scale: 1, // Set scale to 1 to ensure content fits on a single page
  48. useCORS: true, // Allow cross-origin images to load
  49. scrollX: 0,
  50. scrollY: 0,
  51. windowWidth: element.scrollWidth,
  52. windowHeight: element.scrollHeight
  53. },
  54. jsPDF: {
  55. unit: 'in',
  56. format: format, // Set format to A4
  57. orientation: orientation,
  58. compress: true // Enable compression to reduce file size
  59. }
  60. }).toPdf().get('pdf').then(function (pdf) {
  61. // Check if content fits on one page; scale down if needed
  62. let totalHeight = element.offsetHeight;
  63. let pageHeight = pdf.internal.pageSize.height;
  64. if (totalHeight > pageHeight) {
  65. pdf.internal.pageSize.height = totalHeight;
  66. }
  67. }).save().then(() => {
  68. // Restore the visibility of hidden elements
  69. document.querySelector('.button-container').style.display = 'flex'; // Show the button container again
  70. });
  71. }
  72. function formatDateTime(date) {
  73. // Format date and time
  74. const options = {
  75. year: 'numeric',
  76. month: '2-digit',
  77. day: '2-digit',
  78. hour: '2-digit',
  79. minute: '2-digit',
  80. second: '2-digit',
  81. hour12: false, // 24-hour time
  82. timeZone: 'auto' // Use the user's local time zone
  83. };
  84. try {
  85. return new Intl.DateTimeFormat('en-GB', options).format(date);
  86. } catch (error) {
  87. console.error('Error formatting date:', error);
  88. return date.toString(); // Fallback
  89. }
  90. }
  91. function updateGeneratedDate() {
  92. const dateElement = document.getElementById('generatedDate');
  93. if (dateElement) {
  94. const now = new Date();
  95. const formattedDate = formatDateTime(now);
  96. // console.log('Formatted Date:', formattedDate); // Debug log
  97. dateElement.textContent = formattedDate;
  98. } else {
  99. console.error('Date element not found');
  100. }
  101. }
  102. window.onload = updateGeneratedDate;
  103. function redirect(bookingtype) {
  104. if (bookingtype === 'OFFLINE') {
  105. window.location.href = "/communityhall/counter/counterbooking";
  106. } else {
  107. window.location.href = "/communityhall/user/dashboard";
  108. }
  109. }
  110. </script>
  111. </body>
  112. </html>