Nenhuma Descrição

coi.html 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {% extends 'base.html' %}
  2. {% load tailwind_filters %}
  3. {% load legacy_filters %}
  4. {% block title %}Report Dashboard{% endblock %}
  5. {% block content %}
  6. <div class="container mx-auto px-4 py-8" x-data="COIReport">
  7. <h1 class="text-2xl font-bold text-gray-800">Export Center</h1>
  8. {{ lot_no }}
  9. <form method='post'>
  10. {% csrf_token %}
  11. <div class="flex items-center gap-2 mb-4">
  12. <label for="lot-number" class="text-gray-700 font-medium">Lot No. :</label>
  13. <input id="lot-number" type="text" class="border border-gray-300 rounded px-4 py-2 focus:outline-blue-500" placeholder="Enter Lot No." name='lot_no' required x-model="lot_no" value="{{ lot_no }}">
  14. <button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600" type="submit" name="search_lot">
  15. 🔍
  16. </button>
  17. </div>
  18. <button class="bg-blue-100 text-blue-700 px-4 py-2 rounded hover:bg-blue-200">
  19. Option for Export :
  20. </button>
  21. <div class="grid grid-cols-4 gap-4">
  22. {% for key,value in SHEET_NAMES.items %}
  23. <label class="flex items-center space-x-1">
  24. <input type="checkbox" class="rounded" name='exports' value='{{ key }}' x-model='exports'>
  25. <span>{{ value }}</span>
  26. </label>
  27. {% endfor %}
  28. </div>
  29. <div class="grid grid-cols-2 gap-4">
  30. <div class="my-4">
  31. <label for="qa1" class="block mb-2 text-sm font-medium text-gray-900">Select QA.1</label>
  32. <select id="qa1" name="qa1" class="block w-full px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" x-model='qa1'>
  33. <option value="" disabled selected>Choose a user</option>
  34. {% for user in users %}
  35. <option value="{{ user.id }}">{{ user.profile }}</option>
  36. {% endfor %}
  37. </select>
  38. </div>
  39. <div class="my-4">
  40. <label for="qa2" class="block mb-2 text-sm font-medium text-gray-900">Select QA.2</label>
  41. <select id="qa2" name="qa2" class="block w-full px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" x-model='qa2'>
  42. <option value="" disabled selected>Choose a user</option>
  43. {% for user in users %}
  44. <option value="{{ user.id }}">{{ user.profile }}</option>
  45. {% endfor %}
  46. </select>
  47. </div>
  48. </div>
  49. <div class="flex justify-end my-3 space-x-4">
  50. <div>
  51. <button type='button' class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
  52. @click="exportCOI">
  53. Export Excel
  54. </button>
  55. </div>
  56. <!-- TODO: add download here -->
  57. <div class=" text-center" x-show="downloadUrl">
  58. <a :href="downloadUrl" class="block px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2" download>
  59. Download Report
  60. </a>
  61. </div>
  62. </div>
  63. </form>
  64. {{ result }}
  65. <div class="bg-white shadow-md rounded-md p-4">
  66. <table class="w-full text-left border-collapse border border-gray-300">
  67. <tbody>
  68. <tr class="bg-blue-100">
  69. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Product Code :</td>
  70. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1 }}</td>
  71. </tr>
  72. <tr>
  73. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Lot No. :</td>
  74. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO2 }}</td>
  75. </tr>
  76. <tr class="bg-blue-100">
  77. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Customer :</td>
  78. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1C }}</td>
  79. </tr>
  80. <tr>
  81. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Pcs. :</td>
  82. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ pcs }}</td>
  83. </tr>
  84. <tr class="bg-blue-100">
  85. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Shape | Size :</td>
  86. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ size_str }}</td>
  87. </tr>
  88. <tr>
  89. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Specification :</td>
  90. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ spec }}</td>
  91. </tr>
  92. <tr class="bg-blue-100">
  93. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Date :</td>
  94. <td class="border border-gray-300 px-4 py-2 text-gray-700">22/06/2024</td>
  95. </tr>
  96. <tr>
  97. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate1 :</td>
  98. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  99. </tr>
  100. <tr class="bg-blue-100">
  101. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate2 :</td>
  102. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. </div>
  107. </div>
  108. {% for model_name, objs in results.items %}
  109. {% if objs %}
  110. {% include "report/_tbl.html" with objs=objs fields=fields|get_item:model_name header=model_name %}
  111. {% endif %}
  112. {% endfor %}
  113. {% endblock %}
  114. {% block footer_script %}
  115. <style>
  116. /* Remove fixed layout and allow columns to grow dynamically */
  117. table {
  118. table-layout: auto; /* Default is auto, can be explicitly set */
  119. width: 100%; /* Ensures table spans available space */
  120. }
  121. th, td {
  122. white-space: nowrap; /* Prevents text wrapping */
  123. text-overflow: ellipsis; /* Adds ellipsis for overflowed content if combined with max-width */
  124. vertical-align: top; /* Aligns content to the top */
  125. }
  126. </style>
  127. <script type="text/javascript">
  128. function COIReport() {
  129. return {
  130. lot_no: '{{ lot_no }}', // Bind this to the input value
  131. exports: [],
  132. qa1: null,
  133. qa2: null,
  134. gen_report_url: '{% url "report:gen_report" %}',
  135. downloadUrl: null, // Stores the download link after export success
  136. init() {
  137. //alert("COI Report");
  138. this.qa1 = '';
  139. this.qa2 = '';
  140. },
  141. async exportCOI() {
  142. if (!this.lot_no) {
  143. alert("Please enter a Lot No.");
  144. return;
  145. }
  146. try {
  147. // Make POST request using Axios
  148. const response = await axios.post(this.gen_report_url, {
  149. lot_no: this.lot_no,
  150. exports: this.exports,
  151. qa1: this.qa1,
  152. qa2: this.qa2
  153. });
  154. if (response.status === 200) {
  155. const result = response.data;
  156. alert(`Report generated successfully: ${result.file_url}`);
  157. console.log('File URL:', result.file_url);
  158. this.downloadUrl = result.file_url; // Set the download URL
  159. }
  160. } catch (error) {
  161. if (error.response) {
  162. // Server responded with a status other than 2xx
  163. alert(`Error: ${error.response.data.message || 'Failed to generate report'}`);
  164. console.error('Error response:', error.response);
  165. } else if (error.request) {
  166. // Request was made but no response received
  167. alert('No response from server.');
  168. console.error('Request error:', error.request);
  169. } else {
  170. // Something else caused the error
  171. alert('An unexpected error occurred.');
  172. console.error('Unexpected error:', error.message);
  173. }
  174. }
  175. },
  176. };
  177. }
  178. </script>
  179. {% endblock %}