123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- <!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>
- 會計科目:
- <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="">
- <option value="00"></option>
- {% for data in Category_data %}
- <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
- {% endfor %}
- </select>
- 流水號:
- <input id="serialnumber" placeholder="0001" style="height: 25px; width: 45px;">
- 供應商:
- <select id="supplier" onChange="">
- <option value="00"></option>
- {% for data in Supplier_data %}
- <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
- {% endfor %}
- </select><br>
-
- 零件名稱:
- <select id="component_name_select" onChange="">
- <option value="00"></option>
- {% for data in Component_data %}
- <option value="{{data[0]}}">{{data[0]}}</option>
- {% endfor %}
- </select>
- <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();">
- <br>
- <a id="create_component_table_item" href="/create_component_table_item">(零件)新增零件</a>
- <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_stock_table() {
- var sql = 'SELECT 庫存表.時間, 庫存表.內部料號, 庫存表.數量 FROM 零件表';
- sql += ' INNER JOIN 庫存表';
- sql += ' ON 零件表.內部料號 = 庫存表.內部料號';
- search_relation_insertdata(sql)
- }
- // (零件)規格表查詢
- function search_component_standard_table() {
- var sql = 'SELECT 規格表.* FROM 零件表';
- sql += ' INNER JOIN 規格表';
- sql += ' ON 零件表.內部料號 = 規格表.內部料號';
- search_relation_insertdata(sql)
- }
- // 各資料表←關聯→零件表, 程式
- function search_relation_insertdata(sql) {
- var accountingsubjects_select = $("#accountingsubjects").val();
- var category_select = $("#category").val();
- var serialnumber_select = $("#serialnumber").val();
- var supplier_select = $("#supplier").val();
- var component_name_select = $("#component_name_select").val();
- var component_name_input = $("#component_name_input").val();
- var AND_list = [];
- console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
- var sql = sql;
- // 篩選 會計科目/類別/供應商 關鍵字
- if (accountingsubjects_select != '00') {
- AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
- }
- if (category_select != '00') {
- AND_list.push('類別 = "' + category_select + '"')
- }
- if (serialnumber_select != '') {
- AND_list.push('流水號 = "' + serialnumber_select + '"')
- }
- if (supplier_select != '00') {
- AND_list.push('供應商 = "' + supplier_select + '"')
- }
- if (component_name_select != '00') {
- AND_list.push('零件表.名稱 = "' + component_name_select + '"')
- } else if (component_name_input != '') {
- AND_list.push('零件表.名稱 LIKE "%' + component_name_input + '%"')
- }
- console.log("AND_list: ", AND_list)
- if (AND_list != '') {
- sql += ' WHERE ' + AND_list.join(' AND ');
- }
- if (sql.match('INNER JOIN 庫存表')) {
- sql += ' ORDER BY 時間 DESC LIMIT 1'
- }
-
- var sql_data = {
- "sql":sql
- };
- console.log("sql_data: ", sql_data)
- $.get('/sql_get', sql_data, function (res) {
- // console.log("res: " + res)
- // console.log("res.labels:" + res.labels)
- // console.log("res.labels[0]:" + res.labels[0])
- // console.log("res.labels[0][0]:" + res.labels[0][0])
- // console.log("res.sql_field:" + res.sql_field)
- // console.log("res.sql_field[0]:" + res.sql_field[0])
- var data = " ";
- if (res.labels == '') {
- data += '-- 無符合關鍵字之資料 --'
- } else {
- 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>';
- }
- data += '</tr>';
- for (let items = 0; items < res.labels.length; items++) {
- 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]))
- data += '<td>' + res.labels[items][item] + '</td>';
- };
- data += '</tr>';
- };
- data += '</table>';
- }
- var sectorSelect = document.getElementById("result");
- sectorSelect.innerHTML = data;
- }, 'json');
- }
-
- // 修改確認
- function ComfirmUpdate_component(company_id) {
- console.log("修改完成: " + company_id)
- // var new_name = document.getElementById(company_id + '_5_ta');
- // 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 + '\';'
- console.log('sql: ' + sql)
- var sql_data = { "sql":sql };
- $.get('/sql_get', sql_data, function (res) {
- console.log(res)
- }, 'json');
- }
- // 修改
- function update_component(company_id) {
- console.log("修改 " + company_id)
- var old_name =
- target_id = company_id + '_5'
- var target_id = document.getElementById(company_id + '_5');
- var old_name = target_id.innerText;
- 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="button" value="OK" onclick="ComfirmUpdate_component(\'' + company_id + '\')">';
- target_id.insertAdjacentHTML('beforeend', textarea);
- }
- // 刪除
- function delete_component(company_id) {
- console.log("刪除 " + company_id)
- }
- // 零件表查詢
- function search_component_table(){
- var accountingsubjects_select = $("#accountingsubjects").val();
- var category_select = $("#category").val();
- var serialnumber_select = $("#serialnumber").val();
- var supplier_select = $("#supplier").val();
- var component_name_select = $("#component_name_select").val();
- var component_name_input = $("#component_name_input").val();
- var AND_list = [];
- console.log(accountingsubjects_select, category_select, serialnumber_select, supplier_select)
- // sql = 'SELECT * FROM 零件表';
- sql = 'SELECT 內部料號, 會計科目表.會計科目_名稱, 類別表.類別_名稱, 流水號, 供應商.公司, 名稱' +
- ' FROM (' +
- '(零件表 ' +
- 'INNER JOIN 供應商' +
- ' ON 供應商.供應商 = 零件表.供應商' +
- ')' +
- ' INNER JOIN 類別表' +
- ' ON 類別表.類別_編號 = 零件表.類別' +
- ') ' +
- 'INNER JOIN 會計科目表 ' +
- 'ON 會計科目表.會計科目_編號 = 零件表.會計科目' +
- '' ;
- // 篩選 會計科目/類別/供應商 關鍵字
- if (accountingsubjects_select != '00') {
- AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
- }
- if (category_select != '00') {
- AND_list.push('類別 = "' + category_select + '"')
- }
- if (serialnumber_select != '') {
- AND_list.push('流水號 = "' + serialnumber_select + '"')
- }
- if (supplier_select != '00') {
- AND_list.push('零件表.供應商 = "' + supplier_select + '"')
- }
- if (component_name_select != '00') {
- AND_list.push('名稱 = "' + component_name_select + '"')
- } else if (component_name_input != '') {
- AND_list.push('名稱 LIKE "%' + component_name_input + '%"')
- }
- console.log("AND_list: ", AND_list)
- if (AND_list != '') {
- sql += ' WHERE ' + AND_list.join(' AND ');
- }
-
- var sql_data = {
- "sql":sql
- };
- console.log("sql_data: ", sql_data)
- $.get('/sql_get', sql_data, function (res) {
- // console.log("res: " + res)
- // console.log("res.labels:" + res.labels)
- // console.log("res.labels[0]:" + res.labels[0])
- // console.log("res.labels[0][0]:" + res.labels[0][0])
- // console.log("res.sql_field:" + res.sql_field)
- // console.log("res.sql_field[0]:" + res.sql_field[0])
- var data = " ";
- if (res.labels == '') {
- data += '-- 無符合關鍵字之資料 --'
- } else {
- 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>';
- }
- 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.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>';
- }
- var sectorSelect = document.getElementById("result");
- sectorSelect.innerHTML = data;
- }, 'json');
- }
-
-
- </script>
- <div id="result">
- <!-- <table>
- </table> -->
- </div>
-
-
-
-
-
-
- <!-- <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>
|