search_companyid.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. <input list="insert_BOM_module" id="company_id" style="height: 25px;" onChange="get_sqltables()">
  43. <datalist id="insert_BOM_module">
  44. <option value="">可輸入名稱查找內部料號</option>
  45. {% for data in Component_id_name_salesnum %}
  46. {% if data[2] == "" or data[2] == None %}
  47. <option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>
  48. {% else %}
  49. <option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>
  50. {% endif %}
  51. {% endfor %}
  52. </datalist>
  53. <hr>
  54. <!-- <span style="font-weight: bold;">erp 資料庫所有的資料表 :</span>
  55. <div id="result_all_tables"></div>
  56. <br> -->
  57. <span style="font-weight: bold;">所有包含 "某內部料號" 資料的資料表 :</span>
  58. <div id="result_id_tables"></div>
  59. <br>
  60. <span style="font-weight: bold;">名稱為 "某內部料號" 資料的資料表 :</span>
  61. <div id="result_id_BOM"></div>
  62. <br>
  63. <hr>
  64. 選擇新的供應商編號:
  65. <select id="BOM_supplier" onChange="">
  66. <option value="00"></option>
  67. {% for data in Supplier_data %}
  68. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  69. {% endfor %}
  70. </select>
  71. <input type="button" class="input-cond-add" value="OK" onclick="select_supplier()">
  72. <div id="replace_id">
  73. </div>
  74. <br>
  75. <hr>
  76. [請務必謹慎使用] 新的內部料號:
  77. <!-- 會計科目:
  78. <select id="accountingsubjects" onChange="">
  79. <option value="00"></option>
  80. {% for data in AccountingSubjects_data %}
  81. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  82. {% endfor %}
  83. </select>
  84. 類別:
  85. <select id="category" onChange="renewSN();">
  86. <option value="00"></option>
  87. {% for data in Category_data %}
  88. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  89. {% endfor %}
  90. </select>
  91. 流水號:
  92. <input id="serialnumber" style="height: 25px; width: 45px; color: crimson;" readonly>
  93. 供應商:
  94. <select id="supplier" onChange="">
  95. <option value="00"></option>
  96. {% for data in Supplier_data %}
  97. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  98. {% endfor %}
  99. </select> -->
  100. <input id="new_company_id" style="height: 25px;" onChange="">
  101. <input type="button" class="input-cond-add" style="width: 125px;" value="更新內部料號" onclick="update_company_id()"><br>
  102. <br>
  103. <br>
  104. <br>
  105. <hr>
  106. 批次更新內部料號
  107. <input type="button" class="input-cond-add" style="width: auto;" value="批次更新供應商" onclick="batch_tt()"><br>
  108. <script>
  109. var sql = ''; // sql 指令
  110. var data = ''; // 輸出
  111. var new_company_id_exist = true; // 新的內部料號是否已存在判斷。true 存在 false 不存在
  112. function batch_tt() {
  113. batch_select_supplier("01010001T23", "01010001T02");
  114. batch_select_supplier("04010004T23", "04010004T22");
  115. batch_select_supplier("04010128T23", "04010128T22");
  116. batch_select_supplier("04010153T48", "04010153TE2");
  117. batch_select_supplier("04010154T48", "04010154TE2");
  118. batch_select_supplier("04010157T48", "04010157TB1");
  119. batch_select_supplier("04010158T48", "04010158TF3");
  120. batch_select_supplier("04010159T48", "04010159TF3");
  121. batch_select_supplier("04010160T48", "04010160TE8");
  122. batch_select_supplier("04010161T48", "04010161TB1");
  123. batch_select_supplier("04010163T48", "04010163TE2");
  124. batch_select_supplier("04010164T48", "04010164TA6");
  125. batch_select_supplier("04010165T48", "04010165TF2");
  126. batch_select_supplier("04010171T48", "04010171T01");
  127. batch_select_supplier("04010172T48", "04010172T01");
  128. batch_select_supplier("04010173T48", "04010173T01");
  129. batch_select_supplier("04010174T48", "04010174TB1");
  130. batch_select_supplier("04010175T37", "04010175TB1");
  131. batch_select_supplier("04010176T37", "04010176TB1");
  132. batch_select_supplier("04010177T37", "04010177TB1");
  133. batch_select_supplier("04010178T37", "04010178TB1");
  134. batch_select_supplier("04010179T37", "04010179TB1");
  135. batch_select_supplier("04010180T37", "04010180TB1");
  136. batch_select_supplier("04010181T37", "04010181TB1");
  137. batch_select_supplier("04010182T37", "04010182TB1");
  138. batch_select_supplier("04010183T37", "04010183TB1");
  139. batch_select_supplier("04010184T37", "04010184TB1");
  140. batch_select_supplier("04010185T37", "04010185TB1");
  141. batch_select_supplier("04010186T37", "04010186TB1");
  142. batch_select_supplier("04010187T37", "04010187TB1");
  143. }
  144. function batch_select_supplier(old_id, new_id) {
  145. // var old_id = [];
  146. // var new_id = [];
  147. var comfirm_update_company_sup = confirm('將原內部料號 ' + old_id +
  148. ' \n取代成 ' + new_id + '\n請注意此動作不可復原!')
  149. if (comfirm_update_company_sup) {
  150. $.ajax({
  151. type:"GET",
  152. url:"/update_companyid_table_" + old_id + "_" + new_id,
  153. dataType:"JSON",
  154. data:'',
  155. async:false,
  156. success:function (res) {
  157. console.log(res.new_company_id)
  158. console.log(res.has_id_table_list)
  159. alert("更新內部料號供應商 " + old_id + " 之 Table: 成功")
  160. },
  161. error: function (thrownError) {
  162. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  163. alert("更新內部料號供應商 " + old_id + " 之 Table: 未成功")
  164. } else {
  165. console.log("更新內部料號供應商之 Table thrownError" + thrownError)
  166. }
  167. }
  168. })
  169. }
  170. }
  171. function update_company_id() {
  172. var search_company_id = $("#company_id").val();
  173. var new_company_id = $("#new_company_id").val();
  174. if (search_company_id == '' || new_company_id == '') {
  175. alert("請輸入欲取代內部料號和新內部料號")
  176. } else {
  177. sql = 'SELECT 內部料號 FROM 零件表 WHERE 內部料號 = "' + new_company_id + '"';
  178. var sql_data = { "sql":sql };
  179. console.log("sql_data: ", sql_data)
  180. $.ajax({
  181. type:"GET",
  182. url:"/sql_get",
  183. dataType:"JSON",
  184. data:sql_data,
  185. async:false,
  186. success:function (res) {
  187. new_company_id_exist = true;
  188. console.log("res.labels: " + res.labels)
  189. console.log("res.labels.length: " + res.labels.length)
  190. console.log(typeof(res.labels.length))
  191. // 判斷內部料號是否存在 (有無回傳值)
  192. if (res.labels.length == 0) {
  193. new_company_id_exist = false
  194. }
  195. },
  196. error: function (thrownError) {
  197. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  198. alert("更新內部料號 " + company_id + ": 未成功")
  199. } else {
  200. console.log("更新內部料號 thrownError" + thrownError)
  201. }
  202. }
  203. })
  204. if (new_company_id_exist == true) {
  205. alert(new_company_id + " 此內部料號已存在, 請重新輸入 !")
  206. } else {
  207. console.log("new_company_id_exist: " + new_company_id_exist)
  208. console.log("將 " + search_company_id + " 取代成 " + new_company_id)
  209. var confirm_update_company_id = confirm("[請謹慎使用]\n確定將內部料號 " + search_company_id + " 取代成 " + new_company_id + " ?")
  210. if (confirm_update_company_id) {
  211. $.ajax({
  212. type:"GET",
  213. url:"/update_companyid_table_" + search_company_id + "_" + new_company_id,
  214. dataType:"JSON",
  215. data:'',
  216. async:false,
  217. success:function (res) {
  218. alert("更新內部料號 " + search_company_id + " 之 Table: 成功")
  219. console.log(res.new_company_id)
  220. console.log(res.has_id_table_list)
  221. location.reload()
  222. },
  223. error: function (thrownError) {
  224. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  225. alert("更新內部料號 " + search_company_id + " 之 Table: 未成功")
  226. } else {
  227. console.log("更新內部料號之 Table thrownError" + thrownError)
  228. }
  229. }
  230. })
  231. }
  232. }
  233. }
  234. }
  235. function get_sqltables() {
  236. var search_company_id = $("#company_id").val();
  237. console.log("search_company_id: " + search_company_id)
  238. if (search_company_id != '') {
  239. data = '';
  240. $.ajax({
  241. type:"GET",
  242. url:"/search_companyid_table_" + search_company_id,
  243. dataType:"JSON",
  244. data:'',
  245. async:false,
  246. success:function (res) {
  247. // // erp 資料庫所有的資料表 :
  248. // var sectorSelect = document.getElementById("result_all_tables");
  249. // if (res.sql_data != '') {
  250. // sectorSelect.innerHTML = String(res.sql_data).replaceAll(",", "<br>");
  251. // } else {
  252. // sectorSelect.innerHTML = "erp 資料庫無資料表";
  253. // }
  254. // 所有包含 "某內部料號" 資料的資料表 :
  255. var sectorSelect = document.getElementById("result_id_tables");
  256. if (res.has_id_table_list != '') {
  257. sectorSelect.innerHTML = String(res.has_id_table_list).replaceAll(",", "<br>");
  258. } else {
  259. sectorSelect.innerHTML = "無 " + search_company_id + " 內容之資料表";
  260. }
  261. // 名稱為 "某內部料號" 資料的資料表 :
  262. var sectorSelect = document.getElementById("result_id_BOM");
  263. if (res.has_table_list != '') {
  264. sectorSelect.innerHTML = String(res.has_table_list).replaceAll(",", "<br>");
  265. } else {
  266. sectorSelect.innerHTML = "無 " + search_company_id + " 資料表";
  267. }
  268. var replace_data = '調整供應商為';
  269. },
  270. error: function (thrownError) {
  271. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  272. alert("查詢內部料號 " + search_company_id + " 之 Table: 未成功")
  273. } else {
  274. console.log("查詢內部料號之 Table thrownError" + thrownError)
  275. }
  276. }
  277. })
  278. }
  279. }
  280. function select_supplier() {
  281. var search_company_id = $("#company_id").val();
  282. var supplier_select = $("#BOM_supplier").val();
  283. var new_company_id = search_company_id.slice(0, 8) + supplier_select;
  284. var select_supplier_data = '將原內部料號 ' + search_company_id + ' 取代成 ' + new_company_id;
  285. var comfirm_update_company_sup = confirm('將原內部料號 ' + search_company_id + ' \n取代成 ' + new_company_id + '\n請注意此動作不可復原!')
  286. if (comfirm_update_company_sup) {
  287. console.log(search_company_id + ' → ' + new_company_id)
  288. $.ajax({
  289. type:"GET",
  290. url:"/update_companyid_table_" + search_company_id + "_" + new_company_id,
  291. dataType:"JSON",
  292. data:'',
  293. async:false,
  294. success:function (res) {
  295. console.log(res.new_company_id)
  296. console.log(res.has_id_table_list)
  297. alert("更新內部料號供應商 " + search_company_id + " 之 Table: 成功")
  298. },
  299. error: function (thrownError) {
  300. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  301. alert("更新內部料號供應商 " + search_company_id + " 之 Table: 未成功")
  302. } else {
  303. console.log("更新內部料號供應商之 Table thrownError" + thrownError)
  304. }
  305. }
  306. })
  307. }
  308. }
  309. function renewSN() {
  310. var accountingsubjects_select = $("#accountingsubjects").val();
  311. var category_select = $("#category").val();
  312. $.get('/sn_get/' + accountingsubjects_select + '/' + category_select, '', function (res) {
  313. // console.log(res.new_sn)
  314. $('#serialnumber').val(res.new_sn)
  315. }, 'json');
  316. }
  317. </script>
  318. </body>
  319. </html>