123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <!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>
- <!-- 這裡新增零件表中的零件 -->
- 請依序輸入以下欄位, 再按下 "新增零件" 按鈕:<br>
- 會計科目:
- <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" value="—" style="height: 25px; width: 45px;" 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 list="conponents" id="component_name_select">
- <datalist id="conponents">
- <option value=""></option>
- {% for data in Component_data %}
- <option value="{{data[0]}}">{{data[0]}}</option>
- {% endfor %}
- </datalist>
- <br>
-
- <input type="button" id="create_component" value="新增零件" onclick="create_component();">
- <div id="result">
- <!-- <table>
- </table> -->
- </div>
- <script>
- // 輸入完類別後, 流水號自動帶入
- 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');
- }
- // 零件表 新增零件
- function create_component() {
- // 會計科目
- var accountingsubjects_select = $("#accountingsubjects").val();
- // 類別
- var category_select = $("#category").val();
- // 流水號 → 從資料庫找到最大的流水號, 然後 +1
- var serialnumber_select = $("#serialnumber").val();
- // 放到 renewSN 方法內執行
- // 供應商
- var supplier_select = $("#supplier").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);
- 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 + " 已存在, 請重新輸入")
- }
- }
- })
- var sql = 'INSERT INTO 規格表 (`內部料號`) VALUES ("' + 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 + " 已存在, 請重新輸入")
- }
- }
- })
-
- }
-
- </script>
- <hr>
- <!-- 這裡新增零件表中的 會計科目 -->
- 請輸入欲新增的會計科目名稱, 再按下 "新增會計科目項目" 按鈕:<br>
- <input id="create_accountingsubject_id" value="{{new_as_sn}}" style="height: 25px; width: 45px;" readonly>
- <input id="create_accountingsubject_name" value="" style="height: 25px;">
- <input type="button" id="create_accountingsubject" value="新增會計科目項目" onclick="create_accountingsubject();">
- <script>
- function create_accountingsubject() {
- var as_id = $("#create_accountingsubject_id").val();
- var as_name = $("#create_accountingsubject_name").val();
- var sql = '';
- sql += 'INSERT INTO 會計科目表 ' +
- 'VALUES ("' + as_id + '", "' + as_name + '");';
- // console.log("sql: " + sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert('新增 會計科目 成功')
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("會計科目 " + as_id + " 已存在, 請重新輸入")
- }
- }
- })
- }
- </script>
- <hr>
- <!-- 這裡新增零件表中的 類別 -->
- 請輸入欲新增的類別名稱, 再按下 "新增類別項目" 按鈕:<br>
- <input id="create_category_id" value="{{new_ca_sn}}" style="height: 25px; width: 45px;" readonly>
- <input id="create_category_name" value="" style="height: 25px;">
- <input type="button" id="create_category" value="新增類別項目" onclick="create_category();">
- <script>
- function create_category() {
- var ca_id = $("#create_category_id").val();
- var ca_name = $("#create_category_name").val();
- var sql = '';
- sql += 'INSERT INTO 類別表 ' +
- 'VALUES ("' + ca_id + '", "' + ca_name + '");';
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert('新增 類別 成功')
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("類別 " + ca_id + " 已存在, 請重新輸入")
- }
- }
- })
- }
- </script>
- <hr>
- <!-- 這裡新增零件表中的 供應商 -->
- 請輸入欲新增的供應商名稱, 再按下 "新增供應商" 按鈕: (其他資料先以 "" 存入)<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();"><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 sup_id_1 = $("#create_supplier_id_1").val();
- var sup_id_2 = $("#create_supplier_id_2").val();
- var su_name = $("#create_supplier_name").val();
- sql = 'INSERT INTO 供應商 (`供應商`, `公司`) ' +
- 'VALUES ("' + sup_id_1 + sup_id_2 + '", "' + su_name + '");';
- console.log("sql:", sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert('新增 供應商 成功')
- location.reload();
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("供應商 " + su_id + " 已存在, 請重新輸入")
- }
- }
- })
- }
- </script>
- </body>
- </html>
|