Ver código fonte

上傳檔案到 'Rita/ERP_Rita/templates'

rita 2 anos atrás
pai
commit
03ba0d0956

+ 38 - 0
Rita/ERP_Rita/templates/ERP_header.html

@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <!-- 0127 更新 -->
+    <!-- 新 Bootstrap4 核心 CSS 文件 -->
+    <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> -->
+    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
+    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
+    <!-- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> -->
+    <script src="../static/js/jquery.min.js"></script>
+    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
+    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> -->
+    <script src="../static/js/popper.min.js"></script>
+    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
+    <script src="../static/js/bootstrap.min.js"></script>
+    <!-- <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> -->
+    <!-- 0215 生成 PDF 用 -->
+    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
+    <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script> -->
+<!-- 舊的, 網頁讀取有問題 -->
+    <!-- 新 Bootstrap4 核心 CSS 文件 -->
+    <!-- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css"> -->
+    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
+    <!-- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> -->
+    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
+    <!-- <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script> -->
+    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
+    <!-- <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> -->
+    <!-- 可用來建立使用者小圖示 -->
+    <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> -->
+    <link rel="stylesheet" href="../static/css/font-awesome.min.css">
+</head>
+<body>
+    <div style="text-align: right;">
+        <a href="/logout">登出</a>
+    </div>
+</body>

+ 54 - 0
Rita/ERP_Rita/templates/PR.html

@@ -0,0 +1,54 @@
+<!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">
+
+    <!-- 新 Bootstrap4 核心 CSS 文件 -->
+    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
+    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
+    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
+    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
+    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
+    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
+    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
+    <!--可用來建立使用者小圖示-->
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+</head>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
+<body>
+    PR
+</body>
+
+</html>

+ 149 - 0
Rita/ERP_Rita/templates/PR_form.html

@@ -0,0 +1,149 @@
+<!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">
+    
+    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
+    <script src="../static/js/jquery.min.js"></script>
+    <script src="../static/js/popper.min.js"></script>
+    <script src="../static/js/bootstrap.min.js"></script>
+    <link rel="stylesheet" href="../static/css/font-awesome.min.css">
+
+<script>
+    var PR_Form_number = '{{PR_Form_number}}';
+    console.log("PR_Form_number: " + PR_Form_number);
+    var PR_datas_sn = 0;
+    console.log("PR_datas_sn: " + PR_datas_sn);
+</script>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+    .table_dark_bg {
+        background-color: rgb(102, 102, 102);
+        color: #FFF;
+        font-weight: bold;
+    }
+    .table_RFQ_title {
+        font-weight: bold;
+    }
+    .table-css {
+        border: 1px solid #dee2e6;
+        width: 100%;
+    }
+    .table-css td,th {
+        padding: 0.5rem;
+    }
+</style>
+
+<body>
+    <table class="table-css table-bordered" style="font-size: 14px; padding: 0.5rem;">
+        <tr>
+            <td colspan="8" style="text-align: center; font-size: 12px;">
+                {% if PR_Form_number[PR_Form_number.find('T'):] == 'T02' %}
+                    <img src="../static/img/ALMIGHTY_RAY.jpg" width="90px"><br>
+                    瑞智精技股份有限公司<br>
+                    台北市南港區南港路一段 287 巷 2 弄 8 號<br>
+                    service.gitc@gmail.com<br>
+                    (02) 2788 - 8158<br>
+                {% else %}
+                    <img src="../static/img/SKYAI.jpg" width="120px"><br>
+                    金子進科技股份有限公司<br>
+                    台北市南港區南港路一段 287 巷 2 弄 8 號 1 樓<br>
+                    fu@aisky.com.tw<br>
+                    (02) 2788 - 8598<br>
+                    傳真 02 - 2788 - 8158<br>
+                {% endif %}
+            </td>
+        </tr>
+        <tr>
+            <td colspan="8" class="table_dark_bg" style="text-align: center;">請購單</td>
+        </tr>
+        <tr>
+            <td colspan="8">
+                日期 : 
+                <span></span>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="8">
+                請購單號 : {{PR_Form_number}}
+                <span></span>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="8">
+                用途 : {{form_purpose}}
+                <span></span>
+            </td>
+        </tr>
+        <tr class="table_dark_bg" style="text-align: center;">
+            <th>編號</th>
+            <th>內部料號</th>
+            <th>零件名稱</th>
+            <th>原廠料號</th>
+            <th>圖號</th>
+            <th>數量</th>
+            <th>連結</th>
+            <th>供應商</th>
+        </tr>
+        {% for PR in PR_datas %}
+            <tr style="text-align: center;">
+                <td id="{{PR[0]}}_PR_sn">no.</td>
+                <td>{{PR[0]}}</td>
+                <td>{{PR[1]}}</td>
+                <td>{{PR[2]}}</td>
+                <td>{{PR[3]}}</td>
+                <td>{{PR[4]}}</td>
+                <td>{{PR[5]}}</td>
+                <td>{{PR[6]}}</td>
+            </tr>
+            <script>
+                PR_datas_sn = PR_datas_sn+1;
+                // console.log("[++]PR_datas_sn: " + PR_datas_sn);
+                $("#{{PR[0]}}_PR_sn").text(PR_datas_sn);
+            </script>
+        {% endfor %}
+        <tr style="text-align: center;">
+            <td colspan="8">
+                採購主管 : 
+                <span id="PR_PO_manager" style="margin: 0px 120px 0px 0px">{{form_RFQ_manager}}</span>
+                採購 : 
+                <span id="PR_PO_staff" style="margin: 0px 120px 0px 0px">{{form_RFQ_user}}</span>
+                請購主管 : 
+                <span id="PR_PR_manager" style="margin: 0px 120px 0px 0px">{{form_PR_manager}}</span>
+                請購 : 
+                <span id="PR_PR_staff" style="margin: 0px 0px 0px 0px">{{form_PR_user}}</span>
+            </td>
+        </tr>
+    </table>
+</body>
+
+</html>

+ 191 - 0
Rita/ERP_Rita/templates/PR_list.html

@@ -0,0 +1,191 @@
+<!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">
+    
+</head>
+
+<script>
+    var PR_Form_number = '{{PR_Form_number}}';
+    console.log("PR_Form_number: " + PR_Form_number);
+    var USER_NAME = '{{user_name}}';
+    console.log("USER_NAME: " + USER_NAME);
+    var USER_ID = '{{user_id}}';
+    console.log("USER_ID: " + USER_ID);
+    var USER_MANAGER = '{{user_manager}}';
+    console.log("USER_MANAGER: " + USER_MANAGER);
+    var next_PR_companyid = '0711' + '{{new_PR_companyid}}' + 'Txx';
+    console.log("next_PR_companyid: " + next_PR_companyid)
+    // $(document).ready(function() {
+    //     // $('#create_PR_table').attr("href", "/PR_user_" + next_PR_companyid);
+    // });
+</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>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <center><h6 style="margin: 20px;">請購單列表</h6></center>
+    目前使用者:{{user_name}}
+    
+    {% if notice_list != () %}
+        <a href="/notice" target="_blank" style="color: #E43030;">
+            <img src="../static/img/notice.png" style="vertical-align: super;" width="12" alt="有未讀的訊息!">
+        </a>
+    {% endif %}
+
+    <br>
+    <br>
+    <input type="button" class="input-cond-action" id="create_PR_table" value="建立新請購單草稿" onclick="create_PR_table();"><br>
+    <table class="table table-bordered" style="margin-top: 10px;">
+        <tr>
+            <th>現有請購單草稿</th>
+            <th>狀態</th>
+            <th>請購人</th>
+        </tr>
+        {% for table in PR_tables %}
+        <tr>
+            <!-- `請購草稿單號`,`表單狀態`,`員工列表`.`員工英文名字` -->
+            <td><a href="/PR_user_{{table[0].replace('t', 'T')}}" target="_blank">{{table[0].replace('t', 'T')}}</a></td>
+            <td>{{table[1]}}</td>
+            <td>{{table[2]}}</td>
+        </tr>
+        {% endfor %}
+    </table>
+</body>
+<script>
+    var next_PR_companyid;
+    var sql = "";
+
+    function create_PR_table() {
+        sql = "INSERT INTO `表單詳細資料`(`請購草稿單號`, `表單狀態`, `請購人員工編號`, `請購主管員工編號`, `採購主管員工編號`) " + 
+                "VALUES (" + 
+                "'" + next_PR_companyid + "'," + 
+                "'" + "請購申請中" + "'," + 
+                "'" + USER_ID + "'," + 
+                "'" + USER_MANAGER + "'," + 
+                "'" + "HRMA0001T01" + "')";
+                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("表單詳細資料建置完成, 將移動到請購單 : " + next_PR_companyid + "...")
+            },
+            error: function (thrownError) {
+                if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                    alert("建立表單詳細資料 " + next_PR_companyid + " 未成功")
+                } else {
+                    alert("建立表單詳細資料 thrownError" + next_PR_companyid)
+                }
+            }
+        })
+
+        sql = "CREATE TABLE `" + next_PR_companyid + "` ( " +
+                "`內部料號` varchar(11) NOT NULL, " +
+                "`日期` timestamp NOT NULL DEFAULT current_timestamp(), " +
+                "`數量` varchar(11) NULL DEFAULT '', " +
+                "`連結` varchar(2048) NULL DEFAULT '', " +
+                "`採購公司` varchar(5) NULL DEFAULT '', " +
+                "`請購備註` varchar(2048) NULL DEFAULT '', " +
+                "`請購人` varchar(50) NULL DEFAULT '', " +
+                "`請購核可` tinyint(1) NULL DEFAULT 1, " +
+                "`單價` varchar(11) NULL DEFAULT '', " +
+                "`幣別` varchar(10) NOT NULL DEFAULT 'TWD', " +
+                "`營業稅` varchar(11) NULL DEFAULT '', " +
+                "`總金額` varchar(11) NULL DEFAULT '', " +
+                "`交期` varchar(11) NULL DEFAULT '', " +
+                "`詢價備註` varchar(2048) NULL DEFAULT '', " +
+                "`詢價單單號` varchar(11) NULL DEFAULT '', " +
+                "`供應商報價單號` varchar(11) NULL DEFAULT '', " +
+                "`採購主管核可` tinyint(1) NOT NULL DEFAULT 1, " +
+                "`採購單號` varchar(11) NULL DEFAULT '', " +
+                "PRIMARY KEY (內部料號)" +
+                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
+        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) {
+                window.location.href = '/PR_user_' + next_PR_companyid;
+            },
+            error: function (thrownError) {
+                if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                    alert("建立請購單草稿 " + next_PR_companyid + " 未成功")
+                } else {
+                    alert("建立請購單草稿 thrownError" + thrownError)
+                }
+            }
+        })  
+    }
+</script>
+
+</html>

+ 874 - 0
Rita/ERP_Rita/templates/PR_manager.html

@@ -0,0 +1,874 @@
+<!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 USER_NAME = '{{user_name}}';
+        console.log("USER_NAME: " + USER_NAME);
+        var PR_PERSON = '{{PR_person}}';
+        console.log("PR_PERSON: " + PR_PERSON);
+        var RFQ_MANAGER = '{{RFQ_manager}}';
+        console.log("RFQ_MANAGER: " + RFQ_MANAGER);
+        var FORM_STATUS = '{{form_status}}';
+        var data_id = [];   // 存放此資料表所有的內部料號
+        // 取得現在時間 紀錄請購備註時使用
+        var Today = new Date();
+        // 整理請購主管下屬清單
+        var staff_data = '{{staff_data}}'
+        console.log("staff_data: " + staff_data + typeof(staff_data))
+        var PR_person_staff = [];
+        // 顯示零件名稱標題用
+        var tr_title_id_target = '00000000';
+
+        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;
+                });
+            }
+        }
+    </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>
+        PR_person_staff.push('{{staff}}')
+    </script>
+    {% endfor %}
+
+    <center><h6 style="margin: 20px;">新增請購單</h6></center>
+    目前使用者:{{user_name}}<br>
+    請購單號:<span>{{PR_Form_number}}</span><br>
+    表單狀態:{{form_status}}<br>
+    用途:<input type="text" id="{{PR_Form_number}}_purpose" value="{{form_purpose}}" style="height: 25px; width: 50%;">
+    <input type="button" id="{{PR_Form_number}}_savepurpose" value="儲存用途" onclick="update_purpose('{{PR_Form_number}}')">
+    <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>內部料號</th>
+                <th>名稱</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>
+            <!-- 請購單內容:現有資料 -->
+            <!-- <div id="result"> -->
+            <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>核可</td> -->
+                <!-- <td>請購備註</td> -->
+                <td>
+                    <input type="button" class="input-cond-add status-visible" value="修改" onclick="update_PR_item('{{datas[0]}}')"><br>
+                    <input type="button" class="input-cond-delete status-visible" value="刪除" onclick="delete_PR_item('{{datas[0]}}')">
+                </td>
+            </tr>
+            <tr>
+                <th colspan="1">
+                    請購核可 : 
+                    {% if datas[9] == 1 %}
+                        <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')" checked>
+                    {% else %}
+                        <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')">
+                    {% endif %}
+                    <br>
+                    {% if form_status == "請購詢價完成" %}
+                        採購核可 : 
+                        {% if datas[11] == 1 %}
+                            <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" checked>
+                        {% else %}
+                            <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" >
+                        {% endif %}
+                    {% endif %}
+                </th>
+                <td colspan="9">
+                    <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[10]|safe}}</span>
+                    <!-- <hr>
+                    <span id="{{datas[0]}}_PRremark_t">Rita (2022/02/11 11:50:49) 說:111<br>Rita (2022/02/11 11:52:35) 說:222</span> -->
+                </td>
+            </tr>
+        </tbody>
+        {% endfor %}
+        <!-- </div> -->
+        <!-- 請購單內容:新增資料 -->
+        {% 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>內部料號</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;" value="" 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>
+                    <!-- 單位 -->
+                    <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>
+                    <!-- 請購人 -->
+                    <!-- <input type="text" id="PR_PRperson" value="" style="height: 25px; width: 90px;"> -->
+                    <select id="PR_PRperson">
+                        {% for staff in staff_data %}
+                            <option>{{staff}}</option>
+                        {% endfor %}
+                    </select>
+                </td>
+                <!-- <td>
+                    請購核可
+                    <input type="checkbox" id="PR_PRcheck" value="" checked>
+                </td>
+                <td>
+                    請購人備註
+                    <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 90px;">
+                </td> -->
+                <td rowspan="2" 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 colspan="1">
+                    請購核可 : 
+                    <input type="checkbox" id="PR_PRcheck" value="" checked disabled>
+                </th>
+                <th colspan="9">
+                    請購備註 : 
+                    <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 50%;">
+                </td>
+            </tr>
+        </tbody>
+        {% endif %}
+        <tr>
+            <td>
+                {% if form_status == "請購核可中" %}
+                <input type="button" class="input-cond-action status-visible" value="←駁回" onclick="PRmanager_to_user()">
+                {% endif %}
+            </td>
+            <td colspan="8"></td>
+            <td>
+                {% if form_status == "請購核可中" %}
+                <input type="button" class="input-cond-action status-visible" value="詢價→" onclick="PR_to_RFQmanager()">
+                {% endif %}
+            </td>
+        </tr>
+        <script>
+            // 新增零件時, 選擇內部料號後, 出現規格表相關內容
+            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 PRmanager_to_user() {
+                var confirm_to_user = confirm('本表單將駁回給請購人, 請點選[確定]送出通知')
+                if (confirm_to_user) {
+                    // 狀態更新為 請購申請中
+                    sql = "UPDATE `表單詳細資料` SET `表單狀態` = '請購申請中' " + 
+                            "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
+                            
+                    sql_data = { "sql":sql };
+                    console.log("PRmanager_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 ('" + 
+                    PR_PERSON + "','" + 
+                    PR_Form_number + "','" + 
+                    USER_NAME + " 已駁回')";
+
+                    sql_data = { "sql":sql };
+                    console.log("PRmanager_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)
+                            }
+                        }
+                    })
+                }
+            }
+
+            // 主管核可後, 開始詢價
+            function PR_to_RFQmanager() {
+                for (let i = 0; i < data_id.length; i++) {
+                    var checkbox_is_check = $('#' + data_id[i] + '_PRcheck').prop("checked")
+                    console.log("checkbox_is_check: " + checkbox_is_check)
+                    if (!checkbox_is_check) {
+                        alert('內部料號 ' + data_id[i] + ' 未核可, 全數核可才可詢價')
+                        return false
+                    }
+                }
+                // 狀態更新為 採購公司設定
+                sql = "UPDATE `表單詳細資料` SET `表單狀態` = '採購公司設定' " + 
+                        "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
+                        
+                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("調整狀態為\"採購公司設定\"")
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("送出調整狀態 未成功")
+                        } else {
+                            alert("送出調整狀態 thrownError" + thrownError)
+                        }
+                    }
+                })
+                // 通知採購主管
+                sql = "INSERT INTO `通知列表`(`通知對象`,`表單單號`, `內容`) VALUES ('" + 
+                        RFQ_MANAGER + "','" + 
+                        PR_Form_number + "','" + 
+                        USER_NAME + " 送出請購單')";
+
+                sql_data = { "sql":sql };
+                console.log("PR_to_RFQmanager[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 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)
+                console.log("PR_person_staff: " + PR_person_staff)
+                var PR_title_list = ['id', 'name', 'type', 'amount', 'unit', 'picture', 'supplier', 'hyperlink', 'PRperson', 'check', 'PRremark']
+                for (let i = 1; i < PR_title_list.length; i++) {
+                    if (i == 3 || i == 7 || i == 8) {
+                        // i != 1 && i != 2 && i != 5 && i != 6
+                        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: 100px">';
+                        } else if (PR_title_list[i] == 'PRperson'){
+                            textarea = '<select id="'+ id + '_' + PR_title_list[i] + '_ta' + '">';
+                            for (let i = 0; i < PR_person_staff.length; i++) {
+                                textarea += '<option>' + PR_person_staff[i] + '</option>'
+                            }
+                            textarea += '</select>'
+                        } else {
+                            textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 50px">';
+                        }
+                        if (PR_title_list[i] == 'PRperson') {
+                            textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
+                        }
+                        target_id.insertAdjacentHTML('beforeend', textarea);
+                    }
+                    if (PR_title_list[i] == 'PRperson') {
+                        $("#" + id + "_PRperson_ta").val(old_name);
+                    }
+                }
+            }
+
+            // 修改請購單內項目 確認
+            function update_comfirm_PR_item(id) {
+                console.log("修改: " + id)
+                var new_amount_value = $('#' + id + '_amount_ta').val();
+                var new_unit_value = $('#' + id + '_unit_ta').val();
+                var new_hyperlink_value = $('#' + id + '_hyperlink_ta').val();
+                // var new_PRremark_value = $('#' + id + '_PRremark_ta').val();
+                var new_PRperson_value = $('#' + id + '_PRperson_ta').val();
+
+                sql = 'UPDATE ' + PR_Form_number + 
+                    ' SET `數量`="' + new_amount_value + '"' +
+                    ', `單位`="' + new_unit_value + '"' +
+                    ', `連結`="' + new_hyperlink_value + '"' +
+                    // ', `請購備註`="' + new_PRremark_value + '"' +
+                    ', `請購人`="' + new_PRperson_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)
+                            }
+                        }
+                    })
+                }
+            }
+            
+        </script>
+    </table>
+
+    <!-- {% if PR_Form_number[-2:] == 'xx' %}
+        <input type="button" class="input-cond-add" value="送出" style="width: auto;" onclick="PR_to_Purchase()">
+        <input type="button" class="input-cond-add" value="採購人員修改採購公司" style="width: auto;" onclick="Purchase_update_sup()">
+    {% elif PR_Form_number[-2:] == '01' or PR_Form_number[-2:] == '02' %}
+        <input type="button" class="input-cond-add" value="製作請購單 PDF" style="width: auto;" onclick="">
+        <input type="button" class="input-cond-add" value="建立詢購單" style="width: auto;" onclick="">
+    {% endif %} -->
+
+    <script>
+        // 儲存 用途
+        function update_purpose(companyid) {
+            var PR_purpose = $("#" + companyid + "_purpose").val()
+            console.log("PR_purpose: " + PR_purpose)
+            sql = "UPDATE `表單詳細資料` SET `用途` = '" + PR_purpose + "' " + 
+                    "WHERE `表單詳細資料`.`請購草稿單號` = '" + companyid + "';";
+            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 + " 請購用途修改成功 !")
+                    location.reload()
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("請購單 " + PR_Form_number + " 請購用途未修改")
+                    } else {
+                        alert("修改請購用途 thrownError" + thrownError)
+                    }
+                }
+            })
+
+        }
+
+        function checkbox_check(id) {
+            var checkbox_id = $('#' + id + '_PRcheck').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 + '_PRcheck').prop('checked', false);
+                    alert("未輸入內容, 核可狀態未修改")
+                } else if (checkbox_confirm_true == null) {
+                    $('#' + id + '_PRcheck').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 + '_PRcheck').prop('checked', true);
+                    alert("未輸入內容, 核可狀態未修改")
+                } else if (checkbox_confirm_false == null) {
+                    $('#' + id + '_PRcheck').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 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', 'check', 'PRremark']
+
+            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 PR_PRremark_data = USER_NAME +
+                                    " (" + Today.getFullYear()+ "/" + two((Today.getMonth()+1)) + "/" + two(Today.getDate()) + " " + 
+                                    two(Today.getHours()) + ":" + two(Today.getMinutes()) + ":" + two(Today.getSeconds()) + ") 說:" + 
+                                    "[新增零件, 指派請購人為 " + PR_PRperson + " ] " + PR_PRremark + "<br>";
+            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_data: " + PR_PRremark_data)
+            console.log("PR_PRperson: " + PR_PRperson)
+
+            if (PR_id == "") {
+                alert("新增時, 內部料號不可空白 !")
+            } else {
+                var sql = 'INSERT INTO `' + PR_Form_number + 
+                        '` (內部料號, 日期, 數量, 連結, 請購人, 請購核可, 請購備註)' + 
+                        ' VALUES ("' + 
+                        PR_id + 
+                        '", current_timestamp(), "' + 
+                        PR_amount + '", "' + 
+                        PR_hyperlink + '", "' + 
+                        PR_PRperson + '", "' + 
+                        '1' + '", "' + 
+                        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>
+</body>
+
+</html>

+ 555 - 0
Rita/ERP_Rita/templates/PR_new.html

@@ -0,0 +1,555 @@
+<!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">
+    
+</head>
+<script>
+    var PR_Form_number = '{{PR_Form_number}}';
+    var table_row_num = 0;
+
+</script>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <center><h6 style="margin: 20px;">建立請購單</h6></center>
+    <table class="table table-bordered" id="PR_table" style="margin-top: 10px;">
+        <tr>
+            <td colspan="5">
+                日期 :
+                <span id="PR_datetime">(系統代入)</span>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="5">
+                請購單號 :
+                <span id="PR_document_companyid">{{PR_Form_number}}</span>
+            </td>
+        </tr>
+        <!-- 請購單標題 -->
+        <tr>
+            <th>內部料號</th>
+            <th>數量</th>
+            <th>單位</th>
+            <th>連結</th>
+            <!-- <th>單價</th>
+            <th>關稅</th>
+            <th>運費</th>
+            <th>總金額</th>
+            <th>付款狀況</th> -->
+            <th>備註</th>
+        </tr>
+        <!-- </div> -->
+        <!-- 請購單內容:新增資料 -->
+        <tr>
+            <td>
+                <!-- 內部料號 -->
+                <input list="insert_PR_id_item" id="PR_id_0" style="height: 25px;" onChange="">
+                <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>
+                <!-- 數量 -->
+                <input type="text" id="PR_amount_0" value="1" style="height: 25px; width: 50px">
+            </td>
+            <td>
+                <!-- 單位 -->
+                <input type="text" id="PR_unit_0" value="件" style="height: 25px; width: 50px">
+            </td>
+            <td>
+                <input type="text" id="PR_hyperlink_0" value="www" style="height: 25px; width: 200px">
+            </td>
+            <!-- <td> -->
+                <!-- 單價 -->
+                <!-- <input type="text" id="PR_unitprice_0" value="11" style="height: 25px; width: 70px">
+            </td>
+            <td> -->
+                <!-- 關稅 -->
+                <!-- <input type="text" id="PR_tariff_0" value="12" style="height: 25px; width: 70px">
+            </td>
+            <td> -->
+                <!-- 運費 -->
+                <!-- <input type="text" id="PR_shippingfee_0" value="13" style="height: 25px; width: 70px">
+            </td>
+            <td> -->
+                <!-- 總金額 -->
+                <!-- <input type="text" id="PR_totalprice_0" value="135" style="height: 25px; width: 90px">
+            </td>
+            <td> -->
+                <!-- 付款狀況 -->
+                <!-- <input id="PR_payment" value="代墊" style="height: 25px; width: 70px"> -->
+                <!-- <select id="PR_payment_0">
+                    <option value="未付款">未付款</option>
+                    <option value="已付款">已付款</option>
+                </select>
+            </td> -->
+            <td>
+                <!-- 備註 -->
+                <input type="text" id="PR_remark_0" value="備註" style="height: 25px; width: 90px; margin-right: 20px;">
+                <input type="button" value="新增下一筆" onclick="table_add_rows()">
+            </td>
+        </tr>
+        <script>
+            // // 修改請購單內項目
+            // function update_PR_item(id) {
+            //     console.log("修改: " + id)
+            //     var PR_title_list = ['id', 'amount', 'unit', 'supplier', 'unitprice', 'tariff', 'shippingfee', 'totalprice', 'payment']
+            //     for (let i = 1; i < 9; 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 = "";
+            //         textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 60px">';
+            //         if (i == 8) {
+            //             textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
+            //         }
+            //         target_id.insertAdjacentHTML('beforeend', textarea);
+            //     }
+                
+            //     // target_id.insertAdjacentHTML('beforeend', textarea);
+            //     // $(".insert_BOM_person_module").find("option:contains(" + old_name + ")").attr("selected",true);
+            // }
+
+            // // 修改請購單內項目 確認
+            // function update_comfirm_PR_item(id) {
+            //     console.log("修改: " + id)
+            //     var new_amount_value = $('#' + id + '_amount_ta').val();
+            //     var new_unit_value = $('#' + id + '_unit_ta').val();
+            //     // var new_supplier_value = $('#' + id + '_supplier_ta').val();
+            //     var new_unitprice_value = $('#' + id + '_unitprice_ta').val();
+            //     var new_tariff_value = $('#' + id + '_tariff_ta').val();
+            //     var new_shippingfee_value = $('#' + id + '_shippingfee_ta').val();
+            //     var new_totalprice_value = $('#' + id + '_totalprice_ta').val();
+            //     var new_payment_value = $('#' + id + '_payment_ta').val();
+
+            //     sql = 'UPDATE ' + PR_Form_number + ' SET `數量` = "' + new_amount_value + '"' +
+            //       ', `單位` = "' + new_unit_value + '"' +
+            //     //   ', `供應商` = "' + new_supplier_value + '"' +
+            //     //   ', `專案` = "' + new_reason_value + '"' +
+            //     //   ', `用途` = "' + new_person_value + '"' +
+            //       ', `單價` = "' + new_unitprice_value + '"' +
+            //       ', `關稅` = "' + new_tariff_value + '"' +
+            //       ', `運費` = "' + new_shippingfee_value + '"' +
+            //       ', `總金額` = "' + new_totalprice_value + '"' +
+            //       ', `付款狀況` = "' + new_payment_value + '"' +
+            //     //   ', `備註` = "' + new_person_value + '"' +
+            //     //   ', `請購人` = "' + new_person_value + '"' +
+            //       ' WHERE `內部料號` = "' + id + '";';
+            //     console.log('sql: ' + sql)
+            //     var sql_data = { "sql":sql };
+
+            //     $.ajax({
+            //         type:"GET",
+            //         url:"/sql_get",
+            //         dataType:"JSON",
+            //         data:sql_data,
+            //         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 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,
+            //             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 PR_change() {
+                // get_Value();
+                var PR_document_companyid_select = $("#PR_document_companyid_select").val()
+                console.log("PR_document_companyid_select: " + PR_document_companyid_select)
+                var sql = 'SELECT 內部料號 FROM `' + PR_document_companyid_select + '`' ;
+                var sql_data = { "sql":sql };
+
+                $.ajax({
+                    type:"GET",
+                    url:"/sql_get",
+                    dataType:"JSON",
+                    data:sql_data,
+                    success:function (res) {
+                        if (res.labels.length != 0) {
+                            for (let items = 0; items < res.labels.length; items++) {
+                                var data = '<tr>';
+                                for (let item = 0; item < res.labels[items].length; item++) {
+                                    console.log("res.labels[items][item]: ", res.labels[items][item], typeof(res.labels[items][item]))
+                                    if (res.labels[items][item] == null) {
+                                        data += '<td id="' + res.labels[items][0] + '_' + item + '">' + '' + '</td>';
+                                    } else {
+                                        data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
+                                    }
+                                };
+                                // data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_standard(\'' + res.labels[items][0] + '\')"></td>';
+                                data += '</tr>';
+                            };
+                            var sectorSelect = document.getElementById("result");
+                            sectorSelect.innerHTML = data;
+                        }
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未新增")
+                        } else {
+                            alert("新增請購單內容 thrownError" + thrownError)
+                        }
+                    }
+                })
+                
+            }
+        </script>
+        <tr>
+            <td>
+                請購 :
+                <!-- <span id="PR_requisition_person"></span> -->
+                <!-- <input list="insert_PR_person" id="PR_person" style="height: 25px;" onChange="">
+                <datalist id="insert_PR_person">
+                </datalist> -->
+                <select id="PR_person">
+                    <option value=""></option>
+                    <option value="Andrey">Andrey</option>
+                    <option value="Amy">Amy</option>
+                    <option value="Allen">Allen</option>
+                    <option value="Gina">Gina</option>
+                    <option value="FatWolf">FatWolf</option>
+                    <option value="Rita">Rita</option>
+                </select>
+            </td>
+            <td>
+                倉管 :
+                <span id="PR_warehouse_person"></span>
+            </td>
+            <td>
+                管理 :
+                <span id="PR_management_person"></span>
+            </td>
+        </tr>
+    </table>
+    <br>
+    <input type="button" value="取值測試" onclick="get_Value();">
+    <input type="button" class="input-cond-add" value="儲存" onclick="create_PR_table(PR_Form_number);">
+    <div id="result"></div>
+
+    <br>
+
+    <script>
+        var sql = '';
+        var sql_data = { "sql":sql };
+        // 建立請購單 Table + 建立項目
+        function create_PR_table(PR_conpany_id) {
+            console.log("create_PR_table PR_conpany_id: " + PR_conpany_id)
+            
+            PR_insert_items = [];
+            // 取值組合成 SQL 語法
+            // 亦當作未輸入之空格
+
+            for (let row = 0; row <= table_row_num; row++) {
+                data = '(';
+                for (let item = 0; item < PR_title_list.length; item++) {
+
+                    var PR_value = document.getElementById("PR_" + PR_title_list[item] + "_" + row).value;
+                    console.log("PR_" + PR_title_list[item] + "_" + row + ": " + PR_value)
+                    // (內部料號, 數量, 單位, 單價, 關稅, 運費, 總金額, 付款狀況, 備註, 
+                    data += '"' + PR_value + '", ';
+                }
+                // 請購人)
+                var PR_person_value = document.getElementById("PR_person").value;
+                console.log("PR_person: " + PR_person_value)
+                data += '"' + PR_person_value + '")';
+                PR_insert_items.push(data);
+            }
+            console.log("PR_insert_items: " + PR_insert_items)
+
+            // 建立請購單 Table
+            sql = 'CREATE TABLE `' + PR_conpany_id + '` (' +
+                      '`內部料號` varchar(11) NOT NULL, ' +
+                      '`建立日期` TIMESTAMP NOT NULL DEFAULT current_timestamp(), ' +
+                      '`數量` varchar(4) NOT NULL, ' +
+                      '`單位` varchar(10) NULL, ' +
+                      '`連結` varchar(500) NULL, ' +
+                    //   '`單價` varchar(10) NULL, ' +
+                    //   '`關稅` varchar(10) NULL, ' +
+                    //   '`運費` varchar(10) NULL, ' +
+                    //   '`總金額` varchar(10) NULL, ' +
+                    //   '`付款狀況` varchar(10) NULL, ' +
+                      '`備註` varchar(100) NULL, ' +
+                      '`請購人` varchar(10) NULL, ' +
+                      'PRIMARY KEY (內部料號)' +
+                      ');';
+            console.log("sql: " + sql)
+            sql_data = { "sql":sql }
+            $.ajax({
+                type:"GET",
+                url:"/sql_get",
+                dataType:"JSON",
+                data:sql_data,
+                async:false,
+                success:function (res) {
+                    alert("請購單 " + PR_conpany_id + ": 建立成功!")
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("請購單 " + PR_conpany_id + " 未成功")
+                    } else {
+                        alert("請購單建立錯誤: " + thrownError)
+                    }
+                }
+            })
+
+            // 建立請購單項目
+            // sql = 'INSERT INTO `' + PR_conpany_id + '` (內部料號, 數量, 單位, 單價, 關稅, 運費, 總金額, 付款狀況, 備註, 請購人) ' + 
+            //       'VALUES ' + PR_insert_items.join(', ');
+            sql = 'INSERT INTO `' + PR_conpany_id + '` (內部料號, 數量, 單位, 連結, 備註, 請購人) ' + 
+                  'VALUES ' + PR_insert_items.join(', ');
+            console.log("sql: " + sql)
+            sql_data = { "sql":sql }
+            $.ajax({
+                type:"GET",
+                url:"/sql_get",
+                dataType:"JSON",
+                data:sql_data,
+                async:false,
+                success:function (res) {
+                    alert("請購單 " + PR_conpany_id + ": 項目建立成功!")
+                    window.location.assign("/PR_user_" + PR_conpany_id)
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("請購單 " + PR_conpany_id + " 項目建立未成功")
+                    } else {
+                        alert("請購單項目建立錯誤: " + thrownError)
+                    }
+                }
+            })
+        }
+
+        // var PR_title_list = ['id', 'amount', 'unit', 'unitprice', 'tariff', 'shippingfee', 'totalprice', 'payment', 'remark']
+        var PR_title_list = ['id', 'amount', 'unit', 'hyperlink', 'remark']
+        var data = '';
+
+        // 取得欄位值
+        function get_Value() {
+            console.log("get_Value")
+            var PR_insert_items = [];
+            for (let row = 0; row <= table_row_num; row++) {
+                data = '(';
+                for (let item = 0; item < PR_title_list.length; item++) {
+                    var PR_value = document.getElementById("PR_" + PR_title_list[item] + "_" + row).value;
+                    console.log("PR_" + PR_title_list[item] + "_" + row + ": " + PR_value)
+                    // (內部料號, 數量, 單位, 單價, 關稅, 運費, 總金額, 付款狀況, 備註, 請購人)
+                    data += '"' + PR_value + '", ';
+                }
+                var PR_person_value = document.getElementById("PR_person").value;
+                console.log("PR_person: " + PR_person_value)
+                data += '"' + PR_person_value + '")';
+
+                PR_insert_items.push(data);
+            }
+            var selector = document.getElementById("result");
+            selector.innerHTML = PR_insert_items.join(', ');
+        }
+
+        function table_add_rows() {
+            table_row_num++;
+            var table_name = document.getElementById("PR_table");
+            var table_add_row = table_name.insertRow(table_name.rows.length-1);
+            // var table_add_row = table_name.insertRow(table_name.rows.length);  // 最後一行
+
+            // var PR_title_add_list = ['id', 'amount', 'unit', 'unitprice', 'tariff', 'shippingfee', 'totalprice', 'payment', 'remark']
+            for (let i = 0; i < PR_title_list.length; i++) {
+                var cell = table_add_row.insertCell();
+                if (i == 0) {
+                    // 內部料號
+                    data = '<input list="insert_PR_id_item" id="PR_id_' + table_row_num + '" style="height: 25px;" onChange="">' +
+                           '<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>' ;
+                    cell.innerHTML = data;
+                // } else if (i == 1 || i == 2 || i == 5) {
+                //     // 名稱 型號/規格 供應商
+                //     // data = '—' ;
+                //     // cell.innerHTML = data;
+                } else if (i == 1) {
+                    // 數量
+                    data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 50px">' ;
+                    cell.innerHTML = data;
+                } else if (i == 2) {
+                    // 單位
+                    data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 50px">' ;
+                    cell.innerHTML = data;
+                // } else if (i == 3) {
+                //     // 單價
+                //     data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 70px">' ;
+                //     cell.innerHTML = data;
+                // } else if (i == 4) {
+                //     // 關稅
+                //     data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 70px">' ;
+                //     cell.innerHTML = data;
+                // } else if (i == 5) {
+                //     // 運費
+                //     data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 70px">' ;
+                //     cell.innerHTML = data;
+                // } else if (i == 6) {
+                //     // 總金額
+                //     data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 90px">' ;
+                //     cell.innerHTML = data;
+                // } else if (i == 7) {
+                //     // 付款狀況
+                //     data = '<select id="PR_' + PR_title_list[i] + '_' + table_row_num + '">' +
+                //             '<option value="未付款">未付款</option>' +
+                //             '<option value="已付款">已付款</option>' +
+                //             '</select>';
+                //     cell.innerHTML = data;
+                } else if (i == 3) {
+                    // 連結
+                    data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 200px;">';
+                    cell.innerHTML = data;
+                } else if (i == 4) {
+                    // 備註
+                    data = '<input type="text" id="PR_' + PR_title_list[i] + '_' + table_row_num + '" value="" style="height: 25px; width: 90px;">';
+                    cell.innerHTML = data;
+                } else {
+                    cell.innerHTML = i;
+                }
+            }
+        }
+
+        function insert_PR_item() {
+            var PR_document_companyid = $("#PR_document_companyid").text()
+            var PR_document_companyid_select = $("#PR_document_companyid_select").val()
+            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_unitprice = $("#PR_unitprice").val()
+            var PR_tariff = $("#PR_tariff").val()
+            var PR_shippingfee = $("#PR_shippingfee").val()
+            var PR_totalprice = $("#PR_totalprice").val()
+            var PR_payment = $("#PR_payment").val()
+            var PR_remark_project= $("#PR_remark_project").val()
+            var PR_requisition_person = $("#PR_requisition_person").text()
+            console.log("PR_document_companyid: " + PR_document_companyid)
+            console.log("PR_document_companyid_select: " + PR_document_companyid_select)
+            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_unitprice: " + PR_unitprice)
+            console.log("PR_tariff: " + PR_tariff)
+            console.log("PR_shippingfee: " + PR_shippingfee)
+            console.log("PR_totalprice: " + PR_totalprice)
+            console.log("PR_payment: " + PR_payment)
+            console.log("PR_remark_project: " + PR_remark_project)
+            console.log("PR_requisition_person: " + PR_requisition_person)
+
+            // TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+            var sql = 'INSERT INTO `' + PR_Form_number + '`' + 
+                      ' VALUES ("' + PR_id + '", current_timestamp(), "' + PR_amount + '", "' + PR_unit + '", "' +
+                      PR_supplier + '", "' + 
+                      PR_unitprice + '", "' + PR_tariff + '", "' + PR_shippingfee + '", "' + 
+                      PR_totalprice + '", "' + PR_payment + '", "' + PR_remark_project + '", "' + PR_requisition_person + '");';
+            var sql_data = { "sql":sql };
+            console.log("insert_PR_item[sql]:" + sql)
+
+            $.ajax({
+                type:"GET",
+                url:"/sql_get",
+                dataType:"JSON",
+                data:sql_data,
+                success:function (res) {
+                    alert("請購單 " + PR_document_companyid + ":" + PR_id + " 新增成功 !")
+                    location.reload()
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("請購單 " + PR_document_companyid + ":" + PR_id + " 未新增")
+                    } else {
+                        alert("新增請購單內容 thrownError" + thrownError)
+                    }
+                }
+            })
+
+        }
+    </script>
+</body>
+
+</html>

+ 788 - 0
Rita/ERP_Rita/templates/PR_user.html

@@ -0,0 +1,788 @@
+<!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 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';
+        
+        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;
+                });
+            }
+            
+        }
+    </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>
+    用途:<input type="text" id="{{PR_Form_number}}_purpose" value="{{form_purpose}}" style="height: 25px; width: 50%;">
+    <input type="button" id="{{PR_Form_number}}_savepurpose" value="儲存用途" onclick="update_purpose('{{PR_Form_number}}')">
+    <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>內部料號</th>
+                    <th>名稱</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>
+                <!-- 請購單內容:現有資料 -->
+                <!-- <div id="result"> -->
+                <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>核可</td> -->
+                    <!-- <td>請購備註</td> -->
+                    <td>
+                        
+                        <input type="button" class="input-cond-add status-visible" value="修改" onclick="update_PR_item('{{datas[0]}}')"><br>
+                        <input type="button" class="input-cond-delete status-visible" value="刪除" onclick="delete_PR_item('{{datas[0]}}')">
+                        
+                    </td>
+                </tr>
+                <tr>
+                    <th colspan="1">
+                        請購核可 : 
+                        {% if datas[9] == 1 %}
+                            <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')" checked>
+                        {% else %}
+                            <input type="checkbox" id="{{datas[0]}}_PRcheck" class="status-disabled" onclick="checkbox_check('{{datas[0]}}')">
+                        {% endif %}
+                        <br>
+                        {% if form_status == "請購詢價完成" %}
+                            採購核可 : 
+                            {% if datas[11] == 1 %}
+                                <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" checked>
+                            {% else %}
+                                <input type="checkbox" id="{{datas[0]}}_RFQcheck" class="status-disabled" >
+                            {% endif %}
+                        {% endif %}
+                    </th>
+                    <td colspan="9">
+                        <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[10]|safe}}</span>
+                        <!-- <hr>
+                        <span id="{{datas[0]}}_PRremark_t">Rita (2022/02/11 11:50:49) 說:111<br>Rita (2022/02/11 11:52:35) 說:222</span> -->
+                    </td>
+                </tr>
+            </tbody>
+        {% endfor %}
+        <!-- </div> -->
+        <!-- 請購單內容:新增資料 -->
+        {% 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>內部料號</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>
+                    <!-- 單位 -->
+                    <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>
+                    <!-- 請購人 -->
+                    {{user_name}}
+                    <!-- <input type="text" id="PR_PRperson" value="" style="height: 25px; width: 90px;"> -->
+                </td>
+                <!-- <td>
+                    核可
+                    <input type="checkbox" id="PR_PRcheck" value="" checked>
+                </td>
+                <td>
+                    請購人備註
+                    <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 90px;">
+                </td> -->
+                <td rowspan="2" 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 colspan="1">
+                    核可 : 
+                    <input type="checkbox" id="PR_PRcheck" value="" checked disabled>
+                </th>
+                <th colspan="9">
+                    請購備註 : 
+                    <input type="text" id="PR_PRremark" value="" style="height: 25px; width: 50%;">
+                </td>
+            </tr>
+        </tbody>
+        {% endif %}
+        <tr>
+            <td colspan="9"></td>
+            <td>
+                <input type="button" class="input-cond-action status-visible" value="送出→" onclick="PRuser_to_manager()">
+            </td>
+        </tr>
+        <script>
+            // 新增零件時, 選擇內部料號後, 出現規格表相關內容
+            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', 'check', 'PRremark']
+                for (let i = 1; i < PR_title_list.length; i++) {
+                    if (i == 3 || i == 7) {
+                        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: 100px">';
+                        } else {
+                            textarea = '<input id="'+ id + '_' + PR_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 50px">';
+                        }
+                        if (PR_title_list[i] == 'hyperlink') {
+                            textarea += '<input type="button" value="OK" onclick="update_comfirm_PR_item(\'' + id + '\')">';
+                        }
+                        target_id.insertAdjacentHTML('beforeend', textarea);
+                    }
+                }
+            }
+
+            // 修改請購單內項目 確認
+            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();
+
+                sql = 'UPDATE ' + PR_Form_number + ' SET' +
+                    ' `數量`="' + new_amount_value + '"' +
+                    ', `連結`="' + new_hyperlink_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)
+                            }
+                        }
+                    })
+                }
+            }
+            
+        </script>
+    </table>
+
+    <!-- {% if PR_Form_number[-2:] == 'xx' %}
+        <input type="button" class="input-cond-add" value="送出" style="width: auto;" onclick="PR_to_Purchase()">
+        <input type="button" class="input-cond-add" value="採購人員修改採購公司" style="width: auto;" onclick="Purchase_update_sup()">
+    {% elif PR_Form_number[-2:] == '01' or PR_Form_number[-2:] == '02' %}
+        <input type="button" class="input-cond-add" value="製作請購單 PDF" style="width: auto;" onclick="">
+        <input type="button" class="input-cond-add" value="建立詢購單" style="width: auto;" onclick="">
+    {% endif %} -->
+
+    <script>
+        // 儲存 用途
+        function update_purpose(companyid) {
+            var PR_purpose = $("#" + companyid + "_purpose").val()
+            console.log("PR_purpose: " + PR_purpose)
+            sql = "UPDATE `表單詳細資料` SET `用途` = '" + PR_purpose + "' " + 
+                    "WHERE `表單詳細資料`.`請購草稿單號` = '" + companyid + "';";
+            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 + " 請購用途修改成功 !")
+                    location.reload()
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("請購單 " + PR_Form_number + " 請購用途未修改")
+                    } else {
+                        alert("修改請購用途 thrownError" + thrownError)
+                    }
+                }
+            })
+
+        }
+
+        function checkbox_check(id) {
+            var checkbox_id = $('#' + id + '_PRcheck').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 + '_PRcheck').prop('checked', false);
+                    alert("未輸入內容, 核可狀態未修改")
+                } else if (checkbox_confirm_true == null) {
+                    $('#' + id + '_PRcheck').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 + '_PRcheck').prop('checked', true);
+                    alert("未輸入內容, 核可狀態未修改")
+                } else if (checkbox_confirm_false == null) {
+                    $('#' + id + '_PRcheck').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 PRuser_to_manager() {
+            for (let i = 0; i < data_id.length; i++) {
+                var checkbox_is_check = $('#' + data_id[i] + '_PRcheck').prop("checked")
+                console.log("checkbox_is_check: " + checkbox_is_check)
+                if (!checkbox_is_check) {
+                    var confirm_check = confirm('內部料號 ' + data_id[i] + ' 未核可, 確定要繼續嗎 ?')
+                    if (!confirm_check) {
+                        return false;
+                    }
+                }
+            }
+            var confirm_to_manager = confirm('本表單即將送出給直屬主管, 請點選[確定]送出表單')
+            if (confirm_to_manager) {
+                // 狀態更新為 請購核可中
+                sql = "UPDATE `表單詳細資料` SET `表單狀態` = '請購核可中' " + 
+                        "WHERE `表單詳細資料`.`請購草稿單號` = '" + PR_Form_number + "';";
+                        
+                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("調整狀態為\"請購核可中\"")
+                    },
+                    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("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)
+                        }
+                    }
+                })
+            } else {
+                alert("送出取消")
+            }
+            
+        }
+
+        // 採購人員 修改採購公司
+        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', 'check', 'PRremark']
+
+            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 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>";
+            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_data: " + PR_PRremark_data)
+            console.log("PR_PRperson: " + PR_PRperson)
+
+            if (PR_id == "") {
+                alert("新增時, 內部料號不可空白 !")
+            } else {
+                var sql = 'INSERT INTO `' + PR_Form_number + 
+                        '` (內部料號, 日期, 數量, 連結, 請購人, 請購核可, 請購備註)' + 
+                        ' VALUES ("' + 
+                        PR_id + 
+                        '", current_timestamp(), "' + 
+                        PR_amount + '", "' + 
+                        PR_hyperlink + '", "' + 
+                        USER_NAME + '", "' + 
+                        '1' + '", "' + 
+                        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>
+</body>
+
+</html>

+ 221 - 0
Rita/ERP_Rita/templates/RFQ_form.html

@@ -0,0 +1,221 @@
+<!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">
+    
+    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
+    <script src="../static/js/jquery.min.js"></script>
+    <script src="../static/js/popper.min.js"></script>
+    <script src="../static/js/bootstrap.min.js"></script>
+    <link rel="stylesheet" href="../static/css/font-awesome.min.css">
+    
+</head>
+<script>
+    var PR_Form_number = '{{PR_Form_number}}';
+    console.log("PR_Form_number: " + PR_Form_number);
+    var RFQ_datas_sn = 0;
+    console.log("RFQ_datas_sn: " + RFQ_datas_sn);
+</script>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+    .table_dark_bg {
+        background-color: rgb(102, 102, 102);
+        color: #FFF;
+        font-weight: bold;
+    }
+    .table_RFQ_title {
+        font-weight: bold;
+    }
+    .table-css {
+        border: 1px solid #dee2e6;
+        width: 100%;
+    }
+    .table-css td,th {
+        padding: 0.5rem;
+    }
+</style>
+
+<body>
+    <table class="table-css table-bordered" style="font-size: 14px; padding: 0.5rem;">
+        {% for sup in sup_datas %}
+            <tr>
+                <td colspan="11" style="text-align: center; font-size: 12px;">
+                    <img src="../static/img/ALMIGHTY_RAY.jpg" width="90px"><br>
+                    瑞智精技股份有限公司<br>
+                    台北市南港區南港路一段 287 巷 2 弄 8 號<br>
+                    service.gitc@gmail.com<br>
+                    (02) 2788 - 8158<br>
+                </td>
+            </tr>
+            <tr>
+                <td colspan="11" class="table_dark_bg" style="text-align: center;">詢價單</td>
+            </tr>
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">僅致 : </span> 
+                    <span id="RFQ_sup_company">{{sup[0]}}</span>
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title">統一編號 : </span>
+                    {% if sup[6] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[6]}}</span>
+                    {% endif %}
+                </td>
+            </tr>
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">聯絡人 : </span>
+                    {% if sup[1] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[1]}}</span>
+                    {% endif %}
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title"></span> 
+                    <span id=""></span>
+                </td>
+            </tr>
+            
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">地址 : </span>
+                    {% if sup[2] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[2]}}</span>
+                    {% endif %}
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title">日期 : </span> 
+                    <span id=""></span>
+                </td>
+            </tr>
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">電話 : </span>
+                    {% if sup[3] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[3]}}</span>
+                    {% endif %}
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title">廠商編號 : </span>
+                    {% if sup[7] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[7]}}</span>
+                    {% endif %}
+                </td>
+            </tr>
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">傳真 : </span> 
+                    {% if sup[4] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[4]}}</span>
+                    {% endif %}
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title">請購單號 : </span> 
+                    <span id="">請購單號</span>
+                </td>
+            </tr>
+            <tr>
+                <td colspan="7">
+                    <span class="table_RFQ_title">email : </span>
+                    {% if sup[5] == None %}
+                        <span></span>
+                    {% else %}
+                        <span>{{sup[5]}}</span>
+                    {% endif %}
+                </td>
+                <td colspan="4">
+                    <span class="table_RFQ_title">詢價單號 : </span> 
+                    <span id="">詢價單號</span>
+                </td>
+            </tr>
+        {% endfor %}
+        <tr class="table_dark_bg" style="text-align: center;">
+            <th>編號</th>
+            <th>內部料號</th>
+            <th>零件名稱</th>
+            <th>原廠料號</th>
+            <th>圖號</th>
+            <th>幣別</th>
+            <th>單價</th>
+            <th>數量</th>
+            <th>單位</th>
+            <th>總價</th>
+            <th>備註</th>
+        </tr>
+        {% for PR in PR_datas %}
+            <tr style="text-align: center;">
+                <td id="{{PR[0]}}_RFQ_sn">no.</td>
+                <td>{{PR[0]}}</td>
+                <td>{{PR[1]}}</td>
+                <td>{{PR[2]}}</td>
+                <td>{{PR[3]}}</td>
+                <td></td>
+                <td></td>
+                <td>{{PR[4]}}</td>
+                <td>{{PR[5]}}</td>
+                <td></td>
+                <td></td>
+            </tr>
+            <script>
+                RFQ_datas_sn = RFQ_datas_sn+1;
+                // console.log("[++]RFQ_datas_sn: " + RFQ_datas_sn);
+                $("#{{PR[0]}}_RFQ_sn").text(RFQ_datas_sn);
+            </script>
+        {% endfor %}
+        <tr style="text-align: center;">
+            <td colspan="7" rowspan="3"></td>
+            <td>合計</td>
+            <td colspan="3" style="text-align: right;"></td>
+        </tr>
+        <tr style="text-align: center;">
+            <td>稅額</td>
+            <td colspan="3" style="text-align: right;"></td>
+        </tr>
+        <tr style="text-align: center;">
+            <td>總計</td>
+            <td colspan="3" style="text-align: right;"></td>
+        </tr>
+    </table>
+</body>
+
+</html>

+ 990 - 0
Rita/ERP_Rita/templates/RFQ_manager.html

@@ -0,0 +1,990 @@
+<!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>

Diferenças do arquivo suprimidas por serem muito extensas
+ 1186 - 0
Rita/ERP_Rita/templates/RFQ_user.html


Diferenças do arquivo suprimidas por serem muito extensas
+ 813 - 320
Rita/ERP_Rita/templates/create_BOM.html


+ 216 - 23
Rita/ERP_Rita/templates/create_component_table_item.html

@@ -6,19 +6,42 @@
     <title>{{ title }}</title>
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 
-    <!-- 新 Bootstrap4 核心 CSS 文件 -->
-    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
-    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
-    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
-    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
-    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
-    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
-    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
-    <!--可用來建立使用者小圖示-->
-    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
 </head>
 
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
 <body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
     <!-- 這裡新增零件表中的零件 -->
     請依序輸入以下欄位, 再按下 "新增零件" 按鈕:<br>
     會計科目:
@@ -84,17 +107,17 @@
             // 供應商
             var supplier_select = $("#supplier").val();
             // 零件名稱
-            var component_name_select = $("#component_name_select").val();
+            var component_name_select = $("#component_name_select").val().replaceAll("'", "''");
             // 內部料號組合
             var company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
             var AND_list = [];
             // console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select, component_name_select)
 
             var sql = '';
-            sql += 'INSERT INTO 零件表 ' +
-                   'VALUES ("' + company_id + '", "' + accountingsubjects_select + '", "' + category_select + '", "' + serialnumber_select + '", "';
-            sql += supplier_select + '", "' + component_name_select + '");';
-            console.log("sql: " + sql)
+            sql += "INSERT INTO 零件表 " +
+                   "VALUES ('" + company_id + "', '" + accountingsubjects_select + "', '" + category_select + "', '" + serialnumber_select + "', '";
+            sql += supplier_select + "', '" + component_name_select + "');";
+            console.log("sql: " + sql);
 
             var sql_data = { "sql":sql };
 
@@ -103,6 +126,7 @@
                 url:"/sql_get",
                 dataType:"JSON",
                 data:sql_data,
+                async:false,
                 success:function (res) {
                     alert("零件表: 零件新增成功!")
                 },
@@ -114,7 +138,7 @@
 
             })
 
-            var sql = 'INSERT INTO 規格表 (`內部料號`, `名稱`) VALUES ("' + company_id + '", "' + component_name_select + '");';
+            var sql = 'INSERT INTO 規格表 (`內部料號`) VALUES ("' + company_id + '");';
 
             var sql_data = { "sql":sql };
 
@@ -123,6 +147,7 @@
                 url:"/sql_get",
                 dataType:"JSON",
                 data:sql_data,
+                async:false,
                 success:function (res) {
                     alert("規格表: 零件新增成功!")
                 },
@@ -218,17 +243,184 @@
 
     <hr>
     <!-- 這裡新增零件表中的 供應商 -->
-    請輸入欲新增的供應商名稱, 再按下 "新增供應商" 按鈕: (其他資料先以 NULL 存入)<br>
-    <input id="create_supplier_id" value="{{new_su_sn}}" style="height: 25px; width: 45px;" readonly>
+    請輸入欲新增的供應商名稱, 再按下 "新增供應商" 按鈕: (其他資料先以 "" 存入)<br>
+    <!-- <input id="create_supplier_id" value="{{new_su_sn}}" style="height: 25px; width: 45px;" readonly> -->
+    <select id="create_supplier_id_1" onChange="new_sup_sn();">
+        <option value="T" selected>T - 台灣</option>
+        <option value="C">C - 中國</option>
+        <option value="A">A - 美國</option>
+        <option value="J">J - 日本</option>
+    </select>
+    <input id="create_supplier_id_2" value="{{new_su_sn}}" style="height: 25px; width: 45px;" readonly> 
     <input id="create_supplier_name" value="" style="height: 25px;">
-    <input type="button" id="create_supplier" value="新增供應商項目" onclick="create_supplier();">
+    <input type="button" id="create_supplier" value="新增供應商項目" onclick="create_supplier();"><br>
+    <br>
+
+    <br>
+    <hr>
+    若欲檢視供應商資料, 請選擇對應的供應商編號-中文名稱: 
+    <!-- <input id="search_supplier_id" value="" style="height: 25px;"> -->
+    <select id="search_supplier_id" onChange="search_supplier()">
+        <option value="00"></option>
+        {% for data in Supplier_data %}
+            <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
+        {% endfor %}
+    </select>
+    
+    <div id="search_supplier_data"></div>
+    
     <script>
+        // 找到最新的供應商編號
+        function new_sup_sn() {
+            var sup_id_1 = $("#create_supplier_id_1").val();
+            console.log("sup_id_1: " + sup_id_1)
+            $.ajax({
+                type:"GET",
+                url:"/sup_get/" + sup_id_1,
+                dataType:"JSON",
+                data:"",
+                success:function (res) {
+                    document.getElementById("create_supplier_id_2").value = res.sup_sn;
+                },
+                error: function (thrownError) {
+                    alert("供應商新編號 取值失敗")
+                }
+            })
+            
+        }
+
+        // 顯示供應商資料
+        function search_supplier() {
+            var search_supplier_id = $("#search_supplier_id").val();
+            console.log("search_supplier_id: " + search_supplier_id)
+            sql = 'SELECT * FROM `供應商` WHERE 供應商 = "' + search_supplier_id + '"';
+            var sql_data = { "sql":sql };
+            console.log("sql_data: ", sql_data)
+
+            $.ajax({
+                type:"GET",
+                url:"/sql_get",
+                dataType:"JSON",
+                data:sql_data,
+                success:function (res) {
+                    var data = "";
+                    data += '<table id="table_search_supplier" class="table table-bordered" style="margin-top: 10px;">';
+                    for (let fields = 0; fields < res.sql_field.length; fields++) {
+                        data += '<tr>';
+                        data += '<th>' + res.sql_field[fields][0] + '</th>';
+                        console.log("res.labels: " + res.labels)
+                        if (res.labels != '') {
+                            if (res.labels[0][fields] == null) {
+                                data += '<td id="' + res.labels[0][0] + '_' + fields + '">' + '' + '</td>';
+                            } else {
+                                data += '<td id="' + res.labels[0][0] + '_' + fields + '">' + res.labels[0][fields] + '</td>';
+                            }
+                        }
+                        data += '</tr>';
+                    }
+
+                    data += '<tr>'
+                    data += '<td></td>'
+                    data += '<td><input type="button" class="input-cond-add" style="width: 130px;" value="修改供應商資料" onclick="update_supplier(\'' + res.labels[0][0] + '\')"></td>'
+                    data += '</tr>'
+                    
+                    data += '</table>';
+                    var sectorSelect = document.getElementById("search_supplier_data");
+                    sectorSelect.innerHTML = data;
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("供應商: 無此編號 " + search_supplier_id + " 之供應商")
+                    } else {
+                        console.log("供應商查詢 thrownError" + thrownError)
+                    }
+                    data = "";
+                    var sectorSelect = document.getElementById("search_supplier_data");
+                    sectorSelect.innerHTML = data;
+                }
+            })
+        }
+
+        // 修改供應商資料
+        function update_supplier(supplier_id) {
+            for (let i = 1; i < 14; i++) {
+                var target_id = document.getElementById(supplier_id + '_' + i);
+                var old_supplier_name = target_id.innerText;
+                console.log('old_supplier_name: ', old_supplier_name)
+                target_id.innerHTML = "";
+                var textarea = '';
+                if (i == 3 || i == 7 || i == 10 || i == 11 ) {
+                    textarea += '<input id="'+ supplier_id + '_' + i + '_ta' + '" value="' + old_supplier_name + '" style="height: 25px; width: 450px">';
+                } else {
+                    textarea += '<input id="'+ supplier_id + '_' + i + '_ta' + '" value="' + old_supplier_name + '" style="height: 25px; width: 170px">';
+                }
+                if (i == 13) {
+                    textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_supplier(\'' + supplier_id + '\')">';
+                }
+                target_id.insertAdjacentHTML('beforeend', textarea);
+            }
+        }
+
+        // 確認修改供應商資料
+        function ComfirmUpdate_supplier(supplier_id) {
+            var new_name_value = $('#' + supplier_id + '_1_ta').val();
+            var new_person_value = $('#' + supplier_id + '_2_ta').val();
+            var new_address_value = $('#' + supplier_id + '_3_ta').val();
+            var new_ubnumber_value = $('#' + supplier_id + '_4_ta').val();
+            var new_phone_value = $('#' + supplier_id + '_5_ta').val();
+            var new_fax_value = $('#' + supplier_id + '_6_ta').val();
+            var new_email_value = $('#' + supplier_id + '_7_ta').val();
+            var new_cellphone_value = $('#' + supplier_id + '_8_ta').val();
+            var new_lineid_value = $('#' + supplier_id + '_9_ta').val();
+            var new_web_value = $('#' + supplier_id + '_10_ta').val();
+            var new_bank_value = $('#' + supplier_id + '_11_ta').val();
+            var new_payment_value = $('#' + supplier_id + '_12_ta').val();
+            var new_remark_value = $('#' + supplier_id + '_13_ta').val();
+
+            sql = 'UPDATE 供應商 SET `公司` = "' + new_name_value + '"' + 
+                   ', `聯絡人` = "' + new_person_value + '"' + 
+                   ', `地址` = "' + new_address_value + '"' + 
+                   ', `統一編號` = "' + new_ubnumber_value + '"' + 
+                   ', `電話` = "' + new_phone_value + '"' + 
+                   ', `傳真` = "' + new_fax_value + '"' + 
+                   ', `email` = "' + new_email_value + '"' + 
+                   ', `手機` = "' + new_cellphone_value + '"' + 
+                   ', `Line ID` = "' + new_lineid_value + '"' + 
+                   ', `網址` = "' + new_web_value + '"' + 
+                   ', `銀行資料` = "' + new_bank_value + '"' + 
+                   ', `付款方式` = "' + new_payment_value + '"' + 
+                   ', `備註` = "' + new_remark_value + '"' + 
+                   ' WHERE `供應商` = "' + supplier_id + '";'
+            console.log('sql: ' + sql)
+            var sql_data = { "sql":sql };
+
+            $.ajax({
+                type:"GET",
+                url:"/sql_get",
+                dataType:"JSON",
+                data:sql_data,
+                success:function (res) {
+                    search_supplier();
+                    alert("供應商: 修改成功 !")
+                },
+                error: function (thrownError) {
+                    if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                        alert("供應商: 供應商編號 " + supplier_id + " 修改未成功")
+                    } else {
+                        console.log("修改供應商內容 thrownError" + thrownError)
+                    }
+                }
+            })
+        }
+        
+        // 新增供應商項目
         function create_supplier() {
-            var su_id = $("#create_supplier_id").val();
+            // var su_id = $("#create_supplier_id").val();
+            var sup_id_1 = $("#create_supplier_id_1").val();
+            var sup_id_2 = $("#create_supplier_id_2").val();
             var su_name = $("#create_supplier_name").val();
-            var sql = '';
-            sql += 'INSERT INTO 供應商 (`供應商`, `公司`) ' +
-                   'VALUES ("' + su_id + '", "' + su_name + '");';
+            sql = 'INSERT INTO 供應商 (`供應商`, `公司`) ' +
+                  'VALUES ("' + sup_id_1 + sup_id_2 + '", "' + su_name + '");';
             console.log("sql:", sql)
             var sql_data = { "sql":sql };
 
@@ -239,6 +431,7 @@
                 data:sql_data,
                 success:function (res) {
                     alert('新增 供應商 成功')
+                    location.reload();
                 },
                 error: function (thrownError) {
                     if (thrownError.statusText == "INTERNAL SERVER ERROR") {

+ 292 - 299
Rita/ERP_Rita/templates/drop_down_list.html

@@ -1,300 +1,293 @@
-<!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">
-
-    <!-- 新 Bootstrap4 核心 CSS 文件 -->
-    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
-    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
-    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
-    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
-    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
-    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
-    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
-    <!--可用來建立使用者小圖示-->
-    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
-
-    <style>
-        .newcondition_css {
-            padding: 10px;
-            margin-top: 10px;
-            background-color: honeydew;
-        }
-
-        hr {
-            margin-top: 5px;
-            margin-bottom: 5px;
-        }
-    </style>
-
-</head>
-
-<body>
-    <!--     
-    <script>
-        // [系統]更新: Array / renew_system function
-        system_object = new Array();
-        system_object[0] = ["   "];
-        system_object[1] = ["   ", "清洗槽組立"];
-        system_object[2] = ["   ", "發酵桶組立"];
-        system_object[3] = ["   ", "乾燥桶組立"];
-        function renew_system(index) {
-            var Value="";
-            for(var i=0; i<system_object[index].length; i++){
-                Value = Value + '<option value=' + system_object[index][i] + '> ' + system_object[index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("system");
-            sectorSelect.innerHTML = Value;
-            $('#product_index').text(index)
-        }
-        // [模組]更新: Array / renew_system function
-        module_object = new Array();
-        module_object[0] = ["   "];
-        module_object[1] = ["   ", "c1上蓋組立", "c2內桶槽組立"];
-        module_object[2] = ["   ", "f1上蓋組立", "f2控制盒組立"];
-        module_object[3] = ["   ", "d1上蓋組立", "d2控制盒組立"];
-        
-        function renew_module(index) {
-            var Value="";
-            for(var i=0; i<module_object[index].length; i++){
-                Value = Value + '<option value=' + module_object[index][i] + '>' + module_object[index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("module");
-            sectorSelect.innerHTML = Value;
-            $('#system_index').text(index)
-        }
-        // // [零件]更新: Array / renew_system function
-        component_object = new Array();
-        component_object[0] = ["   "];
-        component_object[1][1] = ["   ", "c1_M10平墊圈", "c1_M10螺帽"];
-        component_object[1][2] = ["   ", "c2_內桶槽", "c2_內桶槽固定環"];
-        component_object[2][1] = ["   ", "f1_吸料機入料管", "f1_入料斗擋板"];
-        component_object[2][2] = ["   ", "f2_LED指示燈 綠色 TB12LED-G0201", "f2_K3 LED指示燈-主板"];
-        component_object[3][1] = ["   ", "d1_軸心(單邊出軸)", "d1_墊片M18x25x1.5"];
-        component_object[3][2] = ["   ", "d2_M3x5螺絲", "d2_M3x5銅柱 1公1母"];
-        function renew_component(product_index, index) {
-            var Value="";
-            for(var i=0; i<component_object[product_index][index].length; i++){
-                Value = Value + '<option value=' + component_object[product_index][index] + '>' + component_object[index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("component");
-            sectorSelect.innerHTML = Value;
-            $('#module_index').text(index)
-        }
-        // // 輸出零件 index
-        function renew_item(index) {
-            $('#component_index').text(index)
-        }
-
-    </script>
-     -->
-    <br>
-
-    產品:
-    <select id="product" onChange="renew_system(this.selectedIndex);">
-    </select>
-    系統:
-    <select id="system" onChange="renew_module(this.selectedIndex);">
-    </select>
-    模組:
-    <select id="module" onChange="renew_component(this.selectedIndex);">
-    </select>
-    零件:
-    <select id="component" onChange="">
-        <input type="button" id="input_value" value="取值" onclick="printValue();"><br>
-        取值: <span id="span_value"></span>
-    </select><br>
-
-    <script>
-        // 輸出關鍵字
-        function printValue() {
-            // database 取值語法
-            var data = 'select * from teststock1213';
-            // 取得下拉式選單選擇的 value
-            var product_value = $("#product").val();
-            var system_value = $("#system").val();
-            var module_value = $("#module").val();
-            var component_value = $("#component").val();
-            if (product_value != '*' || system_value != '*' || module_value != '*' || component_value != '*') {
-                data += ' WHERE ';
-
-                if (product_value != '*') {
-                    data += '`產品` = ' + product_value;
-                    if (system_value != '*' || module_value != '*' || component_value != '*') {
-                        data += ' AND ';
-                    }
-                }
-                if (system_value != '*') {
-                    data += '`系統` = ' + system_value;
-                    if (module_value != '*' || component_value != '*') {
-                        data += ' AND ';
-                    }
-                }
-                if (module_value != '*') {
-                    data += '`模組` = ' + module_value;
-                    if (component_value != '*') {
-                        data += ' AND ';
-                    }
-                }
-                if (component_value != '*') {
-                    data += '`零件` = ' + component_value;
-                }
-            }
-
-            // if product_value
-            $("#span_value").text(data)
-        }
-
-        // 資料庫中的所有 [產品]
-        var product_item = ["*", "清洗貨櫃", "發酵貨櫃", "乾燥貨櫃"]
-        var inner = '';
-        for (let i = 0; i < product_item.length; i++) {
-            inner += '<option value="' + product_item[i] + '">' + product_item[i] + '</option>';
-        }
-        var sectorSelect = document.getElementById("product");
-        sectorSelect.innerHTML = inner;
-        // 資料庫中的所有 [系統]
-        var system_item = ["*", "清洗槽組立", "發酵桶組立", "乾燥桶組立"]
-        var inner = '';
-        for (let i = 0; i < system_item.length; i++) {
-            inner += '<option value="' + system_item[i] + '">' + system_item[i] + '</option>';
-        }
-        var sectorSelect = document.getElementById("system");
-        sectorSelect.innerHTML = inner;
-        // 資料庫中的所有 [模組]
-        var module_item = ["*", "上蓋組立", "內桶槽組立", "控制盒組立"]
-        var inner = '';
-        for (let i = 0; i < module_item.length; i++) {
-            inner += '<option value="' + module_item[i] + '">' + module_item[i] + '</option>';
-        }
-        var sectorSelect = document.getElementById("module");
-        sectorSelect.innerHTML = inner;
-        // 資料庫中的所有 [零件]
-        var component_item = ["*", "M10平墊圈", "M10螺帽", "內桶槽", "內桶槽固定環", "吸料機入料管",
-            "入料斗擋板", "LED指示燈_綠色 TB12LED-G0201", "K3 LED指示燈-主板",
-            "軸心(單邊出軸)", "墊片M18x25x1.5", "M3x5螺絲", "M3x5銅柱 1公1母"]
-        var inner = '';
-        for (let i = 0; i < component_item.length; i++) {
-            inner += '<option value="' + component_item[i] + '">' + component_item[i] + '</option>';
-        }
-        var sectorSelect = document.getElementById("component");
-        sectorSelect.innerHTML = inner;
-
-
-        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-        // 系統的 index
-        var sysIndex;
-        // [系統]更新: Array / renew_system function
-        system_object = new Array();
-        system_object[0] = ["*"];
-        system_object[1] = ["*", "清洗槽組立"];
-        system_object[2] = ["*", "發酵桶組立"];
-        system_object[3] = ["*", "乾燥桶組立"];
-        function renew_system(index) {
-            sysIndex = index
-            var inner = '';
-            for (let i = 0; i < system_object[index].length; i++) {
-                inner += '<option value="' + system_object[index][i] + '">' + system_object[index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("system");
-            sectorSelect.innerHTML = inner;
-        }
-
-        // 模組的 index
-        var moIndex;
-        // [模組]更新: Array / renew_system function
-        module_object = new Array();
-        module_object[0] = ["*"];
-        module_object[1] = ["*", "清洗槽組立"];
-        module_object[2] = ["*", "發酵桶組立"];
-        module_object[3] = ["*", "乾燥桶組立"];
-        module_object[0][0] = ["*"];
-        module_object[1][1] = ["*", "c1上蓋組立", "c2內桶槽組立"];
-        module_object[2][1] = ["*", "f1上蓋組立", "f2控制盒組立"];
-        module_object[3][1] = ["*", "d1上蓋組立", "d2控制盒組立"];
-        function renew_module(index) {
-            moIndex = index
-            var inner = '';
-            for (let i = 0; i < module_object[sysIndex][index].length; i++) {
-                inner += '<option value="' + module_object[sysIndex][index][i] + '">' + module_object[sysIndex][index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("module");
-            sectorSelect.innerHTML = inner;
-        }
-
-        // 零件
-        // // [零件]更新: Array / renew_system function
-        component_object = new Array();
-        component_object[0] = ["*"];
-        component_object[1] = ["*", "清洗槽組立"];
-        component_object[2] = ["*", "發酵桶組立"];
-        component_object[3] = ["*", "乾燥桶組立"];
-        component_object[0][0] = ["*"];
-        component_object[1][1] = ["*", "c1上蓋組立", "c2內桶槽組立"];
-        component_object[2][1] = ["*", "f1上蓋組立", "f2控制盒組立"];
-        component_object[3][1] = ["*", "d1上蓋組立", "d2控制盒組立"];
-        component_object[0][0][0] = ["*"];
-        component_object[1][1][0] = ["*"];
-        component_object[1][1][1] = ["*", "c1_M10平墊圈", "c1_M10螺帽"];
-        component_object[1][1][2] = ["*", "c2_內桶槽", "c2_內桶槽固定環"];
-        component_object[2][1][0] = ["*"];
-        component_object[2][1][1] = ["*", "f1_吸料機入料管", "f1_入料斗擋板"];
-        component_object[2][1][2] = ["*", "f2_LED指示燈 綠色 TB12LED-G0201", "f2_K3 LED指示燈-主板"];
-        component_object[3][1][0] = ["*"];
-        component_object[3][1][1] = ["*", "d1_軸心(單邊出軸)", "d1_墊片M18x25x1.5"];
-        component_object[3][1][2] = ["*", "d2_M3x5螺絲", "d2_M3x5銅柱 1公1母"];
-        function renew_component(index) {
-            var Value = "";
-            for (var i = 0; i < component_object[sysIndex][moIndex][index].length; i++) {
-                Value = Value + '<option value="' + component_object[sysIndex][moIndex][index][i] + '">' + component_object[sysIndex][moIndex][index][i] + '</option>';
-            }
-            var sectorSelect = document.getElementById("component");
-            sectorSelect.innerHTML = Value;
-        }
-    </script>
-    <!-- // 資料庫中的所有 [產品]
-        var product_item = ["*", "清洗貨櫃", "發酵貨櫃", "乾燥貨櫃"]
-        var inner = '';
-        for (let i = 0; i < product_item.length; i++) {
-            inner += '<option value="' + product_item[i] + '">' + product_item[i] + '</option>';
-        }
-        var sectorSelect = document.getElementById("product");
-        sectorSelect.innerHTML = inner; -->
-
-    <table class="table table-bordered">
-        <tr>
-            {% for i1 in labels %}
-            <th>{{i1}}</th>
-            {% endfor %}
-        </tr>
-        {% for i in content %}
-        
-        <tr id="tr_content">
-            
-            <td>{{ i[0] }}</td>
-            <td>{{ i[1] }}</td>
-            <td>{{ i[2] }}</td>
-            <td>{{ i[3] }}</td>
-            <td>{{ i[4] }}</td>
-            <td>{{ i[5] }}</td>
-            <td>{{ i[6] }}</td>
-            <td>{{ i[7] }}</td>
-            <td>{{ i[8] }}</td>
-            <td>{{ i[9] }}</td>
-            <td>{{ i[10] }}</td>
-            <td>{{ i[11] }}</td>
-            <td>{{ i[12] }}</td>
-            <td>{{ i[13] }}</td>
-            <td>{{ i[14] }}</td>
-            <td>{{ i[15] }}</td>
-        </tr>
-        {% endfor %}
-    </table>
-
-
-</body>
-
+<!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">
+    
+    <style>
+        .newcondition_css {
+            padding: 10px;
+            margin-top: 10px;
+            background-color: honeydew;
+        }
+
+        hr {
+            margin-top: 5px;
+            margin-bottom: 5px;
+        }
+    </style>
+
+</head>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <!--     
+    <script>
+        // [系統]更新: Array / renew_system function
+        system_object = new Array();
+        system_object[0] = ["   "];
+        system_object[1] = ["   ", "清洗槽組立"];
+        system_object[2] = ["   ", "發酵桶組立"];
+        system_object[3] = ["   ", "乾燥桶組立"];
+        function renew_system(index) {
+            var Value="";
+            for(var i=0; i<system_object[index].length; i++){
+                Value = Value + '<option value=' + system_object[index][i] + '> ' + system_object[index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("system");
+            sectorSelect.innerHTML = Value;
+            $('#product_index').text(index)
+        }
+        // [模組]更新: Array / renew_system function
+        module_object = new Array();
+        module_object[0] = ["   "];
+        module_object[1] = ["   ", "c1上蓋組立", "c2內桶槽組立"];
+        module_object[2] = ["   ", "f1上蓋組立", "f2控制盒組立"];
+        module_object[3] = ["   ", "d1上蓋組立", "d2控制盒組立"];
+        
+        function renew_module(index) {
+            var Value="";
+            for(var i=0; i<module_object[index].length; i++){
+                Value = Value + '<option value=' + module_object[index][i] + '>' + module_object[index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("module");
+            sectorSelect.innerHTML = Value;
+            $('#system_index').text(index)
+        }
+        // // [零件]更新: Array / renew_system function
+        component_object = new Array();
+        component_object[0] = ["   "];
+        component_object[1][1] = ["   ", "c1_M10平墊圈", "c1_M10螺帽"];
+        component_object[1][2] = ["   ", "c2_內桶槽", "c2_內桶槽固定環"];
+        component_object[2][1] = ["   ", "f1_吸料機入料管", "f1_入料斗擋板"];
+        component_object[2][2] = ["   ", "f2_LED指示燈 綠色 TB12LED-G0201", "f2_K3 LED指示燈-主板"];
+        component_object[3][1] = ["   ", "d1_軸心(單邊出軸)", "d1_墊片M18x25x1.5"];
+        component_object[3][2] = ["   ", "d2_M3x5螺絲", "d2_M3x5銅柱 1公1母"];
+        function renew_component(product_index, index) {
+            var Value="";
+            for(var i=0; i<component_object[product_index][index].length; i++){
+                Value = Value + '<option value=' + component_object[product_index][index] + '>' + component_object[index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("component");
+            sectorSelect.innerHTML = Value;
+            $('#module_index').text(index)
+        }
+        // // 輸出零件 index
+        function renew_item(index) {
+            $('#component_index').text(index)
+        }
+
+    </script>
+     -->
+    <br>
+
+    產品:
+    <select id="product" onChange="renew_system(this.selectedIndex);">
+    </select>
+    系統:
+    <select id="system" onChange="renew_module(this.selectedIndex);">
+    </select>
+    模組:
+    <select id="module" onChange="renew_component(this.selectedIndex);">
+    </select>
+    零件:
+    <select id="component" onChange="">
+        <input type="button" id="input_value" value="取值" onclick="printValue();"><br>
+        取值: <span id="span_value"></span>
+    </select><br>
+
+    <script>
+        // 輸出關鍵字
+        function printValue() {
+            // database 取值語法
+            var data = 'select * from teststock1213';
+            // 取得下拉式選單選擇的 value
+            var product_value = $("#product").val();
+            var system_value = $("#system").val();
+            var module_value = $("#module").val();
+            var component_value = $("#component").val();
+            if (product_value != '*' || system_value != '*' || module_value != '*' || component_value != '*') {
+                data += ' WHERE ';
+
+                if (product_value != '*') {
+                    data += '`產品` = ' + product_value;
+                    if (system_value != '*' || module_value != '*' || component_value != '*') {
+                        data += ' AND ';
+                    }
+                }
+                if (system_value != '*') {
+                    data += '`系統` = ' + system_value;
+                    if (module_value != '*' || component_value != '*') {
+                        data += ' AND ';
+                    }
+                }
+                if (module_value != '*') {
+                    data += '`模組` = ' + module_value;
+                    if (component_value != '*') {
+                        data += ' AND ';
+                    }
+                }
+                if (component_value != '*') {
+                    data += '`零件` = ' + component_value;
+                }
+            }
+
+            // if product_value
+            $("#span_value").text(data)
+        }
+
+        // 資料庫中的所有 [產品]
+        var product_item = ["*", "清洗貨櫃", "發酵貨櫃", "乾燥貨櫃"]
+        var inner = '';
+        for (let i = 0; i < product_item.length; i++) {
+            inner += '<option value="' + product_item[i] + '">' + product_item[i] + '</option>';
+        }
+        var sectorSelect = document.getElementById("product");
+        sectorSelect.innerHTML = inner;
+        // 資料庫中的所有 [系統]
+        var system_item = ["*", "清洗槽組立", "發酵桶組立", "乾燥桶組立"]
+        var inner = '';
+        for (let i = 0; i < system_item.length; i++) {
+            inner += '<option value="' + system_item[i] + '">' + system_item[i] + '</option>';
+        }
+        var sectorSelect = document.getElementById("system");
+        sectorSelect.innerHTML = inner;
+        // 資料庫中的所有 [模組]
+        var module_item = ["*", "上蓋組立", "內桶槽組立", "控制盒組立"]
+        var inner = '';
+        for (let i = 0; i < module_item.length; i++) {
+            inner += '<option value="' + module_item[i] + '">' + module_item[i] + '</option>';
+        }
+        var sectorSelect = document.getElementById("module");
+        sectorSelect.innerHTML = inner;
+        // 資料庫中的所有 [零件]
+        var component_item = ["*", "M10平墊圈", "M10螺帽", "內桶槽", "內桶槽固定環", "吸料機入料管",
+            "入料斗擋板", "LED指示燈_綠色 TB12LED-G0201", "K3 LED指示燈-主板",
+            "軸心(單邊出軸)", "墊片M18x25x1.5", "M3x5螺絲", "M3x5銅柱 1公1母"]
+        var inner = '';
+        for (let i = 0; i < component_item.length; i++) {
+            inner += '<option value="' + component_item[i] + '">' + component_item[i] + '</option>';
+        }
+        var sectorSelect = document.getElementById("component");
+        sectorSelect.innerHTML = inner;
+
+
+        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        // 系統的 index
+        var sysIndex;
+        // [系統]更新: Array / renew_system function
+        system_object = new Array();
+        system_object[0] = ["*"];
+        system_object[1] = ["*", "清洗槽組立"];
+        system_object[2] = ["*", "發酵桶組立"];
+        system_object[3] = ["*", "乾燥桶組立"];
+        function renew_system(index) {
+            sysIndex = index
+            var inner = '';
+            for (let i = 0; i < system_object[index].length; i++) {
+                inner += '<option value="' + system_object[index][i] + '">' + system_object[index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("system");
+            sectorSelect.innerHTML = inner;
+        }
+
+        // 模組的 index
+        var moIndex;
+        // [模組]更新: Array / renew_system function
+        module_object = new Array();
+        module_object[0] = ["*"];
+        module_object[1] = ["*", "清洗槽組立"];
+        module_object[2] = ["*", "發酵桶組立"];
+        module_object[3] = ["*", "乾燥桶組立"];
+        module_object[0][0] = ["*"];
+        module_object[1][1] = ["*", "c1上蓋組立", "c2內桶槽組立"];
+        module_object[2][1] = ["*", "f1上蓋組立", "f2控制盒組立"];
+        module_object[3][1] = ["*", "d1上蓋組立", "d2控制盒組立"];
+        function renew_module(index) {
+            moIndex = index
+            var inner = '';
+            for (let i = 0; i < module_object[sysIndex][index].length; i++) {
+                inner += '<option value="' + module_object[sysIndex][index][i] + '">' + module_object[sysIndex][index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("module");
+            sectorSelect.innerHTML = inner;
+        }
+
+        // 零件
+        // // [零件]更新: Array / renew_system function
+        component_object = new Array();
+        component_object[0] = ["*"];
+        component_object[1] = ["*", "清洗槽組立"];
+        component_object[2] = ["*", "發酵桶組立"];
+        component_object[3] = ["*", "乾燥桶組立"];
+        component_object[0][0] = ["*"];
+        component_object[1][1] = ["*", "c1上蓋組立", "c2內桶槽組立"];
+        component_object[2][1] = ["*", "f1上蓋組立", "f2控制盒組立"];
+        component_object[3][1] = ["*", "d1上蓋組立", "d2控制盒組立"];
+        component_object[0][0][0] = ["*"];
+        component_object[1][1][0] = ["*"];
+        component_object[1][1][1] = ["*", "c1_M10平墊圈", "c1_M10螺帽"];
+        component_object[1][1][2] = ["*", "c2_內桶槽", "c2_內桶槽固定環"];
+        component_object[2][1][0] = ["*"];
+        component_object[2][1][1] = ["*", "f1_吸料機入料管", "f1_入料斗擋板"];
+        component_object[2][1][2] = ["*", "f2_LED指示燈 綠色 TB12LED-G0201", "f2_K3 LED指示燈-主板"];
+        component_object[3][1][0] = ["*"];
+        component_object[3][1][1] = ["*", "d1_軸心(單邊出軸)", "d1_墊片M18x25x1.5"];
+        component_object[3][1][2] = ["*", "d2_M3x5螺絲", "d2_M3x5銅柱 1公1母"];
+        function renew_component(index) {
+            var Value = "";
+            for (var i = 0; i < component_object[sysIndex][moIndex][index].length; i++) {
+                Value = Value + '<option value="' + component_object[sysIndex][moIndex][index][i] + '">' + component_object[sysIndex][moIndex][index][i] + '</option>';
+            }
+            var sectorSelect = document.getElementById("component");
+            sectorSelect.innerHTML = Value;
+        }
+    </script>
+    <!-- // 資料庫中的所有 [產品]
+        var product_item = ["*", "清洗貨櫃", "發酵貨櫃", "乾燥貨櫃"]
+        var inner = '';
+        for (let i = 0; i < product_item.length; i++) {
+            inner += '<option value="' + product_item[i] + '">' + product_item[i] + '</option>';
+        }
+        var sectorSelect = document.getElementById("product");
+        sectorSelect.innerHTML = inner; -->
+
+    <table class="table table-bordered">
+        <tr>
+            {% for i1 in labels %}
+            <th>{{i1}}</th>
+            {% endfor %}
+        </tr>
+        {% for i in content %}
+        
+        <tr id="tr_content">
+            
+            <td>{{ i[0] }}</td>
+            <td>{{ i[1] }}</td>
+            <td>{{ i[2] }}</td>
+            <td>{{ i[3] }}</td>
+            <td>{{ i[4] }}</td>
+            <td>{{ i[5] }}</td>
+            <td>{{ i[6] }}</td>
+            <td>{{ i[7] }}</td>
+            <td>{{ i[8] }}</td>
+            <td>{{ i[9] }}</td>
+            <td>{{ i[10] }}</td>
+            <td>{{ i[11] }}</td>
+            <td>{{ i[12] }}</td>
+            <td>{{ i[13] }}</td>
+            <td>{{ i[14] }}</td>
+            <td>{{ i[15] }}</td>
+        </tr>
+        {% endfor %}
+    </table>
+
+
+</body>
+
 </html>

+ 77 - 0
Rita/ERP_Rita/templates/form_not_exist.html

@@ -0,0 +1,77 @@
+<!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">
+
+</head>
+
+<script>
+</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>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <center><h6 style="margin: 20px;">無此表單</h6></center>
+</body>
+</html>

+ 13 - 9
Rita/ERP_Rita/templates/hello.html

@@ -1,10 +1,14 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>{{name}}</title>
-</head>
-<body>
-    <h1>{{name}}</h1>
-</body>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>{{name}}</title>
+</head>
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <h1>{{name}}</h1>
+</body>
 </html>

+ 108 - 10
Rita/ERP_Rita/templates/index.html

@@ -1,11 +1,109 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>Coffee Project</title>
-    db connect!
-</head>
-<body>
-    <h1>Hello Coffee!</h1>
-</body>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>ERP</title>
+    
+</head>
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <h1>ERP</h1>
+
+    <table class="table table-bordered" style="margin-top: 10px;">
+        <tr>
+            <th><a href="/search">/search</a></th>
+            <td>
+                零件表查詢 : 修改零件名稱、刪除零件<br>
+                規格表查詢 : 修改規格表內容<br>
+            </td>
+        </tr>
+        <tr>
+            <th><a href="/create_component_table_item">/create_component_table_item</a></th>
+            <td>
+                新增零件 (會計科目+類別+流水號不重複)<br>
+                新增會計科目項目<br>
+                新增類別項目<br>
+                新增供應商項目<br>
+                修改供應商資料<br>
+            </td>
+        </tr>
+        <tr>
+            <th><a href="/create_BOM">/create_BOM</a></th>
+            <td>
+                新增 BOM 表<br>
+                查詢 BOM 表內容<br>
+                匯出 BOM 表 (.xlsx)<br>
+            </td>
+        </tr>
+        <tr>
+            <th><a href="/search_companyid">/search_companyid</a></th>
+            <td>
+                查詢包含某內部料號之資料表<br>
+                查詢是否有此內部料號之 BOM 表<br>
+                修改舊內部料號 - "新供應商"<br>
+                修改舊內部料號 - "新內部料號"<br>
+            </td>
+        </tr>
+        <tr>
+            <th><a href="/PR_list">/PR_list</a></th>
+            <td>
+                新增請購草稿<br>
+                匯出詢價單 (.pdf)<br>
+                操作前請先登入 !<br>
+                <table>
+                    <tr>
+                        <th>代號</th>
+                        <th>員工編號</th>
+                        <th>職位</th>
+                    </tr>
+                    <tr>
+                        <td>Amy</td>
+                        <td>HRMA0001T01</td>
+                        <td>管理部主管<br>採購部主管</td>
+                    </tr>
+                    <tr>
+                        <td>Andrey</td>
+                        <td>HRRD0001T01</td>
+                        <td>研發部主管</td>
+                    </tr>
+                    <tr>
+                        <td>Gina</td>
+                        <td>HRME0001T02</td>
+                        <td>研發部組員</td>
+                    </tr>
+                    <tr>
+                        <td>Allen</td>
+                        <td>HRRD0002T01</td>
+                        <td>研發部組員</td>
+                    </tr>
+                    <tr>
+                        <td>FatWolf</td>
+                        <td>HRRD0003T01</td>
+                        <td>研發部組員</td>
+                    </tr>
+                    <tr>
+                        <td>Rita</td>
+                        <td>HRRD0004T02</td>
+                        <td>研發部組員</td>
+                    </tr>
+                    <tr>
+                        <td>Ray</td>
+                        <td>HRPU0001T02</td>
+                        <td>採購部主管</td>
+                    </tr>
+                    <tr>
+                        <td>Christina</td>
+                        <td>HRPU0002T02</td>
+                        <td>採購部組員</td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+
+        
+    </table>
+</body>
 </html>

+ 58 - 0
Rita/ERP_Rita/templates/login.html

@@ -0,0 +1,58 @@
+<!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">
+    
+</head>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <div style="text-align: center; padding-top: 100px;">
+        <img src="../static/img/ALMIGHTY_RAY.jpg" height="120px" style="padding-right: 50px;">
+        <img src="../static/img/SKYAI.jpg" height="120px"><br>
+    </div>
+    
+    <form method="post" action="/login" style="text-align: center; padding-top: 30px; vertical-align: middle; font-size: 18px;">
+        請輸入員工編號 :
+        <input type="text" name="user_id" value="" style="height: 25px;">
+        <input type="submit" id="user_exist" value="登入">
+    </form>
+
+</body>
+
+</html>

+ 175 - 0
Rita/ERP_Rita/templates/notice.html

@@ -0,0 +1,175 @@
+<!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">
+    
+</head>
+
+<script>
+    var USER_NAME = '{{user_name}}'
+    console.log("user_name: " + USER_NAME);
+</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>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    <center><h6 style="margin: 20px;">通知列表</h6></center>
+    目前使用者:{{user_name}}<br>
+
+    {% if notice_list == () %}
+        無通知
+    {% else %}
+        <table class="table table-bordered" style="margin-top: 10px;">
+            <tr>
+                <!-- <th>通知對象</th> -->
+                <th>日期</th>
+                <th>表單單號</th>
+                <th>內容</th>
+                <th>已完成</th>
+            </tr>
+            {% for notice in notice_list %}
+            <tr>
+                <!-- <td>{{notice[1]}}</td> -->
+                <td>{{notice[2]}}</td>
+                <td><a href="/PR_user_{{notice[3]}}" target="_blank">{{notice[3]}}</a></td>
+                <td>{{notice[4]}}</td>
+                <td>
+                {% if notice[5] == 0 %}
+                    <input type="checkbox" id="notice_{{notice[0]}}_check" onclick="checkbox_check('{{notice[0]}}', '{{notice[3]}}')">
+                {% elif notice[5] == 1 %}
+                    <input type="checkbox" id="notice_{{notice[0]}}_check" onclick="checkbox_check('{{notice[0]}}', '{{notice[3]}}')" checked>
+                {% endif %}
+                </td>
+            </tr>
+            {% endfor %}
+        </table>
+    {% endif%}
+
+</body>
+<script>
+    function checkbox_check(NoticeNum, FormNum) {
+        var checkbox_id = $('#notice_' + NoticeNum + '_check').prop("checked");
+        console.log("checkbox_id: " + checkbox_id)      // 勾選為 true, 取消為 false
+        if (checkbox_id == true) {
+            // 從空白到勾選
+            var checkbox_confirm_true = confirm("[通知已完成]\n確定已完成 " + FormNum + " 表單, 後續不再提醒 ?")
+            console.log("checkbox_confirm_true: " + checkbox_confirm_true)
+            if (checkbox_confirm_true == true) {
+                sql = 'UPDATE `通知列表` SET `已完成`="1" WHERE `通知編號`="' + NoticeNum + '"';
+                var sql_data = { "sql":sql };
+                console.log("sql")
+                $.ajax({
+                    type:"GET",
+                    url:"/sql_get",
+                    dataType:"JSON",
+                    data:sql_data,
+                    async:false,
+                    success:function (res) {
+                        location.reload()
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("通知 " + NoticeNum + " 勾選未成功")
+                        } else {
+                            alert("通知勾選 thrownError" + thrownError)
+                        }
+                    }
+                })
+            } else {
+                $('#notice_' + NoticeNum + '_check').prop('checked', false);
+            }
+        } else {
+            // // 從勾選到空白
+            // var checkbox_confirm_false = confirm("[通知未完成]\n確定取消勾選 " + FormNum + " 表單?")
+            // console.log("checkbox_confirm_false: " + checkbox_confirm_false)
+            // if (checkbox_confirm_false == true) {
+            //     sql = 'UPDATE `通知列表` SET `已完成`="0" WHERE `通知編號`="' + NoticeNum + '"';
+            //     var sql_data = { "sql":sql };
+            //     console.log("sql")
+            //     $.ajax({
+            //         type:"GET",
+            //         url:"/sql_get",
+            //         dataType:"JSON",
+            //         data:sql_data,
+            //         async:false,
+            //         success:function (res) {
+            //             location.reload()
+            //         },
+            //         error: function (thrownError) {
+            //             if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+            //                 alert("通知 " + NoticeNum + " 取消勾選未成功")
+            //             } else {
+            //                 alert("通知取消勾選 thrownError" + thrownError)
+            //             }
+            //         }
+            //     })
+            // } else {
+            //     $('#notice_' + NoticeNum + '_check').prop('checked', true);
+            // }
+        }
+    }
+
+</script>
+
+</html>

+ 248 - 123
Rita/ERP_Rita/templates/search.html

@@ -5,17 +5,38 @@
     <meta charset="UTF-8">
     <title>{{ title }}</title>
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
-
+<!-- 0127 更新 -->
     <!-- 新 Bootstrap4 核心 CSS 文件 -->
-    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
+    <!-- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css"> -->
+    <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> -->
     <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
-    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
+    <!-- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> -->
     <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
-    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
+    <!-- <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script> -->
     <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
+    <!-- <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> -->
+    <!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> -->
+    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> -->
+    <!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> -->
+    <!-- <script src="../static/js/bootstrap.min.js"></script> -->
+<!-- 舊的, 網頁讀取有問題 -->
+    <!-- 新 Bootstrap4 核心 CSS 文件
+    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
+    jQuery文件。务必在bootstrap.min.js 之前引入
+    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
+    popper.min.js 用于弹窗、提示、下拉菜单
+    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
+    最新的 Bootstrap4 核心 JavaScript 文件
     <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
-    <!--可用來建立使用者小圖示-->
-    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+    可用來建立使用者小圖示
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> -->
+
+    <script>
+        // var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'version', 'path', 'size', 'material', 
+        //                             'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
+        var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'path', 'size', 'material', 
+                                    'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
+    </script>
 </head>
 
 <style>
@@ -48,6 +69,10 @@
 </style>
 
 <body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
     會計科目:
     <select id="accountingsubjects" onChange="">
         <option value="00"></option>
@@ -82,43 +107,50 @@
     <input id="component_name_input" placeholder="零件關鍵字輸入" style="height: 25px; width: 120px;">
     <input type="button" id="search_component_table" value="零件表查詢" onclick="search_component_table();">
     <input type="button" id="search_component_standard_table" value="(零件)規格表查詢" onclick="search_component_standard_table();">
-    <input type="button" id="search_component_stock_table" value="(零件)庫存表查詢" onclick="search_component_stock_table();">
-    <input type="button" id="search_component_import_table" value="(零件)進貨表查詢" onclick="search_component_import_table();">
-    <input type="button" id="search_component_export_table" value="(零件)銷貨表查詢" onclick="search_component_export_table();">
+    <!-- <input type="button" id="search_component_stock_table" value="(零件)庫存表查詢" onclick="search_component_stock_table();" style="display: none;"> -->
+    <!-- <input type="button" id="search_component_import_table" value="(零件)進貨表查詢" onclick="search_component_import_table();" style="display: none;"> -->
+    <!-- <input type="button" id="search_component_export_table" value="(零件)銷貨表查詢" onclick="search_component_export_table();" style="display: none;"> -->
     <br>
     <a id="create_component_table_item" href="/create_component_table_item">(零件)新增零件</a>
     <a id="create_BOM" href="/create_BOM">建立 BOM 表</a>
+    <!-- <a id="update_Picture" href="/update_Picture" disabled="true"><s>更新圖片</s></a> -->
+    <br>
+    <br>
+    <br>
 
     <script>
-        // (零件)銷貨表查詢
-        function search_component_export_table() {
-            var sql = 'SELECT 銷貨表.* FROM 零件表';
-            sql += ' INNER JOIN 銷貨表';
-            sql += ' ON 零件表.內部料號 = 銷貨表.內部料號';
-            search_relation_insertdata(sql)
-        }
-
-        // (零件)進貨表查詢
-        function search_component_import_table() {
-            var sql = 'SELECT 進貨表.* FROM 零件表';
-            sql += ' INNER JOIN 進貨表';
-            sql += ' ON 零件表.內部料號 = 進貨表.內部料號';
-            search_relation_insertdata(sql)
-        }
+        // // (零件)銷貨表查詢
+        // function search_component_export_table() {
+        //     var sql = 'SELECT 銷貨表.* FROM 零件表';
+        //     sql += ' INNER JOIN 銷貨表';
+        //     sql += ' ON 零件表.內部料號 = 銷貨表.內部料號';
+        //     search_relation_insertdata(sql)
+        // }
+
+        // // (零件)進貨表查詢
+        // function search_component_import_table() {
+        //     var sql = 'SELECT 進貨表.* FROM 零件表';
+        //     sql += ' INNER JOIN 進貨表';
+        //     sql += ' ON 零件表.內部料號 = 進貨表.內部料號';
+        //     search_relation_insertdata(sql)
+        // }
+
+        // // (零件)庫存表查詢
+        // function search_component_stock_table() {
+        //     var sql = 'SELECT 庫存表.時間, 庫存表.內部料號, 庫存表.數量 FROM 零件表';
+        //     sql += ' INNER JOIN 庫存表';
+        //     sql += ' ON 零件表.內部料號 = 庫存表.內部料號';
+        //     search_relation_insertdata(sql)
+        // }
 
-        // (零件)庫存表查詢
-        function search_component_stock_table() {
-            var sql = 'SELECT 庫存表.時間, 庫存表.內部料號, 庫存表.數量 FROM 零件表';
-            sql += ' INNER JOIN 庫存表';
-            sql += ' ON 零件表.內部料號 = 庫存表.內部料號';
-            search_relation_insertdata(sql)
-        }
+        
 
         // (零件)規格表查詢
         function search_component_standard_table() {
             var accountingsubjects_select = $("#accountingsubjects").val();
             var category_select = $("#category").val();
             var serialnumber_select = $("#serialnumber").val();
+            serialnumber_select = serialnumber_select.padStart(4, '0')
             var supplier_select = $("#supplier").val();
             var component_name_select = $("#component_name_select").val();
             var component_name_input = $("#component_name_input").val();
@@ -126,9 +158,11 @@
 
             console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
 
-            var sql = 'SELECT 規格表.* FROM 零件表';
-            sql += ' INNER JOIN 規格表';
-            sql += ' ON 零件表.內部料號 = 規格表.內部料號';
+            sql = 'SELECT 零件表.內部料號, 零件表.名稱, 規格表.原廠料號, 規格表.單位, 規格表.圖片, 規格表.圖號, ' + 
+                    '規格表.檔案路徑, 規格表.尺寸, 規格表.`封裝/材質`, 規格表.工作電壓, 規格表.工作電流, 規格表.最大電流, ' + 
+                    '規格表.功率, 規格表.工作溫度, 規格表.備註 ' +
+                    'FROM 零件表 ' + 
+                    'INNER JOIN 規格表 ON 零件表.內部料號 = 規格表.內部料號';
 
             // 篩選 會計科目/類別/供應商 關鍵字
             if (accountingsubjects_select != '00') {
@@ -137,7 +171,7 @@
             if (category_select != '00') {
                 AND_list.push('類別 = "' + category_select + '"')
             }
-            if (serialnumber_select != '') {
+            if (serialnumber_select != '0000') {
                 AND_list.push('流水號 = "' + serialnumber_select + '"')
             }
             if (supplier_select != '00') {
@@ -159,13 +193,18 @@
             $.get('/sql_get', sql_data, function (res) {
                 var data = " ";
                 if (res.labels == '') {
-                    data += '-- 無符合關鍵字之資料 --'
+                    data += '-- 規格表無符合關鍵字之資料 --'
                 } else {
                     data += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
                     data += '<table class="table table-bordered" style="margin-top: 10px;">';
                     data += '<tr>';
                     for (let fields = 0; fields < res.sql_field.length; fields++) {
-                        data += '<th>' + res.sql_field[fields][0] + '</th>';
+                        if (res.sql_field[fields][0] !== '版次') {
+                            data += '<th>' + res.sql_field[fields][0] + '</th>';
+                            if (fields == 0) {
+                                data += '<th>零件名稱</th>';
+                            }
+                        }
                     }
                     data += '<th>' + '修改' + '</th>';
                     data += '</tr>';
@@ -174,9 +213,16 @@
                         for (let item = 0; item < res.labels[items].length; item++) {
                             // console.log("res.labels[items][item]: ", res.labels[items][item], typeof(res.labels[items][item]))
                             if (res.labels[items][item] == null) {
-                                data += '<td id="' + res.labels[items][0] + '_' + item + '">' + '' + '</td>';
+                                data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' + '' + '</td>';
                             } else {
-                                data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
+                                if (standard_title_list[item] == 'picture') {
+                                    data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' + 
+                                            '<img src="../static/Component_IMG/' + res.labels[items][item] + '" width="60" alt="' + res.labels[items][item] + '" onclick="imgZoomIn(\'' + res.labels[items][item] + '\')">' + 
+                                            '</td>';
+                                } else {
+                                    data += '<td id="' + res.labels[items][0] + '_' + standard_title_list[item] + '">' + res.labels[items][item] + '</td>';
+                                }
+                                
                             }
                         };
                         data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_standard(\'' + res.labels[items][0] + '\')"></td>';
@@ -189,44 +235,79 @@
             }, 'json');
         }
 
+        // 規格表 圖片 圖片放大
+        function imgZoomIn(imgName) {
+            // alert("imgName: " + imgName)
+            data = '<img src="../static/Component_IMG/' + imgName + '" width="466" alt="' + imgName + '">';
+            var sectorSelect = document.getElementById("ImgZoomIn_Modal_body");
+            sectorSelect.innerHTML = data;
+            
+            setTimeout(function(){ $('#ImgZoomIn_Modal').modal('show'); }, 300)
+        }
+
         // 規格表 內容修改
         function update_standard(company_id) {
             console.log("修改 " + company_id)
-            for (let i = 2; i < 10; i++) {
-                var target_id = document.getElementById(company_id + '_' + i);
-                var old_name = target_id.innerText;
-                console.log('old_name: ', old_name)
-                target_id.innerHTML = "";
-                textarea = '';
-                textarea += '<input id="'+ company_id + '_' + i + '_ta' + '" value="' + old_name + '" style="height: 25px; width: auto">';
-                if (i == 9) {
-                    textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_standard(\'' + company_id + '\')">';
+            for (let i = 2; i < standard_title_list.length; i++) {
+                // 跳過 picure
+                if (standard_title_list[i] != 'picture') {
+                    var target_id = document.getElementById(company_id + '_' + standard_title_list[i]);
+                    console.log("target_id: " + standard_title_list[i]);
+                    var old_name = target_id.innerText;
+                    console.log(standard_title_list[i] + ' old_name: ', old_name)
+                    target_id.innerHTML = "";
+                    textarea = '';
+                    if (standard_title_list[i] == 'unit' || standard_title_list[i] == 'version' || standard_title_list[i] == 'material' || 
+                        standard_title_list[i] == 'workV' || standard_title_list[i] == 'workI' || standard_title_list[i] == 'power' || standard_title_list[i] == 'maxI') {
+                        textarea += '<input id="'+ company_id + '_' + standard_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 50px">';
+                    } else if (standard_title_list[i] == 'picture') {
+                        textarea += old_name;
+                        console.log(target_id.innerHTML)
+                    } else {
+                        textarea += '<input id="'+ company_id + '_' + standard_title_list[i] + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 150px">';
+                    }
+                    if (i == standard_title_list.length-1) {
+                        textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_standard(\'' + company_id + '\')">';
+                    }
+                    target_id.insertAdjacentHTML('beforeend', textarea);
                 }
-                target_id.insertAdjacentHTML('beforeend', textarea);
             }
         }
 
         // 規格表 修改確認
         function ComfirmUpdate_standard(company_id) {
-            var new_factoryid_value = $('#' + company_id + '_2_ta').val();
-            var new_size_value = $('#' + company_id + '_3_ta').val();
-            var new_material_value = $('#' + company_id + '_4_ta').val();
-            var new_voltage_value = $('#' + company_id + '_5_ta').val();
-            var new_current_value = $('#' + company_id + '_6_ta').val();
-            var new_power_value = $('#' + company_id + '_7_ta').val();
-            var new_maxvoltage_value = $('#' + company_id + '_8_ta').val();
-            var new_temp_value = $('#' + company_id + '_9_ta').val();
-
-            sql = '';
-            sql += 'UPDATE 規格表 SET `原廠料號` = "' + new_factoryid_value + '"';
-            sql += ', `尺寸` = "' + new_size_value + '"';
-            sql += ', `封裝/材質` = "' + new_material_value + '"';
-            sql += ', `工作電壓` = "' + new_voltage_value + '"';
-            sql += ', `工作電流` = "' + new_current_value + '"';
-            sql += ', `功率` = "' + new_power_value + '"';
-            sql += ', `最大電流` = "' + new_maxvoltage_value + '"';
-            sql += ', `工作溫度` = "' + new_temp_value + '"';
-            sql += ' WHERE `內部料號` = "' + company_id + '";'
+            // var standard_title_list = ['id', 'name', 'type', 'unit', 'picture', 'pictureID', 'version', 'path', 'size', 'material', 
+            //                              'workV', 'workI', 'maxI', 'power', 'workTemp', 'remark', ];
+            var new_type_value = $('#' + company_id + '_type_ta').val();
+            var new_unit_value = $('#' + company_id + '_unit_ta').val();
+            // var new_picture_value = $('#' + company_id + '_picture_ta').val();
+            var new_pictureID_value = $('#' + company_id + '_pictureID_ta').val();
+            var new_version_value = $('#' + company_id + '_version_ta').val();
+            var new_path_value = $('#' + company_id + '_path_ta').val();
+            var new_size_value = $('#' + company_id + '_size_ta').val();
+            var new_material_value = $('#' + company_id + '_material_ta').val();
+            var new_workV_value = $('#' + company_id + '_workV_ta').val();
+            var new_workI_value = $('#' + company_id + '_workI_ta').val();
+            var new_maxI_value = $('#' + company_id + '_maxI_ta').val();
+            var new_power_value = $('#' + company_id + '_power_ta').val();
+            var new_workTemp_value = $('#' + company_id + '_workTemp_ta').val();
+            var new_remark_value = $('#' + company_id + '_remark_ta').val();
+
+            sql = 'UPDATE 規格表 SET ' +
+                    '`原廠料號` = "' + new_type_value + '"' + 
+                    ', `單位` = "' + new_unit_value + '"' + 
+                    // ', `圖片` = "' + new_picture_value + '"' + 
+                    ', `圖號` = "' + new_pictureID_value + '"' + 
+                    ', `檔案路徑` = "' + new_path_value + '"' + 
+                    ', `尺寸` = "' + new_size_value + '"' + 
+                    ', `封裝/材質` = "' + new_material_value + '"' + 
+                    ', `工作電壓` = "' + new_workV_value + '"' + 
+                    ', `工作電流` = "' + new_workI_value + '"' + 
+                    ', `功率` = "' + new_power_value + '"' + 
+                    ', `最大電流` = "' + new_maxI_value + '"' + 
+                    ', `工作溫度` = "' + new_workTemp_value + '"' + 
+                    ', `備註` = "' + new_remark_value + '"' + 
+                    ' WHERE `內部料號` = "' + company_id + '";'
             console.log('sql: ' + sql)
             var sql_data = { "sql":sql };
 
@@ -236,6 +317,7 @@
                 dataType:"JSON",
                 data:sql_data,
                 success:function (res) {
+                    search_component_standard_table();
                     alert("規格表: 修改成功 !")
                 },
                 error: function (thrownError) {
@@ -247,7 +329,7 @@
                 }
             })
 
-            search_component_standard_table();
+            
         } 
 
         // 各資料表←關聯→零件表, 程式
@@ -255,6 +337,7 @@
             var accountingsubjects_select = $("#accountingsubjects").val();
             var category_select = $("#category").val();
             var serialnumber_select = $("#serialnumber").val();
+            serialnumber_select = serialnumber_select.padStart(4, '0')
             var supplier_select = $("#supplier").val();
             var component_name_select = $("#component_name_select").val();
             var component_name_input = $("#component_name_input").val();
@@ -269,7 +352,7 @@
             if (category_select != '00') {
                 AND_list.push('類別 = "' + category_select + '"')
             }
-            if (serialnumber_select != '') {
+            if (serialnumber_select != '0000') {
                 AND_list.push('流水號 = "' + serialnumber_select + '"')
             }
             if (supplier_select != '00') {
@@ -333,29 +416,28 @@
             // var new_name_value = new_name.val();
             var new_name_value = $('#' + company_id + '_5_ta').val();
             console.log("new_name_value: " + new_name_value)
-
-            sql = '';
-            sql += 'UPDATE 零件表 SET 名稱 = "' + new_name_value + '" WHERE 內部料號 = "' + company_id + '";'
+            
+            // 零件表名稱修改 
+            sql = "";
+            sql += "UPDATE 零件表 SET 名稱 = '" + new_name_value.replaceAll("'", "''") + "' WHERE 內部料號 = '" + company_id + "';"
             console.log('sql: ' + sql)
             var sql_data = { "sql":sql };
 
             $.get('/sql_get', sql_data, function (res) {
                 // console.log(res)
+                search_component_table();
             }, 'json');
-
-            alert("修改成功 !")
-            search_component_table();
         }
 
         // 修改
         function update_component(company_id) {
             console.log("修改 " + company_id)
             var target_id = document.getElementById(company_id + '_5');
-            var old_name = target_id.innerText;
+            var old_name = target_id.innerText.replaceAll('"', '&quot;').replaceAll("'", "&apos;");
             console.log('old_name: ', old_name)
             target_id.innerHTML = "";
             textarea = '';
-            textarea += '<input id="'+ company_id + '_5_ta' + '" value="' + old_name + '" style="height: 25px; width: auto">';
+            textarea += '<input type="text" id="'+ company_id + '_5_ta' + '" value=\"' + old_name + '\" style="height: 25px; width:auto">';
             textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_component(\'' + company_id + '\')">';
             target_id.insertAdjacentHTML('beforeend', textarea);
         }
@@ -365,48 +447,90 @@
             var delete_data = confirm("確定要刪除內部料號 " + company_id + " 的資料嗎?\n(會同步刪除規格表對應資料)") 
             if (delete_data) {
                 // 刪除零件表
-                var sql = 'DELETE FROM 零件表 WHERE 內部料號 = "' + company_id + '";'
+                // var sql = 'DELETE FROM 零件表 WHERE 內部料號 = "' + company_id + '";'
+                // var sql_data = { "sql":sql };
+                // $.ajax({
+                //     type:"GET",
+                //     url:"/sql_get",
+                //     dataType:"JSON",
+                //     data:sql_data,
+                //     async:false,
+                //     success:function (res) {
+                //         search_component_table()
+                //         alert("零件表: 零件刪除成功!")
+                //     },
+                //     error: function (thrownError) {
+                //         if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                //             alert("零件表: 無內部料號 " + company_id + " 之資料")
+                //         } else {
+                //             alert("零件表刪除錯誤: " + thrownError)
+                //         }
+                //     }
+
+                // })
+
+                // 刪除規格表
+                // var sql = 'DELETE FROM 規格表 WHERE 內部料號 = "' + company_id + '";'
+                // var sql_data = { "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("規格表: 無內部料號 " + company_id + " 之資料")
+                //         } else {
+                //             alert("規格表刪除錯誤: " + thrownError)
+                //         }
+                //     }
+                // })
+
+                // 刪除資料表
+                var sql = 'DROP TABLE ' + company_id + ';';
                 var sql_data = { "sql":sql };
                 $.ajax({
                     type:"GET",
                     url:"/sql_get",
                     dataType:"JSON",
                     data:sql_data,
+                    async:false,
                     success:function (res) {
-                        alert("零件表: 零件刪除成功!")
+                        alert("BOM 表: " + company_id + " 刪除成功!")
                     },
                     error: function (thrownError) {
                         if (thrownError.statusText == "INTERNAL SERVER ERROR") {
-                            alert("零件表: 無內部料號 " + company_id + " 之資料")
+                            alert("BOM 表: 無內部料號 " + company_id + " 之資料表")
                         } else {
-                            alert("零件表刪除錯誤: " + thrownError)
+                            alert("零件表 BOM 表刪除錯誤: " + thrownError)
                         }
                     }
 
                 })
 
-                // 刪除規格表
-                var sql = 'DELETE FROM 規格表 WHERE 內部料號 = "' + company_id + '";'
-                var sql_data = { "sql":sql };
-
                 $.ajax({
                     type:"GET",
-                    url:"/sql_get",
+                    url:"/delete_companyid_table_" + company_id,
                     dataType:"JSON",
-                    data:sql_data,
+                    data:"",
+                    async:false,
                     success:function (res) {
-                        alert("規格表: 零件刪除成功!")
+                        alert("BOM 表: " + res.exist_BOM + " \n之 " + company_id + " 刪除成功!")
                     },
                     error: function (thrownError) {
                         if (thrownError.statusText == "INTERNAL SERVER ERROR") {
-                            alert("規格表: 無內部料號 " + company_id + " 之資料")
+                            alert("BOM 表內刪除零件 : 無內部料號 " + company_id + " 之項目")
                         } else {
-                            alert("規格表刪除錯誤: " + thrownError)
+                            alert("BOM 表內刪除零件錯誤: " + thrownError)
                         }
                     }
 
                 })
-
+                
                 search_component_table();
             }
             
@@ -417,6 +541,7 @@
             var accountingsubjects_select = $("#accountingsubjects").val();
             var category_select = $("#category").val();
             var serialnumber_select = $("#serialnumber").val();
+            serialnumber_select = serialnumber_select.padStart(4, '0')
             var supplier_select = $("#supplier").val();
             var component_name_select = $("#component_name_select").val();
             var component_name_input = $("#component_name_input").val();
@@ -443,7 +568,7 @@
             if (category_select != '00') {
                 AND_list.push('類別 = "' + category_select + '"')
             }
-            if (serialnumber_select != '') {
+            if (serialnumber_select != '0000') {
                 AND_list.push('流水號 = "' + serialnumber_select + '"')
             }
             if (supplier_select != '00') {
@@ -473,25 +598,27 @@
                 // console.log("res.sql_field[0]:" + res.sql_field[0])
                 var data = " ";
                 if (res.labels == '') {
-                    data += '-- 無符合關鍵字之資料 --'
+                    data += '-- 零件表無符合關鍵字之資料 --'
                 } else {
                     data += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
                     data += '<table class="table table-bordered" style="margin-top: 10px;">';
                     data += '<tr>';
+                    // console.log("res.sql_field: " + res.sql_field)
                     for (let fields = 0; fields < res.sql_field.length; fields++) {
                         data += '<th>' + res.sql_field[fields][0] + '</th>';
+                        // console.log("res.sql_field[" + fields + "][0]: " + res.sql_field[fields][0])
                     }
-                    data += '<th>' + '修改' + '</th>';
-                    data += '<th>' + '刪除' + '</th>';
+                    data += '<th>修改</th>';
+                    data += '<th>刪除</th>';
                     data += '</tr>';
                     for (let items = 0; items < res.labels.length; items++) {
                         data += '<tr>';
-                            for (let item = 0; item < res.labels[items].length; item++) {
-                                // data += '<td id="' + res.Component_id[items] + '_' + item + '">' + res.labels[items][item] + '</td>';
-                                data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
-                            };
-                            data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_component(\'' + res.labels[items][0] + '\')"></td>';
-                            data += '<td><input type="button" class="input-cond-delete" value="刪除" onclick="delete_component(\'' + res.labels[items][0] + '\')"></td>';
+                        for (let item = 0; item < res.labels[items].length; item++) {
+                            // data += '<td id="' + res.Component_id[items] + '_' + item + '">' + res.labels[items][item] + '</td>';
+                            data += '<td id="' + res.labels[items][0] + '_' + item + '">' + res.labels[items][item] + '</td>';
+                        };
+                        data += '<td><input type="button" class="input-cond-add" value="修改" onclick="update_component(\'' + res.labels[items][0] + '\')"></td>';
+                        data += '<td><input type="button" class="input-cond-delete" value="刪除" onclick="delete_component(\'' + res.labels[items][0] + '\')"></td>';
                         data += '</tr>';
                     };
                     data += '</table>';
@@ -506,6 +633,25 @@
         
     </script>
 
+    <!-- modal 圖片放大 -->
+    <div class="modal fade" id="ImgZoomIn_Modal">
+        <div class="modal-dialog modal-dialog-centered" style="width: 600px;">
+            <div class="modal-content">
+
+                <!-- 互動視窗 標題 -->
+                <!-- <div class="modal-header">
+                    <h4 id="Modal_title_ImgZoomIn" class="modal-title">乾燥入料儲豆槽 DI1 狀態</h4>
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
+                </div> -->
+
+                <!-- 互動視窗 內容 -->
+                <div class="modal-body" id="ImgZoomIn_Modal_body">
+                    <!-- 圖片 ImgZoomIn -->
+                </div>
+            </div>
+        </div>
+    </div>
+
     <div id="result">
         <!-- <table>
         </table> -->
@@ -515,27 +661,6 @@
         
             
         
-    
-    
-    <!-- <table class="table table-bordered" style="margin-top: 20px;">
-        <tr>
-            {% for i1 in labels %}
-            <th>{{i1}}</th>
-            {% endfor %}
-        </tr>
-        {% for i in content %}
-        <tr>
-            <td>{{ i[0] }}</td>
-            <td>{{ i[1] }}</td>
-            <td>{{ i[2] }}</td>
-            <td>{{ i[3] }}</td>
-            <td>{{ i[4] }}</td>
-            <td>{{ i[5] }}</td>
-            <td>{{ i[6] }}</td>
-            <td>{{ i[7] }}</td>
-        </tr>
-        {% endfor %}
-    </table> -->
 </body>
 
 </html>

+ 345 - 0
Rita/ERP_Rita/templates/search_companyid.html

@@ -0,0 +1,345 @@
+<!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">
+    
+</head>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+    請先輸入欲查詢之內部料號 : 
+    <input list="insert_BOM_module" id="company_id" style="height: 25px;" onChange="get_sqltables()">
+    <datalist id="insert_BOM_module">
+    <option value="">可輸入名稱查找內部料號</option>
+    {% 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>
+    <hr>
+    <!-- <span style="font-weight: bold;">erp 資料庫所有的資料表 :</span>
+    <div id="result_all_tables"></div>
+    <br> -->
+    <span style="font-weight: bold;">所有包含 "某內部料號" 資料的資料表 :</span>
+    <div id="result_id_tables"></div>
+    <br>
+    <span style="font-weight: bold;">名稱為 "某內部料號" 資料的資料表 :</span>
+    <div id="result_id_BOM"></div>
+    <br>
+    <hr>
+
+    選擇新的供應商編號:
+    <select id="BOM_supplier" onChange="">
+        <option value="00"></option>
+        {% for data in Supplier_data %}
+            <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
+        {% endfor %}
+    </select>
+    <input type="button" class="input-cond-add" value="OK" onclick="select_supplier()">
+    <div id="replace_id">
+    </div>
+    <br>
+    <hr>
+
+    [請務必謹慎使用] 新的內部料號:
+    <!-- 會計科目:
+    <select id="accountingsubjects" onChange="">
+        <option value="00"></option>
+        {% for data in AccountingSubjects_data %}
+            <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
+        {% endfor %}
+    </select>
+    類別:
+    <select id="category" onChange="renewSN();">
+        <option value="00"></option>
+        {% for data in Category_data %}
+            <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
+        {% endfor %}
+    </select>
+    流水號:
+    <input id="serialnumber" style="height: 25px; width: 45px; color: crimson;" readonly>
+    供應商:
+    <select id="supplier" onChange="">
+        <option value="00"></option>
+        {% for data in Supplier_data %}
+            <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
+        {% endfor %}
+    </select> -->
+    <input id="new_company_id" style="height: 25px;" onChange="">
+    <input type="button" class="input-cond-add" style="width: 125px;" value="更新內部料號" onclick="update_company_id()"><br>
+    <br>
+    <br>
+    <br>
+    <hr>
+
+    批次更新內部料號 
+    <input type="button" class="input-cond-add" style="width: auto;" value="批次更新供應商" onclick="batch_tt()"><br>
+
+    
+    <script>
+        var sql = '';       // sql 指令
+        var data = '';      // 輸出
+        var new_company_id_exist = true;    // 新的內部料號是否已存在判斷。true 存在 false 不存在
+
+        function batch_tt() {
+            batch_select_supplier("01010001T23", "01010001T02");
+            batch_select_supplier("04010004T23", "04010004T22");
+            batch_select_supplier("04010128T23", "04010128T22");
+            batch_select_supplier("04010153T48", "04010153TE2");
+            batch_select_supplier("04010154T48", "04010154TE2");
+            batch_select_supplier("04010157T48", "04010157TB1");
+            batch_select_supplier("04010158T48", "04010158TF3");
+            batch_select_supplier("04010159T48", "04010159TF3");
+            batch_select_supplier("04010160T48", "04010160TE8");
+            batch_select_supplier("04010161T48", "04010161TB1");
+            batch_select_supplier("04010163T48", "04010163TE2");
+            batch_select_supplier("04010164T48", "04010164TA6");
+            batch_select_supplier("04010165T48", "04010165TF2");
+            batch_select_supplier("04010171T48", "04010171T01");
+            batch_select_supplier("04010172T48", "04010172T01");
+            batch_select_supplier("04010173T48", "04010173T01");
+            batch_select_supplier("04010174T48", "04010174TB1");
+            batch_select_supplier("04010175T37", "04010175TB1");
+            batch_select_supplier("04010176T37", "04010176TB1");
+            batch_select_supplier("04010177T37", "04010177TB1");
+            batch_select_supplier("04010178T37", "04010178TB1");
+            batch_select_supplier("04010179T37", "04010179TB1");
+            batch_select_supplier("04010180T37", "04010180TB1");
+            batch_select_supplier("04010181T37", "04010181TB1");
+            batch_select_supplier("04010182T37", "04010182TB1");
+            batch_select_supplier("04010183T37", "04010183TB1");
+            batch_select_supplier("04010184T37", "04010184TB1");
+            batch_select_supplier("04010185T37", "04010185TB1");
+            batch_select_supplier("04010186T37", "04010186TB1");
+            batch_select_supplier("04010187T37", "04010187TB1");
+        }
+
+        function batch_select_supplier(old_id, new_id) {
+            // var old_id = [];
+            // var new_id = [];
+            var comfirm_update_company_sup = confirm('將原內部料號 ' + old_id + 
+                                                        ' \n取代成 ' + new_id + '\n請注意此動作不可復原!')
+            if (comfirm_update_company_sup) {
+                $.ajax({
+                    type:"GET",
+                    url:"/update_companyid_table_" + old_id + "_" + new_id,
+                    dataType:"JSON",
+                    data:'',
+                    async:false,
+                    success:function (res) {
+                        console.log(res.new_company_id)
+                        console.log(res.has_id_table_list)
+                        alert("更新內部料號供應商 " + old_id + " 之 Table: 成功")
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("更新內部料號供應商 " + old_id + " 之 Table: 未成功")
+                        } else {
+                            console.log("更新內部料號供應商之 Table thrownError" + thrownError)
+                        }
+                    }
+                })
+            }
+        }
+
+        function update_company_id() {
+            var search_company_id = $("#company_id").val();
+            var new_company_id = $("#new_company_id").val();
+            if (search_company_id == '' || new_company_id == '') {
+                alert("請輸入欲取代內部料號和新內部料號")
+            } else {
+                sql = 'SELECT 內部料號 FROM 零件表 WHERE 內部料號 = "' + new_company_id + '"';
+                var sql_data = { "sql":sql };
+                console.log("sql_data: ", sql_data)
+                $.ajax({
+                    type:"GET",
+                    url:"/sql_get",
+                    dataType:"JSON",
+                    data:sql_data,
+                    async:false,
+                    success:function (res) {
+                        new_company_id_exist = true;
+                        console.log("res.labels: " + res.labels)
+                        console.log("res.labels.length: " + res.labels.length)
+                        console.log(typeof(res.labels.length))
+                        // 判斷內部料號是否存在 (有無回傳值)
+                        if (res.labels.length == 0) {
+                            new_company_id_exist = false
+                        }
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("更新內部料號 " + company_id + ": 未成功")
+                        } else {
+                            console.log("更新內部料號 thrownError" + thrownError)
+                        }
+                    }
+                })
+
+                if (new_company_id_exist == true) {
+                    alert(new_company_id + " 此內部料號已存在, 請重新輸入 !")
+                } else {
+                    console.log("new_company_id_exist: " + new_company_id_exist)
+                    console.log("將 " + search_company_id + " 取代成 " + new_company_id)
+                    var confirm_update_company_id = confirm("[請謹慎使用]\n確定將內部料號 " + search_company_id + " 取代成 " + new_company_id + " ?")
+                    if (confirm_update_company_id) {
+                        $.ajax({
+                            type:"GET",
+                            url:"/update_companyid_table_" + search_company_id + "_" + new_company_id,
+                            dataType:"JSON",
+                            data:'',
+                            async:false,
+                            success:function (res) {
+                                alert("更新內部料號 " + search_company_id + " 之 Table: 成功")
+                                console.log(res.new_company_id)
+                                console.log(res.has_id_table_list)
+                                location.reload()
+                            },
+                            error: function (thrownError) {
+                                if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                                    alert("更新內部料號 " + search_company_id + " 之 Table: 未成功")
+                                } else {
+                                    console.log("更新內部料號之 Table thrownError" + thrownError)
+                                }
+                            }
+                        })
+                    }
+                }
+
+                
+            
+            
+            
+            }
+        }
+
+        function get_sqltables() {
+            var search_company_id = $("#company_id").val();
+            console.log("search_company_id: " + search_company_id)
+            if (search_company_id != '') {
+                data = '';
+                $.ajax({
+                    type:"GET",
+                    url:"/search_companyid_table_" + search_company_id,
+                    dataType:"JSON",
+                    data:'',
+                    async:false,
+                    success:function (res) {
+                        // // erp 資料庫所有的資料表 :
+                        // var sectorSelect = document.getElementById("result_all_tables");
+                        // if (res.sql_data != '') {
+                        //     sectorSelect.innerHTML = String(res.sql_data).replaceAll(",", "<br>");
+                        // } else {
+                        //     sectorSelect.innerHTML = "erp 資料庫無資料表";
+                        // }
+                        // 所有包含 "某內部料號" 資料的資料表 :
+                        var sectorSelect = document.getElementById("result_id_tables");
+                        if (res.has_id_table_list != '') {
+                            sectorSelect.innerHTML = String(res.has_id_table_list).replaceAll(",", "<br>");
+                        } else {
+                            sectorSelect.innerHTML = "無 " + search_company_id + " 內容之資料表";
+                        }
+                        // 名稱為 "某內部料號" 資料的資料表 :
+                        var sectorSelect = document.getElementById("result_id_BOM");
+                        if (res.has_table_list != '') {
+                            sectorSelect.innerHTML = String(res.has_table_list).replaceAll(",", "<br>");
+                        } else {
+                            sectorSelect.innerHTML = "無 " + search_company_id + " 資料表";
+                        }
+
+                        var replace_data = '調整供應商為';
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("查詢內部料號 " + search_company_id + " 之 Table: 未成功")
+                        } else {
+                            console.log("查詢內部料號之 Table thrownError" + thrownError)
+                        }
+                    }
+                })
+            }
+        }
+    
+        function select_supplier() {
+            var search_company_id = $("#company_id").val();
+            var supplier_select = $("#BOM_supplier").val();
+            var new_company_id = search_company_id.slice(0, 8) + supplier_select;
+            var select_supplier_data = '將原內部料號 ' + search_company_id + ' 取代成 ' + new_company_id;
+            var comfirm_update_company_sup = confirm('將原內部料號 ' + search_company_id + ' \n取代成 ' + new_company_id + '\n請注意此動作不可復原!')
+            if (comfirm_update_company_sup) {
+                console.log(search_company_id + ' → ' + new_company_id)
+                $.ajax({
+                    type:"GET",
+                    url:"/update_companyid_table_" + search_company_id + "_" + new_company_id,
+                    dataType:"JSON",
+                    data:'',
+                    async:false,
+                    success:function (res) {
+                        console.log(res.new_company_id)
+                        console.log(res.has_id_table_list)
+                        alert("更新內部料號供應商 " + search_company_id + " 之 Table: 成功")
+                    },
+                    error: function (thrownError) {
+                        if (thrownError.statusText == "INTERNAL SERVER ERROR") {
+                            alert("更新內部料號供應商 " + search_company_id + " 之 Table: 未成功")
+                        } else {
+                            console.log("更新內部料號供應商之 Table thrownError" + thrownError)
+                        }
+                    }
+                })
+                
+
+            }
+        }
+    
+        function renewSN() {
+            var accountingsubjects_select = $("#accountingsubjects").val();
+            var category_select = $("#category").val();
+            $.get('/sn_get/' + accountingsubjects_select + '/' + category_select, '', function (res) {
+                // console.log(res.new_sn)
+                $('#serialnumber').val(res.new_sn)
+            }, 'json');
+        }
+
+    </script>
+</body>
+
+</html>

+ 170 - 0
Rita/ERP_Rita/templates/update_Picture.html

@@ -0,0 +1,170 @@
+<!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 src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
+
+    <script>
+        $(function(){
+            
+        });
+    </script>
+    
+</head>
+
+<style>
+    .input-cond-delete {
+        background: #E43030;
+        border: 1px solid #CFCFCF;
+        box-sizing: border-box;
+        border-radius: 5px;
+        margin-left: 5px;
+        width: 65px;
+        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: 65px;
+        height: 33px;
+        font-size: 16px;
+        text-align: center;
+        line-height: 16px;
+        color: #FFFFFF;
+    }
+</style>
+
+<body>
+    <div id="ERP_header">
+        <!-- 匯入共同使用的 header.html 內容 -->
+        {% include 'ERP_header.html' %}
+    </div>
+
+    待測試!!! <br>
+    請選擇欲更新的圖片內部料號 : 
+    <input list="insert_PR_id_item" id="PR_id" style="height: 25px;" onChange="loadOldImg(event)">
+    <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>
+    <br>
+    <span id="showOldImg_filename"></span><br>
+    <img id="showOldImg" width="180">
+
+    <script>
+        var sql = '';
+        var sql_data = { "sql":sql };
+
+        var loadOldImg = function(event) {
+            var reader = new FileReader();
+            reader.onload = function(){
+                var showImg = document.getElementById('PR_id');
+                showImg.src = reader.result;
+            };
+            reader.readAsDataURL(event.target.files[0]);
+        };
+
+        // var loadOldImg = function(event) {
+
+        //     var reader = new FileReader();
+        //     reader.onload = function(evt){
+        //         var new_PR_id = document.getElementById("PR_id");
+        //         console.log("new_PR_id: " + new_PR_id);
+        //         sql = 'SELECT `圖片` FROM `規格表` WHERE `內部料號`="' + new_PR_id + '"'
+        //         sql_data = { "sql":sql };
+
+        //         $.get('/sql_get', sql_data, function (res) {
+        //             if (res.labels[0] != '') {
+        //                 var showImg = document.getElementById('showOldImg');
+        //                 showImg.src = 'C:/Users/USER/Rita/ERP_Rita/static/Component_IMG/' + res.labels[0][0];
+        //                 var showImg_filename = document.getElementById('showOldImg_filename');
+        //                 showImg_filename.value = res.labels[0][0];
+        //             } else {
+        //                 showImg_filename.value = '無圖片上傳';
+        //             }
+                    
+        //         }, 'json');
+        //         var showImg = document.getElementById('05070001T01_showImg');
+        //         showImg.src = reader.result;
+        //     };
+        //     reader.readAsDataURL(event.target.files[0]);
+        // };
+
+        function get_id_updatePicure(id) {
+            var new_PR_id = document.getElementById(id).value;
+            sql = 'SELECT `圖片` FROM `規格表` WHERE `內部料號`="' + new_PR_id + '"'
+            sql_data = { "sql":sql };
+
+            $.get('/sql_get', sql_data, function (res) {
+                if (res.labels[0] != '') {
+                    var showImg = document.getElementById('showOldImg');
+                    showImg.src = 'C:/Users/USER/Rita/ERP_Rita/static/Component_IMG/' + res.labels[0][0];
+                    var showImg_filename = document.getElementById('showOldImg_filename');
+                    showImg_filename.value = res.labels[0][0];
+                } else {
+                    showImg_filename.value = '無圖片上傳';
+                }
+                
+            }, 'json');
+
+        }
+    </script>
+
+    <br>
+    <br>
+
+    <span id="picture_exist"></span>
+
+    <br>
+    <br>
+
+    <hr>
+    圖片上傳至 ERP 檔案內儲存, 測試 OK
+
+    <form action="upload" method="post" enctype="multipart/form-data">
+        <input type="file" id="05070001T01_loadImg" multiple="" accept="image/*" name="file[]" onchange="loadImg(event)"><br/>
+        <img id="05070001T01_showImg" width="60"><br>
+        <input type="submit" value="Upload">
+    </form>
+
+    <script>
+        
+
+        var loadImg = function(event) {
+            var reader = new FileReader();
+            reader.onload = function(){
+                var showImg = document.getElementById('05070001T01_showImg');
+                showImg.src = reader.result;
+            };
+            reader.readAsDataURL(event.target.files[0]);
+        };
+
+        function UploadImg(id) {
+            // 取得檔案名稱
+            var fileName = document.getElementById( id + '_loadImg').value;
+            alert("fileName: " + String(fileName).substr(12))
+
+            // 上傳圖片
+            $.get('/upload/' + String(fileName).substr(12), '', function (res) {
+                alert("UPLOAD success!")
+            }, 'json');
+        }
+    </script>
+</body>
+
+</html>