PR_manager.html 41 KB

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