1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>{{ title }}</title>
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <script>
- var PR_Form_number = '{{PR_Form_number}}';
- console.log("PR_Form_number: " + PR_Form_number);
- var RFQ_Form_number = '0712' + PR_Form_number.substring(4, 8);
- console.log("RFQ_Form_number: " + RFQ_Form_number);
- var USER_NAME = '{{user_name}}'
- console.log("user_name: " + USER_NAME);
- var USER_MANAGER = '{{user_manager}}'
- console.log("user_manager: " + USER_MANAGER);
- var FORM_STATUS = '{{form_status}}';
- var data_id = []; // 存放此資料表所有的內部料號
- // 取得現在時間 紀錄請購備註時使用
- var Today = new Date();
- // 顯示零件名稱標題用
- var tr_title_id_target = '00000000';
- // 取得網址資訊
- var HOST = window.location.host;
- window.onload = function(){
- if (FORM_STATUS != '詢價中') {
- [].forEach.call(document.querySelectorAll('.status-visible'), function (el) {
- el.style.visibility = 'hidden';
- });
- [].forEach.call(document.querySelectorAll('.status-display'), function (el) {
- el.style.display = 'none';
- });
- [].forEach.call(document.querySelectorAll('.status-disabled'), function (el) {
- el.disabled = true;
- });
- }
- create_RFQ_list();
- }
- function create_RFQ_list() {
- sql = "SELECT DISTINCT `零件表`.`供應商`, `供應商`.`公司` " +
- "FROM ( `" + PR_Form_number + "` " +
- "INNER JOIN `零件表` ON `" + PR_Form_number + "`.`內部料號` = `零件表`.`內部料號` ) " +
- "INNER JOIN `供應商` ON `零件表`.`供應商` = `供應商`.`供應商` " +
- "ORDER BY `零件表`.`供應商`"
- var sql_data = { "sql":sql };
- console.log("sql: " + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- console.log("res.labels: " + res.labels)
- console.log("res.labels[0]: " + res.labels[0])
- console.log("res.labels[0][0]: " + res.labels[0][0])
- var RFQ_sup = '';
- for (let sup = 0; sup < res.labels.length; sup++) {
- // 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>';
- RFQ_sup += "<br>" +
- res.labels[sup][1] + " : " +
- "<a href='/RFQ_form_" + PR_Form_number + "_" + res.labels[sup][0] + "' target='_blank'>預覽詢價單 " + RFQ_Form_number + res.labels[sup][0] + "</a>" +
- "—" +
- "<a href='/DL/" + HOST + "/RFQ/" + PR_Form_number + "_" + res.labels[sup][0] + "' target='_blank'>下載</a>"
- }
- RFQ_sup_list.insertAdjacentHTML('beforeend', RFQ_sup);
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("詢價單 供應商查詢 " + new_id + " 未成功")
- } else {
- alert("詢價單 供應商查詢 thrownError" + thrownError)
- }
- }
- })
- }
- </script>
-
- <style>
- .input-cond-delete {
- background: #E43030;
- border: 1px solid #CFCFCF;
- box-sizing: border-box;
- border-radius: 5px;
- margin-left: 5px;
- width: auto;
- height: 33px;
- font-size: 16px;
- text-align: center;
- line-height: 16px;
- color: #FFFFFF;
- }
- .input-cond-add {
- background: #008CBA;
- border: 1px solid #CFCFCF;
- box-sizing: border-box;
- border-radius: 5px;
- margin-left: 5px;
- width: auto;
- /* width: 65px; */
- height: 33px;
- font-size: 16px;
- text-align: center;
- line-height: 16px;
- color: #FFFFFF;
- }
- .input-cond-action {
- background: #FFBD00;
- /* #6BF178 #53DD6C #FFBD00*/
- border: 1px solid #CFCFCF;
- box-sizing: border-box;
- border-radius: 5px;
- margin-left: 5px;
- width: auto;
- height: 33px;
- font-size: 16px;
- text-align: center;
- line-height: 16px;
- color: #000000;
- font-weight: bold;
- }
- .table-tr-title {
- background-color:rgb(0, 131, 72);
- color: #FFFFFF;
- font-weight: bold;
- }
- .table-tr-data {
- background-color:rgb(236, 247, 242);
- }
- .table-tr-newdata {
- background-color:rgb(245, 245, 245);
- }
- </style>
- </head>
- <body>
- <div id="ERP_header">
- <!-- 匯入共同使用的 header.html 內容 -->
- {% include 'ERP_header.html' %}
- </div>
- <center><h6 style="margin: 20px;">新增請購單</h6></center>
- 目前使用者:{{user_name}}<br>
- 請購單號:<span>{{PR_Form_number}}</span><br>
- 表單狀態:{{form_status}}<br>
- 用途:{{form_purpose}}<br>
- <!-- {% for datas in RFQ_supplier_data %}
- 九威金屬設計公司—預覽詢價單 07120002T23—下載
- {% endfor %} -->
- <table class="table table-bordered" style="margin-top: 10px;">
- {% for datas in PR_data %}
- <thead>
- <tr class="table-tr-title" id="{{datas[0]}}_tr_title"></tr>
- <script type="text/javascript">
- var tr_title_id_now = '{{datas[0]}}'.substring(0, 8)
- if (tr_title_id_now != tr_title_id_target) {
- tr_title_id_target = tr_title_id_now
- var target_tr = document.getElementById('{{datas[0]}}_tr_title');
- var target_td = '<td colspan="11">' + '{{datas[1]}}' + '</td>'
- target_tr.insertAdjacentHTML('beforeend', target_td);
- }
- </script>
- </thead>
- <tbody>
- <!-- 請購單標題 -->
- <tr class="table-tr-data">
- <th rowspan="4" style="text-align: center;">
- 採購<br>主管<br>核可<br>
- <br>
- {% if datas[20] == 1 %}
- <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" checked disabled>
- {% else %}
- <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" disabled>
- {% endif %}
- </th>
- <th>內部料號</th>
- <th>名稱</th>
- <th>原廠料號</th>
- <th>數量</th>
- <th>單位</th>
- <th>圖片</th>
- <th>供應商</th>
- <th>連結</th>
- <th>請購人</th>
- <th>
- <p class="status-visible">改/刪</p>
- </th>
- </tr>
- <script>
- // 取得所有內部料號
- data_id.push('{{datas[0]}}')
- // console.log("data_id: " + data_id)
- </script>
- <tr class="table-tr-data">
- <td id="{{datas[0]}}_id">{{datas[0]}}</td>
- <td id="{{datas[0]}}_name">{{datas[1]}}</td>
- <td id="{{datas[0]}}_type">{{datas[2]}}</td>
- <td id="{{datas[0]}}_amount">{{datas[3]}}</td>
- <td id="{{datas[0]}}_unit">{{datas[4]}}</td>
- <td id="{{datas[0]}}_picture">{{datas[5]}}</td>
- <td id="{{datas[0]}}_supplier">{{datas[6]}}</td>
- <td id="{{datas[0]}}_hyperlink">{{datas[7]}}</td>
- <td id="{{datas[0]}}_PRperson">{{datas[9]}}</td>
- <!-- {% if datas[10] == 1 %}
- <td id="{{datas[0]}}_PRmanagercheck">OK</td>
- {% else %}
- <td id="{{datas[0]}}_PRmanagercheck"></td>
- {% endif %} -->
- <td rowspan="3" style="vertical-align: middle;">
- <input type="button" class="input-cond-add status-visible" value="修改" onclick="update_PR_item('{{datas[0]}}')">
- </td>
- </tr>
- <tr class="table-tr-data">
- <!-- <th>採購公司</th> -->
- <th>幣別</th>
- <th>單價</th>
- <th>營業稅</th>
- <th>總金額</th>
- <th>交期</th>
- <th>詢價備註</th>
- <th>詢價單單號</th>
- <th>供應商報價單</th>
- <th></th>
- </tr>
- <tr class="table-tr-data">
- <!-- <td id="{{datas[0]}}_PRcompany">{{datas[11]}}</td> -->
- <td id="{{datas[0]}}_currency">{{datas[12]}}</td>
- <td id="{{datas[0]}}_unitprice">{{datas[13]}}</td>
- <td id="{{datas[0]}}_salestax">{{datas[14]}}</td>
- <td id="{{datas[0]}}_totalprice">{{datas[15]}}</td>
- <td id="{{datas[0]}}_leadtime">{{datas[16]}}</td>
- <td id="{{datas[0]}}_RFQremark">{{datas[17]}}</td>
- <td id="{{datas[0]}}_RFQformid">{{datas[18]}}</td>
- <td id="{{datas[0]}}_RFQsupplierquote">{{datas[19]}}</td>
- <td></td>
- </tr>
- <tr>
- <td colspan="8">
- <span style="font-weight: bold;">請購備註 : </span>
- <input type="text" id="{{datas[0]}}_new_PRremark" style="height: 25px; width: 80%;">
- <input type="button" id="PR_new_PRremark" value="新增備註" style="height: auto;" onclick="insert_new_PRremark('{{datas[0]}}')">
- <br>
- <span id="{{datas[0]}}_PRremark">{{datas[8]|safe}}</span>
- </td>
- <td colspan="3" style="vertical-align: middle; text-align: right;">
- <select id="{{datas[0]}}_parity_supplier" class="status-visible" onChange="">
- <option value="00"></option>
- {% for data in Supplier_data %}
- <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
- {% endfor %}
- </select>
- <br>
- <input type="button" class="input-cond-add status-visible" value="新增比價項目" onclick="insert_PR_parity_item('{{datas[0]}}')">
- </td>
- </tr>
- </tbody>
- {% endfor %}
- {% if PR_Form_number[-2:] == 'xx' %}
- <thead class="status-display">
- <tr class="table-tr-title">
- <td colspan="11">新增零件</td>
- </tr>
- </thead>
- <tbody class="status-display">
- <tr class="table-tr-newdata">
- <th rowspan="5" style="text-align: center;">
- 採購<br>主管<br>核可<br>
- <br>
- <input type="checkbox" id="insert_RFQ_managercheck" onclick="" checked disabled>
- </th>
- <th>內部料號</th>
- <th>名稱</th>
- <th>原廠料號</th>
- <th>數量</th>
- <th>單位</th>
- <th>圖片</th>
- <th>供應商</th>
- <th>連結</th>
- <!-- <th>請購備註</th> -->
- <!-- <th>請購主管核可</th> -->
- <th>請購人</th>
- <th>新增</th>
- </tr>
- <tr class="table-tr-newdata">
- <td>
- <!-- 內部料號 -->
- <input list="insert_PR_id_item" id="PR_id" style="height: 25px;" onChange="get_id_standard(this.id)">
- <datalist id="insert_PR_id_item">
- {% for data in Component_id_name_salesnum %}
- {% if data[2] == '' or data[2] == None %}
- <option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>
- {% else %}
- <option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>
- {% endif %}
- {% endfor %}
- </datalist>
- </td>
- <td>
- <!-- 名稱 -->
- <span id="new_PR_name">——</span>
- </td>
- <td>
- <!-- 原廠料號 -->
- <span id="new_PR_type">——</span>
- </td>
- <td>
- <!-- 數量 -->
- <input id="PR_amount" value="" style="height: 25px; width: 50px">
- </td>
- <td>
- <!-- 單位 -->
- <!-- <input id="PR_unit" value="" style="height: 25px; width: 50px"> -->
- <span id="new_PR_unit">——</span>
- </td>
- <td>
- <!-- 照片 -->
- <span id="new_PR_picture">——</span>
- </td>
- <td>
- <!-- 供應商 -->
- <span id="new_PR_supplier">——</span>
- </td>
- <td>
- <!-- 超連結 -->
- <input id="PR_hyperlink" value="" style="height: 25px; width: 100px">
- </td>
- <!-- <td>
- 請購主管核可
- ——
- </td> -->
- <td>
- <!-- 請購人 -->
- <input type="text" id="PR_PRperson" value="" style="height: 25px; width: 90px;">
- </td>
- <td rowspan="4" style="vertical-align: middle;">
- <!-- OK, 新增下一筆 -->
- <input type="button" class="input-cond-add" value="新增" onclick="insert_PR_item()">
- </td>
- </tr>
- <tr class="table-tr-newdata">
- <th>幣別</th>
- <th>單價</th>
- <th>營業稅</th>
- <th>總金額</th>
- <th>交期</th>
- <th>詢價備註</th>
- <th>詢價單單號</th>
- <th>供應商報價單</th>
- <th></th>
- </tr>
- <tr class="table-tr-newdata">
- <!-- <td>
- 採購公司
- <input type="text" id="RFQ_PRcompany" value="" style="height: 25px; width: 90px;">
- </td> -->
- <td>
- <!-- 幣別 -->
- <input type="text" id="RFQ_currency" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 單價 -->
- <input type="text" id="RFQ_unitprice" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 營業稅 -->
- <input type="text" id="RFQ_salestax" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 總金額 -->
- <input type="text" id="RFQ_totalprice" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 交期 -->
- <input type="text" id="RFQ_leadtime" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 詢價備註 -->
- <input type="text" id="RFQ_RFQremark" value="" style="height: 25px; width: 90px;">
- </td>
- <td>
- <!-- 詢價單單號 -->
- <!-- <input type="text" id="RFQ_RFQformid" value="" style="height: 25px; width: 90px;"> -->
- ——
- </td>
- <td>
- <!-- 供應商報價單 -->
- <input type="text" id="RFQ_RFQsupplierquote" value="" style="height: 25px; width: 90px;">
- </td>
- <td></td>
- </tr>
- <tr class="table-tr-newdata">
- <td colspan="18">
- <!-- 請購人備註 -->
- <span style="font-weight: bold;">請購備註 : </span>
- <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 50%;">
- </td>
- </tr>
- </tbody>
- <tr>
- <td colspan="1">
- <!-- <input type="button" class="input-cond-action" value="PDFt" onclick="PDFt()" style="width: auto;"> -->
- </td>
- <td colspan="9">
- {% if form_status == "詢價中" or form_status == "比價中" or form_status == "請購詢價完成" %}
- <!-- <input type="button" class="input-cond-action" value="產生詢價單" onclick="select_RFQ_sup_form()" style="width: auto;"> -->
- <!-- (點擊後即下載 PDF 至「本機/下載」中, 亦可點擊以下連結顯示網頁版詢價單) -->
- <span id="RFQ_sup_list">詢價單列表 : </span>
- {% endif %}
- </td>
- <td>
- <input type="button" class="input-cond-action status-visible" value="比價→" onclick="RFQ_to_manager()">
- </td>
- </tr>
- {% endif %}
- </table>
- <script>
- var sql = '';
- function PDFt() {
- $.ajax({
- type:"GET",
- url:"/PDF_create/RFQ/07110001Txx_T17",
- dataType:"JSON",
- data:"",
- async:false,
- success:function (res) {
- alert("PDFt " + res.response)
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("PDFt 未成功")
- } else {
- alert("PDFt thrownError" + thrownError)
- }
- }
- })
- }
- // 產生詢價單頁面
- function select_RFQ_sup_form() {
- sql = 'SELECT DISTINCT 零件表.供應商, 供應商.公司 ' +
- 'FROM ( ' + PR_Form_number + ' INNER JOIN 零件表 ON ' + PR_Form_number + '.內部料號 = 零件表.內部料號 ) ' +
- 'INNER JOIN 供應商 ON 零件表.供應商 = 供應商.供應商 ' + 'ORDER BY 零件表.供應商'
- var sql_data = { "sql":sql };
- console.log("sql: " + sql)
- // var sup_list = [];
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- console.log("res.labels: " + res.labels)
- console.log("res.labels[0]: " + res.labels[0])
- console.log("res.labels[0][0]: " + res.labels[0][0])
- var RFQ_sup = '';
- for (let sup = 0; sup < res.labels.length; sup++) {
- // for (let sup = 0; sup < 1; sup++) {
- 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>';
- // sup_list.push(res.labels[sup][0])
- $.ajax({
- type:"GET",
- url:"/PDF_create/RFQ/" + PR_Form_number + "_" + res.labels[sup][0],
- dataType:"JSON",
- data:"",
- async:false,
- success:function (response) {
- // alert(PR_Form_number + '_' + res.labels[sup][0] + " 詢價單 OK")
- // /PDF/' + RFQ_Form_number + sup + '.pdf',
- document.location.href = '/download/' + RFQ_Form_number + res.labels[sup][0] + '.pdf'
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("詢價單建立 " + PR_Form_number + '_' + res.labels[sup][0] + " 未成功")
- } else {
- alert("詢價單建立 thrownError" + thrownError)
- }
- }
- })
- // /download/RFQ-07110001Txx_T17.pdf
- // $.ajax({
- // type:"GET",
- // url:"/download/RFQ-" + PR_Form_number + "_" + res.labels[sup][0] + ".pdf",
- // dataType:"JSON",
- // data:"",
- // async:false,
- // success:function (res) {
- // alert(PR_Form_number + '_' + res.labels[sup][0] + " 下載 OK")
- // },
- // error: function (thrownError) {
- // if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- // alert("詢價單下載 " + new_id + " 未成功")
- // } else {
- // alert("詢價單下載 thrownError" + thrownError)
- // }
- // }
- // })
- }
- RFQ_sup_list.insertAdjacentHTML('beforeend', RFQ_sup);
- // var prompt_RFQ = prompt("請輸入供應商編號, 以建立詢價單 :" + RFQ_sup)
- // if (String(RFQ_sup).includes(prompt_RFQ)) {
- // // 產生詢價單
- // alert("OK")
- // } else {
- // alert("此請購單")
- // }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("詢價單 供應商查詢 " + new_id + " 未成功")
- } else {
- alert("詢價單 供應商查詢 thrownError" + thrownError)
- }
- }
- })
-
- }
- // 新增比價項目
- function insert_PR_parity_item(id) {
- // __1. 取得新供應商編號
- var PR_parity_supplier = $("#" + id + "_parity_supplier").val();
- // 判斷新供應商編號是否未選擇
- if (PR_parity_supplier == '00') {
- alert("請選擇欲比價之新供應商")
- return false
- }
- var new_id = id.substring(0, 8) + PR_parity_supplier
- alert("新供應商為 " + PR_parity_supplier + "\n新內部料號為 " + new_id)
-
- // __2. 零件表建立零件
- sql = 'INSERT INTO 零件表( `內部料號`, `會計科目`, `類別`, `流水號`, `供應商`, `名稱`)' +
- ' SELECT "' + new_id + '" AS `內部料號`, `會計科目`, `類別`, `流水號`, "' + PR_parity_supplier + '" AS `供應商`, `名稱`' +
- ' FROM 零件表 WHERE `內部料號` ="' + id + '"';
- var sql_data = { "sql":sql };
- console.log("sql: " + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("零件表 : 比價零件 " + new_id + " 新增成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("零件表 : 比價零件 " + new_id + " 未成功")
- } else {
- alert("零件表 : 比價零件 thrownError" + thrownError)
- }
- }
- })
- // __3. 規格表建立零件
- sql = 'INSERT INTO 規格表' +
- ' (`內部料號`, `原廠料號`, `單位`, `圖片`, `圖號`, `版次`, `檔案路徑`, ' +
- ' `尺寸`, `封裝/材質`, `工作電壓`, `工作電流`, `最大電流`, `功率`, `工作溫度`, `備註`)' +
- ' SELECT ' +
- ' "' + new_id + '" AS `內部料號`,' +
- ' `原廠料號`, `單位`, `圖片`, `圖號`, `版次`, `檔案路徑`, `尺寸`, `封裝/材質`, `工作電壓`, `工作電流`, `最大電流`, `功率`, `工作溫度`, `備註`' +
- ' FROM 規格表' +
- ' WHERE `內部料號` ="' + id + '"';
- var sql_data = { "sql":sql };
- console.log("sql: " + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("規格表 : 比價零件 " + new_id + " 新增成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("規格表 : 比價零件 " + new_id + " 未成功")
- } else {
- alert("規格表 : 比價零件 thrownError" + thrownError)
- }
- }
- })
- // __4. 此請購草稿建立零件:代入新內部料號、數量、請購人
- var PR_PRremark_data = USER_NAME +
- " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
- two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
- "[新增比價零件] <br>";
- sql = 'INSERT INTO ' + PR_Form_number + '(內部料號, 日期, 數量, 連結, 採購公司, 請購備註, 請購人, 請購核可, 單價, 幣別, ' +
- '營業稅, 總金額, 交期, 詢價備註, 詢價單單號, 供應商報價單號, 採購主管核可, 採購單號)' +
- ' SELECT' +
- ' "' + new_id + '" AS 內部料號,' +
- ' CURRENT_TIME() AS 日期,' +
- ' 數量,' +
- ' "" AS 連結,' +
- ' "" AS 採購公司,' +
- ' "' + PR_PRremark_data + '" AS 請購備註,' +
- ' 請購人,' +
- ' "0" AS 請購核可,' +
- ' "" AS 單價,' +
- ' "" AS 幣別,' +
- ' "" AS 營業稅,' +
- ' "" AS 總金額,' +
- ' "" AS 交期,' +
- ' "" AS 詢價備註,' +
- ' "" AS 詢價單單號,' +
- ' "" AS 供應商報價單號,' +
- ' "1" AS 採購主管核可,' +
- ' "" AS 採購單號' +
- ' FROM ' + PR_Form_number +
- ' WHERE 內部料號 ="' + id + '"';
- var sql_data = { "sql":sql };
- console.log("sql: " + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購 : 比價零件 " + new_id + " 新增成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購 : 比價零件 " + new_id + " 未成功")
- } else {
- alert("請購 : 比價零件 thrownError" + thrownError)
- }
- }
- })
- }
- // 新增零件時, 選擇內部料號後, 出現規格表相關內容
- function get_id_standard(id) {
- var new_PR_id = document.getElementById(id).value;
- // alert("get_id_standard Test: " + new_PR_id)
- sql = 'SELECT 零件表.名稱, `原廠料號`, `單位`, `圖片`, 零件表.供應商' +
- ' FROM 零件表' +
- ' INNER JOIN 規格表' +
- ' ON 零件表.內部料號 = 規格表.內部料號' +
- ' WHERE 零件表.內部料號 = "' + new_PR_id + '"';
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- if (res.labels == '') {
- alert(new_PR_id + " 無此零件")
- document.getElementById('PR_id').value = '';
- document.getElementById('new_PR_name').innerText = '';
- document.getElementById('new_PR_type').innerText = '';
- document.getElementById('new_PR_unit').innerText = '';
- document.getElementById('new_PR_picture').innerText = '';
- document.getElementById('new_PR_supplier').innerText = '';
- } else {
- // 名稱
- document.getElementById('new_PR_name').innerText = res.labels[0][0];
- // 原廠料號
- document.getElementById('new_PR_type').innerText = res.labels[0][1];
- // 單位
- document.getElementById('new_PR_unit').innerText = res.labels[0][2];
- // 圖片
- document.getElementById('new_PR_picture').innerText = res.labels[0][3];
- // 供應商
- document.getElementById('new_PR_supplier').innerText = res.labels[0][4];
- }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("新增零件取值 : " + new_PR_id + " 未成功")
- } else {
- alert("新增零件取值 thrownError" + thrownError)
- }
- }
- })
- }
- // 把日期數字變成兩位數
- function two(params) {
- var date_num = parseInt(params)
- if ( date_num < 10) {
- new_date_num = '0' + String(date_num)
- } else {
- new_date_num = String(date_num)
- }
- return new_date_num
- }
- //
- function insert_new_PRremark(id){
- // 取得原本的請購備註內容
- var old_remark = document.getElementById(id + '_PRremark');
- var old_remark_data = old_remark.innerHTML;
- console.log("old_remark_data: " + old_remark_data)
- // 取得新增的請購備註內容
- var new_remark = document.getElementById(id + '_new_PRremark').value;
- console.log("new_remark: " + new_remark)
- // 組合文字 Rita (2022/02/10 17:55:00) 說:急, 缺, 一定要買!
- var new_remark_data = USER_NAME +
- " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
- two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
- new_remark;
- console.log("new_remark_data: " + new_remark_data)
-
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
- ' WHERE `內部料號`="' + id + '";';
- console.log("[insert_new_PRremark]sql: " + sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購單 " + PR_Form_number + " : " + id + " 請購備註修改成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 請購備註未修改")
- } else {
- alert("修改請購單請購備註內容 thrownError" + thrownError)
- }
- }
- })
- }
- //
- function update_PR_item(id) {
- console.log("修改: " + id)
- var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson',
- 'PRmanagercheck', 'currency', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
- for (let i = 1; i < PR_title_list.length; i++) {
- // if (i != 1 && i != 2 && i != 5 && i != 6 && i != 8 && i != 10 && i != 11 && i != 17) {
- if (PR_title_list[i] == 'amount' || PR_title_list[i] == 'hyperlink' ||
- PR_title_list[i] == 'currency' || PR_title_list[i] == 'unitprice' || PR_title_list[i] == 'salestax' ||
- PR_title_list[i] == 'totalprice' || PR_title_list[i] == 'leadtime' || PR_title_list[i] == 'RFQremark' ||
- PR_title_list[i] == 'RFQsupplierquote') {
- console.log('[update_PR_item] i: ' + i)
- var target_id = document.getElementById(id + '_' + PR_title_list[i]);
- var old_name = target_id.innerText;
- console.log('old_name: ', old_name)
- target_id.innerHTML = "";
- if (PR_title_list[i] == 'hyperlink'){
- textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 240px">';
- } else if (PR_title_list[i] == 'RFQsupplierquote'){
- textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 210px">';
- } else if (PR_title_list[i] == 'currency'){
- textarea = '<select id="'+ id + '_' + PR_title_list[i] + '_ta' + '">' +
- '<option value="TWD">TWD</option>' +
- '<option value="CNY">CNY</option>' +
- '<option value="USD">USD</option>' +
- '</select>';
- } else {
- textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 80px">';
- }
- if (PR_title_list[i] == 'RFQsupplierquote') {
- textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
- }
- target_id.insertAdjacentHTML('beforeend', textarea);
- }
- if (PR_title_list[i] == 'currency') {
- $("#" + id + "_currency_ta").val(old_name);
- }
- }
- }
- // 修改請購單內項目 確認
- function update_comfirm_PR_item(id) {
- console.log("修改: " + id)
- var new_amount_value = $('#' + id + '_amount_ta').val();
- var new_hyperlink_value = $('#' + id + '_hyperlink_ta').val();
- var new_currency_value = $('#' + id + '_currency_ta').val();
- var new_unitprice_value = $('#' + id + '_unitprice_ta').val();
- var new_salestax_value = $('#' + id + '_salestax_ta').val();
- var new_totalprice_value = $('#' + id + '_totalprice_ta').val();
- var new_leadtime_value = $('#' + id + '_leadtime_ta').val();
- var new_RFQremark_value = $('#' + id + '_RFQremark_ta').val();
- var new_RFQsupplierquote_value = $('#' + id + '_RFQsupplierquote_ta').val();
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `數量`="' + new_amount_value + '"' +
- ', `連結`="' + new_hyperlink_value + '"' +
- ', `幣別`="' + new_currency_value + '"' +
- ', `單價`="' + new_unitprice_value + '"' +
- ', `營業稅`="' + new_salestax_value + '"' +
- ', `總金額`="' + new_totalprice_value + '"' +
- ', `交期`="' + new_leadtime_value + '"' +
- ', `詢價備註`="' + new_RFQremark_value + '"' +
- ', `供應商報價單號`="' + new_RFQsupplierquote_value + '"' +
- ' WHERE `內部料號`="' + id + '";';
- console.log('sql: ' + sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
- } else {
- alert("修改請購單項目內容 thrownError" + thrownError)
- }
- }
- })
- }
- // 刪除請購單內項目
- function delete_PR_item(id) {
- console.log("刪除: " + id)
- var comfirm_delete_PR_item = confirm("確定要刪除 " + id + " 零件嗎?")
- if (comfirm_delete_PR_item) {
- sql = 'DELETE FROM ' + PR_Form_number + ' WHERE 內部料號 = "' + id + '";'
- sql_data = { "sql":sql };
- console.log("delete_PR_item[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購單 " + PR_Form_number + " : " + id + " 刪除成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未刪除")
- } else {
- alert("刪除請購單內容 thrownError" + thrownError)
- }
- }
- })
- }
- }
- // 主管核可 勾選 / 取消時都要提醒
- function checkbox_check(id) {
- var checkbox_id = $('#' + id + '_PRmanager_check').prop("checked");
- // console.log("checkbox_id: " + checkbox_id)
- if (checkbox_id == true) {
- // 主管勾選核可 從空白到勾選
- var checkbox_confirm_true = confirm("核可該零件採購, 請按確定")
- if (checkbox_confirm_true) {
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `請購主管核可`="1"' +
- ' WHERE `內部料號`="' + id + '";';
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
- } else {
- alert("修改請購單項目內容 thrownError" + thrownError)
- }
- }
- })
- } else {
- $('#' + id + '_PRmanager_check').prop('checked', false);
- }
- } else {
- // 主管不核可 從勾選到空白
- var checkbox_confirm_false = confirm("取消該零件採購, 請按確定取消該零件採購\n(或是刪除該零件)")
- if (checkbox_confirm_false) {
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `請購主管核可`="0"' +
- ' WHERE `內部料號`="' + id + '";';
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("請購單 " + PR_Form_number + " : " + id + " 項目修改成功 !")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 項目未修改")
- } else {
- alert("修改請購單項目內容 thrownError" + thrownError)
- }
- }
- })
- } else {
- $('#' + id + '_PRmanager_check').prop('checked', true);
- }
- }
- }
- // 主管核可後, 開始詢價
- function RFQ_to_manager() {
- for (let i = 0; i < data_id.length; i++) {
- var unitprice_exist = $('#' + data_id[i] + '_unitprice').text();
- // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
- if (unitprice_exist == '' || parseInt(unitprice_exist) < 0 ) {
- alert(data_id[i] + " 請輸入正確的金額")
- return false
- }
- }
- var confirm_to_user = confirm('本表單即將送出給直屬主管, 請點選[確定]送出表單')
- if (confirm_to_user) {
- // 狀態更新為 比價中
- sql = "UPDATE `表單詳細資料` SET `表單狀態` = '比價中' " +
- "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
-
- sql_data = { "sql":sql };
- console.log("RFQ_to_manager[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("調整狀態為\"比價中\"")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("送出調整狀態 未成功")
- } else {
- alert("送出調整狀態 thrownError" + thrownError)
- }
- }
- })
- // 通知採購主管
- sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
- USER_MANAGER + "','" +
- PR_Form_number + "','" +
- USER_NAME + " 請求比價')";
- sql_data = { "sql":sql };
- console.log("RFQ_to_manager[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("已通知採購主管進行比價")
- window.location.assign("/PR_list")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("比價通知 未成功")
- } else {
- alert("比價通知 thrownError" + thrownError)
- }
- }
- })
- }
- }
-
- // 產生詢價單
- function create_RFQ_form(params) {
- // 1. 確認目前請購單的採購公司皆輸入
- var is_POcompany_empty = true;
- sql = 'SELECT 採購公司 FROM `' + PR_Form_number + '`'
- sql_data = { "sql":sql };
- console.log("delete_PR_item[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- for (let l = 0; l < res.labels.length; l++) {
- if (res.labels[l] == '') {
- is_POcompany_empty = true;
- alert("請購單之採購公司不得為空, 或請刪除該項目")
- } else {
- is_POcompany_empty = false;
- }
- }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("確認採購單之採購公司皆輸入 未成功")
- } else {
- alert("確認採購單之採購公司皆輸入 thrownError" + thrownError)
- }
- }
- })
- // 若採購公司空白, 則跳出 function
- if (is_POcompany_empty) {
- return false
- }
- // 2. 找到詢價單號 0711xxxxT01 / 0711ooooT02
- sql = 'SELECT DISTINCT `TABLE_NAME` FROM information_schema.columns ' +
- 'WHERE `TABLE_NAME` LIKE "%0711%" AND `TABLE_NAME` LIKE "%T01%" ' +
- 'ORDER BY `TABLE_NAME` DESC LIMIT 1'
- sql_data = { "sql":sql };
- // console.log("[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/table_sn_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- console.log("res.new_sn: " + res.new_sn)
- console.log("res.new_table_id: " + res.new_table_id)
- // for (let l = 0; l < res.labels.length; l++) {
- // if (res.labels[l] == '') {
- // is_POcompany_empty = true;
- // alert("請購單之採購公司不得為空, 或請刪除該項目")
- // } else {
- // is_POcompany_empty = false;
- // }
- // }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("確認採購單之採購公司皆輸入 未成功")
- } else {
- alert("確認採購單之採購公司皆輸入 thrownError" + thrownError)
- }
- }
- })
-
- // 3. 依採購公司區分詢價單, 採購公司 T01 者歸類到 0711xxxxT01, 同 T02
- // 4. 填入目前請購單項目的詢價單單號
- }
- // 請購人員 送出請購單
- function PR_to_Purchase() {
- alert("請購單 " + PR_Form_number + " 完成, 將通知採購人員 !")
- }
- // 採購人員 修改採購公司
- function Purchase_update_sup() {
- var purchase_company = prompt("請注意 ! 輸入採購公司後將無法修改 ! \n\n請輸入採購公司 :\nT01 : 金子進\nT02 : 瑞智")
- console.log("purchase_company: " + purchase_company)
- var new_PR_companyid = PR_Form_number.substring(0, 8) + purchase_company;
- console.log("new_PR_companyid: " + new_PR_companyid)
- sql = "RENAME TABLE `" + PR_Form_number + "` TO `" + new_PR_companyid + "`";
- sql_data = { "sql":sql };
- console.log("Purchase_update_sup[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("已將請購單更名為 " + new_PR_companyid + "")
- window.location.assign("/PR_user_" + new_PR_companyid)
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + ": 已存在")
- } else {
- alert("請購單更名錯誤 thrownError" + thrownError)
- }
- }
- })
- }
- function insert_PR_item() {
- // var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson',
- // 'PRmanagercheck', 'currency', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
- var PR_id = $("#PR_id").val()
- var PR_amount = $("#PR_amount").val()
- var PR_supplier = $("#PR_supplier").val()
- var PR_hyperlink = $("#PR_hyperlink").val()
- var PR_PRperson = $("#PR_PRperson").val()
- var RFQ_currency = $("#RFQ_currency").val()
- var RFQ_unitprice = $("#RFQ_unitprice").val()
- var RFQ_salestax = $("#RFQ_salestax").val()
- var RFQ_totalprice = $("#RFQ_totalprice").val()
- var RFQ_leadtime = $("#RFQ_leadtime").val()
- var RFQ_RFQremark = $("#RFQ_RFQremark").val()
- var RFQ_RFQsupplierquote = $("#RFQ_RFQsupplierquote").val()
- var PR_PRremark = $("#PR_PRremark").val()
- var PR_PRremark_data = USER_NAME +
- " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
- two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
- "[新增零件] " + PR_PRremark + "<br>";
- sql = 'INSERT INTO `' + PR_Form_number + '` ' +
- '(內部料號, 日期, 數量, 連結, 請購人, 幣別, 單價, 營業稅, 總金額, 交期, 詢價備註, 供應商報價單號, 請購備註)' +
- ' VALUES ("' + PR_id +
- '", current_timestamp(), "' +
- PR_amount + '", "' +
- PR_hyperlink + '", "' +
- PR_PRperson + '", "' +
-
- RFQ_currency + '", "' +
- RFQ_unitprice + '", "' +
- RFQ_salestax + '", "' +
- RFQ_totalprice + '", "' +
- RFQ_leadtime + '", "' +
- RFQ_RFQremark + '", "' +
- RFQ_RFQsupplierquote + '", "' +
- PR_PRremark_data + '");';
- var sql_data = { "sql":sql };
- console.log("insert_PR_item[sql]:" + sql)
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- console.log("res.sql_data: " + res.sql_data)
- if (res.sql_data != '') {
- alert(res.sql_data)
- } else {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 新增成功 !")
- location.reload()
- }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 " + PR_Form_number + " : " + PR_id + " 未新增")
- } else {
- alert("新增請購單內容 thrownError" + thrownError)
- }
- }
- })
- }
- </script>
- <!--
- 九威金屬設計公司 : <a href="/RFQ_form_07110001Txx_T01" target="_blank">預覽詢價單 07120002T23</a>
- —
- <a href="/download/07120001T01.pdf" target="_blank">下載</a>
- -->
- </body>
- </html>
|