RFQ_manager.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  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 RFQ_Form_number = '0712' + PR_Form_number.substring(4, 8);
  11. console.log("RFQ_Form_number: " + RFQ_Form_number);
  12. var USER_NAME = '{{user_name}}';
  13. console.log("user_name: " + USER_NAME);
  14. var FORM_RFQ_USER = '{{form_RFQ_user}}'
  15. console.log("FORM_RFQ_USER: " + FORM_RFQ_USER);
  16. var FORM_PR_USER = '{{form_PR_user}}'
  17. console.log("FORM_PR_USER: " + FORM_PR_USER);
  18. var FORM_PR_MANAGER = '{{form_PR_manager}}'
  19. console.log("FORM_PR_MANAGER: " + FORM_PR_MANAGER);
  20. var FORM_STATUS = '{{form_status}}';
  21. var data_id = []; // 存放此資料表所有的內部料號
  22. // 取得現在時間 紀錄請購備註時使用
  23. var Today = new Date();
  24. // 顯示零件名稱標題用
  25. var tr_title_id_target = '00000000';
  26. // 採購員工列表
  27. var RFQ_person_staff = [];
  28. // 取得網址資訊
  29. var HOST = window.location.host;
  30. window.onload = function(){
  31. create_PR_list();
  32. create_PO_list();
  33. }
  34. function create_PR_list() {
  35. let PRcompany_T01_haveitem = false;
  36. let PRcompany_T02_haveitem = false;
  37. for (let i = 0; i < data_id.length; i++) {
  38. var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
  39. // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
  40. if (PRcompany_exist == 'T01') {
  41. PRcompany_T01_haveitem = true;
  42. } else if (PRcompany_exist == 'T02') {
  43. PRcompany_T02_haveitem = true;
  44. }
  45. }
  46. var PR_form_list = '';
  47. if (PRcompany_T01_haveitem) {
  48. PR_form_list += '<br>金子進 : <a href="/PR_form_' + PR_Form_number + '_T01" target="_blank">預覽請購單 ' + PR_Form_number.substring(0, 8) + 'T01</a>' +
  49. '—' +
  50. '<a href="/DL/' + HOST + '/PR/' + PR_Form_number + '_T01" target="_blank">下載</a>'
  51. }
  52. if (PRcompany_T02_haveitem) {
  53. PR_form_list += '<br>瑞智 : <a href="/PR_form_' + PR_Form_number + '_T02" target="_blank">預覽請購單 ' + PR_Form_number.substring(0, 8) + 'T02</a>' +
  54. '—' +
  55. '<a href="/DL/' + HOST + '/PR/' + PR_Form_number + '_T02" target="_blank">下載</a>'
  56. }
  57. PR_sup_list.insertAdjacentHTML('beforeend', PR_form_list);
  58. }
  59. function create_PO_list() {
  60. let PRcompany_T01_itemlist = [];
  61. let PRcompany_T02_itemlist = [];
  62. for (let i = 0; i < data_id.length; i++) {
  63. var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
  64. var supplier_text = $('#' + data_id[i] + '_supplier').text();
  65. if (PRcompany_exist == 'T01' && !PRcompany_T01_itemlist.includes(supplier_text)) {
  66. PRcompany_T01_itemlist.push(supplier_text);
  67. } else if (PRcompany_exist == 'T02' && !PRcompany_T02_itemlist.includes(supplier_text)) {
  68. PRcompany_T02_itemlist.push(supplier_text);
  69. }
  70. }
  71. console.log("PRcompany_T01_itemlist: " + PRcompany_T01_itemlist)
  72. console.log("PRcompany_T02_itemlist: " + PRcompany_T02_itemlist)
  73. var PO_form_list = '';
  74. if (PRcompany_T01_itemlist.length != 0) {
  75. PO_form_list += '<br>金子進 : <br>';
  76. for (let x = 0; x < PRcompany_T01_itemlist.length; x++) {
  77. PO_form_list += '<a href="#" target="_blank">預覽採購單 0713' + PR_Form_number.substring(4, 8) + PRcompany_T01_itemlist[x] + '</a>' +
  78. '—' +
  79. '<a href="#" target="_blank">下載</a><br>'
  80. }
  81. }
  82. if (PRcompany_T02_itemlist.length != 0) {
  83. PO_form_list += '瑞智 : <br>';
  84. for (let x = 0; x < PRcompany_T02_itemlist.length; x++) {
  85. PO_form_list += '<a href="#" target="_blank">預覽採購單 0713' + PR_Form_number.substring(4, 8) + PRcompany_T02_itemlist[x] + '</a>' +
  86. '—' +
  87. '<a href="#" target="_blank">下載</a><br>'
  88. }
  89. }
  90. PO_sup_list.insertAdjacentHTML('beforeend', PO_form_list);
  91. }
  92. </script>
  93. <style>
  94. .input-cond-delete {
  95. background: #E43030;
  96. border: 1px solid #CFCFCF;
  97. box-sizing: border-box;
  98. border-radius: 5px;
  99. margin-left: 5px;
  100. width: auto;
  101. height: 33px;
  102. font-size: 16px;
  103. text-align: center;
  104. line-height: 16px;
  105. color: #FFFFFF;
  106. }
  107. .input-cond-add {
  108. background: #008CBA;
  109. border: 1px solid #CFCFCF;
  110. box-sizing: border-box;
  111. border-radius: 5px;
  112. margin-left: 5px;
  113. width: auto;
  114. /* width: 65px; */
  115. height: 33px;
  116. font-size: 16px;
  117. text-align: center;
  118. line-height: 16px;
  119. color: #FFFFFF;
  120. }
  121. .input-cond-action {
  122. background: #FFBD00;
  123. /* #6BF178 #53DD6C #FFBD00*/
  124. border: 1px solid #CFCFCF;
  125. box-sizing: border-box;
  126. border-radius: 5px;
  127. margin-left: 5px;
  128. width: auto;
  129. height: 33px;
  130. font-size: 16px;
  131. text-align: center;
  132. line-height: 16px;
  133. color: #000000;
  134. font-weight: bold;
  135. }
  136. .table-tr-title {
  137. background-color:rgb(0, 131, 72);
  138. color: #FFFFFF;
  139. font-weight: bold;
  140. }
  141. .table-tr-data {
  142. background-color:rgb(236, 247, 242);
  143. }
  144. .table-tr-newdata {
  145. background-color:rgb(245, 245, 245);
  146. }
  147. </style>
  148. </head>
  149. <body>
  150. <div id="ERP_header">
  151. <!-- 匯入共同使用的 header.html 內容 -->
  152. {% include 'ERP_header.html' %}
  153. </div>
  154. {% for staff in staff_data %}
  155. <script>
  156. RFQ_person_staff.push('{{staff[0]}}' + '-' + '{{staff[1]}}')
  157. console.log("RFQ_person_staff: " + RFQ_person_staff)
  158. </script>
  159. {% endfor %}
  160. <center><h6 style="margin: 20px;">新增請購單</h6></center>
  161. 目前使用者:{{user_name}}<br>
  162. 請購單號:<span>{{PR_Form_number}}</span><br>
  163. 表單狀態:{{form_status}}<br>
  164. 用途:{{form_purpose}}<br>
  165. <table class="table table-bordered" style="margin-top: 10px;">
  166. {% for datas in PR_data %}
  167. <thead>
  168. <tr class="table-tr-title" id="{{datas[0]}}_tr_title"></tr>
  169. <script type="text/javascript">
  170. var tr_title_id_now = '{{datas[0]}}'.substring(0, 8)
  171. if (tr_title_id_now != tr_title_id_target) {
  172. tr_title_id_target = tr_title_id_now
  173. var target_tr = document.getElementById('{{datas[0]}}_tr_title');
  174. var target_td = '<td colspan="11">' + '{{datas[1]}}' + '</td>'
  175. target_tr.insertAdjacentHTML('beforeend', target_td);
  176. }
  177. </script>
  178. </thead>
  179. <tbody>
  180. <!-- 請購單標題 -->
  181. <tr class="table-tr-data">
  182. <th rowspan="4" style="text-align: center;">
  183. 採購<br>主管<br>核可<br>
  184. <br>
  185. {% if datas[17] == 1 %}
  186. <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" checked>
  187. {% else %}
  188. <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')">
  189. {% endif %}
  190. </th>
  191. <th>內部料號</th>
  192. <th>名稱</th>
  193. <th>原廠料號</th>
  194. <th>數量</th>
  195. <th>單位</th>
  196. <th>圖片</th>
  197. <th>供應商</th>
  198. <th>連結</th>
  199. <th>請購人</th>
  200. <th>
  201. {% if form_status == "採購公司設定" %}
  202. 修改
  203. {% endif %}
  204. </th>
  205. </tr>
  206. <script>
  207. // 取得所有內部料號
  208. data_id.push('{{datas[0]}}');
  209. </script>
  210. <tr class="table-tr-data">
  211. <td id="{{datas[0]}}_id">{{datas[0]}}</td>
  212. <td id="{{datas[0]}}_name">{{datas[1]}}</td>
  213. <td id="{{datas[0]}}_type">{{datas[2]}}</td>
  214. <td id="{{datas[0]}}_amount">{{datas[3]}}</td>
  215. <td id="{{datas[0]}}_unit">{{datas[4]}}</td>
  216. <td id="{{datas[0]}}_picture">{{datas[5]}}</td>
  217. <td id="{{datas[0]}}_supplier">{{datas[6]}}</td>
  218. <td id="{{datas[0]}}_hyperlink">{{datas[7]}}</td>
  219. <td id="{{datas[0]}}_PRperson">{{datas[8]}}</td>
  220. <td rowspan="3" style="vertical-align: middle;">
  221. {% if form_status == "採購公司設定" %}
  222. <input type="button" class="input-cond-add" value="修改" onclick="update_PR_item('{{datas[0]}}')">
  223. {% endif %}
  224. </td>
  225. <!-- {% if datas[10] == 1 %}
  226. <td id="{{datas[0]}}_PRmanagercheck">OK</td>
  227. {% else %}
  228. <td id="{{datas[0]}}_PRmanagercheck"></td>
  229. {% endif %} -->
  230. </tr>
  231. <tr class="table-tr-data">
  232. <th>幣別</th>
  233. <th>單價</th>
  234. <th>營業稅</th>
  235. <th>總金額</th>
  236. <th>交期</th>
  237. <th>詢價備註</th>
  238. <th>詢價單</th>
  239. <th>供應商報價單</th>
  240. <th>採購公司</th>
  241. </tr>
  242. <tr class="table-tr-data">
  243. <td id="{{datas[0]}}_currency">{{datas[9]}}</td>
  244. <td id="{{datas[0]}}_unitprice">{{datas[10]}}</td>
  245. <td id="{{datas[0]}}_salestax">{{datas[11]}}</td>
  246. <td id="{{datas[0]}}_totalprice">{{datas[12]}}</td>
  247. <td id="{{datas[0]}}_leadtime">{{datas[13]}}</td>
  248. <td id="{{datas[0]}}_RFQremark">{{datas[14]}}</td>
  249. <td id="{{datas[0]}}_RFQformid">{{datas[15]}}</td>
  250. <td id="{{datas[0]}}_RFQsupplierquote">{{datas[16]}}</td>
  251. <td id="{{datas[0]}}_PRcompany">{{datas[18]}}</td>
  252. </tr>
  253. <tr>
  254. <td colspan="11">
  255. <span style="font-weight: bold;">請購備註 : </span>
  256. <input type="text" id="{{datas[0]}}_new_PRremark" style="height: 25px; width: 50%;">
  257. <input type="button" id="PR_new_PRremark" value="新增備註" style="height: auto;" onclick="insert_new_PRremark('{{datas[0]}}')">
  258. <br>
  259. <span id="{{datas[0]}}_PRremark">{{datas[19]|safe}}</span>
  260. </td>
  261. </tr>
  262. </tbody>
  263. {% endfor %}
  264. <tr>
  265. <td>
  266. {% if form_status == "比價中" %}
  267. <input type="button" class="input-cond-action" value="←駁回" onclick="RFQ_to_user()">
  268. {% endif %}
  269. </td>
  270. <td colspan="4">
  271. {% if form_status == "詢價中" or form_status == "比價中" or form_status == "請購詢價完成" %}
  272. <!-- <input type="button" class="input-cond-action" value="產生請購單" onclick="select_PR_sup_form()" style="width: auto;"> -->
  273. <!-- (點擊後即下載 PDF 至「本機/下載」中, 亦可點擊以下連結顯示網頁版請購單) -->
  274. <span id="PR_sup_list">請購單列表 : </span>
  275. {% endif %}
  276. </td>
  277. <td colspan="4">
  278. {% if form_status == "請購詢價完成" %}
  279. <span id="PO_sup_list">採購單列表 : </span>
  280. {% endif %}
  281. </td>
  282. <td colspan="2" align="right">
  283. {% if form_status == "採購公司設定" %}
  284. <select id="RFQ_RFQuser">
  285. <option value=""></option>
  286. {% for staff in staff_data %}
  287. <option value="{{staff[0]}}">{{staff[0]}} - {{staff[1]}}</option>
  288. {% endfor %}
  289. </select>
  290. <input type="button" class="input-cond-action" value="指派採購人員→" onclick="PR_set_RFQuser()">
  291. {% elif form_status == "比價中" %}
  292. <input type="button" class="input-cond-action" value="決行→" onclick="PR_to_Purchase()">
  293. {% elif form_status == "請購詢價完成" %}
  294. <input type="button" class="input-cond-action" value="前往採購頁面" onclick="createPOpage()">
  295. {% endif %}
  296. </td>
  297. </tr>
  298. </table>
  299. <script>
  300. var sql = '';
  301. function createPOpage() {
  302. alert("建立採購單 TABLE")
  303. }
  304. // 採購主管 指派 採購人員
  305. function PR_set_RFQuser() {
  306. // 1. 確認每個零件都有採購公司
  307. for (let i = 0; i < data_id.length; i++) {
  308. var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
  309. // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
  310. if (PRcompany_exist != 'T01' && PRcompany_exist != 'T02') {
  311. alert(data_id[i] + " 請輸入採購公司")
  312. return false
  313. }
  314. }
  315. // 2. 取得採購人員員工編號
  316. var RFQ_user = $('#RFQ_RFQuser').val();
  317. if (RFQ_user == '') {
  318. alert("請選擇採購人員")
  319. return false
  320. }
  321. // 3. 儲存採購人員
  322. sql = "UPDATE `表單詳細資料` SET `採購人員工編號` = '" + RFQ_user + "' " +
  323. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  324. var sql_data = { "sql":sql };
  325. console.log("sql: " + sql)
  326. $.ajax({
  327. type:"GET",
  328. url:"/sql_get",
  329. dataType:"JSON",
  330. data:sql_data,
  331. async:false,
  332. success:function (res) {
  333. alert("儲存採購人員")
  334. },
  335. error: function (thrownError) {
  336. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  337. alert("儲存採購人員 未成功")
  338. } else {
  339. alert("儲存採購人員 thrownError" + thrownError.statusText)
  340. }
  341. }
  342. })
  343. // 4. 儲存狀態:詢價中
  344. sql = "UPDATE `表單詳細資料` SET `表單狀態` = '詢價中' " +
  345. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  346. sql_data = { "sql":sql };
  347. console.log("PR_set_RFQuser[sql]:" + sql)
  348. $.ajax({
  349. type:"GET",
  350. url:"/sql_get",
  351. dataType:"JSON",
  352. data:sql_data,
  353. async:false,
  354. success:function (res) {
  355. alert("調整狀態為\"詢價中\"")
  356. },
  357. error: function (thrownError) {
  358. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  359. alert("送出調整狀態 未成功")
  360. } else {
  361. alert("送出調整狀態 thrownError" + thrownError)
  362. }
  363. }
  364. })
  365. // 5. 通知採購人員
  366. sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
  367. RFQ_user + "','" +
  368. PR_Form_number + "','" +
  369. USER_NAME + " 已指定採購公司')";
  370. sql_data = { "sql":sql };
  371. console.log("PR_set_RFQuser[sql]:" + sql)
  372. $.ajax({
  373. type:"GET",
  374. url:"/sql_get",
  375. dataType:"JSON",
  376. data:sql_data,
  377. async:false,
  378. success:function (res) {
  379. alert("已通知採購人員")
  380. window.location.assign("/PR_list")
  381. },
  382. error: function (thrownError) {
  383. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  384. alert("送出通知 未成功")
  385. } else {
  386. alert("送出通知 thrownError" + thrownError)
  387. }
  388. }
  389. })
  390. }
  391. // 產生請購單
  392. function select_PR_sup_form() {
  393. let PRcompany_T01_haveitem = false;
  394. let PRcompany_T02_haveitem = false;
  395. for (let i = 0; i < data_id.length; i++) {
  396. var checkbox_is_check = $('#' + data_id[i] + '_RFQmanagercheck').prop("checked")
  397. console.log(data_id[i] + " checkbox_is_check: " + checkbox_is_check)
  398. var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
  399. console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
  400. // 採購主管核可打勾 + 採購公司 != T01 + 採購公司 != T02, 判定為未填寫採購公司
  401. if (checkbox_is_check == true) {
  402. if (PRcompany_exist == 'T01') {
  403. PRcompany_T01_haveitem = true;
  404. } else if (PRcompany_exist == 'T02') {
  405. PRcompany_T02_haveitem = true;
  406. } else {
  407. alert(data_id[i] + " 已核可, 請輸入採購公司")
  408. return false
  409. }
  410. }
  411. console.log(data_id[i] + " OK")
  412. }
  413. if (PRcompany_T01_haveitem) {
  414. $.ajax({
  415. type:"GET",
  416. url:"/PDF_create/PR/" + PR_Form_number + "_T01",
  417. dataType:"JSON",
  418. data:"",
  419. async:false,
  420. success:function (response) {
  421. document.location.href = '/download/' + PR_Form_number.substring(0, 8) + 'T01.pdf'
  422. },
  423. error: function (thrownError) {
  424. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  425. alert("請購單 T01 建立 " + PR_Form_number.substring(0, 8) + "T01 未成功")
  426. } else {
  427. alert("請購單 T01 建立 thrownError" + thrownError)
  428. }
  429. }
  430. })
  431. }
  432. if (PRcompany_T02_haveitem) {
  433. $.ajax({
  434. type:"GET",
  435. url:"/PDF_create/PR/" + PR_Form_number + "_T02",
  436. dataType:"JSON",
  437. data:"",
  438. async:false,
  439. success:function (response) {
  440. document.location.href = '/download/' + PR_Form_number.substring(0, 8) + 'T02.pdf'
  441. },
  442. error: function (thrownError) {
  443. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  444. alert("請購單 T02 建立 " + PR_Form_number.substring(0, 8) + "T02 未成功")
  445. } else {
  446. alert("請購單 T02 建立 thrownError" + thrownError)
  447. }
  448. }
  449. })
  450. }
  451. }
  452. // 採購主管駁回
  453. function RFQ_to_user() {
  454. var confirm_RFQ_to_user = confirm("確定將此請購單駁回給採購人員 ?\n溫馨提醒 : 可填寫請購備註告知駁回原因")
  455. if (confirm_RFQ_to_user) {
  456. // 狀態更新為 詢價中
  457. sql = "UPDATE `表單詳細資料` SET `表單狀態` = '詢價中' " +
  458. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  459. sql_data = { "sql":sql };
  460. console.log("RFQ_to_user[sql]:" + sql)
  461. $.ajax({
  462. type:"GET",
  463. url:"/sql_get",
  464. dataType:"JSON",
  465. data:sql_data,
  466. async:false,
  467. success:function (res) {
  468. alert("調整狀態為\"詢價中\"")
  469. },
  470. error: function (thrownError) {
  471. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  472. alert("送出調整狀態 未成功")
  473. } else {
  474. alert("送出調整狀態 thrownError" + thrownError)
  475. }
  476. }
  477. })
  478. // 通知請購人員
  479. sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
  480. FORM_RFQ_USER + "','" +
  481. PR_Form_number + "','" +
  482. USER_NAME + " 已駁回')";
  483. sql_data = { "sql":sql };
  484. console.log("RFQ_to_user[sql]:" + sql)
  485. $.ajax({
  486. type:"GET",
  487. url:"/sql_get",
  488. dataType:"JSON",
  489. data:sql_data,
  490. async:false,
  491. success:function (res) {
  492. alert("已通知採購人員")
  493. window.location.assign("/PR_list")
  494. },
  495. error: function (thrownError) {
  496. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  497. alert("送出通知 未成功")
  498. } else {
  499. alert("送出通知 thrownError" + thrownError)
  500. }
  501. }
  502. })
  503. } else {
  504. alert("取消駁回")
  505. }
  506. }
  507. // 主管核可 勾選 / 取消時都要提醒
  508. function checkbox_check(id) {
  509. var checkbox_id = $('#' + id + '_RFQmanagercheck').prop("checked");
  510. // console.log("checkbox_id: " + checkbox_id)
  511. if (checkbox_id == true) {
  512. // 主管勾選核可 從空白到勾選
  513. var checkbox_confirm_true = prompt("[勾選 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
  514. console.log("checkbox_confirm_true: " + checkbox_confirm_true)
  515. if (checkbox_confirm_true == '') {
  516. $('#' + id + '_RFQmanagercheck').prop('checked', false);
  517. alert("未輸入內容, 核可狀態未修改")
  518. } else if (checkbox_confirm_true == null) {
  519. $('#' + id + '_RFQmanagercheck').prop('checked', false);
  520. alert("取消, 核可狀態未修改")
  521. } else {
  522. var old_remark = document.getElementById(id + '_PRremark');
  523. var old_remark_data = old_remark.innerHTML;
  524. var new_remark_data = USER_NAME +
  525. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  526. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  527. "[核可勾選] " +
  528. checkbox_confirm_true;
  529. sql = 'UPDATE ' + PR_Form_number +
  530. ' SET `採購主管核可`="1"' +
  531. ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  532. ' WHERE `內部料號`="' + id + '";';
  533. var sql_data = { "sql":sql };
  534. console.log("sql")
  535. $.ajax({
  536. type:"GET",
  537. url:"/sql_get",
  538. dataType:"JSON",
  539. data:sql_data,
  540. async:false,
  541. success:function (res) {
  542. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  543. location.reload()
  544. },
  545. error: function (thrownError) {
  546. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  547. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  548. } else {
  549. alert("修改請購單請購備註內容 thrownError" + thrownError)
  550. }
  551. }
  552. })
  553. }
  554. } else {
  555. // 主管不核可 從勾選到空白
  556. var checkbox_confirm_false = prompt("[取消 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
  557. console.log("checkbox_confirm_false: " + checkbox_confirm_false)
  558. if (checkbox_confirm_false == '') {
  559. $('#' + id + '_RFQmanagercheck').prop('checked', true);
  560. alert("未輸入內容, 核可狀態未修改")
  561. } else if (checkbox_confirm_false == null) {
  562. $('#' + id + '_RFQmanagercheck').prop('checked', true);
  563. alert("取消, 核可狀態未修改")
  564. } else {
  565. var old_remark = document.getElementById(id + '_PRremark');
  566. var old_remark_data = old_remark.innerHTML;
  567. var new_remark_data = USER_NAME +
  568. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  569. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  570. "[核可取消] " +
  571. checkbox_confirm_false;
  572. sql = 'UPDATE ' + PR_Form_number +
  573. ' SET `採購主管核可`="0"' +
  574. ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  575. ' WHERE `內部料號`="' + id + '";';
  576. var sql_data = { "sql":sql };
  577. console.log("sql")
  578. $.ajax({
  579. type:"GET",
  580. url:"/sql_get",
  581. dataType:"JSON",
  582. data:sql_data,
  583. async:false,
  584. success:function (res) {
  585. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  586. location.reload()
  587. },
  588. error: function (thrownError) {
  589. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  590. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  591. } else {
  592. alert("修改請購單請購備註內容 thrownError" + thrownError)
  593. }
  594. }
  595. })
  596. }
  597. }
  598. }
  599. //
  600. function update_PR_item(id) {
  601. console.log("修改: " + id)
  602. var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson',
  603. 'PRmanagercheck', 'currency', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
  604. for (let i = 1; i < PR_title_list.length; i++) {
  605. if (PR_title_list[i] == 'PRcompany') {
  606. var target_id = document.getElementById(id + '_' + PR_title_list[i]);
  607. var old_name = target_id.innerText;
  608. console.log('old_name: ', old_name)
  609. target_id.innerHTML = "";
  610. if (PR_title_list[i] == 'PRcompany') {
  611. textarea = '<select id="'+ id + '_' + PR_title_list[i] + '_ta' + '">'
  612. textarea += '<option value="T01">T01-金子進</option>';
  613. textarea += '<option value="T02">T02-瑞智</option>';
  614. textarea += '</select>'
  615. textarea += '<br><input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
  616. }
  617. target_id.insertAdjacentHTML('beforeend', textarea);
  618. }
  619. if (PR_title_list[i] == 'PRcompany') {
  620. $("#" + id + "_PRcompany_ta").val(old_name);
  621. }
  622. }
  623. }
  624. // 修改請購單內項目 確認
  625. function update_comfirm_PR_item(id) {
  626. console.log("修改: " + id)
  627. // 修改採購公司
  628. var new_PRcompany_value = $('#' + id + '_PRcompany_ta').val();
  629. // 修改請購備註
  630. // var old_remark = document.getElementById(id + '_PRremark');
  631. // var old_remark_data = old_remark.innerHTML;
  632. var old_remark_data = document.getElementById(id + '_PRremark').innerHTML;
  633. var new_remark_data = USER_NAME +
  634. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  635. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  636. "[修改採購公司為 " + new_PRcompany_value + " ] ";
  637. sql = 'UPDATE ' + PR_Form_number +
  638. ' SET `採購公司`="' + new_PRcompany_value + '"' +
  639. ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  640. ' WHERE `內部料號`="' + id + '";';
  641. console.log('sql: ' + sql)
  642. var sql_data = { "sql":sql };
  643. $.ajax({
  644. type:"GET",
  645. url:"/sql_get",
  646. dataType:"JSON",
  647. data:sql_data,
  648. async:false,
  649. success:function (res) {
  650. alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
  651. location.reload()
  652. },
  653. error: function (thrownError) {
  654. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  655. alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
  656. } else {
  657. alert("修改請購單項目內容 thrownError" + thrownError)
  658. }
  659. }
  660. })
  661. }
  662. // 刪除請購單內項目
  663. function delete_PR_item(id) {
  664. console.log("刪除: " + id)
  665. var comfirm_delete_PR_item = confirm("確定要刪除 " + id + " 零件嗎?")
  666. if (comfirm_delete_PR_item) {
  667. sql = 'DELETE FROM ' + PR_Form_number + ' WHERE 內部料號 = "' + id + '";'
  668. sql_data = { "sql":sql };
  669. console.log("delete_PR_item[sql]:" + sql)
  670. $.ajax({
  671. type:"GET",
  672. url:"/sql_get",
  673. dataType:"JSON",
  674. data:sql_data,
  675. async:false,
  676. success:function (res) {
  677. alert("請購單 " + PR_Form_number + " : " + id + " 刪除成功 !")
  678. location.reload()
  679. },
  680. error: function (thrownError) {
  681. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  682. alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未刪除")
  683. } else {
  684. alert("刪除請購單內容 thrownError" + thrownError)
  685. }
  686. }
  687. })
  688. }
  689. }
  690. // 把日期數字變成兩位數
  691. function two(params) {
  692. var date_num = parseInt(params)
  693. if ( date_num < 10) {
  694. new_date_num = '0' + String(date_num)
  695. } else {
  696. new_date_num = String(date_num)
  697. }
  698. return new_date_num
  699. }
  700. // 新增請購備註
  701. function insert_new_PRremark(id){
  702. // 取得原本的請購備註內容
  703. var old_remark = document.getElementById(id + '_PRremark');
  704. var old_remark_data = old_remark.innerHTML;
  705. console.log("old_remark_data: " + old_remark_data)
  706. // 取得新增的請購備註內容
  707. var new_remark = document.getElementById(id + '_new_PRremark').value;
  708. console.log("new_remark: " + new_remark)
  709. // 組合文字 Rita (2022/02/10 17:55:00) 說:急, 缺, 一定要買!
  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. new_remark;
  714. console.log("new_remark_data: " + new_remark_data)
  715. sql = 'UPDATE ' + PR_Form_number +
  716. ' SET `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  717. ' WHERE `內部料號`="' + id + '";';
  718. console.log("[insert_new_PRremark]sql: " + sql)
  719. var sql_data = { "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. 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. function PR_to_Purchase() {
  741. var checkbox_check_id = [];
  742. for (let i = 0; i < data_id.length; i++) {
  743. var checkbox_is_check = $('#' + data_id[i] + '_RFQmanagercheck').prop("checked")
  744. console.log("checkbox_is_check: " + checkbox_is_check)
  745. if (checkbox_is_check == true) {
  746. checkbox_check_id.push(data_id[i])
  747. }
  748. }
  749. if (checkbox_check_id == '') {
  750. alert("未有零件選取, 取消決行")
  751. return false
  752. } else {
  753. alert("選取 " + checkbox_check_id.length + " 項零件, 進入採購流程")
  754. }
  755. // 狀態更新為 請購詢價完成
  756. sql = "UPDATE `表單詳細資料` SET `表單狀態` = '請購詢價完成' " +
  757. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  758. sql_data = { "sql":sql };
  759. console.log("PR_to_Purchase[sql]:" + sql)
  760. $.ajax({
  761. type:"GET",
  762. url:"/sql_get",
  763. dataType:"JSON",
  764. data:sql_data,
  765. async:false,
  766. success:function (res) {
  767. alert("調整狀態為\"請購詢價完成\"")
  768. },
  769. error: function (thrownError) {
  770. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  771. alert("送出調整狀態 未成功")
  772. } else {
  773. alert("送出調整狀態 thrownError" + thrownError)
  774. }
  775. }
  776. })
  777. // 通知請購主管
  778. sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES " +
  779. "('" + FORM_PR_USER + "','" + PR_Form_number + "','" + USER_NAME + " 已決行')," +
  780. "('" + FORM_PR_MANAGER + "','" + PR_Form_number + "','" + USER_NAME + " 已決行')";
  781. sql_data = { "sql":sql };
  782. console.log("PRuser_to_manager[sql]:" + sql)
  783. $.ajax({
  784. type:"GET",
  785. url:"/sql_get",
  786. dataType:"JSON",
  787. data:sql_data,
  788. async:false,
  789. success:function (res) {
  790. alert("已通知請購主管、請購人")
  791. window.location.assign("/PR_list")
  792. },
  793. error: function (thrownError) {
  794. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  795. alert("送出通知 未成功")
  796. } else {
  797. alert("送出通知 thrownError" + thrownError)
  798. }
  799. }
  800. })
  801. }
  802. // 採購人員 修改採購公司
  803. function Purchase_update_sup() {
  804. var purchase_company = prompt("請注意 ! 輸入採購公司後將無法修改 ! \n\n請輸入採購公司 :\nT01 : 金子進\nT02 : 瑞智")
  805. console.log("purchase_company: " + purchase_company)
  806. var new_PR_companyid = PR_Form_number.substring(0, 8) + purchase_company;
  807. console.log("new_PR_companyid: " + new_PR_companyid)
  808. sql = "RENAME TABLE `" + PR_Form_number + "` TO `" + new_PR_companyid + "`";
  809. sql_data = { "sql":sql };
  810. console.log("Purchase_update_sup[sql]:" + sql)
  811. $.ajax({
  812. type:"GET",
  813. url:"/sql_get",
  814. dataType:"JSON",
  815. data:sql_data,
  816. async:false,
  817. success:function (res) {
  818. alert("已將請購單更名為 " + new_PR_companyid + "")
  819. window.location.assign("/PR_user_" + new_PR_companyid)
  820. },
  821. error: function (thrownError) {
  822. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  823. alert("請購單 " + PR_Form_number + ": 已存在")
  824. } else {
  825. alert("請購單更名錯誤 thrownError" + thrownError)
  826. }
  827. }
  828. })
  829. }
  830. function insert_PR_item() {
  831. // var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRremark', 'PRperson',
  832. // 'PRmanagercheck', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
  833. var PR_id = $("#PR_id").val()
  834. var PR_amount = $("#PR_amount").val()
  835. var PR_unit = $("#PR_unit").val()
  836. var PR_supplier = $("#PR_supplier").val()
  837. var PR_hyperlink = $("#PR_hyperlink").val()
  838. var PR_PRremark = $("#PR_PRremark").val()
  839. var PR_PRperson = $("#PR_PRperson").val()
  840. var RFQ_PRcompany = $("#RFQ_PRcompany").val()
  841. var RFQ_unitprice = $("#RFQ_unitprice").val()
  842. var RFQ_salestax = $("#RFQ_salestax").val()
  843. var RFQ_totalprice = $("#RFQ_totalprice").val()
  844. var RFQ_leadtime = $("#RFQ_leadtime").val()
  845. var RFQ_RFQremark = $("#RFQ_RFQremark").val()
  846. var RFQ_RFQsupplierquote = $("#RFQ_RFQsupplierquote").val()
  847. console.log("PR_id: " + PR_id)
  848. console.log("PR_amount: " + PR_amount)
  849. console.log("PR_unit: " + PR_unit)
  850. console.log("PR_supplier: " + PR_supplier)
  851. console.log("PR_hyperlink: " + PR_hyperlink)
  852. console.log("PR_PRremark: " + PR_PRremark)
  853. console.log("PR_PRperson: " + PR_PRperson)
  854. console.log("RFQ_PRcompany: " + RFQ_PRcompany)
  855. console.log("RFQ_unitprice: " + RFQ_unitprice)
  856. console.log("RFQ_salestax: " + RFQ_salestax)
  857. console.log("RFQ_totalprice: " + RFQ_totalprice)
  858. console.log("RFQ_leadtime: " + RFQ_leadtime)
  859. console.log("RFQ_RFQremark: " + RFQ_RFQremark)
  860. console.log("RFQ_RFQsupplierquote: " + RFQ_RFQsupplierquote)
  861. sql = 'INSERT INTO `' + PR_Form_number + '` ' +
  862. '(內部料號, 日期, 數量, 單位, 連結, 請購備註, 請購人, 採購公司, 單價, 營業稅, 總金額, 交期, 詢價備註, 供應商報價單號)' +
  863. ' VALUES ("' + PR_id +
  864. '", current_timestamp(), "' +
  865. PR_amount + '", "' +
  866. PR_unit + '", "' +
  867. PR_hyperlink + '", "' +
  868. PR_PRremark + '", "' +
  869. PR_PRperson + '", "' +
  870. RFQ_PRcompany + '", "' +
  871. RFQ_unitprice + '", "' +
  872. RFQ_salestax + '", "' +
  873. RFQ_totalprice + '", "' +
  874. RFQ_leadtime + '", "' +
  875. RFQ_RFQremark + '", "' +
  876. RFQ_RFQsupplierquote + '");';
  877. var sql_data = { "sql":sql };
  878. console.log("insert_PR_item[sql]:" + sql)
  879. $.ajax({
  880. type:"GET",
  881. url:"/sql_get",
  882. dataType:"JSON",
  883. data:sql_data,
  884. async:false,
  885. success:function (res) {
  886. console.log("res.sql_data: " + res.sql_data)
  887. if (res.sql_data != '') {
  888. alert(res.sql_data)
  889. } else {
  890. alert("請購單 " + PR_Form_number + " : " + PR_id + " 新增成功 !")
  891. location.reload()
  892. }
  893. },
  894. error: function (thrownError) {
  895. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  896. alert("請購單 " + PR_Form_number + " : " + PR_id + " 未新增")
  897. } else {
  898. alert("新增請購單內容 thrownError" + thrownError)
  899. }
  900. }
  901. })
  902. }
  903. </script>
  904. <!-- <a href="/PR_form_07110001Txx_T01" target="_blank">預覽請購單 07110001T01</a>
  905. <a href="/PDF_create/PR/07110001Txx_T01" target="_blank">產生</a>
  906. <a href="/download/07110001T01.pdf" target="_blank">下載PDF</a>
  907. <br> -->
  908. <!-- <a onclick="javascript:Foo('T01');" href="#">不影響 GIF 的連結</a> -->
  909. <!-- <a href="/DL/PR/07110001Txx_T01" target="_blank">TEST</a> -->
  910. <!-- function Foo(companyid) {
  911. document.location.href = '/PDF_create/PR/07110001Txx_T01';
  912. setTimeout("alert('OK')", 3000 )
  913. setTimeout("document.location.href = '/download/07110001T01.pdf';", 3000 )
  914. } -->
  915. </body>
  916. </html>