create_BOM.html 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  8. <script>
  9. var USERNAME = '{{USERNAME}}';
  10. console.log("USERNAME: " + USERNAME);
  11. $(function(){
  12. // var manual_createBOM = confirm("請先在上方, 輸入新 BOM 表內部料號及名稱 \
  13. // \n再到下方, 搜尋零件並輸入數量, 再按下[加入] \
  14. // \n可以透過上方的 [查看現有加入零件] 檢查所選零件 \
  15. // \n最後, 按下 [新增模組/系統成品] 即可建立 BOM !")
  16. // if (manual_createBOM) {
  17. // var manual_searchBOM = confirm("若要查詢 BOM 表 \
  18. // \n可以先從 [零件表查詢] 中找到內部料號 \
  19. // \n輸入完成再按下 [BOM 表查詢]")
  20. // }
  21. });
  22. </script>
  23. </head>
  24. <style>
  25. .input-cond-delete {
  26. background: #E43030;
  27. border: 1px solid #CFCFCF;
  28. box-sizing: border-box;
  29. border-radius: 5px;
  30. margin-left: 5px;
  31. width: 65px;
  32. height: 33px;
  33. font-size: 16px;
  34. text-align: center;
  35. line-height: 16px;
  36. color: #FFFFFF;
  37. }
  38. .input-cond-add {
  39. background: #008CBA;
  40. border: 1px solid #CFCFCF;
  41. box-sizing: border-box;
  42. border-radius: 5px;
  43. margin-left: 5px;
  44. width: 65px;
  45. height: 33px;
  46. font-size: 16px;
  47. text-align: center;
  48. line-height: 16px;
  49. color: #FFFFFF;
  50. }
  51. </style>
  52. <body>
  53. <div id="ERP_header">
  54. <!-- 匯入共同使用的 header.html 內容 -->
  55. {% include 'ERP_header.html' %}
  56. </div>
  57. <!-- 建立 BOM 表名稱用 --------------------------------------------------------------------------------------- -->
  58. 請輸入欲新增的 BOM 表名稱:<br>
  59. 會計科目:
  60. <select id="BOM_accountingsubjects" onChange="">
  61. <option value="00"></option>
  62. {% for data in AccountingSubjects_data %}
  63. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  64. {% endfor %}
  65. </select>
  66. 類別:
  67. <select id="BOM_category" onChange="renewSN();">
  68. <option value="00"></option>
  69. {% for data in Category_data %}
  70. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  71. {% endfor %}
  72. </select>
  73. 流水號:
  74. <input id="BOM_serialnumber" style="height: 25px; width: 45px;">
  75. 供應商:
  76. <select id="BOM_supplier" onChange="">
  77. <option value="00"></option>
  78. {% for data in Supplier_data %}
  79. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  80. {% endfor %}
  81. </select>
  82. 名稱:
  83. <input list="BOM_module" id="BOM_module_name_select">
  84. <datalist id="BOM_module">
  85. <option value=""></option>
  86. {% for data in Component_data %}
  87. <option value="{{data[0]}}">{{data[0]}}</option>
  88. {% endfor %}
  89. </datalist>
  90. <br>
  91. <hr>
  92. 可搜尋欲加入的零件或是查詢 BOM 表內容:<br>
  93. <!-- 索取現有零件用 --------------------------------------------------------------------------------------- -->
  94. 會計科目:
  95. <select id="accountingsubjects" onChange="">
  96. <option value="00"></option>
  97. {% for data in AccountingSubjects_data %}
  98. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  99. {% endfor %}
  100. </select>
  101. 類別:
  102. <select id="category" onChange="">
  103. <option value="00"></option>
  104. {% for data in Category_data %}
  105. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  106. {% endfor %}
  107. </select>
  108. 流水號:
  109. <input id="serialnumber" style="height: 25px; width: 45px;">
  110. 供應商:
  111. <select id="supplier" onChange="">
  112. <option value="00"></option>
  113. {% for data in Supplier_data %}
  114. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  115. {% endfor %}
  116. </select><br>
  117. 零件名稱:
  118. <select id="component_name_select" onChange="">
  119. <option value="00"></option>
  120. {% for data in Component_data %}
  121. <option value="{{data[0]}}">{{data[0]}}</option>
  122. {% endfor %}
  123. </select>
  124. <input id="component_name_input" placeholder="零件關鍵字輸入" style="height: 25px; width: 120px;">
  125. <input type="button" id="search_component_table" value="零件表查詢" onclick="search_component_table();">
  126. <input type="button" id="search_BOM_table" value="BOM 表查詢" onclick="search_BOM_table();">
  127. <div id="result"></div>
  128. <script>
  129. var BOM_company_id;
  130. // 儲存欲加入的零件 數量_顯示用有加名稱
  131. var module_amount_list = [];
  132. // 儲存欲加入的零件 數量_sql 用無名稱注意格式
  133. var module_amount_sqllist = [];
  134. // BOM 表查詢
  135. function search_BOM_table() {
  136. var accountingsubjects_select = $("#accountingsubjects").val();
  137. var category_select = $("#category").val();
  138. var serialnumber_select = $("#serialnumber").val();
  139. serialnumber_select = serialnumber_select.padStart(4, '0')
  140. var supplier_select = $("#supplier").val();
  141. // console.log("accountingsubjects_select: " + accountingsubjects_select)
  142. // console.log("category_select: " + category_select)
  143. // console.log("serialnumber_select: " + serialnumber_select)
  144. // console.log("supplier_select: " + supplier_select)
  145. // 若要查詢 BOM 表內容要以內部料號查詢, 所以輸入欄位不可空
  146. if (accountingsubjects_select == '00' || category_select == '00' || serialnumber_select == '0000' || supplier_select == '00' ) {
  147. alert("若要查詢 BOM 表\n請先找到內部料號對應的會計科目、類別、流水號、供應商\n輸入完成再按下 [BOM 表查詢]");
  148. } else {
  149. // 內部料號組合
  150. BOM_company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
  151. // console.log("BOM_company_id: " + BOM_company_id)
  152. // sql = 'SELECT * FROM `' + BOM_company_id + '` ORDER BY 內部料號';
  153. sql = 'SELECT 零件表.內部料號, 零件表.名稱, 規格表.原廠料號, 規格表.圖片, 數量, 位置, ' + BOM_company_id + '.備註, 設計原因, 填寫人' +
  154. ' FROM (`' + BOM_company_id + '`' +
  155. ' INNER JOIN 零件表' +
  156. ' ON 零件表.內部料號 = ' + BOM_company_id + '.內部料號' +
  157. ' )' +
  158. ' INNER JOIN 規格表' +
  159. ' ON 規格表.內部料號 = ' + BOM_company_id + '.內部料號' +
  160. ' ORDER BY 內部料號'
  161. var sql_data = { "sql":sql };
  162. console.log("sql_data: ", sql_data)
  163. $.ajax({
  164. type:"GET",
  165. url:"/sql_get",
  166. dataType:"JSON",
  167. data:sql_data,
  168. success:function (res) {
  169. var data = "";
  170. data += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
  171. data += '<table id="table_BOM" class="table table-bordered" style="margin-top: 10px;">';
  172. data += '<tr>';
  173. // for (let fields = 0; fields < res.sql_field.length; fields++) {
  174. // data += '<th>' + res.sql_field[fields][0] + '</th>';
  175. // }
  176. data += '<th>內部料號</th>';
  177. data += '<th>名稱</th>';
  178. data += '<th>原廠料號</th>';
  179. data += '<th>圖片</th>';
  180. data += '<th>數量</th>';
  181. data += '<th>位置</th>';
  182. data += '<th>備註</th>';
  183. data += '<th>設計原因</th>';
  184. data += '<th>填寫人</th>';
  185. data += '<th>修改</th>';
  186. data += '<th>刪除</th>';
  187. data += '</tr>';
  188. if (res.labels != '') {
  189. for (let items = 0; items < res.labels.length; items++) {
  190. data += '<tr>';
  191. for (let item = 0; item < res.labels[items].length; item++) {
  192. if (res.labels[items][item] == null) {
  193. data += '<td id="' + res.labels[items][0] + '_' + item + '">' + '' + '</td>';
  194. } else {
  195. if ((item == 3) && (res.labels[items][item].indexOf(".pdf") != -1)) {
  196. data += '<td><a href="' + res.labels[items][item] + '" target="_blank">圖片連結</a></td>'
  197. } else if ((item == 3) && (res.labels[items][item].indexOf(".png") != -1)) {
  198. data += '<td><a href="' + res.labels[items][item] + '" target="_blank"><img src="' + 'http://60.250.156.230:3000/rita/ERP/raw/master/SHT11.png' + '" width="50px"></a></td>'
  199. } else {
  200. data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
  201. }
  202. }
  203. };
  204. data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_BOM_item(\'' + res.labels[items][0] + '\')"></td>';
  205. data += '<td><input type="button" class="input-cond-delete" value="刪除" onclick="delete_BOM_item(\'' + res.labels[items][0] + '\')"></td>';
  206. data += '</tr>';
  207. };
  208. }
  209. data += '<tr class="noExl">';
  210. data += '<td>';
  211. // data += '<select id="newcom_id" onChange="">';
  212. // data += '<option value="00"></option>';
  213. // data += '{% for data in Company_ID_data %}';
  214. // data += '<option value="{{data[0]}}">{{data[0]}}</option>';
  215. // data += '{% endfor %}';
  216. // data += '</select>';
  217. data += '<input list="insert_BOM_module" id="newcom_id" style="height: 25px;" onChange="get_company_id()">';
  218. data += '<datalist id="insert_BOM_module">';
  219. data += '<option value="">可輸入名稱查找內部料號</option>';
  220. // data += '{% for data in Component_id_name %}';
  221. // data += '<option value="{{data[0]}}">{{data[1]}}</option>';
  222. // data += '{% endfor %}';
  223. data += '{% for data in Component_id_name_salesnum %}';
  224. data += '{% if data[2] == "" or data[2] == None %}';
  225. data += '<option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>';
  226. data += '{% else %}';
  227. data += '<option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>';
  228. data += '{% endif %}';
  229. data += '{% endfor %}';
  230. data += '</datalist>';
  231. data += '</td>';
  232. data += '<td>';
  233. data += '(自動代入)'
  234. // data += '<select id="newcom_id" onChange="">';
  235. // data += '<option value="00"></option>';
  236. // data += '{% for data in Component_name_data %}';
  237. // data += '<option value="{{data[0]}}">{{data[0]}}</option>';
  238. // data += '{% endfor %}';
  239. // data += '</select>';
  240. data += '</td>';
  241. data += '<td></td>';
  242. data += '<td></td>';
  243. data += '<td><input id="newcom_1_ta" value="" style="height: 25px; width: auto" size="5"></td>';
  244. data += '<td><input id="newcom_2_ta" value="" style="height: 25px; width: auto" size="15"></td>';
  245. data += '<td><input id="newcom_3_ta" value="" style="height: 25px; width: auto" size="10"></td>';
  246. data += '<td><input id="newcom_4_ta" value="" style="height: 25px; width: auto" size="10"></td>';
  247. data += '<td>';
  248. // data += '<input list="insert_BOM_person_module" id="newcom_name" style="height: 25px;" onChange="">';
  249. // data += '<datalist id="insert_BOM_person_module">';
  250. // data += '<option value="Andrey"></option>';
  251. // data += '<option value="Amy"></option>';
  252. // data += '<option value="Allen"></option>';
  253. // data += '<option value="Gina"></option>';
  254. // data += '<option value="FatWolf"></option>';
  255. // data += '<option value="Rita"></option>';
  256. // data += '</datalist>';
  257. data += '(自動代入)';
  258. data += '</td>';
  259. data += '<td>';
  260. data += '<input type="button" style="width: auto;" class="input-cond-add" value="新增零件至 BOM" onclick="BOM_insert_component(\'' + BOM_company_id + '\')">';
  261. data += '</td>';
  262. data += '<td><input type="button" style="width: auto;" class="input-cond-delete" value="刪除此 BOM 表" onclick="delete_BOM_table(\'' + BOM_company_id + '\')"></td>';
  263. data += '</tr>';
  264. data += '</table>';
  265. data += '<input type="button" style="width: auto;" class="input-cond-add" value="匯出表單" onclick="export_BOM_table(\'' + BOM_company_id + '\')">';
  266. var sectorSelect = document.getElementById("result");
  267. sectorSelect.innerHTML = data;
  268. },
  269. error: function (thrownError) {
  270. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  271. alert("BOM 表: 無此內部料號 " + BOM_company_id + " 之資料表")
  272. } else {
  273. console.log("BOM 表查詢 thrownError" + thrownError)
  274. }
  275. var data = "";
  276. var sectorSelect = document.getElementById("result");
  277. sectorSelect.innerHTML = data;
  278. }
  279. })
  280. }
  281. }
  282. // 新增 BOM 表零件時, 選擇名稱自動帶入內部料號
  283. function get_company_id() {
  284. var new_component_name = $("#newcom_id").val();
  285. console.log("new_component_name: " + new_component_name) // 03040001T01
  286. }
  287. // 新增零件至 BOM
  288. function BOM_insert_component(BOM_company_id) {
  289. var new_com_0 = $("#newcom_id").val();
  290. var new_com_1 = $("#newcom_1_ta").val()
  291. var new_com_2 = $("#newcom_2_ta").val()
  292. var new_com_3 = $("#newcom_3_ta").val()
  293. var new_com_4 = $("#newcom_4_ta").val()
  294. // var new_com_5 = $("#newcom_name").val()
  295. console.log("new_com_0: " + new_com_0)
  296. console.log("new_com_1: " + new_com_1)
  297. console.log("new_com_2: " + new_com_2)
  298. console.log("new_com_3: " + new_com_3)
  299. console.log("new_com_4: " + new_com_4)
  300. // console.log("new_com_5: " + new_com_5)
  301. var sql = 'INSERT INTO `' + BOM_company_id + '`';
  302. sql += ' VALUES ("' + new_com_0 + '", "' + new_com_1 + '", "' + new_com_2 + '", "' + new_com_3 + '", "' + new_com_4 + '", "' + USERNAME + '");';
  303. console.log("sql: ", sql)
  304. var sql_data = { "sql":sql };
  305. $.ajax({
  306. type:"GET",
  307. url:"/sql_get",
  308. dataType:"JSON",
  309. data:sql_data,
  310. success:function (res) {
  311. search_BOM_table()
  312. },
  313. error: function (thrownError) {
  314. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  315. alert("BOM 表: " + BOM_company_id + " 新增零件未成功")
  316. } else {
  317. console.log("BOM 表新增零件 thrownError" + thrownError)
  318. }
  319. }
  320. })
  321. }
  322. // 匯出 BOM 表
  323. function export_BOM_table(BOM_company_id) {
  324. // alert("匯出功能測試中")
  325. console.log("匯出 BOM 表: " + BOM_company_id)
  326. sql = 'SELECT * FROM `' + BOM_company_id + '`'; // 原始 BOM 表資料, 未來可加上 零件名稱
  327. var sql = 'SELECT ' + BOM_company_id + '.內部料號, ';
  328. sql += '零件表.名稱, ';
  329. sql += BOM_company_id + '.數量, ';
  330. sql += BOM_company_id + '.位置, ';
  331. sql += BOM_company_id + '.備註, ';
  332. sql += BOM_company_id + '.設計原因, ';
  333. sql += BOM_company_id + '.填寫人 ';
  334. sql += 'FROM `' + BOM_company_id + '` ';
  335. sql += ' INNER JOIN 零件表';
  336. sql += ' ON 零件表.內部料號 = ' + BOM_company_id + '.內部料號';
  337. var sql_data = { "sql":sql };
  338. console.log("sql_data: ", sql_data)
  339. $.ajax({
  340. type:"GET",
  341. url:"/export_excel/" + BOM_company_id,
  342. dataType:"JSON",
  343. data:sql_data,
  344. success:function (res) {
  345. document.location.href = '/download/BOM_' + BOM_company_id + '.xlsx'
  346. alert(BOM_company_id + " 匯出 Excel 成功\n檔案路徑: \n" + res.file_location)
  347. // var html = '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8" /><title>Excel</title>';
  348. // html += '';
  349. // html += document.getElementById('table_BOM').innerHTML + '';
  350. // window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
  351. // console.log("res.sql_data_new: " + res.sql_data_new + typeof(res.sql_data_new))
  352. // TableToExcel.convert(table[0],{
  353. // name:BOM_company_id + '.xlsx',
  354. // sheet:{ name:BOM_company_id }
  355. // });
  356. // $("#table_BOM").table2excel({
  357. // exclude:".noExl",
  358. // name:BOM_company_id + "_0106",
  359. // filename:BOM_company_id,
  360. // fileext:".xls"
  361. // });
  362. // window.open('data:application/vnd.ms-excel,' + encodeURIComponent(res.sql_data_new));
  363. console.log("Excel create")
  364. },
  365. error: function (thrownError) {
  366. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  367. alert("BOM 表: 無此內部料號 " + BOM_company_id + " 之資料表")
  368. } else {
  369. console.log("BOM 表查詢 thrownError" + thrownError)
  370. }
  371. }
  372. })
  373. }
  374. // 刪除此 BOM 表
  375. function delete_BOM_table(BOM_company_id) {
  376. console.log("刪除 BOM 表: " + BOM_company_id)
  377. var drop_table = confirm("確定要刪除 " + BOM_company_id + " 資料表?\n此動作不可回復")
  378. if (drop_table) {
  379. sql = 'DROP TABLE ' + BOM_company_id + ';';
  380. console.log("sql: " + sql)
  381. var sql_data = { "sql":sql };
  382. console.log("sql_data: " + sql_data)
  383. $.ajax({
  384. type:"GET",
  385. url:"/sql_get",
  386. dataType:"JSON",
  387. data:sql_data,
  388. success:function (res) {
  389. alert("BOM 表: " + BOM_company_id + "刪除成功 !")
  390. },
  391. error: function (thrownError) {
  392. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  393. alert("BOM 表: " + BOM_company_id + " 刪除未成功")
  394. } else {
  395. console.log("BOM Table 刪除 thrownError" + thrownError)
  396. }
  397. }
  398. })
  399. var sql = 'DELETE FROM 規格表 WHERE 內部料號 = "' + BOM_company_id + '";'
  400. var sql_data = { "sql":sql };
  401. $.ajax({
  402. type:"GET",
  403. url:"/sql_get",
  404. dataType:"JSON",
  405. data:sql_data,
  406. success:function (res) {
  407. alert("規格表: " + BOM_company_id + "刪除成功 !")
  408. },
  409. error: function (thrownError) {
  410. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  411. alert("規格表: " + BOM_company_id + " 刪除未成功")
  412. } else {
  413. console.log("規格表: 刪除 thrownError" + thrownError)
  414. }
  415. }
  416. })
  417. var sql = 'DELETE FROM 零件表 WHERE 內部料號 = "' + BOM_company_id + '";'
  418. var sql_data = { "sql":sql };
  419. $.ajax({
  420. type:"GET",
  421. url:"/sql_get",
  422. dataType:"JSON",
  423. data:sql_data,
  424. success:function (res) {
  425. alert("零件表: " + BOM_company_id + "刪除成功 !")
  426. },
  427. error: function (thrownError) {
  428. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  429. alert("零件表: " + BOM_company_id + " 刪除未成功")
  430. } else {
  431. console.log("零件表: 刪除 thrownError" + thrownError)
  432. }
  433. }
  434. })
  435. location.reload()
  436. }
  437. }
  438. // 修改 BOM 表內項目
  439. function update_BOM_item(company_id) {
  440. console.log("修改 " + company_id)
  441. for (let i = 4; i < 8; i++) {
  442. var target_id = document.getElementById(company_id + '_' + i);
  443. var old_name = target_id.innerText;
  444. console.log('old_name: ', old_name)
  445. target_id.innerHTML = "";
  446. textarea = '<input id="'+ company_id + '_' + i + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 100px">';
  447. if (i == 7) {
  448. textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_BOM_item(\'' + company_id + '\')">';
  449. }
  450. target_id.insertAdjacentHTML('beforeend', textarea);
  451. }
  452. // var target_id = document.getElementById(company_id + '_8');
  453. // var old_name = target_id.innerText;
  454. // console.log("old_name-NAME: " + old_name)
  455. // target_id.innerHTML = "";
  456. // textarea = '<input list="insert_BOM_person_module" id="newcom_name" style="height: 25px; width: 100px" onChange="">';
  457. // textarea += '<datalist id="insert_BOM_person_module">' +
  458. // '<option value="Andrey"></option>' +
  459. // '<option value="Amy"></option>' +
  460. // '<option value="Allen"></option>' +
  461. // '<option value="Gina"></option>' +
  462. // '<option value="FatWolf"></option>' +
  463. // '<option value="Rita"></option>' +
  464. // '</datalist>';
  465. // target_id.insertAdjacentHTML('beforeend', textarea);
  466. // $(".insert_BOM_person_module").find("option:contains(" + old_name + ")").attr("selected",true);
  467. // // $("#insert_BOM_person_module select").val(old_name).change();
  468. }
  469. // 修改確認 BOM 表內項目
  470. function ComfirmUpdate_BOM_item(company_id) {
  471. console.log("修改確認 " + company_id )
  472. var new_amount_value = $('#' + company_id + '_4_ta').val();
  473. var new_position_value = $('#' + company_id + '_5_ta').val();
  474. var new_remark_value = $('#' + company_id + '_6_ta').val();
  475. var new_reason_value = $('#' + company_id + '_7_ta').val();
  476. // var new_person_value = $('#newcom_name').val();
  477. // console.log("new_person_value: " + new_person_value)
  478. sql = 'UPDATE ' + BOM_company_id + ' SET `數量` = "' + new_amount_value + '"' +
  479. ', `位置` = "' + new_position_value + '"' +
  480. ', `備註` = "' + new_remark_value + '"' +
  481. ', `設計原因` = "' + new_reason_value + '"' +
  482. ', `填寫人` = "' + USERNAME + '"' +
  483. ' WHERE `內部料號` = "' + company_id + '";';
  484. console.log('sql: ' + sql)
  485. var sql_data = { "sql":sql };
  486. $.ajax({
  487. type:"GET",
  488. url:"/sql_get",
  489. dataType:"JSON",
  490. data:sql_data,
  491. success:function (res) {
  492. search_BOM_table();
  493. alert("BOM 表: 修改成功 !")
  494. },
  495. error: function (thrownError) {
  496. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  497. alert("規格表: 內部料號 " + company_id + " 修改未成功")
  498. } else {
  499. console.log("修改規格表內容 thrownError" + thrownError)
  500. }
  501. }
  502. })
  503. }
  504. // 刪除 BOM 表內項目
  505. function delete_BOM_item(company_id) {
  506. console.log("刪除 " + company_id)
  507. var delete_data = confirm("確定要刪除 " + BOM_company_id + " BOM 表內的 " + company_id + "?")
  508. if (delete_data) {
  509. // 刪除 BOM 表內的指定零件
  510. var sql = 'DELETE FROM ' + BOM_company_id + ' WHERE 內部料號 = "' + company_id + '";'
  511. var sql_data = { "sql":sql };
  512. $.ajax({
  513. type:"GET",
  514. url:"/sql_get",
  515. dataType:"JSON",
  516. data:sql_data,
  517. success:function (res) {
  518. alert("BOM 表: 項目刪除成功!")
  519. search_BOM_table()
  520. },
  521. error: function (thrownError) {
  522. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  523. alert("BOM 表: 無內部料號 " + company_id + " 之項目資料")
  524. } else {
  525. alert("BOM 表項目刪除錯誤: " + thrownError)
  526. }
  527. }
  528. })
  529. }
  530. }
  531. // 加入 BOM 表
  532. function insert_module(company_id) {
  533. var select_amount = $("#BOM_amount" + company_id).val();
  534. select_amount = parseInt(select_amount)
  535. console.log("select_amount: " + select_amount)
  536. // console.log("typeof(select_amount): " + typeof(select_amount)) // string
  537. var select_name = $("#" + company_id + "_5").text();
  538. console.log("select_name: " + select_name)
  539. var repeat_word = module_amount_list.indexOf(company_id)
  540. console.log("repeat_word: " + repeat_word)
  541. if (select_amount != '') {
  542. if (repeat_word != -1) {
  543. module_amount_list.splice(repeat_word, 3)
  544. }
  545. module_amount_list.push(company_id)
  546. module_amount_list.push(select_name)
  547. module_amount_list.push(select_amount)
  548. // console.log("現有零件: " + module_amount_list)
  549. alert("零件加入成功 !\n\"" + select_name + "\"×" + select_amount)
  550. view_component();
  551. } else if (select_amount == 0) {
  552. if (repeat_word != -1) {
  553. module_amount_list.splice(repeat_word, 3)
  554. }
  555. view_component();
  556. } else {
  557. alert("請輸入零件數量, 且數量為正整數")
  558. }
  559. }
  560. // 輸入完類別後, 流水號自動帶入
  561. function renewSN() {
  562. var BOM_accountingsubjects_select = $("#BOM_accountingsubjects").val();
  563. var BOM_category_select = $("#BOM_category").val();
  564. $.get('/sn_get/' + BOM_accountingsubjects_select + '/' + BOM_category_select, '', function (res) {
  565. // console.log(res.new_sn)
  566. $('#BOM_serialnumber').val(res.new_sn)
  567. }, 'json');
  568. }
  569. // 各資料表←關聯→零件表, 程式
  570. // function search_relation_insertdata(sql) {
  571. // var accountingsubjects_select = $("#accountingsubjects").val();
  572. // var category_select = $("#category").val();
  573. // var serialnumber_select = $("#serialnumber").val();
  574. // serialnumber_select = serialnumber_select.padStart(4, '0')
  575. // var supplier_select = $("#supplier").val();
  576. // var component_name_select = $("#component_name_select").val();
  577. // var component_name_input = $("#component_name_input").val();
  578. // var AND_list = [];
  579. // console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
  580. // var sql = sql;
  581. // // 篩選 會計科目/類別/供應商 關鍵字
  582. // if (accountingsubjects_select != '00') {
  583. // AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
  584. // }
  585. // if (category_select != '00') {
  586. // AND_list.push('類別 = "' + category_select + '"')
  587. // }
  588. // if (serialnumber_select != '0000') {
  589. // AND_list.push('流水號 = "' + serialnumber_select + '"')
  590. // }
  591. // if (supplier_select != '00') {
  592. // AND_list.push('供應商 = "' + supplier_select + '"')
  593. // }
  594. // if (component_name_select != '00') {
  595. // AND_list.push('零件表.名稱 = "' + component_name_select + '"')
  596. // } else if (component_name_input != '') {
  597. // AND_list.push('零件表.名稱 LIKE "%' + component_name_input + '%"')
  598. // }
  599. // console.log("AND_list: ", AND_list)
  600. // if (AND_list != '') {
  601. // sql += ' WHERE ' + AND_list.join(' AND ');
  602. // }
  603. // if (sql.match('INNER JOIN 庫存表')) {
  604. // sql += ' ORDER BY 時間 DESC LIMIT 1'
  605. // }
  606. // var sql_data = {
  607. // "sql":sql
  608. // };
  609. // console.log("sql_data: ", sql_data)
  610. // $.get('/sql_get', sql_data, function (res) {
  611. // // console.log("res: " + res)
  612. // // console.log("res.labels:" + res.labels)
  613. // // console.log("res.labels[0]:" + res.labels[0])
  614. // // console.log("res.labels[0][0]:" + res.labels[0][0])
  615. // // console.log("res.sql_field:" + res.sql_field)
  616. // // console.log("res.sql_field[0]:" + res.sql_field[0])
  617. // var data = "";
  618. // if (res.labels == '') {
  619. // data += '-- 無符合關鍵字之資料 --'
  620. // } else {
  621. // data += '<table class="table table-bordered" style="margin-top: 10px;">';
  622. // data += '<tr>';
  623. // for (let fields = 0; fields < res.sql_field.length; fields++) {
  624. // data += '<th>' + res.sql_field[fields][0] + '</th>';
  625. // }
  626. // data += '</tr>';
  627. // for (let items = 0; items < res.labels.length; items++) {
  628. // data += '<tr>';
  629. // for (let item = 0; item < res.labels[items].length; item++) {
  630. // console.log("res.labels[items][item]: ", res.labels[items][item], typeof(res.labels[items][item]))
  631. // data += '<td>' + res.labels[items][item] + '</td>';
  632. // };
  633. // data += '</tr>';
  634. // };
  635. // data += '</table>';
  636. // }
  637. // var sectorSelect = document.getElementById("result");
  638. // sectorSelect.innerHTML = data;
  639. // }, 'json');
  640. // }
  641. // 零件表查詢
  642. function search_component_table(){
  643. var accountingsubjects_select = $("#accountingsubjects").val();
  644. var category_select = $("#category").val();
  645. var serialnumber_select = $("#serialnumber").val();
  646. serialnumber_select = serialnumber_select.padStart(4, '0')
  647. var supplier_select = $("#supplier").val();
  648. var component_name_select = $("#component_name_select").val();
  649. var component_name_input = $("#component_name_input").val();
  650. var AND_list = [];
  651. console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
  652. // sql = 'SELECT * FROM 零件表';
  653. sql = 'SELECT 零件表.內部料號, 會計科目表.會計科目_名稱, 類別表.類別_名稱, 流水號, 供應商.公司, 零件表.名稱, 規格表.原廠料號 ' +
  654. 'FROM (' +
  655. '(' +
  656. '(零件表 ' +
  657. 'INNER JOIN 會計科目表 ' +
  658. 'ON 會計科目表.會計科目_編號 = 零件表.會計科目 ' +
  659. ') ' +
  660. 'INNER JOIN 類別表 ' +
  661. 'ON 類別表.類別_編號 = 零件表.類別 ' +
  662. ') ' +
  663. 'INNER JOIN 供應商 ' +
  664. 'ON 供應商.供應商 = 零件表.供應商 ' +
  665. ') ' +
  666. 'INNER JOIN 規格表 ' +
  667. 'ON 規格表.內部料號 = 零件表.內部料號 ';
  668. // 篩選 會計科目/類別/供應商 關鍵字
  669. if (accountingsubjects_select != '00') {
  670. AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
  671. }
  672. if (category_select != '00') {
  673. AND_list.push('類別 = "' + category_select + '"')
  674. }
  675. if (serialnumber_select != '0000') {
  676. AND_list.push('流水號 = "' + serialnumber_select + '"')
  677. }
  678. if (supplier_select != '00') {
  679. AND_list.push('零件表.供應商 = "' + supplier_select + '"')
  680. }
  681. if (component_name_select != '00') {
  682. AND_list.push('名稱 = "' + component_name_select + '"')
  683. } else if (component_name_input != '') {
  684. AND_list.push('名稱 LIKE "%' + component_name_input + '%"')
  685. }
  686. console.log("AND_list: ", AND_list)
  687. if (AND_list != '') {
  688. sql += ' WHERE ' + AND_list.join(' AND ');
  689. }
  690. var sql_data = { "sql":sql };
  691. console.log("sql_data: ", sql_data)
  692. $.get('/sql_get', sql_data, function (res) {
  693. // console.log("res: " + res)
  694. // console.log("res.labels:" + res.labels)
  695. // console.log("res.labels[0]:" + res.labels[0])
  696. // console.log("res.labels[0][0]:" + res.labels[0][0])
  697. // console.log("res.sql_field:" + res.sql_field)
  698. // console.log("res.sql_field[0]:" + res.sql_field[0])
  699. // console.log("res.Component_id[0]:" + res.Component_id[0])
  700. var data = "";
  701. if (res.labels == '') {
  702. data += '-- 無符合關鍵字之資料 --'
  703. } else {
  704. data += '<table class="table table-bordered" style="margin-top: 10px;">';
  705. data += '<tr>';
  706. // for (let fields = 0; fields < res.sql_field.length; fields++) {
  707. // data += '<th>' + res.sql_field[fields][0] + '</th>';
  708. // }
  709. data += '<th>內部料號</th>';
  710. data += '<th>會計科目</th>';
  711. data += '<th>類別</th>';
  712. data += '<th>流水號</th>';
  713. data += '<th>供應商</th>';
  714. data += '<th>名稱</th>';
  715. data += '<th>原廠料號</th>';
  716. data += '<th>輸入零件數量</th>';
  717. data += '<th>加入至新 BOM 表</th>';
  718. data += '</tr>';
  719. for (let items = 0; items < res.labels.length; items++) {
  720. data += '<tr>';
  721. for (let item = 0; item < res.labels[items].length; item++) {
  722. if (res.labels[items][item] == null) {
  723. data += '<td id="' + res.labels[items][0] + '_' + item + '"></td>';
  724. } else {
  725. data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
  726. }
  727. };
  728. // <input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
  729. data += '<td><input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,\'\').replace(\'.\',\'\')}else{this.value=this.value.replace(/\\D/g,\'\').replace(\'.\',\'\')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,\'\').replace(\'.\',\'\')}else{this.value=this.value.replace(/\\D/g,\'\').replace(\'.\',\'\')}"'
  730. data += 'id="BOM_amount' + res.labels[items][0] + '" style="height: 25px; width: 90px;"></td>';
  731. data += '<td><input type="button" class="input-cond-add" value="加入" onclick="insert_module(\'' + res.labels[items][0] + '\')"></td>';
  732. data += '</tr>';
  733. };
  734. data += '</table>';
  735. }
  736. var sectorSelect = document.getElementById("result");
  737. sectorSelect.innerHTML = data;
  738. }, 'json');
  739. }
  740. // 查看現有零件
  741. function view_component() {
  742. var data = '現有零件: <br>';
  743. // 網頁顯示用 "內部料號"_"名稱"_"數量"<br>
  744. for (let i = 0; i < module_amount_list.length; i++) {
  745. if (i%3 == 0) {
  746. data += '"' + module_amount_list[i] + '"_'
  747. } else if (i%3 == 1) {
  748. data += '"' + module_amount_list[i] + '"_'
  749. } else if (i%3 == 2) {
  750. data += '"' + module_amount_list[i] + '"<br>'
  751. }
  752. }
  753. // data += 'SQL: <br>' +
  754. // 'INSERT INTO `' + 'company_id' + '` (`內部料號`, `數量`) ' +
  755. // 'VALUES ' + module_amount_sqllist.join(', ') + ';';
  756. var sectorSelect = document.getElementById("view_component_data");
  757. sectorSelect.innerHTML = data;
  758. }
  759. // 新增模組/系統/成品
  760. function create_module() {
  761. // 會計科目
  762. var accountingsubjects_select = $("#BOM_accountingsubjects").val();
  763. // 類別
  764. var category_select = $("#BOM_category").val();
  765. // 流水號 → 從資料庫找到最大的流水號, 然後 +1
  766. var serialnumber_select = $("#BOM_serialnumber").val();
  767. // 放到 renewSN 方法內執行
  768. // 供應商
  769. var supplier_select = $("#BOM_supplier").val();
  770. // 零件名稱
  771. var component_name_select = $("#BOM_module_name_select").val();
  772. // 內部料號組合
  773. var company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
  774. var AND_list = [];
  775. // console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select, component_name_select)
  776. if (accountingsubjects_select == '00' || accountingsubjects_select == '00' || supplier_select == '00' || component_name_select == '') {
  777. alert("請先輸入 BOM 表會計科目、類別、供應商及名稱\n再新建模組")
  778. } else {
  779. // !!! 將模組加入零件表中
  780. var sql = '';
  781. sql += 'INSERT INTO 零件表 ' +
  782. 'VALUES ("' + company_id + '", "' + accountingsubjects_select + '", "' + category_select + '", "' + serialnumber_select + '", "';
  783. sql += supplier_select + '", "' + component_name_select + '");';
  784. console.log("sql: " + sql)
  785. var sql_data = { "sql":sql };
  786. $.ajax({
  787. type:"GET",
  788. url:"/sql_get",
  789. dataType:"JSON",
  790. data:sql_data,
  791. async:false,
  792. success:function (res) {
  793. alert("零件表 " + company_id + " 新增成功!")
  794. // data = '-- 新增成功! --'
  795. // var sectorSelect = document.getElementById("result");
  796. // sectorSelect.innerHTML = data;
  797. },
  798. error: function (thrownError) {
  799. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  800. alert("零件表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  801. } else {
  802. console.log("新建模組零件 thrownError" + thrownError)
  803. }
  804. }
  805. })
  806. // !!! 將模組加入規格表中 (留下內部料號, 其他 NULL)
  807. var sql = '';
  808. sql += 'INSERT INTO 規格表 (`內部料號`)' +
  809. ' VALUES ("' + company_id + '");';
  810. console.log("sql: " + sql)
  811. var sql_data = { "sql":sql };
  812. $.ajax({
  813. type:"GET",
  814. url:"/sql_get",
  815. dataType:"JSON",
  816. data:sql_data,
  817. async:false,
  818. success:function (res) {
  819. alert("規格表 " + company_id + " 新增成功!")
  820. // data = '-- 新增成功! --'
  821. // var sectorSelect = document.getElementById("result");
  822. // sectorSelect.innerHTML = data;
  823. },
  824. error: function (thrownError) {
  825. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  826. alert("規格表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  827. } else {
  828. console.log("新建模組零件 thrownError" + thrownError)
  829. }
  830. }
  831. })
  832. // !!! 建立模組 Table
  833. var sql = '';
  834. sql += 'CREATE TABLE `' + company_id + '` ( ' +
  835. '內部料號 varchar(11) NOT NULL DEFAULT "00", ' +
  836. '數量 varchar(4) NOT NULL,' +
  837. '位置 varchar(100) NULL,' +
  838. '備註 varchar(200) NULL,' +
  839. '設計原因 varchar(200) NULL,' +
  840. '填寫人 varchar(20) NULL,' +
  841. 'PRIMARY KEY (內部料號)' +
  842. ');';
  843. console.log("sql: " + sql)
  844. var sql_data = { "sql":sql };
  845. $.ajax({
  846. type:"GET",
  847. url:"/sql_get",
  848. dataType:"JSON",
  849. data:sql_data,
  850. async:false,
  851. success:function (res) {
  852. alert("資料表 " + company_id + " 建立成功!")
  853. },
  854. error: function (thrownError) {
  855. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  856. alert("資料表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  857. } else {
  858. console.log("新建模組 Table thrownError" + thrownError)
  859. }
  860. }
  861. })
  862. // 儲存欲加入的零件 數量_sql 用無名稱注意格式
  863. var module_amount_sqllist = [];
  864. // SQL 語法
  865. var sql_data_list = '';
  866. for (let i = 0; i < module_amount_list.length; i++) {
  867. if (i%3 == 0) {
  868. // 內部料號
  869. sql_data_list = '("' + module_amount_list[i] + '", '
  870. }
  871. if (i%3 == 2) {
  872. // 數量 + 填寫人
  873. sql_data_list += '"' + module_amount_list[i] + '", "' + USERNAME + '")'
  874. module_amount_sqllist.push(sql_data_list)
  875. }
  876. }
  877. console.log("module_amount_sqllist: " + module_amount_sqllist)
  878. // !!! 將所選零件加入模組 Table
  879. var sql = '';
  880. sql += 'INSERT INTO `' + company_id + '` (`內部料號`, `數量`, `填寫人`) ' +
  881. 'VALUES ' + module_amount_sqllist.join(', ') + ';';
  882. console.log("sql: " + sql)
  883. var sql_data = { "sql":sql };
  884. if (module_amount_sqllist.length == 0) {
  885. alert("資料表 " + company_id + ": 加入零件為空, 故此 BOM 表無零件")
  886. location.reload()
  887. } else {
  888. $.ajax({
  889. type:"GET",
  890. url:"/sql_get",
  891. dataType:"JSON",
  892. data:sql_data,
  893. async:false,
  894. success:function (res) {
  895. alert("資料表 " + company_id + ": 零件增加成功!")
  896. location.reload()
  897. },
  898. error: function (thrownError) {
  899. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  900. alert("內部料號 " + company_id + " 已存在, 請重新輸入")
  901. } else {
  902. console.log("零件加入模組 thrownError" + thrownError)
  903. }
  904. }
  905. })
  906. }
  907. }
  908. }
  909. </script>
  910. <br>
  911. <hr>
  912. <!-- <input type="button" id="view_component" value="查看現有加入零件" onclick="view_component();"> -->
  913. <div id="view_component_data">現有零件 :</div>
  914. <br>
  915. 零件加入完成後, 請按下
  916. <input type="button" id="create_module" value="新增模組/系統/成品" onclick="create_module();">
  917. <!-- <script>
  918. // 查看現有零件
  919. function view_component() {
  920. var data = '現有零件: <br>';
  921. // 網頁顯示用 "內部料號"_"名稱"_"數量"<br>
  922. for (let i = 0; i < module_amount_list.length; i++) {
  923. if (i%3 == 0) {
  924. data += '"' + module_amount_list[i] + '"_'
  925. } else if (i%3 == 1) {
  926. data += '"' + module_amount_list[i] + '"_'
  927. } else if (i%3 == 2) {
  928. data += '"' + module_amount_list[i] + '"<br>'
  929. }
  930. }
  931. // data += 'SQL: <br>' +
  932. // 'INSERT INTO `' + 'company_id' + '` (`內部料號`, `數量`) ' +
  933. // 'VALUES ' + module_amount_sqllist.join(', ') + ';';
  934. var sectorSelect = document.getElementById("view_component_data");
  935. sectorSelect.innerHTML = data;
  936. }
  937. // 新增模組/系統/成品
  938. function create_module() {
  939. // 會計科目
  940. var accountingsubjects_select = $("#BOM_accountingsubjects").val();
  941. // 類別
  942. var category_select = $("#BOM_category").val();
  943. // 流水號 → 從資料庫找到最大的流水號, 然後 +1
  944. var serialnumber_select = $("#BOM_serialnumber").val();
  945. // 放到 renewSN 方法內執行
  946. // 供應商
  947. var supplier_select = $("#BOM_supplier").val();
  948. // 零件名稱
  949. var component_name_select = $("#BOM_module_name_select").val();
  950. // 內部料號組合
  951. var company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
  952. var AND_list = [];
  953. console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select, component_name_select)
  954. // !!! 將模組加入零件表中
  955. var sql = '';
  956. sql += 'INSERT INTO 零件表 ' +
  957. 'VALUES ("' + company_id + '", "' + accountingsubjects_select + '", "' + category_select + '", "' + serialnumber_select + '", "';
  958. sql += supplier_select + '", "' + component_name_select + '");';
  959. console.log("sql: " + sql)
  960. var sql_data = { "sql":sql };
  961. $.ajax({
  962. type:"GET",
  963. url:"/sql_get",
  964. dataType:"JSON",
  965. data:sql_data,
  966. success:function (res) {
  967. alert("零件表 " + company_id + " 新增成功!")
  968. // data = '-- 新增成功! --'
  969. // var sectorSelect = document.getElementById("result");
  970. // sectorSelect.innerHTML = data;
  971. },
  972. error: function (thrownError) {
  973. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  974. alert("零件表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  975. } else {
  976. console.log("新建模組零件 thrownError" + thrownError)
  977. }
  978. }
  979. })
  980. // !!! 將模組加入規格表中 (留下內部料號, 其他 NULL)
  981. var sql = '';
  982. sql += 'INSERT INTO 規格表 (`內部料號`)' +
  983. 'VALUES ("' + company_id + '");';
  984. console.log("sql: " + sql)
  985. var sql_data = { "sql":sql };
  986. $.ajax({
  987. type:"GET",
  988. url:"/sql_get",
  989. dataType:"JSON",
  990. data:sql_data,
  991. success:function (res) {
  992. alert("規格表 " + company_id + " 新增成功!")
  993. // data = '-- 新增成功! --'
  994. // var sectorSelect = document.getElementById("result");
  995. // sectorSelect.innerHTML = data;
  996. },
  997. error: function (thrownError) {
  998. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  999. alert("規格表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  1000. } else {
  1001. console.log("新建模組零件 thrownError" + thrownError)
  1002. }
  1003. }
  1004. })
  1005. // !!! 建立模組 Table
  1006. var sql = '';
  1007. sql += 'CREATE TABLE `' + company_id + '` ( ' +
  1008. '內部料號 varchar(11) NOT NULL DEFAULT "00", ' +
  1009. '數量 varchar(4) NOT NULL,' +
  1010. '位置 varchar(100) NULL,' +
  1011. '備註 varchar(200) NULL,' +
  1012. '設計原因 varchar(200) NULL,' +
  1013. '填寫人 varchar(20) NULL,' +
  1014. 'PRIMARY KEY (內部料號)' +
  1015. ');';
  1016. console.log("sql: " + sql)
  1017. var sql_data = { "sql":sql };
  1018. $.ajax({
  1019. type:"GET",
  1020. url:"/sql_get",
  1021. dataType:"JSON",
  1022. data:sql_data,
  1023. success:function (res) {
  1024. alert("資料表 " + company_id + " 建立成功!")
  1025. module_amount_sqllist = [];
  1026. // SQL 語法
  1027. var sql_data_list = '';
  1028. for (let i = 0; i < module_amount_list.length; i++) {
  1029. if (i%3 == 0) {
  1030. sql_data_list = '("' + module_amount_list[i] + '", '
  1031. }
  1032. if (i%3 == 2) {
  1033. sql_data_list += '"' + module_amount_list[i] + '")'
  1034. module_amount_sqllist.push(sql_data_list)
  1035. }
  1036. }
  1037. // !!! 將所選零件加入模組 Table
  1038. var sql = '';
  1039. sql += 'INSERT INTO `' + company_id + '` (`內部料號`, `數量`) ' +
  1040. 'VALUES ' + module_amount_sqllist.join(', ') + ';';
  1041. console.log("sql: " + sql)
  1042. var sql_data = { "sql":sql };
  1043. if (module_amount_sqllist.length == 0) {
  1044. alert("資料表 " + company_id + ": 加入零件為空, 故此 BOM 表無零件")
  1045. location.reload()
  1046. } else {
  1047. $.ajax({
  1048. type:"GET",
  1049. url:"/sql_get",
  1050. dataType:"JSON",
  1051. data:sql_data,
  1052. success:function (res) {
  1053. alert("資料表 " + company_id + ": 零件增加成功!")
  1054. location.reload()
  1055. },
  1056. error: function (thrownError) {
  1057. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  1058. alert("內部料號 " + company_id + " 已存在, 請重新輸入")
  1059. } else {
  1060. console.log("零件加入模組 thrownError" + thrownError)
  1061. }
  1062. }
  1063. })
  1064. }
  1065. },
  1066. error: function (thrownError) {
  1067. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  1068. alert("資料表: 內部料號 " + company_id + " 已存在, 請重新輸入")
  1069. } else {
  1070. console.log("新建模組 Table thrownError" + thrownError)
  1071. }
  1072. }
  1073. })
  1074. }
  1075. </script> -->
  1076. <br>
  1077. <br>
  1078. <!-- <input type="button" style="width: auto;" class="input-cond-add" value="匯出表單" onclick="export_BOM_table('03030001T01')"> -->
  1079. <!-- <iframe width="100px" src="/plugins/pdfjs-1.4.20/web/viewer.html?file=http://60.250.156.230:3000/rita/ERP/src/1ac36a99cc9721451b4baafd67d98b54bb315bcd/pH_probe.pdf"></iframe> -->
  1080. </body>
  1081. </html>