search.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. <!-- 0127 更新 -->
  8. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  9. <!-- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css"> -->
  10. <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> -->
  11. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  12. <!-- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> -->
  13. <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
  14. <!-- <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script> -->
  15. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  16. <!-- <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> -->
  17. <!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> -->
  18. <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> -->
  19. <!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> -->
  20. <!-- <script src="../static/js/bootstrap.min.js"></script> -->
  21. <!-- 舊的, 網頁讀取有問題 -->
  22. <!-- 新 Bootstrap4 核心 CSS 文件
  23. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  24. jQuery文件。务必在bootstrap.min.js 之前引入
  25. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  26. popper.min.js 用于弹窗、提示、下拉菜单
  27. <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  28. 最新的 Bootstrap4 核心 JavaScript 文件
  29. <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  30. 可用來建立使用者小圖示
  31. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> -->
  32. <script>
  33. // var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'version', 'path', 'size', 'material',
  34. // 'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
  35. var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'path', 'size', 'material',
  36. 'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
  37. </script>
  38. </head>
  39. <style>
  40. .input-cond-delete {
  41. background: #E43030;
  42. border: 1px solid #CFCFCF;
  43. box-sizing: border-box;
  44. border-radius: 5px;
  45. margin-left: 5px;
  46. width: 65px;
  47. height: 33px;
  48. font-size: 16px;
  49. text-align: center;
  50. line-height: 16px;
  51. color: #FFFFFF;
  52. }
  53. .input-cond-add {
  54. background: #008CBA;
  55. border: 1px solid #CFCFCF;
  56. box-sizing: border-box;
  57. border-radius: 5px;
  58. margin-left: 5px;
  59. width: 65px;
  60. height: 33px;
  61. font-size: 16px;
  62. text-align: center;
  63. line-height: 16px;
  64. color: #FFFFFF;
  65. }
  66. </style>
  67. <body>
  68. <div id="ERP_header">
  69. <!-- 匯入共同使用的 header.html 內容 -->
  70. {% include 'ERP_header.html' %}
  71. </div>
  72. 會計科目:
  73. <select id="accountingsubjects" onChange="">
  74. <option value="00"></option>
  75. {% for data in AccountingSubjects_data %}
  76. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  77. {% endfor %}
  78. </select>
  79. 類別:
  80. <select id="category" onChange="">
  81. <option value="00"></option>
  82. {% for data in Category_data %}
  83. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  84. {% endfor %}
  85. </select>
  86. 流水號:
  87. <input id="serialnumber" placeholder="0001" style="height: 25px; width: 45px;">
  88. 供應商:
  89. <select id="supplier" onChange="">
  90. <option value="00"></option>
  91. {% for data in Supplier_data %}
  92. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  93. {% endfor %}
  94. </select><br>
  95. 零件名稱:
  96. <select id="component_name_select" onChange="">
  97. <option value="00"></option>
  98. {% for data in Component_data %}
  99. <option value="{{data[0]}}">{{data[0]}}</option>
  100. {% endfor %}
  101. </select>
  102. <input id="component_name_input" placeholder="零件關鍵字輸入" style="height: 25px; width: 120px;">
  103. <input type="button" id="search_component_table" value="零件表查詢" onclick="search_component_table();">
  104. <input type="button" id="search_component_standard_table" value="(零件)規格表查詢" onclick="search_component_standard_table();">
  105. <!-- <input type="button" id="search_component_stock_table" value="(零件)庫存表查詢" onclick="search_component_stock_table();" style="display: none;"> -->
  106. <!-- <input type="button" id="search_component_import_table" value="(零件)進貨表查詢" onclick="search_component_import_table();" style="display: none;"> -->
  107. <!-- <input type="button" id="search_component_export_table" value="(零件)銷貨表查詢" onclick="search_component_export_table();" style="display: none;"> -->
  108. <br>
  109. <a id="create_component_table_item" href="/create_component_table_item">(零件)新增零件</a>
  110. <a id="create_BOM" href="/create_BOM">建立 BOM 表</a>
  111. <!-- <a id="update_Picture" href="/update_Picture" disabled="true"><s>更新圖片</s></a> -->
  112. <br>
  113. <br>
  114. <br>
  115. <script>
  116. // // (零件)銷貨表查詢
  117. // function search_component_export_table() {
  118. // var sql = 'SELECT 銷貨表.* FROM 零件表';
  119. // sql += ' INNER JOIN 銷貨表';
  120. // sql += ' ON 零件表.內部料號 = 銷貨表.內部料號';
  121. // search_relation_insertdata(sql)
  122. // }
  123. // // (零件)進貨表查詢
  124. // function search_component_import_table() {
  125. // var sql = 'SELECT 進貨表.* FROM 零件表';
  126. // sql += ' INNER JOIN 進貨表';
  127. // sql += ' ON 零件表.內部料號 = 進貨表.內部料號';
  128. // search_relation_insertdata(sql)
  129. // }
  130. // // (零件)庫存表查詢
  131. // function search_component_stock_table() {
  132. // var sql = 'SELECT 庫存表.時間, 庫存表.內部料號, 庫存表.數量 FROM 零件表';
  133. // sql += ' INNER JOIN 庫存表';
  134. // sql += ' ON 零件表.內部料號 = 庫存表.內部料號';
  135. // search_relation_insertdata(sql)
  136. // }
  137. // (零件)規格表查詢
  138. function search_component_standard_table() {
  139. var accountingsubjects_select = $("#accountingsubjects").val();
  140. var category_select = $("#category").val();
  141. var serialnumber_select = $("#serialnumber").val();
  142. serialnumber_select = serialnumber_select.padStart(4, '0')
  143. var supplier_select = $("#supplier").val();
  144. var component_name_select = $("#component_name_select").val();
  145. var component_name_input = $("#component_name_input").val();
  146. var AND_list = [];
  147. console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
  148. sql = 'SELECT 零件表.內部料號, 零件表.名稱, 規格表.原廠料號, 規格表.單位, 規格表.圖片, 規格表.圖號, ' +
  149. '規格表.檔案路徑, 規格表.尺寸, 規格表.`封裝/材質`, 規格表.工作電壓, 規格表.工作電流, 規格表.最大電流, ' +
  150. '規格表.功率, 規格表.工作溫度, 規格表.備註 ' +
  151. 'FROM 零件表 ' +
  152. 'INNER JOIN 規格表 ON 零件表.內部料號 = 規格表.內部料號';
  153. // 篩選 會計科目/類別/供應商 關鍵字
  154. if (accountingsubjects_select != '00') {
  155. AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
  156. }
  157. if (category_select != '00') {
  158. AND_list.push('類別 = "' + category_select + '"')
  159. }
  160. if (serialnumber_select != '0000') {
  161. AND_list.push('流水號 = "' + serialnumber_select + '"')
  162. }
  163. if (supplier_select != '00') {
  164. AND_list.push('供應商 = "' + supplier_select + '"')
  165. }
  166. if (component_name_select != '00') {
  167. AND_list.push('零件表.名稱 = "' + component_name_select + '"')
  168. } else if (component_name_input != '') {
  169. AND_list.push('零件表.名稱 LIKE "%' + component_name_input + '%"')
  170. }
  171. console.log("AND_list: ", AND_list)
  172. if (AND_list != '') {
  173. sql += ' WHERE ' + AND_list.join(' AND ');
  174. }
  175. var sql_data = { "sql":sql };
  176. console.log("sql_data: ", sql_data)
  177. $.get('/sql_get', sql_data, function (res) {
  178. var data = " ";
  179. if (res.labels == '') {
  180. data += '-- 規格表無符合關鍵字之資料 --'
  181. } else {
  182. data += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
  183. data += '<table class="table table-bordered" style="margin-top: 10px;">';
  184. data += '<tr>';
  185. for (let fields = 0; fields < res.sql_field.length; fields++) {
  186. if (res.sql_field[fields][0] !== '版次') {
  187. data += '<th>' + res.sql_field[fields][0] + '</th>';
  188. if (fields == 0) {
  189. data += '<th>零件名稱</th>';
  190. }
  191. }
  192. }
  193. data += '<th>' + '修改' + '</th>';
  194. data += '</tr>';
  195. for (let items = 0; items < res.labels.length; items++) {
  196. data += '<tr>';
  197. for (let item = 0; item < res.labels[items].length; item++) {
  198. // console.log("res.labels[items][item]: ", res.labels[items][item], typeof(res.labels[items][item]))
  199. if (res.labels[items][item] == null) {
  200. data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' + '' + '</td>';
  201. } else {
  202. if (standard_title_list[item] == 'picture') {
  203. data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' +
  204. '<img src="../static/Component_IMG/' + res.labels[items][item] + '" width="60" alt="' + res.labels[items][item] + '" onclick="imgZoomIn(\'' + res.labels[items][item] + '\')">' +
  205. '</td>';
  206. } else {
  207. data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' + res.labels[items][item] + '</td>';
  208. }
  209. }
  210. };
  211. data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_standard(\'' + res.labels[items][0] + '\')"></td>';
  212. data += '</tr>';
  213. };
  214. data += '</table>';
  215. }
  216. var sectorSelect = document.getElementById("result");
  217. sectorSelect.innerHTML = data;
  218. }, 'json');
  219. }
  220. // 規格表 圖片 圖片放大
  221. function imgZoomIn(imgName) {
  222. // alert("imgName: " + imgName)
  223. data = '<img src="../static/Component_IMG/' + imgName + '" width="466" alt="' + imgName + '">';
  224. var sectorSelect = document.getElementById("ImgZoomIn_Modal_body");
  225. sectorSelect.innerHTML = data;
  226. setTimeout(function(){ $('#ImgZoomIn_Modal').modal('show'); }, 300)
  227. }
  228. // 規格表 內容修改
  229. function update_standard(company_id) {
  230. console.log("修改 " + company_id)
  231. for (let i = 2; i < standard_title_list.length; i++) {
  232. // 跳過 picure
  233. if (standard_title_list[i] != 'picture') {
  234. var target_id = document.getElementById(company_id + '_' + standard_title_list[i]);
  235. console.log("target_id: " + standard_title_list[i]);
  236. var old_name = target_id.innerText;
  237. console.log(standard_title_list[i] + ' old_name: ', old_name)
  238. target_id.innerHTML = "";
  239. textarea = '';
  240. if (standard_title_list[i] == 'unit' || standard_title_list[i] == 'version' || standard_title_list[i] == 'material' ||
  241. standard_title_list[i] == 'workV' || standard_title_list[i] == 'workI' || standard_title_list[i] == 'power' || standard_title_list[i] == 'maxI') {
  242. textarea += '<input id="'+ company_id + '_' + standard_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 50px">';
  243. } else if (standard_title_list[i] == 'picture') {
  244. textarea += old_name;
  245. console.log(target_id.innerHTML)
  246. } else {
  247. textarea += '<input id="'+ company_id + '_' + standard_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 150px">';
  248. }
  249. if (i == standard_title_list.length-1) {
  250. textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_standard(\'' + company_id + '\')">';
  251. }
  252. target_id.insertAdjacentHTML('beforeend', textarea);
  253. }
  254. }
  255. }
  256. // 規格表 修改確認
  257. function ComfirmUpdate_standard(company_id) {
  258. // var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'version', 'path', 'size', 'material',
  259. // 'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
  260. var new_type_value = $('#' + company_id + '_type_ta').val();
  261. var new_unit_value = $('#' + company_id + '_unit_ta').val();
  262. // var new_picture_value = $('#' + company_id + '_picture_ta').val();
  263. var new_pictureID_value = $('#' + company_id + '_pictureID_ta').val();
  264. var new_version_value = $('#' + company_id + '_version_ta').val();
  265. var new_path_value = $('#' + company_id + '_path_ta').val();
  266. var new_size_value = $('#' + company_id + '_size_ta').val();
  267. var new_material_value = $('#' + company_id + '_material_ta').val();
  268. var new_workV_value = $('#' + company_id + '_workV_ta').val();
  269. var new_workI_value = $('#' + company_id + '_workI_ta').val();
  270. var new_maxI_value = $('#' + company_id + '_maxI_ta').val();
  271. var new_power_value = $('#' + company_id + '_power_ta').val();
  272. var new_workTemp_value = $('#' + company_id + '_workTemp_ta').val();
  273. var new_remark_value = $('#' + company_id + '_remark_ta').val();
  274. sql = 'UPDATE 規格表 SET ' +
  275. '`原廠料號` = "' + new_type_value + '"' +
  276. ', `單位` = "' + new_unit_value + '"' +
  277. // ', `圖片` = "' + new_picture_value + '"' +
  278. ', `圖號` = "' + new_pictureID_value + '"' +
  279. ', `檔案路徑` = "' + new_path_value + '"' +
  280. ', `尺寸` = "' + new_size_value + '"' +
  281. ', `封裝/材質` = "' + new_material_value + '"' +
  282. ', `工作電壓` = "' + new_workV_value + '"' +
  283. ', `工作電流` = "' + new_workI_value + '"' +
  284. ', `功率` = "' + new_power_value + '"' +
  285. ', `最大電流` = "' + new_maxI_value + '"' +
  286. ', `工作溫度` = "' + new_workTemp_value + '"' +
  287. ', `備註` = "' + new_remark_value + '"' +
  288. ' WHERE `內部料號` = "' + company_id + '";'
  289. console.log('sql: ' + sql)
  290. var sql_data = { "sql":sql };
  291. $.ajax({
  292. type:"GET",
  293. url:"/sql_get",
  294. dataType:"JSON",
  295. data:sql_data,
  296. success:function (res) {
  297. search_component_standard_table();
  298. alert("規格表: 修改成功 !")
  299. },
  300. error: function (thrownError) {
  301. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  302. alert("規格表: 內部料號 " + company_id + " 修改未成功")
  303. } else {
  304. console.log("修改規格表內容 thrownError" + thrownError)
  305. }
  306. }
  307. })
  308. }
  309. // 各資料表←關聯→零件表, 程式
  310. function search_relation_insertdata(sql) {
  311. var accountingsubjects_select = $("#accountingsubjects").val();
  312. var category_select = $("#category").val();
  313. var serialnumber_select = $("#serialnumber").val();
  314. serialnumber_select = serialnumber_select.padStart(4, '0')
  315. var supplier_select = $("#supplier").val();
  316. var component_name_select = $("#component_name_select").val();
  317. var component_name_input = $("#component_name_input").val();
  318. var AND_list = [];
  319. console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
  320. var sql = sql;
  321. // 篩選 會計科目/類別/供應商 關鍵字
  322. if (accountingsubjects_select != '00') {
  323. AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
  324. }
  325. if (category_select != '00') {
  326. AND_list.push('類別 = "' + category_select + '"')
  327. }
  328. if (serialnumber_select != '0000') {
  329. AND_list.push('流水號 = "' + serialnumber_select + '"')
  330. }
  331. if (supplier_select != '00') {
  332. AND_list.push('供應商 = "' + supplier_select + '"')
  333. }
  334. if (component_name_select != '00') {
  335. AND_list.push('零件表.名稱 = "' + component_name_select + '"')
  336. } else if (component_name_input != '') {
  337. AND_list.push('零件表.名稱 LIKE "%' + component_name_input + '%"')
  338. }
  339. console.log("AND_list: ", AND_list)
  340. if (AND_list != '') {
  341. sql += ' WHERE ' + AND_list.join(' AND ');
  342. }
  343. if (sql.match('INNER JOIN 庫存表')) {
  344. sql += ' ORDER BY 時間 DESC LIMIT 1'
  345. }
  346. var sql_data = {
  347. "sql":sql
  348. };
  349. console.log("sql_data: ", sql_data)
  350. $.get('/sql_get', sql_data, function (res) {
  351. // console.log("res: " + res)
  352. // console.log("res.labels:" + res.labels)
  353. // console.log("res.labels[0]:" + res.labels[0])
  354. // console.log("res.labels[0][0]:" + res.labels[0][0])
  355. // console.log("res.sql_field:" + res.sql_field)
  356. // console.log("res.sql_field[0]:" + res.sql_field[0])
  357. var data = " ";
  358. if (res.labels == '') {
  359. data += '-- 無符合關鍵字之資料 --'
  360. } else {
  361. data += '<table class="table table-bordered" style="margin-top: 10px;">';
  362. data += '<tr>';
  363. for (let fields = 0; fields < res.sql_field.length; fields++) {
  364. data += '<th>' + res.sql_field[fields][0] + '</th>';
  365. }
  366. data += '</tr>';
  367. for (let items = 0; items < res.labels.length; items++) {
  368. data += '<tr>';
  369. for (let item = 0; item < res.labels[items].length; item++) {
  370. // console.log("res.labels[items][item]: ", res.labels[items][item], typeof(res.labels[items][item]))
  371. data += '<td>' + res.labels[items][item] + '</td>';
  372. };
  373. data += '</tr>';
  374. };
  375. data += '</table>';
  376. }
  377. var sectorSelect = document.getElementById("result");
  378. sectorSelect.innerHTML = data;
  379. }, 'json');
  380. }
  381. // 修改確認
  382. function ComfirmUpdate_component(company_id) {
  383. console.log("修改完成: " + company_id)
  384. // var new_name = document.getElementById(company_id + '_5_ta');
  385. // var new_name_value = new_name.val();
  386. var new_name_value = $('#' + company_id + '_5_ta').val();
  387. console.log("new_name_value: " + new_name_value)
  388. // 零件表名稱修改
  389. sql = "";
  390. sql += "UPDATE 零件表 SET 名稱 = '" + new_name_value.replaceAll("'", "''") + "' WHERE 內部料號 = '" + company_id + "';"
  391. console.log('sql: ' + sql)
  392. var sql_data = { "sql":sql };
  393. $.get('/sql_get', sql_data, function (res) {
  394. // console.log(res)
  395. search_component_table();
  396. }, 'json');
  397. }
  398. // 修改
  399. function update_component(company_id) {
  400. console.log("修改 " + company_id)
  401. var target_id = document.getElementById(company_id + '_5');
  402. var old_name = target_id.innerText.replaceAll('"', '&quot;').replaceAll("'", "&apos;");
  403. console.log('old_name: ', old_name)
  404. target_id.innerHTML = "";
  405. textarea = '';
  406. textarea += '<input type="text" id="'+ company_id + '_5_ta' + '" value=\"' + old_name + '\" style="height: 25px; width:auto">';
  407. textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_component(\'' + company_id + '\')">';
  408. target_id.insertAdjacentHTML('beforeend', textarea);
  409. }
  410. // 刪除
  411. function delete_component(company_id) {
  412. var delete_data = confirm("確定要刪除內部料號 " + company_id + " 的資料嗎?\n(會同步刪除規格表對應資料)")
  413. if (delete_data) {
  414. // 刪除零件表
  415. // var sql = 'DELETE FROM 零件表 WHERE 內部料號 = "' + company_id + '";'
  416. // var sql_data = { "sql":sql };
  417. // $.ajax({
  418. // type:"GET",
  419. // url:"/sql_get",
  420. // dataType:"JSON",
  421. // data:sql_data,
  422. // async:false,
  423. // success:function (res) {
  424. // search_component_table()
  425. // alert("零件表: 零件刪除成功!")
  426. // },
  427. // error: function (thrownError) {
  428. // if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  429. // alert("零件表: 無內部料號 " + company_id + " 之資料")
  430. // } else {
  431. // alert("零件表刪除錯誤: " + thrownError)
  432. // }
  433. // }
  434. // })
  435. // 刪除規格表
  436. // var sql = 'DELETE FROM 規格表 WHERE 內部料號 = "' + company_id + '";'
  437. // var sql_data = { "sql":sql };
  438. // $.ajax({
  439. // type:"GET",
  440. // url:"/sql_get",
  441. // dataType:"JSON",
  442. // data:sql_data,
  443. // async:false,
  444. // success:function (res) {
  445. // alert("規格表: 零件刪除成功!")
  446. // },
  447. // error: function (thrownError) {
  448. // if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  449. // alert("規格表: 無內部料號 " + company_id + " 之資料")
  450. // } else {
  451. // alert("規格表刪除錯誤: " + thrownError)
  452. // }
  453. // }
  454. // })
  455. // 刪除資料表
  456. var sql = 'DROP TABLE ' + company_id + ';';
  457. var sql_data = { "sql":sql };
  458. $.ajax({
  459. type:"GET",
  460. url:"/sql_get",
  461. dataType:"JSON",
  462. data:sql_data,
  463. async:false,
  464. success:function (res) {
  465. alert("BOM 表: " + company_id + " 刪除成功!")
  466. },
  467. error: function (thrownError) {
  468. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  469. alert("BOM 表: 無內部料號 " + company_id + " 之資料表")
  470. } else {
  471. alert("零件表 BOM 表刪除錯誤: " + thrownError)
  472. }
  473. }
  474. })
  475. $.ajax({
  476. type:"GET",
  477. url:"/delete_companyid_table_" + company_id,
  478. dataType:"JSON",
  479. data:"",
  480. async:false,
  481. success:function (res) {
  482. alert("BOM 表: " + res.exist_BOM + " \n之 " + company_id + " 刪除成功!")
  483. },
  484. error: function (thrownError) {
  485. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  486. alert("BOM 表內刪除零件 : 無內部料號 " + company_id + " 之項目")
  487. } else {
  488. alert("BOM 表內刪除零件錯誤: " + thrownError)
  489. }
  490. }
  491. })
  492. search_component_table();
  493. }
  494. }
  495. // 零件表查詢
  496. function search_component_table(){
  497. var accountingsubjects_select = $("#accountingsubjects").val();
  498. var category_select = $("#category").val();
  499. var serialnumber_select = $("#serialnumber").val();
  500. serialnumber_select = serialnumber_select.padStart(4, '0')
  501. var supplier_select = $("#supplier").val();
  502. var component_name_select = $("#component_name_select").val();
  503. var component_name_input = $("#component_name_input").val();
  504. var AND_list = [];
  505. console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
  506. // sql = 'SELECT * FROM 零件表';
  507. sql = 'SELECT 內部料號, 會計科目表.會計科目_名稱, 類別表.類別_名稱, 流水號, 供應商.公司, 名稱' +
  508. ' FROM (' +
  509. '(零件表 ' +
  510. 'INNER JOIN 供應商' +
  511. ' ON 供應商.供應商 = 零件表.供應商' +
  512. ')' +
  513. ' INNER JOIN 類別表' +
  514. ' ON 類別表.類別_編號 = 零件表.類別' +
  515. ') ' +
  516. 'INNER JOIN 會計科目表 ' +
  517. 'ON 會計科目表.會計科目_編號 = 零件表.會計科目' +
  518. '' ;
  519. // 篩選 會計科目/類別/供應商 關鍵字
  520. if (accountingsubjects_select != '00') {
  521. AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
  522. }
  523. if (category_select != '00') {
  524. AND_list.push('類別 = "' + category_select + '"')
  525. }
  526. if (serialnumber_select != '0000') {
  527. AND_list.push('流水號 = "' + serialnumber_select + '"')
  528. }
  529. if (supplier_select != '00') {
  530. AND_list.push('零件表.供應商 = "' + supplier_select + '"')
  531. }
  532. if (component_name_select != '00') {
  533. AND_list.push('名稱 = \'' + component_name_select + '\'')
  534. } else if (component_name_input != '') {
  535. AND_list.push('名稱 LIKE \'%' + component_name_input + '%\'')
  536. }
  537. console.log("AND_list: ", AND_list)
  538. if (AND_list != '') {
  539. sql += ' WHERE ' + AND_list.join(' AND ');
  540. }
  541. var sql_data = {
  542. "sql":sql
  543. };
  544. console.log("sql_data: ", sql_data)
  545. $.get('/sql_get', sql_data, function (res) {
  546. // console.log("res: " + res)
  547. // console.log("res.labels:" + res.labels)
  548. // console.log("res.labels[0]:" + res.labels[0])
  549. // console.log("res.labels[0][0]:" + res.labels[0][0])
  550. // console.log("res.sql_field:" + res.sql_field)
  551. // console.log("res.sql_field[0]:" + res.sql_field[0])
  552. var data = " ";
  553. if (res.labels == '') {
  554. data += '-- 零件表無符合關鍵字之資料 --'
  555. } else {
  556. data += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
  557. data += '<table class="table table-bordered" style="margin-top: 10px;">';
  558. data += '<tr>';
  559. // console.log("res.sql_field: " + res.sql_field)
  560. for (let fields = 0; fields < res.sql_field.length; fields++) {
  561. data += '<th>' + res.sql_field[fields][0] + '</th>';
  562. // console.log("res.sql_field[" + fields + "][0]: " + res.sql_field[fields][0])
  563. }
  564. data += '<th>修改</th>';
  565. data += '<th>刪除</th>';
  566. data += '</tr>';
  567. for (let items = 0; items < res.labels.length; items++) {
  568. data += '<tr>';
  569. for (let item = 0; item < res.labels[items].length; item++) {
  570. // data += '<td id="' + res.Component_id[items] + '_' + item + '">' + res.labels[items][item] + '</td>';
  571. data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
  572. };
  573. data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_component(\'' + res.labels[items][0] + '\')"></td>';
  574. data += '<td><input type="button" class="input-cond-delete" value="刪除" onclick="delete_component(\'' + res.labels[items][0] + '\')"></td>';
  575. data += '</tr>';
  576. };
  577. data += '</table>';
  578. }
  579. var sectorSelect = document.getElementById("result");
  580. sectorSelect.innerHTML = data;
  581. }, 'json');
  582. }
  583. </script>
  584. <!-- modal 圖片放大 -->
  585. <div class="modal fade" id="ImgZoomIn_Modal">
  586. <div class="modal-dialog modal-dialog-centered" style="width: 600px;">
  587. <div class="modal-content">
  588. <!-- 互動視窗 標題 -->
  589. <!-- <div class="modal-header">
  590. <h4 id="Modal_title_ImgZoomIn" class="modal-title">乾燥入料儲豆槽 DI1 狀態</h4>
  591. <button type="button" class="close" data-dismiss="modal">&times;</button>
  592. </div> -->
  593. <!-- 互動視窗 內容 -->
  594. <div class="modal-body" id="ImgZoomIn_Modal_body">
  595. <!-- 圖片 ImgZoomIn -->
  596. </div>
  597. </div>
  598. </div>
  599. </div>
  600. <div id="result">
  601. <!-- <table>
  602. </table> -->
  603. </div>
  604. </body>
  605. </html>