Nessuna descrizione

coi.html 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. </form>
  19. <button class="bg-blue-100 text-blue-700 px-4 py-2 rounded hover:bg-blue-200">
  20. Option for Export :
  21. </button>
  22. <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
  23. {% for key,value in SHEET_NAMES.items %}
  24. <label class="flex items-center space-x-1">
  25. <input type="checkbox" class="rounded" name='exports' value='{{ key }}'
  26. x-model='exports' required>
  27. <span>{{ value }}</span>
  28. </label>
  29. {% endfor %}
  30. </div>
  31. <div class="grid grid-cols-2 gap-4">
  32. <div class="my-4">
  33. <label for="qa1" class="block mb-2 text-sm font-medium text-gray-900">Select QA.1</label>
  34. <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' required>
  35. <option value="" disabled selected>Choose a user</option>
  36. {% for user in users %}
  37. <option value="{{ user.id }}">{{ user.profile }}</option>
  38. {% endfor %}
  39. </select>
  40. </div>
  41. <div class="my-4">
  42. <label for="qa2" class="block mb-2 text-sm font-medium text-gray-900">Select QA.2</label>
  43. <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' required>
  44. <option value="" disabled selected>Choose a user</option>
  45. {% for user in users %}
  46. <option value="{{ user.id }}">{{ user.profile }}</option>
  47. {% endfor %}
  48. </select>
  49. </div>
  50. </div>
  51. <div class="flex justify-end my-3 space-x-4">
  52. <div class="flex items-center space-x-4 my-4">
  53. <!-- Radio button for 'Accepted' -->
  54. <label class="flex items-center space-x-2">
  55. <input type="radio" name="status" id="accepted" value="accepted"
  56. class="rounded" x-model="acceptStatus" />
  57. <span>Accepted</span>
  58. </label>
  59. <!-- Radio button for 'Special Accepted' -->
  60. <label class="flex items-center space-x-2">
  61. <input type="radio" name="status" id="special_accepted" value="special_accepted"
  62. class="rounded" x-model="acceptStatus" />
  63. <span>Special Accepted</span>
  64. </label>
  65. </div>
  66. <div>
  67. <button type='button' class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
  68. @click="exportCOI">
  69. Export Excel
  70. </button>
  71. </div>
  72. <!-- TODO: add download here -->
  73. <div class=" text-center" x-show="downloadUrl">
  74. <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 x-text="downText">
  75. </a>
  76. </div>
  77. </div>
  78. <div class="bg-white shadow-md rounded-md p-4">
  79. <table class="w-full text-left border-collapse border border-gray-300">
  80. <tbody>
  81. <tr class="bg-blue-100">
  82. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Product Code :</td>
  83. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ code }}</td>
  84. </tr>
  85. <tr>
  86. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Lot No. :</td>
  87. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO2 }}</td>
  88. </tr>
  89. <tr class="bg-blue-100">
  90. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Customer :</td>
  91. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1C }}</td>
  92. </tr>
  93. <tr>
  94. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Pcs. :</td>
  95. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ pcs }}</td>
  96. </tr>
  97. <tr class="bg-blue-100">
  98. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Shape | Size :</td>
  99. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ size_str }}</td>
  100. </tr>
  101. <tr class="bg-blue-100">
  102. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Tool :</td>
  103. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO_TOOL }}</td>
  104. </tr>
  105. <tr>
  106. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Specification :</td>
  107. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ spec }}</td>
  108. </tr>
  109. <tr class="bg-blue-100">
  110. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Date :</td>
  111. <td class="border border-gray-300 px-4 py-2 text-gray-700">-</td>
  112. </tr>
  113. <tr>
  114. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate1 :</td>
  115. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  116. </tr>
  117. <tr class="bg-blue-100">
  118. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate2 :</td>
  119. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  120. </tr>
  121. </tbody>
  122. </table>
  123. </div>
  124. </div>
  125. {% for model_name, objs in results.items %}
  126. {% if objs %}
  127. {% include "report/_tbl.html" with objs=objs fields=fields|get_item:model_name header=model_name %}
  128. {% endif %}
  129. {% endfor %}
  130. {% endblock %}
  131. {% block footer_script %}
  132. <style>
  133. /* Remove fixed layout and allow columns to grow dynamically */
  134. table {
  135. table-layout: auto; /* Default is auto, can be explicitly set */
  136. width: 100%; /* Ensures table spans available space */
  137. }
  138. th, td {
  139. white-space: nowrap; /* Prevents text wrapping */
  140. text-overflow: ellipsis; /* Adds ellipsis for overflowed content if combined with max-width */
  141. vertical-align: top; /* Aligns content to the top */
  142. }
  143. </style>
  144. <script type="text/javascript">
  145. function COIReport() {
  146. return {
  147. lot_no: '{{ lot_no }}', // Bind this to the input value
  148. exports: {{ selected_templates|default:"[]"|safe }},
  149. qa1: null,
  150. qa2: null,
  151. gen_report_url: '{% url "report:gen_report" %}',
  152. acceptStatus: 'accepted',
  153. downloadUrl: null, // Stores the download link after export success
  154. downText: "Download Excel",
  155. init() {
  156. //alert("COI Report");
  157. this.qa1 = '';
  158. this.qa2 = '';
  159. },
  160. async exportCOI() {
  161. if (!this.lot_no) {
  162. alert("Please enter a Lot No.");
  163. return;
  164. }
  165. if (!this.qa1) {
  166. alert("Select QA.1");
  167. return;
  168. }
  169. if (!this.qa2) {
  170. alert("Select QA.2");
  171. return;
  172. }
  173. if (this.exports.length == 0) {
  174. alert("Select Export Template");
  175. return;
  176. }
  177. try {
  178. // Make POST request using Axios
  179. const response = await axios.post(this.gen_report_url, {
  180. lot_no: this.lot_no,
  181. exports: this.exports,
  182. qa1: this.qa1,
  183. qa2: this.qa2,
  184. acceptStatus: this.acceptStatus
  185. });
  186. this.downText = "Processing ..."
  187. if (response.status === 200) {
  188. const result = response.data;
  189. //alert(`Report generated successfully: ${result.file_url}`);
  190. setTimeout(() => {
  191. this.downText = "Download Excel"
  192. }, 2000);
  193. console.log('File URL:', result.file_url);
  194. this.downloadUrl = result.file_url; // Set the download URL
  195. }else {
  196. this.downText = "Error ..."
  197. }
  198. } catch (error) {
  199. this.downText = "Error ..."
  200. if (error.response) {
  201. // Server responded with a status other than 2xx
  202. alert(`Error: ${error.response.data.message || 'Failed to generate report'}`);
  203. console.error('Error response:', error.response);
  204. } else if (error.request) {
  205. // Request was made but no response received
  206. alert('No response from server.');
  207. console.error('Request error:', error.request);
  208. } else {
  209. // Something else caused the error
  210. alert('An unexpected error occurred.');
  211. console.error('Unexpected error:', error.message);
  212. }
  213. }
  214. },
  215. };
  216. }
  217. </script>
  218. {% endblock %}