RFQ_user.html 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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 USER_MANAGER = '{{user_manager}}'
  15. console.log("user_manager: " + USER_MANAGER);
  16. var FORM_STATUS = '{{form_status}}';
  17. var data_id = []; // 存放此資料表所有的內部料號
  18. // 取得現在時間 紀錄請購備註時使用
  19. var Today = new Date();
  20. // 顯示零件名稱標題用
  21. var tr_title_id_target = '00000000';
  22. // 取得網址資訊
  23. var HOST = window.location.host;
  24. window.onload = function(){
  25. if (FORM_STATUS != '詢價中') {
  26. [].forEach.call(document.querySelectorAll('.status-visible'), function (el) {
  27. el.style.visibility = 'hidden';
  28. });
  29. [].forEach.call(document.querySelectorAll('.status-display'), function (el) {
  30. el.style.display = 'none';
  31. });
  32. [].forEach.call(document.querySelectorAll('.status-disabled'), function (el) {
  33. el.disabled = true;
  34. });
  35. }
  36. create_RFQ_list();
  37. }
  38. function create_RFQ_list() {
  39. sql = "SELECT DISTINCT `零件表`.`供應商`, `供應商`.`公司` " +
  40. "FROM ( `" + PR_Form_number + "` " +
  41. "INNER JOIN `零件表` ON `" + PR_Form_number + "`.`內部料號` = `零件表`.`內部料號` ) " +
  42. "INNER JOIN `供應商` ON `零件表`.`供應商` = `供應商`.`供應商` " +
  43. "ORDER BY `零件表`.`供應商`"
  44. var sql_data = { "sql":sql };
  45. console.log("sql: " + sql)
  46. $.ajax({
  47. type:"GET",
  48. url:"/sql_get",
  49. dataType:"JSON",
  50. data:sql_data,
  51. async:false,
  52. success:function (res) {
  53. console.log("res.labels: " + res.labels)
  54. console.log("res.labels[0]: " + res.labels[0])
  55. console.log("res.labels[0][0]: " + res.labels[0][0])
  56. var RFQ_sup = '';
  57. for (let sup = 0; sup < res.labels.length; sup++) {
  58. // RFQ_sup += '<br><a href="/RFQ_form_' + PR_Form_number + '_' + res.labels[sup][0] + '" target="_blank">' + res.labels[sup][0] + ' - ' + res.labels[sup][1] + '</a>';
  59. RFQ_sup += "<br>" +
  60. res.labels[sup][1] + " : " +
  61. "<a href='/RFQ_form_" + PR_Form_number + "_" + res.labels[sup][0] + "' target='_blank'>預覽詢價單 " + RFQ_Form_number + res.labels[sup][0] + "</a>" +
  62. "—" +
  63. "<a href='/DL/" + HOST + "/RFQ/" + PR_Form_number + "_" + res.labels[sup][0] + "' target='_blank'>下載</a>"
  64. }
  65. RFQ_sup_list.insertAdjacentHTML('beforeend', RFQ_sup);
  66. },
  67. error: function (thrownError) {
  68. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  69. alert("詢價單 供應商查詢 " + new_id + " 未成功")
  70. } else {
  71. alert("詢價單 供應商查詢 thrownError" + thrownError)
  72. }
  73. }
  74. })
  75. }
  76. </script>
  77. <style>
  78. .input-cond-delete {
  79. background: #E43030;
  80. border: 1px solid #CFCFCF;
  81. box-sizing: border-box;
  82. border-radius: 5px;
  83. margin-left: 5px;
  84. width: auto;
  85. height: 33px;
  86. font-size: 16px;
  87. text-align: center;
  88. line-height: 16px;
  89. color: #FFFFFF;
  90. }
  91. .input-cond-add {
  92. background: #008CBA;
  93. border: 1px solid #CFCFCF;
  94. box-sizing: border-box;
  95. border-radius: 5px;
  96. margin-left: 5px;
  97. width: auto;
  98. /* width: 65px; */
  99. height: 33px;
  100. font-size: 16px;
  101. text-align: center;
  102. line-height: 16px;
  103. color: #FFFFFF;
  104. }
  105. .input-cond-action {
  106. background: #FFBD00;
  107. /* #6BF178 #53DD6C #FFBD00*/
  108. border: 1px solid #CFCFCF;
  109. box-sizing: border-box;
  110. border-radius: 5px;
  111. margin-left: 5px;
  112. width: auto;
  113. height: 33px;
  114. font-size: 16px;
  115. text-align: center;
  116. line-height: 16px;
  117. color: #000000;
  118. font-weight: bold;
  119. }
  120. .table-tr-title {
  121. background-color:rgb(0, 131, 72);
  122. color: #FFFFFF;
  123. font-weight: bold;
  124. }
  125. .table-tr-data {
  126. background-color:rgb(236, 247, 242);
  127. }
  128. .table-tr-newdata {
  129. background-color:rgb(245, 245, 245);
  130. }
  131. </style>
  132. </head>
  133. <body>
  134. <div id="ERP_header">
  135. <!-- 匯入共同使用的 header.html 內容 -->
  136. {% include 'ERP_header.html' %}
  137. </div>
  138. <center><h6 style="margin: 20px;">新增請購單</h6></center>
  139. 目前使用者:{{user_name}}<br>
  140. 請購單號:<span>{{PR_Form_number}}</span><br>
  141. 表單狀態:{{form_status}}<br>
  142. 用途:{{form_purpose}}<br>
  143. <!-- {% for datas in RFQ_supplier_data %}
  144. 九威金屬設計公司—預覽詢價單 07120002T23—下載
  145. {% endfor %} -->
  146. <table class="table table-bordered" style="margin-top: 10px;">
  147. {% for datas in PR_data %}
  148. <thead>
  149. <tr class="table-tr-title" id="{{datas[0]}}_tr_title"></tr>
  150. <script type="text/javascript">
  151. var tr_title_id_now = '{{datas[0]}}'.substring(0, 8)
  152. if (tr_title_id_now != tr_title_id_target) {
  153. tr_title_id_target = tr_title_id_now
  154. var target_tr = document.getElementById('{{datas[0]}}_tr_title');
  155. var target_td = '<td colspan="11">' + '{{datas[1]}}' + '</td>'
  156. target_tr.insertAdjacentHTML('beforeend', target_td);
  157. }
  158. </script>
  159. </thead>
  160. <tbody>
  161. <!-- 請購單標題 -->
  162. <tr class="table-tr-data">
  163. <th rowspan="4" style="text-align: center;">
  164. 採購<br>主管<br>核可<br>
  165. <br>
  166. {% if datas[20] == 1 %}
  167. <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" checked disabled>
  168. {% else %}
  169. <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" disabled>
  170. {% endif %}
  171. </th>
  172. <th>內部料號</th>
  173. <th>名稱</th>
  174. <th>原廠料號</th>
  175. <th>數量</th>
  176. <th>單位</th>
  177. <th>圖片</th>
  178. <th>供應商</th>
  179. <th>連結</th>
  180. <th>請購人</th>
  181. <th>
  182. <p class="status-visible">改/刪</p>
  183. </th>
  184. </tr>
  185. <script>
  186. // 取得所有內部料號
  187. data_id.push('{{datas[0]}}')
  188. // console.log("data_id: " + data_id)
  189. </script>
  190. <tr class="table-tr-data">
  191. <td id="{{datas[0]}}_id">{{datas[0]}}</td>
  192. <td id="{{datas[0]}}_name">{{datas[1]}}</td>
  193. <td id="{{datas[0]}}_type">{{datas[2]}}</td>
  194. <td id="{{datas[0]}}_amount">{{datas[3]}}</td>
  195. <td id="{{datas[0]}}_unit">{{datas[4]}}</td>
  196. <td id="{{datas[0]}}_picture">{{datas[5]}}</td>
  197. <td id="{{datas[0]}}_supplier">{{datas[6]}}</td>
  198. <td id="{{datas[0]}}_hyperlink">{{datas[7]}}</td>
  199. <td id="{{datas[0]}}_PRperson">{{datas[9]}}</td>
  200. <!-- {% if datas[10] == 1 %}
  201. <td id="{{datas[0]}}_PRmanagercheck">OK</td>
  202. {% else %}
  203. <td id="{{datas[0]}}_PRmanagercheck"></td>
  204. {% endif %} -->
  205. <td rowspan="3" style="vertical-align: middle;">
  206. <input type="button" class="input-cond-add status-visible" value="修改" onclick="update_PR_item('{{datas[0]}}')">
  207. </td>
  208. </tr>
  209. <tr class="table-tr-data">
  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-data">
  222. <!-- <td id="{{datas[0]}}_PRcompany">{{datas[11]}}</td> -->
  223. <td id="{{datas[0]}}_currency">{{datas[12]}}</td>
  224. <td id="{{datas[0]}}_unitprice">{{datas[13]}}</td>
  225. <td id="{{datas[0]}}_salestax">{{datas[14]}}</td>
  226. <td id="{{datas[0]}}_totalprice">{{datas[15]}}</td>
  227. <td id="{{datas[0]}}_leadtime">{{datas[16]}}</td>
  228. <td id="{{datas[0]}}_RFQremark">{{datas[17]}}</td>
  229. <td id="{{datas[0]}}_RFQformid">{{datas[18]}}</td>
  230. <td id="{{datas[0]}}_RFQsupplierquote">{{datas[19]}}</td>
  231. <td></td>
  232. </tr>
  233. <tr>
  234. <td colspan="8">
  235. <span style="font-weight: bold;">請購備註 : </span>
  236. <input type="text" id="{{datas[0]}}_new_PRremark" style="height: 25px; width: 80%;">
  237. <input type="button" id="PR_new_PRremark" value="新增備註" style="height: auto;" onclick="insert_new_PRremark('{{datas[0]}}')">
  238. <br>
  239. <span id="{{datas[0]}}_PRremark">{{datas[8]|safe}}</span>
  240. </td>
  241. <td colspan="3" style="vertical-align: middle; text-align: right;">
  242. <select id="{{datas[0]}}_parity_supplier" class="status-visible" onChange="">
  243. <option value="00"></option>
  244. {% for data in Supplier_data %}
  245. <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
  246. {% endfor %}
  247. </select>
  248. <br>
  249. <input type="button" class="input-cond-add status-visible" value="新增比價項目" onclick="insert_PR_parity_item('{{datas[0]}}')">
  250. </td>
  251. </tr>
  252. </tbody>
  253. {% endfor %}
  254. {% if PR_Form_number[-2:] == 'xx' %}
  255. <thead class="status-display">
  256. <tr class="table-tr-title">
  257. <td colspan="11">新增零件</td>
  258. </tr>
  259. </thead>
  260. <tbody class="status-display">
  261. <tr class="table-tr-newdata">
  262. <th rowspan="5" style="text-align: center;">
  263. 採購<br>主管<br>核可<br>
  264. <br>
  265. <input type="checkbox" id="insert_RFQ_managercheck" onclick="" checked disabled>
  266. </th>
  267. <th>內部料號</th>
  268. <th>名稱</th>
  269. <th>原廠料號</th>
  270. <th>數量</th>
  271. <th>單位</th>
  272. <th>圖片</th>
  273. <th>供應商</th>
  274. <th>連結</th>
  275. <!-- <th>請購備註</th> -->
  276. <!-- <th>請購主管核可</th> -->
  277. <th>請購人</th>
  278. <th>新增</th>
  279. </tr>
  280. <tr class="table-tr-newdata">
  281. <td>
  282. <!-- 內部料號 -->
  283. <input list="insert_PR_id_item" id="PR_id" style="height: 25px;" onChange="get_id_standard(this.id)">
  284. <datalist id="insert_PR_id_item">
  285. {% for data in Component_id_name_salesnum %}
  286. {% if data[2] == '' or data[2] == None %}
  287. <option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>
  288. {% else %}
  289. <option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>
  290. {% endif %}
  291. {% endfor %}
  292. </datalist>
  293. </td>
  294. <td>
  295. <!-- 名稱 -->
  296. <span id="new_PR_name">——</span>
  297. </td>
  298. <td>
  299. <!-- 原廠料號 -->
  300. <span id="new_PR_type">——</span>
  301. </td>
  302. <td>
  303. <!-- 數量 -->
  304. <input id="PR_amount" value="" style="height: 25px; width: 50px">
  305. </td>
  306. <td>
  307. <!-- 單位 -->
  308. <!-- <input id="PR_unit" value="" style="height: 25px; width: 50px"> -->
  309. <span id="new_PR_unit">——</span>
  310. </td>
  311. <td>
  312. <!-- 照片 -->
  313. <span id="new_PR_picture">——</span>
  314. </td>
  315. <td>
  316. <!-- 供應商 -->
  317. <span id="new_PR_supplier">——</span>
  318. </td>
  319. <td>
  320. <!-- 超連結 -->
  321. <input id="PR_hyperlink" value="" style="height: 25px; width: 100px">
  322. </td>
  323. <!-- <td>
  324. 請購主管核可
  325. ——
  326. </td> -->
  327. <td>
  328. <!-- 請購人 -->
  329. <input type="text" id="PR_PRperson" value="" style="height: 25px; width: 90px;">
  330. </td>
  331. <td rowspan="4" style="vertical-align: middle;">
  332. <!-- OK, 新增下一筆 -->
  333. <input type="button" class="input-cond-add" value="新增" onclick="insert_PR_item()">
  334. </td>
  335. </tr>
  336. <tr class="table-tr-newdata">
  337. <th>幣別</th>
  338. <th>單價</th>
  339. <th>營業稅</th>
  340. <th>總金額</th>
  341. <th>交期</th>
  342. <th>詢價備註</th>
  343. <th>詢價單單號</th>
  344. <th>供應商報價單</th>
  345. <th></th>
  346. </tr>
  347. <tr class="table-tr-newdata">
  348. <!-- <td>
  349. 採購公司
  350. <input type="text" id="RFQ_PRcompany" value="" style="height: 25px; width: 90px;">
  351. </td> -->
  352. <td>
  353. <!-- 幣別 -->
  354. <input type="text" id="RFQ_currency" value="" style="height: 25px; width: 90px;">
  355. </td>
  356. <td>
  357. <!-- 單價 -->
  358. <input type="text" id="RFQ_unitprice" value="" style="height: 25px; width: 90px;">
  359. </td>
  360. <td>
  361. <!-- 營業稅 -->
  362. <input type="text" id="RFQ_salestax" value="" style="height: 25px; width: 90px;">
  363. </td>
  364. <td>
  365. <!-- 總金額 -->
  366. <input type="text" id="RFQ_totalprice" value="" style="height: 25px; width: 90px;">
  367. </td>
  368. <td>
  369. <!-- 交期 -->
  370. <input type="text" id="RFQ_leadtime" value="" style="height: 25px; width: 90px;">
  371. </td>
  372. <td>
  373. <!-- 詢價備註 -->
  374. <input type="text" id="RFQ_RFQremark" value="" style="height: 25px; width: 90px;">
  375. </td>
  376. <td>
  377. <!-- 詢價單單號 -->
  378. <!-- <input type="text" id="RFQ_RFQformid" value="" style="height: 25px; width: 90px;"> -->
  379. ——
  380. </td>
  381. <td>
  382. <!-- 供應商報價單 -->
  383. <input type="text" id="RFQ_RFQsupplierquote" value="" style="height: 25px; width: 90px;">
  384. </td>
  385. <td></td>
  386. </tr>
  387. <tr class="table-tr-newdata">
  388. <td colspan="18">
  389. <!-- 請購人備註 -->
  390. <span style="font-weight: bold;">請購備註 : </span>
  391. <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 50%;">
  392. </td>
  393. </tr>
  394. </tbody>
  395. <tr>
  396. <td colspan="1">
  397. <!-- <input type="button" class="input-cond-action" value="PDFt" onclick="PDFt()" style="width: auto;"> -->
  398. </td>
  399. <td colspan="9">
  400. {% if form_status == "詢價中" or form_status == "比價中" or form_status == "請購詢價完成" %}
  401. <!-- <input type="button" class="input-cond-action" value="產生詢價單" onclick="select_RFQ_sup_form()" style="width: auto;"> -->
  402. <!-- (點擊後即下載 PDF 至「本機/下載」中, 亦可點擊以下連結顯示網頁版詢價單) -->
  403. <span id="RFQ_sup_list">詢價單列表 : </span>
  404. {% endif %}
  405. </td>
  406. <td>
  407. <input type="button" class="input-cond-action status-visible" value="比價→" onclick="RFQ_to_manager()">
  408. </td>
  409. </tr>
  410. {% endif %}
  411. </table>
  412. <script>
  413. var sql = '';
  414. function PDFt() {
  415. $.ajax({
  416. type:"GET",
  417. url:"/PDF_create/RFQ/07110001Txx_T17",
  418. dataType:"JSON",
  419. data:"",
  420. async:false,
  421. success:function (res) {
  422. alert("PDFt " + res.response)
  423. },
  424. error: function (thrownError) {
  425. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  426. alert("PDFt 未成功")
  427. } else {
  428. alert("PDFt thrownError" + thrownError)
  429. }
  430. }
  431. })
  432. }
  433. // 產生詢價單頁面
  434. function select_RFQ_sup_form() {
  435. sql = 'SELECT DISTINCT 零件表.供應商, 供應商.公司 ' +
  436. 'FROM ( ' + PR_Form_number + ' INNER JOIN 零件表 ON ' + PR_Form_number + '.內部料號 = 零件表.內部料號 ) ' +
  437. 'INNER JOIN 供應商 ON 零件表.供應商 = 供應商.供應商 ' + 'ORDER BY 零件表.供應商'
  438. var sql_data = { "sql":sql };
  439. console.log("sql: " + sql)
  440. // var sup_list = [];
  441. $.ajax({
  442. type:"GET",
  443. url:"/sql_get",
  444. dataType:"JSON",
  445. data:sql_data,
  446. async:false,
  447. success:function (res) {
  448. console.log("res.labels: " + res.labels)
  449. console.log("res.labels[0]: " + res.labels[0])
  450. console.log("res.labels[0][0]: " + res.labels[0][0])
  451. var RFQ_sup = '';
  452. for (let sup = 0; sup < res.labels.length; sup++) {
  453. // for (let sup = 0; sup < 1; sup++) {
  454. RFQ_sup += '<br><a href="/RFQ_form_' + PR_Form_number + '_' + res.labels[sup][0] + '" target="_blank">' + res.labels[sup][0] + ' - ' + res.labels[sup][1] + '</a>';
  455. // sup_list.push(res.labels[sup][0])
  456. $.ajax({
  457. type:"GET",
  458. url:"/PDF_create/RFQ/" + PR_Form_number + "_" + res.labels[sup][0],
  459. dataType:"JSON",
  460. data:"",
  461. async:false,
  462. success:function (response) {
  463. // alert(PR_Form_number + '_' + res.labels[sup][0] + " 詢價單 OK")
  464. // /PDF/' + RFQ_Form_number + sup + '.pdf',
  465. document.location.href = '/download/' + RFQ_Form_number + res.labels[sup][0] + '.pdf'
  466. },
  467. error: function (thrownError) {
  468. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  469. alert("詢價單建立 " + PR_Form_number + '_' + res.labels[sup][0] + " 未成功")
  470. } else {
  471. alert("詢價單建立 thrownError" + thrownError)
  472. }
  473. }
  474. })
  475. // /download/RFQ-07110001Txx_T17.pdf
  476. // $.ajax({
  477. // type:"GET",
  478. // url:"/download/RFQ-" + PR_Form_number + "_" + res.labels[sup][0] + ".pdf",
  479. // dataType:"JSON",
  480. // data:"",
  481. // async:false,
  482. // success:function (res) {
  483. // alert(PR_Form_number + '_' + res.labels[sup][0] + " 下載 OK")
  484. // },
  485. // error: function (thrownError) {
  486. // if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  487. // alert("詢價單下載 " + new_id + " 未成功")
  488. // } else {
  489. // alert("詢價單下載 thrownError" + thrownError)
  490. // }
  491. // }
  492. // })
  493. }
  494. RFQ_sup_list.insertAdjacentHTML('beforeend', RFQ_sup);
  495. // var prompt_RFQ = prompt("請輸入供應商編號, 以建立詢價單 :" + RFQ_sup)
  496. // if (String(RFQ_sup).includes(prompt_RFQ)) {
  497. // // 產生詢價單
  498. // alert("OK")
  499. // } else {
  500. // alert("此請購單")
  501. // }
  502. },
  503. error: function (thrownError) {
  504. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  505. alert("詢價單 供應商查詢 " + new_id + " 未成功")
  506. } else {
  507. alert("詢價單 供應商查詢 thrownError" + thrownError)
  508. }
  509. }
  510. })
  511. }
  512. // 新增比價項目
  513. function insert_PR_parity_item(id) {
  514. // __1. 取得新供應商編號
  515. var PR_parity_supplier = $("#" + id + "_parity_supplier").val();
  516. // 判斷新供應商編號是否未選擇
  517. if (PR_parity_supplier == '00') {
  518. alert("請選擇欲比價之新供應商")
  519. return false
  520. }
  521. var new_id = id.substring(0, 8) + PR_parity_supplier
  522. alert("新供應商為 " + PR_parity_supplier + "\n新內部料號為 " + new_id)
  523. // __2. 零件表建立零件
  524. sql = 'INSERT INTO 零件表( `內部料號`, `會計科目`, `類別`, `流水號`, `供應商`, `名稱`)' +
  525. ' SELECT "' + new_id + '" AS `內部料號`, `會計科目`, `類別`, `流水號`, "' + PR_parity_supplier + '" AS `供應商`, `名稱`' +
  526. ' FROM 零件表 WHERE `內部料號` ="' + id + '"';
  527. var sql_data = { "sql":sql };
  528. console.log("sql: " + sql)
  529. $.ajax({
  530. type:"GET",
  531. url:"/sql_get",
  532. dataType:"JSON",
  533. data:sql_data,
  534. async:false,
  535. success:function (res) {
  536. alert("零件表 : 比價零件 " + new_id + " 新增成功 !")
  537. },
  538. error: function (thrownError) {
  539. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  540. alert("零件表 : 比價零件 " + new_id + " 未成功")
  541. } else {
  542. alert("零件表 : 比價零件 thrownError" + thrownError)
  543. }
  544. }
  545. })
  546. // __3. 規格表建立零件
  547. sql = 'INSERT INTO 規格表' +
  548. ' (`內部料號`, `原廠料號`, `單位`, `圖片`, `圖號`, `版次`, `檔案路徑`, ' +
  549. ' `尺寸`, `封裝/材質`, `工作電壓`, `工作電流`, `最大電流`, `功率`, `工作溫度`, `備註`)' +
  550. ' SELECT ' +
  551. ' "' + new_id + '" AS `內部料號`,' +
  552. ' `原廠料號`, `單位`, `圖片`, `圖號`, `版次`, `檔案路徑`, `尺寸`, `封裝/材質`, `工作電壓`, `工作電流`, `最大電流`, `功率`, `工作溫度`, `備註`' +
  553. ' FROM 規格表' +
  554. ' WHERE `內部料號` ="' + id + '"';
  555. var sql_data = { "sql":sql };
  556. console.log("sql: " + sql)
  557. $.ajax({
  558. type:"GET",
  559. url:"/sql_get",
  560. dataType:"JSON",
  561. data:sql_data,
  562. async:false,
  563. success:function (res) {
  564. alert("規格表 : 比價零件 " + new_id + " 新增成功 !")
  565. },
  566. error: function (thrownError) {
  567. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  568. alert("規格表 : 比價零件 " + new_id + " 未成功")
  569. } else {
  570. alert("規格表 : 比價零件 thrownError" + thrownError)
  571. }
  572. }
  573. })
  574. // __4. 此請購草稿建立零件:代入新內部料號、數量、請購人
  575. var PR_PRremark_data = USER_NAME +
  576. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  577. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  578. "[新增比價零件] <br>";
  579. sql = 'INSERT INTO ' + PR_Form_number + '(內部料號, 日期, 數量, 連結, 採購公司, 請購備註, 請購人, 請購核可, 單價, 幣別, ' +
  580. '營業稅, 總金額, 交期, 詢價備註, 詢價單單號, 供應商報價單號, 採購主管核可, 採購單號)' +
  581. ' SELECT' +
  582. ' "' + new_id + '" AS 內部料號,' +
  583. ' CURRENT_TIME() AS 日期,' +
  584. ' 數量,' +
  585. ' "" AS 連結,' +
  586. ' "" AS 採購公司,' +
  587. ' "' + PR_PRremark_data + '" AS 請購備註,' +
  588. ' 請購人,' +
  589. ' "0" AS 請購核可,' +
  590. ' "" AS 單價,' +
  591. ' "" AS 幣別,' +
  592. ' "" AS 營業稅,' +
  593. ' "" AS 總金額,' +
  594. ' "" AS 交期,' +
  595. ' "" AS 詢價備註,' +
  596. ' "" AS 詢價單單號,' +
  597. ' "" AS 供應商報價單號,' +
  598. ' "1" AS 採購主管核可,' +
  599. ' "" AS 採購單號' +
  600. ' FROM ' + PR_Form_number +
  601. ' WHERE 內部料號 ="' + id + '"';
  602. var sql_data = { "sql":sql };
  603. console.log("sql: " + sql)
  604. $.ajax({
  605. type:"GET",
  606. url:"/sql_get",
  607. dataType:"JSON",
  608. data:sql_data,
  609. async:false,
  610. success:function (res) {
  611. alert("請購 : 比價零件 " + new_id + " 新增成功 !")
  612. location.reload()
  613. },
  614. error: function (thrownError) {
  615. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  616. alert("請購 : 比價零件 " + new_id + " 未成功")
  617. } else {
  618. alert("請購 : 比價零件 thrownError" + thrownError)
  619. }
  620. }
  621. })
  622. }
  623. // 新增零件時, 選擇內部料號後, 出現規格表相關內容
  624. function get_id_standard(id) {
  625. var new_PR_id = document.getElementById(id).value;
  626. // alert("get_id_standard Test: " + new_PR_id)
  627. sql = 'SELECT 零件表.名稱, `原廠料號`, `單位`, `圖片`, 零件表.供應商' +
  628. ' FROM 零件表' +
  629. ' INNER JOIN 規格表' +
  630. ' ON 零件表.內部料號 = 規格表.內部料號' +
  631. ' WHERE 零件表.內部料號 = "' + new_PR_id + '"';
  632. var sql_data = { "sql":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. if (res.labels == '') {
  641. alert(new_PR_id + " 無此零件")
  642. document.getElementById('PR_id').value = '';
  643. document.getElementById('new_PR_name').innerText = '';
  644. document.getElementById('new_PR_type').innerText = '';
  645. document.getElementById('new_PR_unit').innerText = '';
  646. document.getElementById('new_PR_picture').innerText = '';
  647. document.getElementById('new_PR_supplier').innerText = '';
  648. } else {
  649. // 名稱
  650. document.getElementById('new_PR_name').innerText = res.labels[0][0];
  651. // 原廠料號
  652. document.getElementById('new_PR_type').innerText = res.labels[0][1];
  653. // 單位
  654. document.getElementById('new_PR_unit').innerText = res.labels[0][2];
  655. // 圖片
  656. document.getElementById('new_PR_picture').innerText = res.labels[0][3];
  657. // 供應商
  658. document.getElementById('new_PR_supplier').innerText = res.labels[0][4];
  659. }
  660. },
  661. error: function (thrownError) {
  662. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  663. alert("新增零件取值 : " + new_PR_id + " 未成功")
  664. } else {
  665. alert("新增零件取值 thrownError" + thrownError)
  666. }
  667. }
  668. })
  669. }
  670. // 把日期數字變成兩位數
  671. function two(params) {
  672. var date_num = parseInt(params)
  673. if ( date_num < 10) {
  674. new_date_num = '0' + String(date_num)
  675. } else {
  676. new_date_num = String(date_num)
  677. }
  678. return new_date_num
  679. }
  680. //
  681. function insert_new_PRremark(id){
  682. // 取得原本的請購備註內容
  683. var old_remark = document.getElementById(id + '_PRremark');
  684. var old_remark_data = old_remark.innerHTML;
  685. console.log("old_remark_data: " + old_remark_data)
  686. // 取得新增的請購備註內容
  687. var new_remark = document.getElementById(id + '_new_PRremark').value;
  688. console.log("new_remark: " + new_remark)
  689. // 組合文字 Rita (2022/02/10 17:55:00) 說:急, 缺, 一定要買!
  690. var new_remark_data = USER_NAME +
  691. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  692. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  693. new_remark;
  694. console.log("new_remark_data: " + new_remark_data)
  695. sql = 'UPDATE ' + PR_Form_number +
  696. ' SET `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
  697. ' WHERE `內部料號`="' + id + '";';
  698. console.log("[insert_new_PRremark]sql: " + sql)
  699. var sql_data = { "sql":sql };
  700. $.ajax({
  701. type:"GET",
  702. url:"/sql_get",
  703. dataType:"JSON",
  704. data:sql_data,
  705. async:false,
  706. success:function (res) {
  707. alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
  708. location.reload()
  709. },
  710. error: function (thrownError) {
  711. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  712. alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
  713. } else {
  714. alert("修改請購單請購備註內容 thrownError" + thrownError)
  715. }
  716. }
  717. })
  718. }
  719. //
  720. function update_PR_item(id) {
  721. console.log("修改: " + id)
  722. var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson',
  723. 'PRmanagercheck', 'currency', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
  724. for (let i = 1; i < PR_title_list.length; i++) {
  725. // if (i != 1 && i != 2 && i != 5 && i != 6 && i != 8 && i != 10 && i != 11 && i != 17) {
  726. if (PR_title_list[i] == 'amount' || PR_title_list[i] == 'hyperlink' ||
  727. PR_title_list[i] == 'currency' || PR_title_list[i] == 'unitprice' || PR_title_list[i] == 'salestax' ||
  728. PR_title_list[i] == 'totalprice' || PR_title_list[i] == 'leadtime' || PR_title_list[i] == 'RFQremark' ||
  729. PR_title_list[i] == 'RFQsupplierquote') {
  730. console.log('[update_PR_item] i: ' + i)
  731. var target_id = document.getElementById(id + '_' + PR_title_list[i]);
  732. var old_name = target_id.innerText;
  733. console.log('old_name: ', old_name)
  734. target_id.innerHTML = "";
  735. if (PR_title_list[i] == 'hyperlink'){
  736. textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 240px">';
  737. } else if (PR_title_list[i] == 'RFQsupplierquote'){
  738. textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 210px">';
  739. } else if (PR_title_list[i] == 'currency'){
  740. textarea = '<select id="'+ id + '_' + PR_title_list[i] + '_ta' + '">' +
  741. '<option value="TWD">TWD</option>' +
  742. '<option value="CNY">CNY</option>' +
  743. '<option value="USD">USD</option>' +
  744. '</select>';
  745. } else {
  746. textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 80px">';
  747. }
  748. if (PR_title_list[i] == 'RFQsupplierquote') {
  749. textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
  750. }
  751. target_id.insertAdjacentHTML('beforeend', textarea);
  752. }
  753. if (PR_title_list[i] == 'currency') {
  754. $("#" + id + "_currency_ta").val(old_name);
  755. }
  756. }
  757. }
  758. // 修改請購單內項目 確認
  759. function update_comfirm_PR_item(id) {
  760. console.log("修改: " + id)
  761. var new_amount_value = $('#' + id + '_amount_ta').val();
  762. var new_hyperlink_value = $('#' + id + '_hyperlink_ta').val();
  763. var new_currency_value = $('#' + id + '_currency_ta').val();
  764. var new_unitprice_value = $('#' + id + '_unitprice_ta').val();
  765. var new_salestax_value = $('#' + id + '_salestax_ta').val();
  766. var new_totalprice_value = $('#' + id + '_totalprice_ta').val();
  767. var new_leadtime_value = $('#' + id + '_leadtime_ta').val();
  768. var new_RFQremark_value = $('#' + id + '_RFQremark_ta').val();
  769. var new_RFQsupplierquote_value = $('#' + id + '_RFQsupplierquote_ta').val();
  770. sql = 'UPDATE ' + PR_Form_number +
  771. ' SET `數量`="' + new_amount_value + '"' +
  772. ', `連結`="' + new_hyperlink_value + '"' +
  773. ', `幣別`="' + new_currency_value + '"' +
  774. ', `單價`="' + new_unitprice_value + '"' +
  775. ', `營業稅`="' + new_salestax_value + '"' +
  776. ', `總金額`="' + new_totalprice_value + '"' +
  777. ', `交期`="' + new_leadtime_value + '"' +
  778. ', `詢價備註`="' + new_RFQremark_value + '"' +
  779. ', `供應商報價單號`="' + new_RFQsupplierquote_value + '"' +
  780. ' WHERE `內部料號`="' + id + '";';
  781. console.log('sql: ' + sql)
  782. var sql_data = { "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("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
  791. location.reload()
  792. },
  793. error: function (thrownError) {
  794. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  795. alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
  796. } else {
  797. alert("修改請購單項目內容 thrownError" + thrownError)
  798. }
  799. }
  800. })
  801. }
  802. // 刪除請購單內項目
  803. function delete_PR_item(id) {
  804. console.log("刪除: " + id)
  805. var comfirm_delete_PR_item = confirm("確定要刪除 " + id + " 零件嗎?")
  806. if (comfirm_delete_PR_item) {
  807. sql = 'DELETE FROM ' + PR_Form_number + ' WHERE 內部料號 = "' + id + '";'
  808. sql_data = { "sql":sql };
  809. console.log("delete_PR_item[sql]:" + sql)
  810. $.ajax({
  811. type:"GET",
  812. url:"/sql_get",
  813. dataType:"JSON",
  814. data:sql_data,
  815. async:false,
  816. success:function (res) {
  817. alert("請購單 " + PR_Form_number + " : " + id + " 刪除成功 !")
  818. location.reload()
  819. },
  820. error: function (thrownError) {
  821. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  822. alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未刪除")
  823. } else {
  824. alert("刪除請購單內容 thrownError" + thrownError)
  825. }
  826. }
  827. })
  828. }
  829. }
  830. // 主管核可 勾選 / 取消時都要提醒
  831. function checkbox_check(id) {
  832. var checkbox_id = $('#' + id + '_PRmanager_check').prop("checked");
  833. // console.log("checkbox_id: " + checkbox_id)
  834. if (checkbox_id == true) {
  835. // 主管勾選核可 從空白到勾選
  836. var checkbox_confirm_true = confirm("核可該零件採購, 請按確定")
  837. if (checkbox_confirm_true) {
  838. sql = 'UPDATE ' + PR_Form_number +
  839. ' SET `請購主管核可`="1"' +
  840. ' WHERE `內部料號`="' + id + '";';
  841. var sql_data = { "sql":sql };
  842. $.ajax({
  843. type:"GET",
  844. url:"/sql_get",
  845. dataType:"JSON",
  846. data:sql_data,
  847. async:false,
  848. success:function (res) {
  849. alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
  850. location.reload()
  851. },
  852. error: function (thrownError) {
  853. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  854. alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
  855. } else {
  856. alert("修改請購單項目內容 thrownError" + thrownError)
  857. }
  858. }
  859. })
  860. } else {
  861. $('#' + id + '_PRmanager_check').prop('checked', false);
  862. }
  863. } else {
  864. // 主管不核可 從勾選到空白
  865. var checkbox_confirm_false = confirm("取消該零件採購, 請按確定取消該零件採購\n(或是刪除該零件)")
  866. if (checkbox_confirm_false) {
  867. sql = 'UPDATE ' + PR_Form_number +
  868. ' SET `請購主管核可`="0"' +
  869. ' WHERE `內部料號`="' + id + '";';
  870. var sql_data = { "sql":sql };
  871. $.ajax({
  872. type:"GET",
  873. url:"/sql_get",
  874. dataType:"JSON",
  875. data:sql_data,
  876. async:false,
  877. success:function (res) {
  878. alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
  879. location.reload()
  880. },
  881. error: function (thrownError) {
  882. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  883. alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
  884. } else {
  885. alert("修改請購單項目內容 thrownError" + thrownError)
  886. }
  887. }
  888. })
  889. } else {
  890. $('#' + id + '_PRmanager_check').prop('checked', true);
  891. }
  892. }
  893. }
  894. // 主管核可後, 開始詢價
  895. function RFQ_to_manager() {
  896. for (let i = 0; i < data_id.length; i++) {
  897. var unitprice_exist = $('#' + data_id[i] + '_unitprice').text();
  898. // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
  899. if (unitprice_exist == '' || parseInt(unitprice_exist) < 0 ) {
  900. alert(data_id[i] + " 請輸入正確的金額")
  901. return false
  902. }
  903. }
  904. var confirm_to_user = confirm('本表單即將送出給直屬主管, 請點選[確定]送出表單')
  905. if (confirm_to_user) {
  906. // 狀態更新為 比價中
  907. sql = "UPDATE `表單詳細資料` SET `表單狀態` = '比價中' " +
  908. "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
  909. sql_data = { "sql":sql };
  910. console.log("RFQ_to_manager[sql]:" + sql)
  911. $.ajax({
  912. type:"GET",
  913. url:"/sql_get",
  914. dataType:"JSON",
  915. data:sql_data,
  916. async:false,
  917. success:function (res) {
  918. alert("調整狀態為\"比價中\"")
  919. },
  920. error: function (thrownError) {
  921. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  922. alert("送出調整狀態 未成功")
  923. } else {
  924. alert("送出調整狀態 thrownError" + thrownError)
  925. }
  926. }
  927. })
  928. // 通知採購主管
  929. sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
  930. USER_MANAGER + "','" +
  931. PR_Form_number + "','" +
  932. USER_NAME + " 請求比價')";
  933. sql_data = { "sql":sql };
  934. console.log("RFQ_to_manager[sql]:" + sql)
  935. $.ajax({
  936. type:"GET",
  937. url:"/sql_get",
  938. dataType:"JSON",
  939. data:sql_data,
  940. async:false,
  941. success:function (res) {
  942. alert("已通知採購主管進行比價")
  943. window.location.assign("/PR_list")
  944. },
  945. error: function (thrownError) {
  946. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  947. alert("比價通知 未成功")
  948. } else {
  949. alert("比價通知 thrownError" + thrownError)
  950. }
  951. }
  952. })
  953. }
  954. }
  955. // 產生詢價單
  956. function create_RFQ_form(params) {
  957. // 1. 確認目前請購單的採購公司皆輸入
  958. var is_POcompany_empty = true;
  959. sql = 'SELECT 採購公司 FROM `' + PR_Form_number + '`'
  960. sql_data = { "sql":sql };
  961. console.log("delete_PR_item[sql]:" + sql)
  962. $.ajax({
  963. type:"GET",
  964. url:"/sql_get",
  965. dataType:"JSON",
  966. data:sql_data,
  967. async:false,
  968. success:function (res) {
  969. for (let l = 0; l < res.labels.length; l++) {
  970. if (res.labels[l] == '') {
  971. is_POcompany_empty = true;
  972. alert("請購單之採購公司不得為空, 或請刪除該項目")
  973. } else {
  974. is_POcompany_empty = false;
  975. }
  976. }
  977. },
  978. error: function (thrownError) {
  979. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  980. alert("確認採購單之採購公司皆輸入 未成功")
  981. } else {
  982. alert("確認採購單之採購公司皆輸入 thrownError" + thrownError)
  983. }
  984. }
  985. })
  986. // 若採購公司空白, 則跳出 function
  987. if (is_POcompany_empty) {
  988. return false
  989. }
  990. // 2. 找到詢價單號 0711xxxxT01 / 0711ooooT02
  991. sql = 'SELECT DISTINCT `TABLE_NAME` FROM information_schema.columns ' +
  992. 'WHERE `TABLE_NAME` LIKE "%0711%" AND `TABLE_NAME` LIKE "%T01%" ' +
  993. 'ORDER BY `TABLE_NAME` DESC LIMIT 1'
  994. sql_data = { "sql":sql };
  995. // console.log("[sql]:" + sql)
  996. $.ajax({
  997. type:"GET",
  998. url:"/table_sn_get",
  999. dataType:"JSON",
  1000. data:sql_data,
  1001. async:false,
  1002. success:function (res) {
  1003. console.log("res.new_sn: " + res.new_sn)
  1004. console.log("res.new_table_id: " + res.new_table_id)
  1005. // for (let l = 0; l < res.labels.length; l++) {
  1006. // if (res.labels[l] == '') {
  1007. // is_POcompany_empty = true;
  1008. // alert("請購單之採購公司不得為空, 或請刪除該項目")
  1009. // } else {
  1010. // is_POcompany_empty = false;
  1011. // }
  1012. // }
  1013. },
  1014. error: function (thrownError) {
  1015. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  1016. alert("確認採購單之採購公司皆輸入 未成功")
  1017. } else {
  1018. alert("確認採購單之採購公司皆輸入 thrownError" + thrownError)
  1019. }
  1020. }
  1021. })
  1022. // 3. 依採購公司區分詢價單, 採購公司 T01 者歸類到 0711xxxxT01, 同 T02
  1023. // 4. 填入目前請購單項目的詢價單單號
  1024. }
  1025. // 請購人員 送出請購單
  1026. function PR_to_Purchase() {
  1027. alert("請購單 " + PR_Form_number + " 完成, 將通知採購人員 !")
  1028. }
  1029. // 採購人員 修改採購公司
  1030. function Purchase_update_sup() {
  1031. var purchase_company = prompt("請注意 ! 輸入採購公司後將無法修改 ! \n\n請輸入採購公司 :\nT01 : 金子進\nT02 : 瑞智")
  1032. console.log("purchase_company: " + purchase_company)
  1033. var new_PR_companyid = PR_Form_number.substring(0, 8) + purchase_company;
  1034. console.log("new_PR_companyid: " + new_PR_companyid)
  1035. sql = "RENAME TABLE `" + PR_Form_number + "` TO `" + new_PR_companyid + "`";
  1036. sql_data = { "sql":sql };
  1037. console.log("Purchase_update_sup[sql]:" + sql)
  1038. $.ajax({
  1039. type:"GET",
  1040. url:"/sql_get",
  1041. dataType:"JSON",
  1042. data:sql_data,
  1043. async:false,
  1044. success:function (res) {
  1045. alert("已將請購單更名為 " + new_PR_companyid + "")
  1046. window.location.assign("/PR_user_" + new_PR_companyid)
  1047. },
  1048. error: function (thrownError) {
  1049. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  1050. alert("請購單 " + PR_Form_number + ": 已存在")
  1051. } else {
  1052. alert("請購單更名錯誤 thrownError" + thrownError)
  1053. }
  1054. }
  1055. })
  1056. }
  1057. function insert_PR_item() {
  1058. // var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson',
  1059. // 'PRmanagercheck', 'currency', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
  1060. var PR_id = $("#PR_id").val()
  1061. var PR_amount = $("#PR_amount").val()
  1062. var PR_supplier = $("#PR_supplier").val()
  1063. var PR_hyperlink = $("#PR_hyperlink").val()
  1064. var PR_PRperson = $("#PR_PRperson").val()
  1065. var RFQ_currency = $("#RFQ_currency").val()
  1066. var RFQ_unitprice = $("#RFQ_unitprice").val()
  1067. var RFQ_salestax = $("#RFQ_salestax").val()
  1068. var RFQ_totalprice = $("#RFQ_totalprice").val()
  1069. var RFQ_leadtime = $("#RFQ_leadtime").val()
  1070. var RFQ_RFQremark = $("#RFQ_RFQremark").val()
  1071. var RFQ_RFQsupplierquote = $("#RFQ_RFQsupplierquote").val()
  1072. var PR_PRremark = $("#PR_PRremark").val()
  1073. var PR_PRremark_data = USER_NAME +
  1074. " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
  1075. two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
  1076. "[新增零件] " + PR_PRremark + "<br>";
  1077. sql = 'INSERT INTO `' + PR_Form_number + '` ' +
  1078. '(內部料號, 日期, 數量, 連結, 請購人, 幣別, 單價, 營業稅, 總金額, 交期, 詢價備註, 供應商報價單號, 請購備註)' +
  1079. ' VALUES ("' + PR_id +
  1080. '", current_timestamp(), "' +
  1081. PR_amount + '", "' +
  1082. PR_hyperlink + '", "' +
  1083. PR_PRperson + '", "' +
  1084. RFQ_currency + '", "' +
  1085. RFQ_unitprice + '", "' +
  1086. RFQ_salestax + '", "' +
  1087. RFQ_totalprice + '", "' +
  1088. RFQ_leadtime + '", "' +
  1089. RFQ_RFQremark + '", "' +
  1090. RFQ_RFQsupplierquote + '", "' +
  1091. PR_PRremark_data + '");';
  1092. var sql_data = { "sql":sql };
  1093. console.log("insert_PR_item[sql]:" + sql)
  1094. $.ajax({
  1095. type:"GET",
  1096. url:"/sql_get",
  1097. dataType:"JSON",
  1098. data:sql_data,
  1099. async:false,
  1100. success:function (res) {
  1101. console.log("res.sql_data: " + res.sql_data)
  1102. if (res.sql_data != '') {
  1103. alert(res.sql_data)
  1104. } else {
  1105. alert("請購單 " + PR_Form_number + " : " + PR_id + " 新增成功 !")
  1106. location.reload()
  1107. }
  1108. },
  1109. error: function (thrownError) {
  1110. if (thrownError.statusText == "INTERNAL SERVER ERROR") {
  1111. alert("請購單 " + PR_Form_number + " : " + PR_id + " 未新增")
  1112. } else {
  1113. alert("新增請購單內容 thrownError" + thrownError)
  1114. }
  1115. }
  1116. })
  1117. }
  1118. </script>
  1119. <!--
  1120. 九威金屬設計公司 : <a href="/RFQ_form_07110001Txx_T01" target="_blank">預覽詢價單 07120002T23</a>
  1121. <a href="/download/07120001T01.pdf" target="_blank">下載</a>
  1122. -->
  1123. </body>
  1124. </html>