説明なし

coi.html 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. {% extends 'base.html' %}
  2. {% load tailwind_filters %}
  3. {% block title %}Report Dashboard{% endblock %}
  4. {% block content %}
  5. <div class="container mx-auto px-4 py-8" x-data="COIReport">
  6. <h1 class="text-2xl font-bold text-gray-800">Export Center</h1>
  7. <form method='post'>
  8. {% csrf_token %}
  9. <div class="flex items-center gap-2 mb-4">
  10. <label for="lot-number" class="text-gray-700 font-medium">Lot No. :</label>
  11. <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">
  12. <button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600" type="submit" name="search_lot">
  13. 🔍
  14. </button>
  15. </div>
  16. <button class="bg-blue-100 text-blue-700 px-4 py-2 rounded hover:bg-blue-200">
  17. Option for Export :
  18. </button>
  19. <div class="grid grid-cols-4 gap-4">
  20. {% for key,value in SHEET_NAMES.items %}
  21. <label class="flex items-center space-x-1">
  22. <input type="checkbox" class="rounded" name='exports' value='{{ key }}' x-model='exports'>
  23. <span>{{ value }}</span>
  24. </label>
  25. {% endfor %}
  26. </div>
  27. <div class="grid grid-cols-2 gap-4">
  28. <div class="my-4">
  29. <label for="qa1" class="block mb-2 text-sm font-medium text-gray-900">Select QA.1</label>
  30. <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'>
  31. <option value="" disabled selected>Choose a user</option>
  32. {% for user in users %}
  33. <option value="{{ user.id }}">{{ user.profile }}</option>
  34. {% endfor %}
  35. </select>
  36. </div>
  37. <div class="my-4">
  38. <label for="qa2" class="block mb-2 text-sm font-medium text-gray-900">Select QA.2</label>
  39. <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'>
  40. <option value="" disabled selected>Choose a user</option>
  41. {% for user in users %}
  42. <option value="{{ user.id }}">{{ user.profile }}</option>
  43. {% endfor %}
  44. </select>
  45. </div>
  46. </div>
  47. <div class="flex justify-end my-3 space-x-4">
  48. <div>
  49. <button type='button' class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
  50. @click="exportCOI">
  51. Export Excel
  52. </button>
  53. </div>
  54. <!-- TODO: add download here -->
  55. <div class=" text-center" x-show="downloadUrl">
  56. <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>
  57. Download Report
  58. </a>
  59. </div>
  60. </div>
  61. </form>
  62. {{ result }}
  63. <div class="bg-white shadow-md rounded-md p-4">
  64. <table class="w-full text-left border-collapse border border-gray-300">
  65. <tbody>
  66. <tr class="bg-blue-100">
  67. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Product Code :</td>
  68. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1 }}</td>
  69. </tr>
  70. <tr>
  71. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Lot No. :</td>
  72. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO2 }}</td>
  73. </tr>
  74. <tr class="bg-blue-100">
  75. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Customer :</td>
  76. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1C }}</td>
  77. </tr>
  78. <tr>
  79. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Pcs. :</td>
  80. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ pcs }}</td>
  81. </tr>
  82. <tr class="bg-blue-100">
  83. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Shape | Size :</td>
  84. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ size_str }}</td>
  85. </tr>
  86. <tr>
  87. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Specification :</td>
  88. <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ spec }}</td>
  89. </tr>
  90. <tr class="bg-blue-100">
  91. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Date :</td>
  92. <td class="border border-gray-300 px-4 py-2 text-gray-700">22/06/2024</td>
  93. </tr>
  94. <tr>
  95. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate1 :</td>
  96. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  97. </tr>
  98. <tr class="bg-blue-100">
  99. <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Inspection Indicate2 :</td>
  100. <td class="border border-gray-300 px-4 py-2 text-gray-700"></td>
  101. </tr>
  102. </tbody>
  103. </table>
  104. </div>
  105. </div>
  106. {% include "report/_hardnessout.html" %}
  107. <div class="border-t border-gray-300 my-4"></div>
  108. {% include "report/_hardness_outin.html" %}
  109. <div class="border-t border-gray-300 my-4"></div>
  110. {% include "report/_hardnessboth.html" %}
  111. <div class="border-t border-gray-300 my-4"></div>
  112. {% include "report/_dimen.html" %}
  113. <div class="border-t border-gray-300 my-4"></div>
  114. {% include "report/_dimen_app.html" %}
  115. <div class="border-t border-gray-300 my-4"></div>
  116. {% include "report/_dimen_bal.html" %}
  117. <div class="border-t border-gray-300 my-4"></div>
  118. {% include "report/_dim_bl_app_hard.html" %}
  119. <div class="border-t border-gray-300 my-4"></div>
  120. {% include "report/_dim_bal_app_rot_hard.html" %}
  121. <div class="border-t border-gray-300 my-4"></div>
  122. {% include "report/_t8p.html" %}
  123. <div class="border-t border-gray-300 my-4"></div>
  124. {% include "report/_cen.html" %}
  125. {% endblock %}
  126. {% block footer_script %}
  127. <script type="text/javascript">
  128. function COIReport() {
  129. return {
  130. 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 %}