PR_user.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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>
  8. var PR_Form_number = '{{PR_Form_number}}';
  9. console.log("PR_Form_number: " + PR_Form_number);
  10. var USER_NAME = '{{user_name}}'
  11. console.log("user_name: " + USER_NAME);
  12. var USER_MANAGER = '{{user_manager}}'
  13. console.log("user_manager: " + USER_MANAGER);
  14. var FORM_STATUS = '{{form_status}}';
  15. var data_id = []; // 存放此資料表所有的內部料號
  16. // 取得現在時間 紀錄請購備註時使用
  17. var Today = new Date();
  18. // 顯示零件名稱標題用
  19. var tr_title_id_target = '00000000';
  20. window.onload = function(){
  21. if (FORM_STATUS != '請購申請中') {
  22. [].forEach.call(document.querySelectorAll('.status-visible'), function (el) {
  23. el.style.visibility = 'hidden';
  24. });
  25. [].forEach.call(document.querySelectorAll('.status-display'), function (el) {
  26. el.style.display = 'none';
  27. });
  28. [].forEach.call(document.querySelectorAll('.status-disabled'), function (el) {
  29. el.disabled = true;
  30. });
  31. }
  32. }
  33. </script>
  34. <style>
  35. .input-cond-delete {
  36. background: #E43030;
  37. border: 1px solid #CFCFCF;
  38. box-sizing: border-box;
  39. border-radius: 5px;
  40. margin-left: 5px;
  41. width: auto;
  42. height: 33px;
  43. font-size: 16px;
  44. text-align: center;
  45. line-height: 16px;
  46. color: #FFFFFF;
  47. }
  48. .input-cond-add {
  49. background: #008CBA;
  50. border: 1px solid #CFCFCF;
  51. box-sizing: border-box;
  52. border-radius: 5px;
  53. margin-left: 5px;
  54. width: auto;
  55. /* width: 65px; */
  56. height: 33px;
  57. font-size: 16px;
  58. text-align: center;
  59. line-height: 16px;
  60. color: #FFFFFF;
  61. }
  62. .input-cond-action {
  63. background: #FFBD00;
  64. /* #6BF178 #53DD6C #FFBD00*/
  65. border: 1px solid #CFCFCF;
  66. box-sizing: border-box;
  67. border-radius: 5px;
  68. margin-left: 5px;
  69. width: auto;
  70. height: 33px;
  71. font-size: 16px;
  72. text-align: center;
  73. line-height: 16px;
  74. color: #000000;
  75. font-weight: bold;
  76. }
  77. .table-tr-title {
  78. background-color:rgb(0, 131, 72);
  79. color: #FFFFFF;
  80. font-weight: bold;
  81. }
  82. .table-tr-data {
  83. background-color:rgb(236, 247, 242);
  84. }
  85. .table-tr-newdata {
  86. background-color:rgb(245, 245, 245);
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <div id="ERP_header">
  92. <!-- 匯入共同使用的 header.html 內容 -->
  93. {% include 'ERP_header.html' %}
  94. </div>
  95. <center><h6 style="margin: 20px;">新增請購單</h6></center>
  96. 目前使用者:{{user_name}}<br>
  97. 請購單號:<span>{{PR_Form_number}}</span><br>
  98. 表單狀態:{{form_status}}<br>
  99. 用途:<input type="text" id="{{PR_Form_number}}_purpose" value="{{form_purpose}}" style="height: 25px; width: 50%;">
  100. <input type="button" id="{{PR_Form_number}}_savepurpose" value="儲存用途" onclick="update_purpose('{{PR_Form_number}}')">
  101. <br>
  102. <table class="table table-bordered" style="margin-top: 10px;">
  103. {% for datas in PR_data %}
  104. <thead>
  105. <tr class="table-tr-title" id="{{datas[0]}}_tr_title"></tr>
  106. <script type="text/javascript">
  107. var tr_title_id_now = '{{datas[0]}}'.substring(0, 8)
  108. if (tr_title_id_now != tr_title_id_target) {
  109. tr_title_id_target = tr_title_id_now
  110. var target_tr = document.getElementById('{{datas[0]}}_tr_title');
  111. var target_td = '<td colspan="11">' + '{{datas[1]}}' + '</td>'
  112. target_tr.insertAdjacentHTML('beforeend', target_td);
  113. }
  114. </script>
  115. </thead>
  116. <tbody>
  117. <!-- 請購單標題 -->
  118. <tr class="table-tr-data">
  119. <th>內部料號</th>
  120. <th>名稱</th>
  121. <th>原廠料號</th>
  122. <th>數量</th>
  123. <th>單位</th>
  124. <th>圖片</th>
  125. <th>供應商</th>
  126. <th>連結</th>
  127. <th>請購人</th>
  128. <!-- <th>核可</th>
  129. <th>請購備註</th> -->
  130. <th>
  131. <p class="status-visible">改/刪</p>
  132. </th>
  133. </tr>
  134. <!-- 請購單內容:現有資料 -->
  135. <!-- <div id="result"> -->
  136. <script>
  137. // 取得所有內部料號
  138. data_id.push('{{datas[0]}}')
  139. </script>
  140. <tr class="table-tr-data">
  141. <td id="{{datas[0]}}_id">{{datas[0]}}</td>
  142. <td id="{{datas[0]}}_name">{{datas[1]}}</td>
  143. <td id="{{datas[0]}}_type">{{datas[2]}}</td>
  144. <td id="{{datas[0]}}_amount">{{datas[3]}}</td>
  145. <td id="{{datas[0]}}_unit">{{datas[4]}}</td>
  146. <td id="{{datas[0]}}_picture">{{datas[5]}}</td>
  147. <td id="{{datas[0]}}_supplier">{{datas[6]}}</td>
  148. <td id="{{datas[0]}}_hyperlink">{{datas[7]}}</td>
  149. <td id="{{datas[0]}}_PRperson">{{datas[8]}}</td>
  150. <!-- <td>核可</td> -->
  151. <!-- <td>請購備註</td> -->
  152. <td>
  153. <input type="button" class="input-cond-add status-visible" value="修改" onclick="update_PR_item('{{datas[0]}}')"><br>
  154. <input type="button" class="input-cond-delete status-visible" value="刪除" onclick="delete_PR_item('{{datas[0]}}')">
  155. </td>
  156. </tr>
  157. <tr>
  158. <th colspan="1">
  159. 請購核可 :
  160. {% if datas[9] == 1 %}
  161. <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')" checked>
  162. {% else %}
  163. <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')">
  164. {% endif %}
  165. <br>
  166. {% if form_status == "請購詢價完成" %}
  167. 採購核可 :
  168. {% if datas[11] == 1 %}
  169. <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" checked>
  170. {% else %}
  171. <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" >
  172. {% endif %}
  173. {% endif %}
  174. </th>
  175. <td colspan="9">
  176. <span style="font-weight: bold;">請購備註 : </span>
  177. <input type="text" id="{{datas[0]}}_new_PRremark" style="height: 25px; width: 50%;">
  178. <input type="button" id="PR_new_PRremark" value="新增備註" style="height: auto;" onclick="insert_new_PRremark('{{datas[0]}}')">
  179. <br>
  180. <span id="{{datas[0]}}_PRremark">{{datas[10]|safe}}</span>
  181. <!-- <hr>
  182. <span id="{{datas[0]}}_PRremark_t">Rita (2022/02/11 11:50:49) 說:111<br>Rita (2022/02/11 11:52:35) 說:222</span> -->
  183. </td>
  184. </tr>
  185. </tbody>
  186. {% endfor %}
  187. <!-- </div> -->
  188. <!-- 請購單內容:新增資料 -->
  189. {% if PR_Form_number[-2:] == 'xx' %}
  190. <thead class="status-display">
  191. <tr class="table-tr-title">
  192. <td colspan="11">新增零件</td>
  193. </tr>
  194. </thead>
  195. <tbody class="status-display">
  196. <tr class="table-tr-newdata">
  197. <th>內部料號</th>
  198. <th>名稱</th>
  199. <th>原廠料號</th>
  200. <th>數量</th>
  201. <th>單位</th>
  202. <th>圖片</th>
  203. <th>供應商</th>
  204. <th>連結</th>
  205. <th>請購人</th>
  206. <!-- <th>核可</th>
  207. <th>請購備註</th> -->
  208. <th>新增</th>
  209. </tr>
  210. <tr class="table-tr-newdata">
  211. <td>
  212. <!-- 內部料號 -->
  213. <input list="insert_PR_id_item" id="PR_id" style="height: 25px;" onChange="get_id_standard(this.id)">
  214. <datalist id="insert_PR_id_item">
  215. {% for data in Component_id_name_salesnum %}
  216. {% if data[2] == '' or data[2] == None %}
  217. <option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>
  218. {% else %}
  219. <option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>
  220. {% endif %}
  221. {% endfor %}
  222. </datalist>
  223. </td>
  224. <td>
  225. <!-- 名稱 -->
  226. <span id="new_PR_name">——</span>
  227. </td>
  228. <td>
  229. <!-- 原廠料號 -->
  230. <span id="new_PR_type">——</span>
  231. </td>
  232. <td>
  233. <!-- 數量 -->
  234. <input id="PR_amount" value="" style="height: 25px; width: 50px">
  235. </td>
  236. <td>
  237. <!-- 單位 -->
  238. <span id="new_PR_unit">——</span>
  239. </td>
  240. <td>
  241. <!-- 照片 -->
  242. <span id="new_PR_picture">——</span>
  243. </td>
  244. <td>
  245. <!-- 供應商 -->
  246. <span id="new_PR_supplier">——</span>
  247. </td>
  248. <td>
  249. <!-- 超連結 -->
  250. <input id="PR_hyperlink" value="" style="height: 25px; width: 100px">
  251. </td>
  252. <td>
  253. <!-- 請購人 -->
  254. {{user_name}}
  255. <!-- <input type="text" id="PR_PRperson" value="" style="height: 25px; width: 90px;"> -->
  256. </td>
  257. <!-- <td>
  258. 核可
  259. <input type="checkbox" id="PR_PRcheck" value="" checked>
  260. </td>
  261. <td>
  262. 請購人備註
  263. <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 90px;">
  264. </td> -->
  265. <td rowspan="2" style="vertical-align: middle;">
  266. <!-- OK, 新增下一筆 -->
  267. <input type="button" class="input-cond-add" value="新增" onclick="insert_PR_item()">
  268. </td>
  269. </tr>
  270. <tr class="table-tr-newdata">
  271. <th colspan="1">
  272. 核可 :
  273. <input type="checkbox" id="PR_PRcheck" value="" checked disabled>
  274. </th>
  275. <th colspan="9">
  276. 請購備註 :
  277. <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 50%;">
  278. </td>
  279. </tr>
  280. </tbody>
  281. {% endif %}
  282. <tr>
  283. <td colspan="9"></td>
  284. <td>
  285. <input type="button" class="input-cond-action status-visible" value="送出→" onclick="PRuser_to_manager()">
  286. </td>
  287. </tr>
  288. <script>
  289. // 新增零件時, 選擇內部料號後, 出現規格表相關內容
  290. function get_id_standard(id) {
  291. var new_PR_id = document.getElementById(id).value;
  292. // alert("get_id_standard Test: " + new_PR_id)
  293. sql = 'SELECT 零件表.名稱, `原廠料號`, `單位`, `圖片`, 零件表.供應商' +
  294. ' FROM 零件表' +
  295. ' INNER JOIN 規格表' +
  296. ' ON 零件表.內部料號 = 規格表.內部料號' +
  297. ' WHERE 零件表.內部料號 = "' + new_PR_id + '"';
  298. var sql_data = { "sql":sql };
  299. $.ajax({
  300. type:"GET",
  301. url:"/sql_get",
  302. dataType:"JSON",
  303. data:sql_data,
  304. async:false,
  305. success:function (res) {
  306. if (res.labels == '') {
  307. alert(new_PR_id + " 無此零件")
  308. document.getElementById('PR_id').value = '';
  309. document.getElementById('new_PR_name').innerText = '';
  310. document.getElementById('new_PR_type').innerText = '';
  311. document.getElementById('new_PR_unit').innerText = '';
  312. document.getElementById('new_PR_picture').innerText = '';
  313. document.getElementById('new_PR_supplier').innerText = '';
  314. } else {
  315. // 名稱
  316. document.getElementById('new_PR_name').innerText = res.labels[0][0];
  317. // 原廠料號
  318. document.getElementById('new_PR_type').innerText = res.labels[0][1];
  319. // 單位
  320. document.getElementById('new_PR_unit').innerText = res.labels[0][2];
  321. // 圖片
  322. document.getElementById('new_PR_picture').innerText = res.labels[0][3];
  323. // 供應商
  324. document.getElementById('new_PR_supplier').innerText = res.labels[0][4];
  325. }
  326. },
  327. error: function (thrownError) {
  328. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  329. alert("新增零件取值 : " + new_PR_id + " 未成功")
  330. } else {
  331. alert("新增零件取值 thrownError" + thrownError)
  332. }
  333. }
  334. })
  335. }
  336. // 把日期數字變成兩位數
  337. function two(params) {
  338. var date_num = parseInt(params)
  339. if ( date_num < 10) {
  340. new_date_num = '0' + String(date_num)
  341. } else {
  342. new_date_num = String(date_num)
  343. }
  344. return new_date_num
  345. }
  346. //
  347. function insert_new_PRremark(id){
  348. // 取得原本的請購備註內容
  349. var old_remark = document.getElementById(id + '_PRremark');
  350. var old_remark_data = old_remark.innerHTML;
  351. console.log("old_remark_data: " + old_remark_data)
  352. // 取得新增的請購備註內容
  353. var new_remark = document.getElementById(id + '_new_PRremark').value;
  354. console.log("new_remark: " + new_remark)
  355. // 組合文字 Rita (2022/02/10 17:55:00) 說:急, 缺, 一定要買!
  356. var new_remark_data = USER_NAME +
  357. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  358. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  359. new_remark;
  360. console.log("new_remark_data: " + new_remark_data)
  361. sql = 'UPDATE ' + PR_Form_number +
  362. ' SET `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  363. ' WHERE `內部料號`="' + id + '";';
  364. console.log("[insert_new_PRremark]sql: " + sql)
  365. var sql_data = { "sql":sql };
  366. $.ajax({
  367. type:"GET",
  368. url:"/sql_get",
  369. dataType:"JSON",
  370. data:sql_data,
  371. async:false,
  372. success:function (res) {
  373. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  374. location.reload()
  375. },
  376. error: function (thrownError) {
  377. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  378. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  379. } else {
  380. alert("修改請購單請購備註內容 thrownError" + thrownError)
  381. }
  382. }
  383. })
  384. }
  385. //
  386. function update_PR_item(id) {
  387. console.log("修改: " + id)
  388. var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson', 'check', 'PRremark']
  389. for (let i = 1; i < PR_title_list.length; i++) {
  390. if (i == 3 || i == 7) {
  391. var target_id = document.getElementById(id + '_' + PR_title_list[i]);
  392. var old_name = target_id.innerText;
  393. console.log('old_name: ', old_name)
  394. target_id.innerHTML = "";
  395. if (PR_title_list[i] == 'hyperlink') {
  396. textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 100px">';
  397. } else {
  398. textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 50px">';
  399. }
  400. if (PR_title_list[i] == 'hyperlink') {
  401. textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
  402. }
  403. target_id.insertAdjacentHTML('beforeend', textarea);
  404. }
  405. }
  406. }
  407. // 修改請購單內項目 確認
  408. function update_comfirm_PR_item(id) {
  409. console.log("修改: " + id)
  410. var new_amount_value = $('#' + id + '_amount_ta').val();
  411. var new_hyperlink_value = $('#' + id + '_hyperlink_ta').val();
  412. sql = 'UPDATE ' + PR_Form_number + ' SET' +
  413. ' `數量`="' + new_amount_value + '"' +
  414. ', `連結`="' + new_hyperlink_value + '"' +
  415. ' WHERE `內部料號`="' + id + '";';
  416. console.log('sql: ' + sql)
  417. var sql_data = { "sql":sql };
  418. $.ajax({
  419. type:"GET",
  420. url:"/sql_get",
  421. dataType:"JSON",
  422. data:sql_data,
  423. async:false,
  424. success:function (res) {
  425. alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
  426. location.reload()
  427. },
  428. error: function (thrownError) {
  429. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  430. alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
  431. } else {
  432. alert("修改請購單項目內容 thrownError" + thrownError)
  433. }
  434. }
  435. })
  436. }
  437. // 刪除請購單內項目
  438. function delete_PR_item(id) {
  439. console.log("刪除: " + id)
  440. var comfirm_delete_PR_item = confirm("確定要刪除 " + id + " 零件嗎?")
  441. if (comfirm_delete_PR_item) {
  442. sql = 'DELETE FROM ' + PR_Form_number + ' WHERE 內部料號 = "' + id + '";'
  443. sql_data = { "sql":sql };
  444. console.log("delete_PR_item[sql]:" + sql)
  445. $.ajax({
  446. type:"GET",
  447. url:"/sql_get",
  448. dataType:"JSON",
  449. data:sql_data,
  450. async:false,
  451. success:function (res) {
  452. alert("請購單 " + PR_Form_number + " : " + id + " 刪除成功 !")
  453. location.reload()
  454. },
  455. error: function (thrownError) {
  456. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  457. alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未刪除")
  458. } else {
  459. alert("刪除請購單內容 thrownError" + thrownError)
  460. }
  461. }
  462. })
  463. }
  464. }
  465. </script>
  466. </table>
  467. <!-- {% if PR_Form_number[-2:] == 'xx' %}
  468. <input type="button" class="input-cond-add" value="送出" style="width: auto;" onclick="PR_to_Purchase()">
  469. <input type="button" class="input-cond-add" value="採購人員修改採購公司" style="width: auto;" onclick="Purchase_update_sup()">
  470. {% elif PR_Form_number[-2:] == '01' or PR_Form_number[-2:] == '02' %}
  471. <input type="button" class="input-cond-add" value="製作請購單 PDF" style="width: auto;" onclick="">
  472. <input type="button" class="input-cond-add" value="建立詢購單" style="width: auto;" onclick="">
  473. {% endif %} -->
  474. <script>
  475. // 儲存 用途
  476. function update_purpose(companyid) {
  477. var PR_purpose = $("#" + companyid + "_purpose").val()
  478. console.log("PR_purpose: " + PR_purpose)
  479. sql = "UPDATE `表單詳細資料` SET `用途` = '" + PR_purpose + "' " +
  480. "WHERE `表單詳細資料`.`請購草稿單號` = '" + companyid + "';";
  481. var sql_data = { "sql":sql };
  482. console.log("sql")
  483. $.ajax({
  484. type:"GET",
  485. url:"/sql_get",
  486. dataType:"JSON",
  487. data:sql_data,
  488. async:false,
  489. success:function (res) {
  490. alert("請購單 " + PR_Form_number + " 請購用途修改成功 !")
  491. location.reload()
  492. },
  493. error: function (thrownError) {
  494. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  495. alert("請購單 " + PR_Form_number + " 請購用途未修改")
  496. } else {
  497. alert("修改請購用途 thrownError" + thrownError)
  498. }
  499. }
  500. })
  501. }
  502. function checkbox_check(id) {
  503. var checkbox_id = $('#' + id + '_PRcheck').prop("checked");
  504. // console.log("checkbox_id: " + checkbox_id)
  505. if (checkbox_id == true) {
  506. // 主管勾選核可 從空白到勾選
  507. var checkbox_confirm_true = prompt("[勾選 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
  508. console.log("checkbox_confirm_true: " + checkbox_confirm_true)
  509. if (checkbox_confirm_true == '') {
  510. $('#' + id + '_PRcheck').prop('checked', false);
  511. alert("未輸入內容, 核可狀態未修改")
  512. } else if (checkbox_confirm_true == null) {
  513. $('#' + id + '_PRcheck').prop('checked', false);
  514. alert("取消, 核可狀態未修改")
  515. } else {
  516. var old_remark = document.getElementById(id + '_PRremark');
  517. var old_remark_data = old_remark.innerHTML;
  518. var new_remark_data = USER_NAME +
  519. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  520. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  521. "[核可勾選] " + checkbox_confirm_true;
  522. sql = 'UPDATE ' + PR_Form_number +
  523. ' SET `請購核可`="1"' +
  524. ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  525. ' WHERE `內部料號`="' + id + '";';
  526. var sql_data = { "sql":sql };
  527. console.log("sql")
  528. $.ajax({
  529. type:"GET",
  530. url:"/sql_get",
  531. dataType:"JSON",
  532. data:sql_data,
  533. async:false,
  534. success:function (res) {
  535. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  536. location.reload()
  537. },
  538. error: function (thrownError) {
  539. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  540. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  541. } else {
  542. alert("修改請購單請購備註內容 thrownError" + thrownError)
  543. }
  544. }
  545. })
  546. }
  547. } else {
  548. // 主管不核可 從勾選到空白
  549. var checkbox_confirm_false = prompt("[取消 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
  550. console.log("checkbox_confirm_false: " + checkbox_confirm_false)
  551. if (checkbox_confirm_false == '') {
  552. $('#' + id + '_PRcheck').prop('checked', true);
  553. alert("未輸入內容, 核可狀態未修改")
  554. } else if (checkbox_confirm_false == null) {
  555. $('#' + id + '_PRcheck').prop('checked', true);
  556. alert("取消, 核可狀態未修改")
  557. } else {
  558. var old_remark = document.getElementById(id + '_PRremark');
  559. var old_remark_data = old_remark.innerHTML;
  560. var new_remark_data = USER_NAME +
  561. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  562. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  563. "[核可取消] " + checkbox_confirm_false;
  564. sql = 'UPDATE ' + PR_Form_number +
  565. ' SET `請購核可`="0"' +
  566. ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  567. ' WHERE `內部料號`="' + id + '";';
  568. var sql_data = { "sql":sql };
  569. console.log("sql")
  570. $.ajax({
  571. type:"GET",
  572. url:"/sql_get",
  573. dataType:"JSON",
  574. data:sql_data,
  575. async:false,
  576. success:function (res) {
  577. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  578. location.reload()
  579. },
  580. error: function (thrownError) {
  581. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  582. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  583. } else {
  584. alert("修改請購單請購備註內容 thrownError" + thrownError)
  585. }
  586. }
  587. })
  588. }
  589. }
  590. }
  591. // 請購人員 送出請購單 給請購主管
  592. function PRuser_to_manager() {
  593. for (let i = 0; i < data_id.length; i++) {
  594. var checkbox_is_check = $('#' + data_id[i] + '_PRcheck').prop("checked")
  595. console.log("checkbox_is_check: " + checkbox_is_check)
  596. if (!checkbox_is_check) {
  597. var confirm_check = confirm('內部料號 ' + data_id[i] + ' 未核可, 確定要繼續嗎 ?')
  598. if (!confirm_check) {
  599. return false;
  600. }
  601. }
  602. }
  603. var confirm_to_manager = confirm('本表單即將送出給直屬主管, 請點選[確定]送出表單')
  604. if (confirm_to_manager) {
  605. // 狀態更新為 請購核可中
  606. sql = "UPDATE `表單詳細資料` SET `表單狀態` = '請購核可中' " +
  607. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  608. sql_data = { "sql":sql };
  609. console.log("PRuser_to_manager[sql]:" + sql)
  610. $.ajax({
  611. type:"GET",
  612. url:"/sql_get",
  613. dataType:"JSON",
  614. data:sql_data,
  615. async:false,
  616. success:function (res) {
  617. alert("調整狀態為\"請購核可中\"")
  618. },
  619. error: function (thrownError) {
  620. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  621. alert("送出調整狀態 未成功")
  622. } else {
  623. alert("送出調整狀態 thrownError" + thrownError)
  624. }
  625. }
  626. })
  627. // 通知請購主管
  628. sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
  629. USER_MANAGER + "','" +
  630. PR_Form_number + "','" +
  631. USER_NAME + " 已送出')";
  632. sql_data = { "sql":sql };
  633. console.log("PRuser_to_manager[sql]:" + sql)
  634. $.ajax({
  635. type:"GET",
  636. url:"/sql_get",
  637. dataType:"JSON",
  638. data:sql_data,
  639. async:false,
  640. success:function (res) {
  641. alert("已通知部門主管")
  642. window.location.assign("/PR_list")
  643. },
  644. error: function (thrownError) {
  645. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  646. alert("送出通知 未成功")
  647. } else {
  648. alert("送出通知 thrownError" + thrownError)
  649. }
  650. }
  651. })
  652. } else {
  653. alert("送出取消")
  654. }
  655. }
  656. // 採購人員 修改採購公司
  657. function Purchase_update_sup() {
  658. var purchase_company = prompt("請注意 ! 輸入採購公司後將無法修改 ! \n\n請輸入採購公司 :\nT01 : 金子進\nT02 : 瑞智")
  659. console.log("purchase_company: " + purchase_company)
  660. var new_PR_companyid = PR_Form_number.substring(0, 8) + purchase_company;
  661. console.log("new_PR_companyid: " + new_PR_companyid)
  662. sql = "RENAME TABLE `" + PR_Form_number + "` TO `" + new_PR_companyid + "`";
  663. sql_data = { "sql":sql };
  664. console.log("Purchase_update_sup[sql]:" + sql)
  665. $.ajax({
  666. type:"GET",
  667. url:"/sql_get",
  668. dataType:"JSON",
  669. data:sql_data,
  670. async:false,
  671. success:function (res) {
  672. alert("已將請購單更名為 " + new_PR_companyid + "")
  673. window.location.assign("/PR_user_" + new_PR_companyid)
  674. },
  675. error: function (thrownError) {
  676. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  677. alert("請購單 " + PR_Form_number + ": 已存在")
  678. } else {
  679. alert("請購單更名錯誤 thrownError" + thrownError)
  680. }
  681. }
  682. })
  683. }
  684. function insert_PR_item() {
  685. // var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson', 'check', 'PRremark']
  686. var PR_id = $("#PR_id").val()
  687. var PR_amount = $("#PR_amount").val()
  688. var PR_unit = $("#PR_unit").val()
  689. var PR_supplier = $("#PR_supplier").val()
  690. var PR_hyperlink = $("#PR_hyperlink").val()
  691. var PR_PRremark = $("#PR_PRremark").val()
  692. var PR_PRperson = $("#PR_PRperson").val()
  693. var PR_PRremark_data = USER_NAME +
  694. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  695. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  696. "[新增零件] " + PR_PRremark + "<br>";
  697. console.log("PR_id: " + PR_id)
  698. console.log("PR_amount: " + PR_amount)
  699. console.log("PR_unit: " + PR_unit)
  700. console.log("PR_supplier: " + PR_supplier)
  701. console.log("PR_hyperlink: " + PR_hyperlink)
  702. console.log("PR_PRremark_data: " + PR_PRremark_data)
  703. console.log("PR_PRperson: " + PR_PRperson)
  704. if (PR_id == "") {
  705. alert("新增時, 內部料號不可空白 !")
  706. } else {
  707. var sql = 'INSERT INTO `' + PR_Form_number +
  708. '` (內部料號, 日期, 數量, 連結, 請購人, 請購核可, 請購備註)' +
  709. ' VALUES ("' +
  710. PR_id +
  711. '", current_timestamp(), "' +
  712. PR_amount + '", "' +
  713. PR_hyperlink + '", "' +
  714. USER_NAME + '", "' +
  715. '1' + '", "' +
  716. PR_PRremark_data +
  717. '");';
  718. var sql_data = { "sql":sql };
  719. console.log("insert_PR_item[sql]:" + sql)
  720. $.ajax({
  721. type:"GET",
  722. url:"/sql_get",
  723. dataType:"JSON",
  724. data:sql_data,
  725. async:false,
  726. success:function (res) {
  727. console.log("res.sql_data: " + res.sql_data)
  728. if (res.sql_data != '') {
  729. alert(res.sql_data)
  730. } else {
  731. alert("請購單 " + PR_Form_number + " : " + PR_id + " 新增成功 !")
  732. location.reload()
  733. }
  734. },
  735. error: function (thrownError) {
  736. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  737. alert("請購單 " + PR_Form_number + " : " + PR_id + " 未新增")
  738. } else {
  739. alert("新增請購單內容 thrownError" + thrownError)
  740. }
  741. }
  742. })
  743. }
  744. }
  745. </script>
  746. </body>
  747. </html>