123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990 |
- <!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 FORM_RFQ_USER = '{{form_RFQ_user}}'
- console.log("FORM_RFQ_USER: " + FORM_RFQ_USER);
- var FORM_PR_USER = '{{form_PR_user}}'
- console.log("FORM_PR_USER: " + FORM_PR_USER);
- var FORM_PR_MANAGER = '{{form_PR_manager}}'
- console.log("FORM_PR_MANAGER: " + FORM_PR_MANAGER);
- var FORM_STATUS = '{{form_status}}';
- var data_id = []; // 存放此資料表所有的內部料號
- // 取得現在時間 紀錄請購備註時使用
- var Today = new Date();
- // 顯示零件名稱標題用
- var tr_title_id_target = '00000000';
- // 採購員工列表
- var RFQ_person_staff = [];
- // 取得網址資訊
- var HOST = window.location.host;
- window.onload = function(){
- create_PR_list();
- create_PO_list();
- }
- function create_PR_list() {
- let PRcompany_T01_haveitem = false;
- let PRcompany_T02_haveitem = false;
- for (let i = 0; i < data_id.length; i++) {
- var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
- // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
- if (PRcompany_exist == 'T01') {
- PRcompany_T01_haveitem = true;
- } else if (PRcompany_exist == 'T02') {
- PRcompany_T02_haveitem = true;
- }
- }
- var PR_form_list = '';
- if (PRcompany_T01_haveitem) {
- PR_form_list += '<br>金子進 : <a href="/PR_form_' + PR_Form_number + '_T01" target="_blank">預覽請購單 ' + PR_Form_number.substring(0, 8) + 'T01</a>' +
- '—' +
- '<a href="/DL/' + HOST + '/PR/' + PR_Form_number + '_T01" target="_blank">下載</a>'
- }
- if (PRcompany_T02_haveitem) {
- PR_form_list += '<br>瑞智 : <a href="/PR_form_' + PR_Form_number + '_T02" target="_blank">預覽請購單 ' + PR_Form_number.substring(0, 8) + 'T02</a>' +
- '—' +
- '<a href="/DL/' + HOST + '/PR/' + PR_Form_number + '_T02" target="_blank">下載</a>'
- }
- PR_sup_list.insertAdjacentHTML('beforeend', PR_form_list);
- }
- function create_PO_list() {
- let PRcompany_T01_itemlist = [];
- let PRcompany_T02_itemlist = [];
- for (let i = 0; i < data_id.length; i++) {
- var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
- var supplier_text = $('#' + data_id[i] + '_supplier').text();
- if (PRcompany_exist == 'T01' && !PRcompany_T01_itemlist.includes(supplier_text)) {
- PRcompany_T01_itemlist.push(supplier_text);
- } else if (PRcompany_exist == 'T02' && !PRcompany_T02_itemlist.includes(supplier_text)) {
- PRcompany_T02_itemlist.push(supplier_text);
- }
- }
- console.log("PRcompany_T01_itemlist: " + PRcompany_T01_itemlist)
- console.log("PRcompany_T02_itemlist: " + PRcompany_T02_itemlist)
- var PO_form_list = '';
- if (PRcompany_T01_itemlist.length != 0) {
- PO_form_list += '<br>金子進 : <br>';
- for (let x = 0; x < PRcompany_T01_itemlist.length; x++) {
- PO_form_list += '<a href="#" target="_blank">預覽採購單 0713' + PR_Form_number.substring(4, 8) + PRcompany_T01_itemlist[x] + '</a>' +
- '—' +
- '<a href="#" target="_blank">下載</a><br>'
- }
- }
- if (PRcompany_T02_itemlist.length != 0) {
- PO_form_list += '瑞智 : <br>';
- for (let x = 0; x < PRcompany_T02_itemlist.length; x++) {
- PO_form_list += '<a href="#" target="_blank">預覽採購單 0713' + PR_Form_number.substring(4, 8) + PRcompany_T02_itemlist[x] + '</a>' +
- '—' +
- '<a href="#" target="_blank">下載</a><br>'
- }
- }
- PO_sup_list.insertAdjacentHTML('beforeend', PO_form_list);
-
- }
-
- </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>
- {% for staff in staff_data %}
- <script>
- RFQ_person_staff.push('{{staff[0]}}' + '-' + '{{staff[1]}}')
- console.log("RFQ_person_staff: " + RFQ_person_staff)
- </script>
- {% endfor %}
- <center><h6 style="margin: 20px;">新增請購單</h6></center>
- 目前使用者:{{user_name}}<br>
- 請購單號:<span>{{PR_Form_number}}</span><br>
- 表單狀態:{{form_status}}<br>
- 用途:{{form_purpose}}<br>
- <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[17] == 1 %}
- <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')" checked>
- {% else %}
- <input type="checkbox" id="{{datas[0]}}_RFQmanagercheck" onclick="checkbox_check('{{datas[0]}}')">
- {% endif %}
- </th>
- <th>內部料號</th>
- <th>名稱</th>
- <th>原廠料號</th>
- <th>數量</th>
- <th>單位</th>
- <th>圖片</th>
- <th>供應商</th>
- <th>連結</th>
- <th>請購人</th>
- <th>
- {% if form_status == "採購公司設定" %}
- 修改
- {% endif %}
- </th>
- </tr>
- <script>
- // 取得所有內部料號
- data_id.push('{{datas[0]}}');
- </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[8]}}</td>
- <td rowspan="3" style="vertical-align: middle;">
- {% if form_status == "採購公司設定" %}
- <input type="button" class="input-cond-add" value="修改" onclick="update_PR_item('{{datas[0]}}')">
- {% endif %}
- </td>
- <!-- {% if datas[10] == 1 %}
- <td id="{{datas[0]}}_PRmanagercheck">OK</td>
- {% else %}
- <td id="{{datas[0]}}_PRmanagercheck"></td>
- {% endif %} -->
- </tr>
- <tr class="table-tr-data">
- <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]}}_currency">{{datas[9]}}</td>
- <td id="{{datas[0]}}_unitprice">{{datas[10]}}</td>
- <td id="{{datas[0]}}_salestax">{{datas[11]}}</td>
- <td id="{{datas[0]}}_totalprice">{{datas[12]}}</td>
- <td id="{{datas[0]}}_leadtime">{{datas[13]}}</td>
- <td id="{{datas[0]}}_RFQremark">{{datas[14]}}</td>
- <td id="{{datas[0]}}_RFQformid">{{datas[15]}}</td>
- <td id="{{datas[0]}}_RFQsupplierquote">{{datas[16]}}</td>
- <td id="{{datas[0]}}_PRcompany">{{datas[18]}}</td>
- </tr>
- <tr>
- <td colspan="11">
- <span style="font-weight: bold;">請購備註 : </span>
- <input type="text" id="{{datas[0]}}_new_PRremark" style="height: 25px; width: 50%;">
- <input type="button" id="PR_new_PRremark" value="新增備註" style="height: auto;" onclick="insert_new_PRremark('{{datas[0]}}')">
- <br>
- <span id="{{datas[0]}}_PRremark">{{datas[19]|safe}}</span>
- </td>
- </tr>
- </tbody>
- {% endfor %}
- <tr>
- <td>
- {% if form_status == "比價中" %}
- <input type="button" class="input-cond-action" value="←駁回" onclick="RFQ_to_user()">
- {% endif %}
- </td>
- <td colspan="4">
- {% if form_status == "詢價中" or form_status == "比價中" or form_status == "請購詢價完成" %}
- <!-- <input type="button" class="input-cond-action" value="產生請購單" onclick="select_PR_sup_form()" style="width: auto;"> -->
- <!-- (點擊後即下載 PDF 至「本機/下載」中, 亦可點擊以下連結顯示網頁版請購單) -->
- <span id="PR_sup_list">請購單列表 : </span>
- {% endif %}
- </td>
- <td colspan="4">
- {% if form_status == "請購詢價完成" %}
- <span id="PO_sup_list">採購單列表 : </span>
- {% endif %}
- </td>
- <td colspan="2" align="right">
- {% if form_status == "採購公司設定" %}
- <select id="RFQ_RFQuser">
- <option value=""></option>
- {% for staff in staff_data %}
- <option value="{{staff[0]}}">{{staff[0]}} - {{staff[1]}}</option>
- {% endfor %}
- </select>
- <input type="button" class="input-cond-action" value="指派採購人員→" onclick="PR_set_RFQuser()">
- {% elif form_status == "比價中" %}
- <input type="button" class="input-cond-action" value="決行→" onclick="PR_to_Purchase()">
- {% elif form_status == "請購詢價完成" %}
- <input type="button" class="input-cond-action" value="前往採購頁面" onclick="createPOpage()">
- {% endif %}
- </td>
- </tr>
- </table>
- <script>
- var sql = '';
- function createPOpage() {
- alert("建立採購單 TABLE")
-
- }
- // 採購主管 指派 採購人員
- function PR_set_RFQuser() {
- // 1. 確認每個零件都有採購公司
- for (let i = 0; i < data_id.length; i++) {
- var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
- // console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
- if (PRcompany_exist != 'T01' && PRcompany_exist != 'T02') {
- alert(data_id[i] + " 請輸入採購公司")
- return false
- }
- }
-
- // 2. 取得採購人員員工編號
- var RFQ_user = $('#RFQ_RFQuser').val();
- if (RFQ_user == '') {
- alert("請選擇採購人員")
- return false
- }
- // 3. 儲存採購人員
- sql = "UPDATE `表單詳細資料` SET `採購人員工編號` = '" + RFQ_user + "' " +
- "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
- 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("儲存採購人員")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("儲存採購人員 未成功")
- } else {
- alert("儲存採購人員 thrownError" + thrownError.statusText)
- }
- }
- })
- // 4. 儲存狀態:詢價中
- sql = "UPDATE `表單詳細資料` SET `表單狀態` = '詢價中' " +
- "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
-
- sql_data = { "sql":sql };
- console.log("PR_set_RFQuser[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)
- }
- }
- })
- // 5. 通知採購人員
- sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" +
- RFQ_user + "','" +
- PR_Form_number + "','" +
- USER_NAME + " 已指定採購公司')";
- sql_data = { "sql":sql };
- console.log("PR_set_RFQuser[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 select_PR_sup_form() {
- let PRcompany_T01_haveitem = false;
- let PRcompany_T02_haveitem = false;
- for (let i = 0; i < data_id.length; i++) {
- var checkbox_is_check = $('#' + data_id[i] + '_RFQmanagercheck').prop("checked")
- console.log(data_id[i] + " checkbox_is_check: " + checkbox_is_check)
- var PRcompany_exist = $('#' + data_id[i] + '_PRcompany').text();
- console.log(data_id[i] + " PRcompany_exist: " + PRcompany_exist)
- // 採購主管核可打勾 + 採購公司 != T01 + 採購公司 != T02, 判定為未填寫採購公司
- if (checkbox_is_check == true) {
- if (PRcompany_exist == 'T01') {
- PRcompany_T01_haveitem = true;
- } else if (PRcompany_exist == 'T02') {
- PRcompany_T02_haveitem = true;
- } else {
- alert(data_id[i] + " 已核可, 請輸入採購公司")
- return false
- }
- }
- console.log(data_id[i] + " OK")
- }
- if (PRcompany_T01_haveitem) {
- $.ajax({
- type:"GET",
- url:"/PDF_create/PR/" + PR_Form_number + "_T01",
- dataType:"JSON",
- data:"",
- async:false,
- success:function (response) {
- document.location.href = '/download/' + PR_Form_number.substring(0, 8) + 'T01.pdf'
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 T01 建立 " + PR_Form_number.substring(0, 8) + "T01 未成功")
- } else {
- alert("請購單 T01 建立 thrownError" + thrownError)
- }
- }
- })
- }
- if (PRcompany_T02_haveitem) {
- $.ajax({
- type:"GET",
- url:"/PDF_create/PR/" + PR_Form_number + "_T02",
- dataType:"JSON",
- data:"",
- async:false,
- success:function (response) {
- document.location.href = '/download/' + PR_Form_number.substring(0, 8) + 'T02.pdf'
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("請購單 T02 建立 " + PR_Form_number.substring(0, 8) + "T02 未成功")
- } else {
- alert("請購單 T02 建立 thrownError" + thrownError)
- }
- }
- })
-
- }
-
- }
- // 採購主管駁回
- function RFQ_to_user() {
- var confirm_RFQ_to_user = confirm("確定將此請購單駁回給採購人員 ?\n溫馨提醒 : 可填寫請購備註告知駁回原因")
- if (confirm_RFQ_to_user) {
- // 狀態更新為 詢價中
- sql = "UPDATE `表單詳細資料` SET `表單狀態` = '詢價中' " +
- "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
-
- sql_data = { "sql":sql };
- console.log("RFQ_to_user[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 ('" +
- FORM_RFQ_USER + "','" +
- PR_Form_number + "','" +
- USER_NAME + " 已駁回')";
- sql_data = { "sql":sql };
- console.log("RFQ_to_user[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)
- }
- }
- })
- } else {
- alert("取消駁回")
- }
-
- }
- // 主管核可 勾選 / 取消時都要提醒
- function checkbox_check(id) {
- var checkbox_id = $('#' + id + '_RFQmanagercheck').prop("checked");
- // console.log("checkbox_id: " + checkbox_id)
- if (checkbox_id == true) {
- // 主管勾選核可 從空白到勾選
- var checkbox_confirm_true = prompt("[勾選 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
- console.log("checkbox_confirm_true: " + checkbox_confirm_true)
- if (checkbox_confirm_true == '') {
- $('#' + id + '_RFQmanagercheck').prop('checked', false);
- alert("未輸入內容, 核可狀態未修改")
- } else if (checkbox_confirm_true == null) {
- $('#' + id + '_RFQmanagercheck').prop('checked', false);
- alert("取消, 核可狀態未修改")
- } else {
- var old_remark = document.getElementById(id + '_PRremark');
- var old_remark_data = old_remark.innerHTML;
- var new_remark_data = USER_NAME +
- " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
- two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
- "[核可勾選] " +
- checkbox_confirm_true;
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `採購主管核可`="1"' +
- ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
- ' WHERE `內部料號`="' + id + '";';
- var sql_data = { "sql":sql };
- console.log("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 {
- // 主管不核可 從勾選到空白
- var checkbox_confirm_false = prompt("[取消 " + id + "]\n若要改變核可狀態, 請輸入請購備註:")
- console.log("checkbox_confirm_false: " + checkbox_confirm_false)
- if (checkbox_confirm_false == '') {
- $('#' + id + '_RFQmanagercheck').prop('checked', true);
- alert("未輸入內容, 核可狀態未修改")
- } else if (checkbox_confirm_false == null) {
- $('#' + id + '_RFQmanagercheck').prop('checked', true);
- alert("取消, 核可狀態未修改")
- } else {
- var old_remark = document.getElementById(id + '_PRremark');
- var old_remark_data = old_remark.innerHTML;
- var new_remark_data = USER_NAME +
- " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " +
- two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" +
- "[核可取消] " +
- checkbox_confirm_false;
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `採購主管核可`="0"' +
- ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
- ' WHERE `內部料號`="' + id + '";';
- var sql_data = { "sql":sql };
- console.log("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 (PR_title_list[i] == 'PRcompany') {
- 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] == 'PRcompany') {
- textarea = '<select id="'+ id + '_' + PR_title_list[i] + '_ta' + '">'
- textarea += '<option value="T01">T01-金子進</option>';
- textarea += '<option value="T02">T02-瑞智</option>';
- textarea += '</select>'
- textarea += '<br><input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
- }
- target_id.insertAdjacentHTML('beforeend', textarea);
- }
- if (PR_title_list[i] == 'PRcompany') {
- $("#" + id + "_PRcompany_ta").val(old_name);
- }
- }
- }
- // 修改請購單內項目 確認
- function update_comfirm_PR_item(id) {
- console.log("修改: " + id)
- // 修改採購公司
- var new_PRcompany_value = $('#' + id + '_PRcompany_ta').val();
- // 修改請購備註
- // var old_remark = document.getElementById(id + '_PRremark');
- // var old_remark_data = old_remark.innerHTML;
- var old_remark_data = document.getElementById(id + '_PRremark').innerHTML;
- 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_PRcompany_value + " ] ";
- sql = 'UPDATE ' + PR_Form_number +
- ' SET `採購公司`="' + new_PRcompany_value + '"' +
- ', `請購備註`="' + old_remark_data + new_remark_data + '<br>' + '"' +
- ' 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 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 PR_to_Purchase() {
- var checkbox_check_id = [];
- for (let i = 0; i < data_id.length; i++) {
- var checkbox_is_check = $('#' + data_id[i] + '_RFQmanagercheck').prop("checked")
- console.log("checkbox_is_check: " + checkbox_is_check)
- if (checkbox_is_check == true) {
- checkbox_check_id.push(data_id[i])
- }
- }
- if (checkbox_check_id == '') {
- alert("未有零件選取, 取消決行")
- return false
- } else {
- alert("選取 " + checkbox_check_id.length + " 項零件, 進入採購流程")
- }
- // 狀態更新為 請購詢價完成
- sql = "UPDATE `表單詳細資料` SET `表單狀態` = '請購詢價完成' " +
- "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
-
- sql_data = { "sql":sql };
- console.log("PR_to_Purchase[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 " +
- "('" + FORM_PR_USER + "','" + PR_Form_number + "','" + USER_NAME + " 已決行')," +
- "('" + FORM_PR_MANAGER + "','" + PR_Form_number + "','" + USER_NAME + " 已決行')";
- sql_data = { "sql":sql };
- console.log("PRuser_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 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', 'PRremark', 'PRperson',
- // 'PRmanagercheck', 'PRcompany', 'unitprice', 'salestax', 'totalprice', 'leadtime', 'RFQremark', 'RFQformid', 'RFQsupplierquote']
- var PR_id = $("#PR_id").val()
- var PR_amount = $("#PR_amount").val()
- var PR_unit = $("#PR_unit").val()
- var PR_supplier = $("#PR_supplier").val()
- var PR_hyperlink = $("#PR_hyperlink").val()
- var PR_PRremark = $("#PR_PRremark").val()
- var PR_PRperson = $("#PR_PRperson").val()
- var RFQ_PRcompany = $("#RFQ_PRcompany").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()
- console.log("PR_id: " + PR_id)
- console.log("PR_amount: " + PR_amount)
- console.log("PR_unit: " + PR_unit)
- console.log("PR_supplier: " + PR_supplier)
- console.log("PR_hyperlink: " + PR_hyperlink)
- console.log("PR_PRremark: " + PR_PRremark)
- console.log("PR_PRperson: " + PR_PRperson)
- console.log("RFQ_PRcompany: " + RFQ_PRcompany)
- console.log("RFQ_unitprice: " + RFQ_unitprice)
- console.log("RFQ_salestax: " + RFQ_salestax)
- console.log("RFQ_totalprice: " + RFQ_totalprice)
- console.log("RFQ_leadtime: " + RFQ_leadtime)
- console.log("RFQ_RFQremark: " + RFQ_RFQremark)
- console.log("RFQ_RFQsupplierquote: " + RFQ_RFQsupplierquote)
-
- sql = 'INSERT INTO `' + PR_Form_number + '` ' +
- '(內部料號, 日期, 數量, 單位, 連結, 請購備註, 請購人, 採購公司, 單價, 營業稅, 總金額, 交期, 詢價備註, 供應商報價單號)' +
- ' VALUES ("' + PR_id +
- '", current_timestamp(), "' +
- PR_amount + '", "' +
- PR_unit + '", "' +
- PR_hyperlink + '", "' +
- PR_PRremark + '", "' +
- PR_PRperson + '", "' +
-
- RFQ_PRcompany + '", "' +
- RFQ_unitprice + '", "' +
- RFQ_salestax + '", "' +
- RFQ_totalprice + '", "' +
- RFQ_leadtime + '", "' +
- RFQ_RFQremark + '", "' +
- RFQ_RFQsupplierquote + '");';
- 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="/PR_form_07110001Txx_T01" target="_blank">預覽請購單 07110001T01</a>
- —
- <a href="/PDF_create/PR/07110001Txx_T01" target="_blank">產生</a>
- —
- <a href="/download/07110001T01.pdf" target="_blank">下載PDF</a>
- <br> -->
- <!-- <a onclick="javascript:Foo('T01');" href="#">不影響 GIF 的連結</a> -->
- <!-- <a href="/DL/PR/07110001Txx_T01" target="_blank">TEST</a> -->
- <!-- function Foo(companyid) {
- document.location.href = '/PDF_create/PR/07110001Txx_T01';
- setTimeout("alert('OK')", 3000 )
- setTimeout("document.location.href = '/download/07110001T01.pdf';", 3000 )
- } -->
- </body>
- </html>
|