create_component_table_item.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ title }}</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. </head>
  8. <style>
  9. .input-cond-delete {
  10. background: #E43030;
  11. border: 1px solid #CFCFCF;
  12. box-sizing: border-box;
  13. border-radius: 5px;
  14. margin-left: 5px;
  15. width: 65px;
  16. height: 33px;
  17. font-size: 16px;
  18. text-align: center;
  19. line-height: 16px;
  20. color: #FFFFFF;
  21. }
  22. .input-cond-add {
  23. background: #008CBA;
  24. border: 1px solid #CFCFCF;
  25. box-sizing: border-box;
  26. border-radius: 5px;
  27. margin-left: 5px;
  28. width: 65px;
  29. height: 33px;
  30. font-size: 16px;
  31. text-align: center;
  32. line-height: 16px;
  33. color: #FFFFFF;
  34. }
  35. </style>
  36. <body>
  37. <div id="ERP_header">
  38. <!-- 匯入共同使用的 header.html 內容 -->
  39. {% include 'ERP_header.html' %}
  40. </div>
  41. <!-- 這裡新增零件表中的零件 -->
  42. 請依序輸入以下欄位, 再按下 "新增零件" 按鈕:<br>
  43. 會計科目:
  44. <select id="accountingsubjects" onChange="">
  45. <option value="00"></option>
  46. {% for data in AccountingSubjects_data %}
  47. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  48. {% endfor %}
  49. </select>
  50. 類別:
  51. <select id="category" onChange="renewSN();">
  52. <option value="00"></option>
  53. {% for data in Category_data %}
  54. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  55. {% endfor %}
  56. </select>
  57. 流水號:
  58. <input id="serialnumber" value="—" style="height: 25px; width: 45px;" readonly>
  59. 供應商:
  60. <select id="supplier" onChange="">
  61. <option value="00"></option>
  62. {% for data in Supplier_data %}
  63. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  64. {% endfor %}
  65. </select>
  66. 零件名稱:
  67. <input list="conponents" id="component_name_select">
  68. <datalist id="conponents">
  69. <option value=""></option>
  70. {% for data in Component_data %}
  71. <option value="{{data[0]}}">{{data[0]}}</option>
  72. {% endfor %}
  73. </datalist>
  74. <br>
  75. <input type="button" id="create_component" value="新增零件" onclick="create_component();">
  76. <div id="result">
  77. <!-- <table>
  78. </table> -->
  79. </div>
  80. <script>
  81. // 輸入完類別後, 流水號自動帶入
  82. function renewSN() {
  83. var accountingsubjects_select = $("#accountingsubjects").val();
  84. var category_select = $("#category").val();
  85. $.get('/sn_get/' + accountingsubjects_select + '/' + category_select, '', function (res) {
  86. // console.log(res.new_sn)
  87. $('#serialnumber').val(res.new_sn)
  88. }, 'json');
  89. }
  90. // 零件表 新增零件
  91. function create_component() {
  92. // 會計科目
  93. var accountingsubjects_select = $("#accountingsubjects").val();
  94. // 類別
  95. var category_select = $("#category").val();
  96. // 流水號 → 從資料庫找到最大的流水號, 然後 +1
  97. var serialnumber_select = $("#serialnumber").val();
  98. // 放到 renewSN 方法內執行
  99. // 供應商
  100. var supplier_select = $("#supplier").val();
  101. // 零件名稱
  102. var component_name_select = $("#component_name_select").val().replaceAll("'", "''");
  103. // 內部料號組合
  104. var company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
  105. var AND_list = [];
  106. // console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select, component_name_select)
  107. var sql = '';
  108. sql += "INSERT INTO 零件表 " +
  109. "VALUES ('" + company_id + "', '" + accountingsubjects_select + "', '" + category_select + "', '" + serialnumber_select + "', '";
  110. sql += supplier_select + "', '" + component_name_select + "');";
  111. console.log("sql: " + sql);
  112. var sql_data = { "sql":sql };
  113. $.ajax({
  114. type:"GET",
  115. url:"/sql_get",
  116. dataType:"JSON",
  117. data:sql_data,
  118. async:false,
  119. success:function (res) {
  120. alert("零件表: 零件新增成功!")
  121. },
  122. error: function (thrownError) {
  123. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  124. alert("零件表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  125. }
  126. }
  127. })
  128. var sql = 'INSERT INTO 規格表 (`內部料號`) VALUES ("' + company_id + '");';
  129. var sql_data = { "sql":sql };
  130. $.ajax({
  131. type:"GET",
  132. url:"/sql_get",
  133. dataType:"JSON",
  134. data:sql_data,
  135. async:false,
  136. success:function (res) {
  137. alert("規格表: 零件新增成功!")
  138. },
  139. error: function (thrownError) {
  140. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  141. alert("規格表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  142. }
  143. }
  144. })
  145. }
  146. </script>
  147. <hr>
  148. <!-- 這裡新增零件表中的 會計科目 -->
  149. 請輸入欲新增的會計科目名稱, 再按下 "新增會計科目項目" 按鈕:<br>
  150. <input id="create_accountingsubject_id" value="{{new_as_sn}}" style="height: 25px; width: 45px;" readonly>
  151. <input id="create_accountingsubject_name" value="" style="height: 25px;">
  152. <input type="button" id="create_accountingsubject" value="新增會計科目項目" onclick="create_accountingsubject();">
  153. <script>
  154. function create_accountingsubject() {
  155. var as_id = $("#create_accountingsubject_id").val();
  156. var as_name = $("#create_accountingsubject_name").val();
  157. var sql = '';
  158. sql += 'INSERT INTO 會計科目表 ' +
  159. 'VALUES ("' + as_id + '", "' + as_name + '");';
  160. // console.log("sql: " + sql)
  161. var sql_data = { "sql":sql };
  162. $.ajax({
  163. type:"GET",
  164. url:"/sql_get",
  165. dataType:"JSON",
  166. data:sql_data,
  167. success:function (res) {
  168. alert('新增 會計科目 成功')
  169. },
  170. error: function (thrownError) {
  171. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  172. alert("會計科目 " + as_id + " 已存在, 請重新輸入")
  173. }
  174. }
  175. })
  176. }
  177. </script>
  178. <hr>
  179. <!-- 這裡新增零件表中的 類別 -->
  180. 請輸入欲新增的類別名稱, 再按下 "新增類別項目" 按鈕:<br>
  181. <input id="create_category_id" value="{{new_ca_sn}}" style="height: 25px; width: 45px;" readonly>
  182. <input id="create_category_name" value="" style="height: 25px;">
  183. <input type="button" id="create_category" value="新增類別項目" onclick="create_category();">
  184. <script>
  185. function create_category() {
  186. var ca_id = $("#create_category_id").val();
  187. var ca_name = $("#create_category_name").val();
  188. var sql = '';
  189. sql += 'INSERT INTO 類別表 ' +
  190. 'VALUES ("' + ca_id + '", "' + ca_name + '");';
  191. var sql_data = { "sql":sql };
  192. $.ajax({
  193. type:"GET",
  194. url:"/sql_get",
  195. dataType:"JSON",
  196. data:sql_data,
  197. success:function (res) {
  198. alert('新增 類別 成功')
  199. },
  200. error: function (thrownError) {
  201. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  202. alert("類別 " + ca_id + " 已存在, 請重新輸入")
  203. }
  204. }
  205. })
  206. }
  207. </script>
  208. <hr>
  209. <!-- 這裡新增零件表中的 供應商 -->
  210. 請輸入欲新增的供應商名稱, 再按下 "新增供應商" 按鈕: (其他資料先以 "" 存入)<br>
  211. <!-- <input id="create_supplier_id" value="{{new_su_sn}}" style="height: 25px; width: 45px;" readonly> -->
  212. <select id="create_supplier_id_1" onChange="new_sup_sn();">
  213. <option value="T" selected>T - 台灣</option>
  214. <option value="C">C - 中國</option>
  215. <option value="A">A - 美國</option>
  216. <option value="J">J - 日本</option>
  217. </select>
  218. <input id="create_supplier_id_2" value="{{new_su_sn}}" style="height: 25px; width: 45px;" readonly>
  219. <input id="create_supplier_name" value="" style="height: 25px;">
  220. <input type="button" id="create_supplier" value="新增供應商項目" onclick="create_supplier();"><br>
  221. <br>
  222. <br>
  223. <hr>
  224. 若欲檢視供應商資料, 請選擇對應的供應商編號-中文名稱:
  225. <!-- <input id="search_supplier_id" value="" style="height: 25px;"> -->
  226. <select id="search_supplier_id" onChange="search_supplier()">
  227. <option value="00"></option>
  228. {% for data in Supplier_data %}
  229. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  230. {% endfor %}
  231. </select>
  232. <div id="search_supplier_data"></div>
  233. <script>
  234. // 找到最新的供應商編號
  235. function new_sup_sn() {
  236. var sup_id_1 = $("#create_supplier_id_1").val();
  237. console.log("sup_id_1: " + sup_id_1)
  238. $.ajax({
  239. type:"GET",
  240. url:"/sup_get/" + sup_id_1,
  241. dataType:"JSON",
  242. data:"",
  243. success:function (res) {
  244. document.getElementById("create_supplier_id_2").value = res.sup_sn;
  245. },
  246. error: function (thrownError) {
  247. alert("供應商新編號 取值失敗")
  248. }
  249. })
  250. }
  251. // 顯示供應商資料
  252. function search_supplier() {
  253. var search_supplier_id = $("#search_supplier_id").val();
  254. console.log("search_supplier_id: " + search_supplier_id)
  255. sql = 'SELECT * FROM `供應商` WHERE 供應商 = "' + search_supplier_id + '"';
  256. var sql_data = { "sql":sql };
  257. console.log("sql_data: ", sql_data)
  258. $.ajax({
  259. type:"GET",
  260. url:"/sql_get",
  261. dataType:"JSON",
  262. data:sql_data,
  263. success:function (res) {
  264. var data = "";
  265. data += '<table id="table_search_supplier" class="table table-bordered" style="margin-top: 10px;">';
  266. for (let fields = 0; fields < res.sql_field.length; fields++) {
  267. data += '<tr>';
  268. data += '<th>' + res.sql_field[fields][0] + '</th>';
  269. console.log("res.labels: " + res.labels)
  270. if (res.labels != '') {
  271. if (res.labels[0][fields] == null) {
  272. data += '<td id="' + res.labels[0][0] + '_' + fields + '">' + '' + '</td>';
  273. } else {
  274. data += '<td id="' + res.labels[0][0] + '_' + fields + '">' + res.labels[0][fields] + '</td>';
  275. }
  276. }
  277. data += '</tr>';
  278. }
  279. data += '<tr>'
  280. data += '<td></td>'
  281. data += '<td><input type="button" class="input-cond-add" style="width: 130px;" value="修改供應商資料" onclick="update_supplier(\'' + res.labels[0][0] + '\')"></td>'
  282. data += '</tr>'
  283. data += '</table>';
  284. var sectorSelect = document.getElementById("search_supplier_data");
  285. sectorSelect.innerHTML = data;
  286. },
  287. error: function (thrownError) {
  288. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  289. alert("供應商: 無此編號 " + search_supplier_id + " 之供應商")
  290. } else {
  291. console.log("供應商查詢 thrownError" + thrownError)
  292. }
  293. data = "";
  294. var sectorSelect = document.getElementById("search_supplier_data");
  295. sectorSelect.innerHTML = data;
  296. }
  297. })
  298. }
  299. // 修改供應商資料
  300. function update_supplier(supplier_id) {
  301. for (let i = 1; i < 14; i++) {
  302. var target_id = document.getElementById(supplier_id + '_' + i);
  303. var old_supplier_name = target_id.innerText;
  304. console.log('old_supplier_name: ', old_supplier_name)
  305. target_id.innerHTML = "";
  306. var textarea = '';
  307. if (i == 3 || i == 7 || i == 10 || i == 11 ) {
  308. textarea += '<input id="'+ supplier_id + '_' + i + '_ta' + '" value="' + old_supplier_name + '" style="height: 25px; width: 450px">';
  309. } else {
  310. textarea += '<input id="'+ supplier_id + '_' + i + '_ta' + '" value="' + old_supplier_name + '" style="height: 25px; width: 170px">';
  311. }
  312. if (i == 13) {
  313. textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_supplier(\'' + supplier_id + '\')">';
  314. }
  315. target_id.insertAdjacentHTML('beforeend', textarea);
  316. }
  317. }
  318. // 確認修改供應商資料
  319. function ComfirmUpdate_supplier(supplier_id) {
  320. var new_name_value = $('#' + supplier_id + '_1_ta').val();
  321. var new_person_value = $('#' + supplier_id + '_2_ta').val();
  322. var new_address_value = $('#' + supplier_id + '_3_ta').val();
  323. var new_ubnumber_value = $('#' + supplier_id + '_4_ta').val();
  324. var new_phone_value = $('#' + supplier_id + '_5_ta').val();
  325. var new_fax_value = $('#' + supplier_id + '_6_ta').val();
  326. var new_email_value = $('#' + supplier_id + '_7_ta').val();
  327. var new_cellphone_value = $('#' + supplier_id + '_8_ta').val();
  328. var new_lineid_value = $('#' + supplier_id + '_9_ta').val();
  329. var new_web_value = $('#' + supplier_id + '_10_ta').val();
  330. var new_bank_value = $('#' + supplier_id + '_11_ta').val();
  331. var new_payment_value = $('#' + supplier_id + '_12_ta').val();
  332. var new_remark_value = $('#' + supplier_id + '_13_ta').val();
  333. sql = 'UPDATE 供應商 SET `公司` = "' + new_name_value + '"' +
  334. ', `聯絡人` = "' + new_person_value + '"' +
  335. ', `地址` = "' + new_address_value + '"' +
  336. ', `統一編號` = "' + new_ubnumber_value + '"' +
  337. ', `電話` = "' + new_phone_value + '"' +
  338. ', `傳真` = "' + new_fax_value + '"' +
  339. ', `email` = "' + new_email_value + '"' +
  340. ', `手機` = "' + new_cellphone_value + '"' +
  341. ', `Line ID` = "' + new_lineid_value + '"' +
  342. ', `網址` = "' + new_web_value + '"' +
  343. ', `銀行資料` = "' + new_bank_value + '"' +
  344. ', `付款方式` = "' + new_payment_value + '"' +
  345. ', `備註` = "' + new_remark_value + '"' +
  346. ' WHERE `供應商` = "' + supplier_id + '";'
  347. console.log('sql: ' + sql)
  348. var sql_data = { "sql":sql };
  349. $.ajax({
  350. type:"GET",
  351. url:"/sql_get",
  352. dataType:"JSON",
  353. data:sql_data,
  354. success:function (res) {
  355. search_supplier();
  356. alert("供應商: 修改成功 !")
  357. },
  358. error: function (thrownError) {
  359. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  360. alert("供應商: 供應商編號 " + supplier_id + " 修改未成功")
  361. } else {
  362. console.log("修改供應商內容 thrownError" + thrownError)
  363. }
  364. }
  365. })
  366. }
  367. // 新增供應商項目
  368. function create_supplier() {
  369. // var su_id = $("#create_supplier_id").val();
  370. var sup_id_1 = $("#create_supplier_id_1").val();
  371. var sup_id_2 = $("#create_supplier_id_2").val();
  372. var su_name = $("#create_supplier_name").val();
  373. sql = 'INSERT INTO 供應商 (`供應商`, `公司`) ' +
  374. 'VALUES ("' + sup_id_1 + sup_id_2 + '", "' + su_name + '");';
  375. console.log("sql:", sql)
  376. var sql_data = { "sql":sql };
  377. $.ajax({
  378. type:"GET",
  379. url:"/sql_get",
  380. dataType:"JSON",
  381. data:sql_data,
  382. success:function (res) {
  383. alert('新增 供應商 成功')
  384. location.reload();
  385. },
  386. error: function (thrownError) {
  387. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  388. alert("供應商 " + su_id + " 已存在, 請重新輸入")
  389. }
  390. }
  391. })
  392. }
  393. </script>
  394. </body>
  395. </html>