12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- <!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>
- var USERNAME = '{{USERNAME}}';
- console.log("USERNAME: " + USERNAME);
- $(function(){
- // var manual_createBOM = confirm("請先在上方, 輸入新 BOM 表內部料號及名稱 \
- // \n再到下方, 搜尋零件並輸入數量, 再按下[加入] \
- // \n可以透過上方的 [查看現有加入零件] 檢查所選零件 \
- // \n最後, 按下 [新增模組/系統成品] 即可建立 BOM !")
- // if (manual_createBOM) {
- // var manual_searchBOM = confirm("若要查詢 BOM 表 \
- // \n可以先從 [零件表查詢] 中找到內部料號 \
- // \n輸入完成再按下 [BOM 表查詢]")
- // }
- });
- </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>
- <!-- 建立 BOM 表名稱用 --------------------------------------------------------------------------------------- -->
- 請輸入欲新增的 BOM 表名稱:<br>
- 會計科目:
- <select id="BOM_accountingsubjects" onChange="">
- <option value="00"></option>
- {% for data in AccountingSubjects_data %}
- <option value="{{data[0]}}">{{data[0]}}-{{data[1]}}</option>
- {% endfor %}
- </select>
- 類別:
- <select id="BOM_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="BOM_serialnumber" style="height: 25px; width: 45px;">
- 供應商:
- <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 list="BOM_module" id="BOM_module_name_select">
- <datalist id="BOM_module">
- <option value=""></option>
- {% for data in Component_data %}
- <option value="{{data[0]}}">{{data[0]}}</option>
- {% endfor %}
- </datalist>
- <br>
- <hr>
- 可搜尋欲加入的零件或是查詢 BOM 表內容:<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="">
- <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;">
- 供應商:
- <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_BOM_table" value="BOM 表查詢" onclick="search_BOM_table();">
- <div id="result"></div>
-
- <script>
- var BOM_company_id;
- // 儲存欲加入的零件 數量_顯示用有加名稱
- var module_amount_list = [];
- // 儲存欲加入的零件 數量_sql 用無名稱注意格式
- var module_amount_sqllist = [];
- // BOM 表查詢
- function search_BOM_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();
- // console.log("accountingsubjects_select: " + accountingsubjects_select)
- // console.log("category_select: " + category_select)
- // console.log("serialnumber_select: " + serialnumber_select)
- // console.log("supplier_select: " + supplier_select)
-
- // 若要查詢 BOM 表內容要以內部料號查詢, 所以輸入欄位不可空
- if (accountingsubjects_select == '00' || category_select == '00' || serialnumber_select == '0000' || supplier_select == '00' ) {
- alert("若要查詢 BOM 表\n請先找到內部料號對應的會計科目、類別、流水號、供應商\n輸入完成再按下 [BOM 表查詢]");
- } else {
- // 內部料號組合
- BOM_company_id = accountingsubjects_select + category_select + serialnumber_select + supplier_select;
- // console.log("BOM_company_id: " + BOM_company_id)
- // sql = 'SELECT * FROM `' + BOM_company_id + '` ORDER BY 內部料號';
- sql = 'SELECT 零件表.內部料號, 零件表.名稱, 規格表.原廠料號, 規格表.圖片, 數量, 位置, ' + BOM_company_id + '.備註, 設計原因, 填寫人' +
- ' FROM (`' + BOM_company_id + '`' +
- ' INNER JOIN 零件表' +
- ' ON 零件表.內部料號 = ' + BOM_company_id + '.內部料號' +
- ' )' +
- ' INNER JOIN 規格表' +
- ' ON 規格表.內部料號 = ' + BOM_company_id + '.內部料號' +
- ' ORDER BY 內部料號'
- 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 += '查詢結果: 共 ' + res.labels.length + ' 筆<br>'
- data += '<table id="table_BOM" 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 += '<th>內部料號</th>';
- data += '<th>名稱</th>';
- data += '<th>原廠料號</th>';
- data += '<th>圖片</th>';
- data += '<th>數量</th>';
- data += '<th>位置</th>';
- data += '<th>備註</th>';
- data += '<th>設計原因</th>';
- data += '<th>填寫人</th>';
- data += '<th>修改</th>';
- data += '<th>刪除</th>';
- data += '</tr>';
- if (res.labels != '') {
- for (let items = 0; items < res.labels.length; items++) {
- data += '<tr>';
- for (let item = 0; item < res.labels[items].length; item++) {
- if (res.labels[items][item] == null) {
- data += '<td id="' + res.labels[items][0] + '_' + item + '">' + '' + '</td>';
- } else {
- if ((item == 3) && (res.labels[items][item].indexOf(".pdf") != -1)) {
- data += '<td><a href="' + res.labels[items][item] + '" target="_blank">圖片連結</a></td>'
- } else if ((item == 3) && (res.labels[items][item].indexOf(".png") != -1)) {
- data += '<td><a href="' + res.labels[items][item] + '" target="_blank"><img src="' + 'http://60.250.156.230:3000/rita/ERP/raw/master/SHT11.png' + '" width="50px"></a></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_BOM_item(\'' + res.labels[items][0] + '\')"></td>';
- data += '<td><input type="button" class="input-cond-delete" value="刪除" onclick="delete_BOM_item(\'' + res.labels[items][0] + '\')"></td>';
- data += '</tr>';
- };
- }
- data += '<tr class="noExl">';
-
- data += '<td>';
- // data += '<select id="newcom_id" onChange="">';
- // data += '<option value="00"></option>';
- // data += '{% for data in Company_ID_data %}';
- // data += '<option value="{{data[0]}}">{{data[0]}}</option>';
- // data += '{% endfor %}';
- // data += '</select>';
- data += '<input list="insert_BOM_module" id="newcom_id" style="height: 25px;" onChange="get_company_id()">';
- data += '<datalist id="insert_BOM_module">';
- data += '<option value="">可輸入名稱查找內部料號</option>';
- // data += '{% for data in Component_id_name %}';
- // data += '<option value="{{data[0]}}">{{data[1]}}</option>';
- // data += '{% endfor %}';
- data += '{% for data in Component_id_name_salesnum %}';
- data += '{% if data[2] == "" or data[2] == None %}';
- data += '<option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>';
- data += '{% else %}';
- data += '<option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>';
- data += '{% endif %}';
- data += '{% endfor %}';
- data += '</datalist>';
- data += '</td>';
- data += '<td>';
- data += '(自動代入)'
- // data += '<select id="newcom_id" onChange="">';
- // data += '<option value="00"></option>';
- // data += '{% for data in Component_name_data %}';
- // data += '<option value="{{data[0]}}">{{data[0]}}</option>';
- // data += '{% endfor %}';
- // data += '</select>';
- data += '</td>';
- data += '<td></td>';
- data += '<td></td>';
- data += '<td><input id="newcom_1_ta" value="" style="height: 25px; width: auto" size="5"></td>';
- data += '<td><input id="newcom_2_ta" value="" style="height: 25px; width: auto" size="15"></td>';
- data += '<td><input id="newcom_3_ta" value="" style="height: 25px; width: auto" size="10"></td>';
- data += '<td><input id="newcom_4_ta" value="" style="height: 25px; width: auto" size="10"></td>';
- data += '<td>';
- // data += '<input list="insert_BOM_person_module" id="newcom_name" style="height: 25px;" onChange="">';
- // data += '<datalist id="insert_BOM_person_module">';
- // data += '<option value="Andrey"></option>';
- // data += '<option value="Amy"></option>';
- // data += '<option value="Allen"></option>';
- // data += '<option value="Gina"></option>';
- // data += '<option value="FatWolf"></option>';
- // data += '<option value="Rita"></option>';
- // data += '</datalist>';
- data += '(自動代入)';
- data += '</td>';
- data += '<td>';
- data += '<input type="button" style="width: auto;" class="input-cond-add" value="新增零件至 BOM" onclick="BOM_insert_component(\'' + BOM_company_id + '\')">';
- data += '</td>';
- data += '<td><input type="button" style="width: auto;" class="input-cond-delete" value="刪除此 BOM 表" onclick="delete_BOM_table(\'' + BOM_company_id + '\')"></td>';
-
- data += '</tr>';
-
- data += '</table>';
- data += '<input type="button" style="width: auto;" class="input-cond-add" value="匯出表單" onclick="export_BOM_table(\'' + BOM_company_id + '\')">';
- var sectorSelect = document.getElementById("result");
- sectorSelect.innerHTML = data;
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("BOM 表: 無此內部料號 " + BOM_company_id + " 之資料表")
- } else {
- console.log("BOM 表查詢 thrownError" + thrownError)
- }
- var data = "";
- var sectorSelect = document.getElementById("result");
- sectorSelect.innerHTML = data;
- }
- })
- }
- }
- // 新增 BOM 表零件時, 選擇名稱自動帶入內部料號
- function get_company_id() {
- var new_component_name = $("#newcom_id").val();
- console.log("new_component_name: " + new_component_name) // 03040001T01
- }
- // 新增零件至 BOM
- function BOM_insert_component(BOM_company_id) {
- var new_com_0 = $("#newcom_id").val();
- var new_com_1 = $("#newcom_1_ta").val()
- var new_com_2 = $("#newcom_2_ta").val()
- var new_com_3 = $("#newcom_3_ta").val()
- var new_com_4 = $("#newcom_4_ta").val()
- // var new_com_5 = $("#newcom_name").val()
- console.log("new_com_0: " + new_com_0)
- console.log("new_com_1: " + new_com_1)
- console.log("new_com_2: " + new_com_2)
- console.log("new_com_3: " + new_com_3)
- console.log("new_com_4: " + new_com_4)
- // console.log("new_com_5: " + new_com_5)
- var sql = 'INSERT INTO `' + BOM_company_id + '`';
- sql += ' VALUES ("' + new_com_0 + '", "' + new_com_1 + '", "' + new_com_2 + '", "' + new_com_3 + '", "' + new_com_4 + '", "' + USERNAME + '");';
- console.log("sql: ", sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- search_BOM_table()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("BOM 表: " + BOM_company_id + " 新增零件未成功")
- } else {
- console.log("BOM 表新增零件 thrownError" + thrownError)
- }
- }
- })
-
-
- }
- // 匯出 BOM 表
- function export_BOM_table(BOM_company_id) {
- // alert("匯出功能測試中")
- console.log("匯出 BOM 表: " + BOM_company_id)
- sql = 'SELECT * FROM `' + BOM_company_id + '`'; // 原始 BOM 表資料, 未來可加上 零件名稱
- var sql = 'SELECT ' + BOM_company_id + '.內部料號, ';
- sql += '零件表.名稱, ';
- sql += BOM_company_id + '.數量, ';
- sql += BOM_company_id + '.位置, ';
- sql += BOM_company_id + '.備註, ';
- sql += BOM_company_id + '.設計原因, ';
- sql += BOM_company_id + '.填寫人 ';
- sql += 'FROM `' + BOM_company_id + '` ';
- sql += ' INNER JOIN 零件表';
- sql += ' ON 零件表.內部料號 = ' + BOM_company_id + '.內部料號';
- var sql_data = { "sql":sql };
- console.log("sql_data: ", sql_data)
- $.ajax({
- type:"GET",
- url:"/export_excel/" + BOM_company_id,
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- document.location.href = '/download/BOM_' + BOM_company_id + '.xlsx'
- alert(BOM_company_id + " 匯出 Excel 成功\n檔案路徑: \n" + res.file_location)
- // var html = '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8" /><title>Excel</title>';
- // html += '';
- // html += document.getElementById('table_BOM').innerHTML + '';
- // window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
- // console.log("res.sql_data_new: " + res.sql_data_new + typeof(res.sql_data_new))
- // TableToExcel.convert(table[0],{
- // name:BOM_company_id + '.xlsx',
- // sheet:{ name:BOM_company_id }
- // });
- // $("#table_BOM").table2excel({
- // exclude:".noExl",
- // name:BOM_company_id + "_0106",
- // filename:BOM_company_id,
- // fileext:".xls"
- // });
- // window.open('data:application/vnd.ms-excel,' + encodeURIComponent(res.sql_data_new));
- console.log("Excel create")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("BOM 表: 無此內部料號 " + BOM_company_id + " 之資料表")
- } else {
- console.log("BOM 表查詢 thrownError" + thrownError)
- }
- }
- })
- }
- // 刪除此 BOM 表
- function delete_BOM_table(BOM_company_id) {
- console.log("刪除 BOM 表: " + BOM_company_id)
- var drop_table = confirm("確定要刪除 " + BOM_company_id + " 資料表?\n此動作不可回復")
- if (drop_table) {
- sql = 'DROP TABLE ' + BOM_company_id + ';';
- console.log("sql: " + sql)
- 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) {
- alert("BOM 表: " + BOM_company_id + "刪除成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("BOM 表: " + BOM_company_id + " 刪除未成功")
- } else {
- console.log("BOM Table 刪除 thrownError" + thrownError)
- }
- }
- })
- var sql = 'DELETE FROM 規格表 WHERE 內部料號 = "' + BOM_company_id + '";'
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert("規格表: " + BOM_company_id + "刪除成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("規格表: " + BOM_company_id + " 刪除未成功")
- } else {
- console.log("規格表: 刪除 thrownError" + thrownError)
- }
- }
- })
- var sql = 'DELETE FROM 零件表 WHERE 內部料號 = "' + BOM_company_id + '";'
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert("零件表: " + BOM_company_id + "刪除成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("零件表: " + BOM_company_id + " 刪除未成功")
- } else {
- console.log("零件表: 刪除 thrownError" + thrownError)
- }
- }
- })
-
- location.reload()
- }
- }
- // 修改 BOM 表內項目
- function update_BOM_item(company_id) {
- console.log("修改 " + company_id)
- for (let i = 4; i < 8; 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 = '<input id="'+ company_id + '_' + i + '_ta' + '" value="' + old_name + '" style="height: 25px; width: 100px">';
- if (i == 7) {
- textarea += '<input type="button" value="OK" onclick="ComfirmUpdate_BOM_item(\'' + company_id + '\')">';
- }
- target_id.insertAdjacentHTML('beforeend', textarea);
- }
- // var target_id = document.getElementById(company_id + '_8');
- // var old_name = target_id.innerText;
- // console.log("old_name-NAME: " + old_name)
- // target_id.innerHTML = "";
- // textarea = '<input list="insert_BOM_person_module" id="newcom_name" style="height: 25px; width: 100px" onChange="">';
- // textarea += '<datalist id="insert_BOM_person_module">' +
- // '<option value="Andrey"></option>' +
- // '<option value="Amy"></option>' +
- // '<option value="Allen"></option>' +
- // '<option value="Gina"></option>' +
- // '<option value="FatWolf"></option>' +
- // '<option value="Rita"></option>' +
- // '</datalist>';
-
- // target_id.insertAdjacentHTML('beforeend', textarea);
- // $(".insert_BOM_person_module").find("option:contains(" + old_name + ")").attr("selected",true);
- // // $("#insert_BOM_person_module select").val(old_name).change();
- }
- // 修改確認 BOM 表內項目
- function ComfirmUpdate_BOM_item(company_id) {
- console.log("修改確認 " + company_id )
- var new_amount_value = $('#' + company_id + '_4_ta').val();
- var new_position_value = $('#' + company_id + '_5_ta').val();
- var new_remark_value = $('#' + company_id + '_6_ta').val();
- var new_reason_value = $('#' + company_id + '_7_ta').val();
- // var new_person_value = $('#newcom_name').val();
- // console.log("new_person_value: " + new_person_value)
- sql = 'UPDATE ' + BOM_company_id + ' SET `數量` = "' + new_amount_value + '"' +
- ', `位置` = "' + new_position_value + '"' +
- ', `備註` = "' + new_remark_value + '"' +
- ', `設計原因` = "' + new_reason_value + '"' +
- ', `填寫人` = "' + USERNAME + '"' +
- ' WHERE `內部料號` = "' + company_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_BOM_table();
- alert("BOM 表: 修改成功 !")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("規格表: 內部料號 " + company_id + " 修改未成功")
- } else {
- console.log("修改規格表內容 thrownError" + thrownError)
- }
- }
- })
- }
- // 刪除 BOM 表內項目
- function delete_BOM_item(company_id) {
- console.log("刪除 " + company_id)
- var delete_data = confirm("確定要刪除 " + BOM_company_id + " BOM 表內的 " + company_id + "?")
- if (delete_data) {
- // 刪除 BOM 表內的指定零件
- var sql = 'DELETE FROM ' + BOM_company_id + ' WHERE 內部料號 = "' + company_id + '";'
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert("BOM 表: 項目刪除成功!")
- search_BOM_table()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("BOM 表: 無內部料號 " + company_id + " 之項目資料")
- } else {
- alert("BOM 表項目刪除錯誤: " + thrownError)
- }
- }
- })
-
- }
-
- }
- // 加入 BOM 表
- function insert_module(company_id) {
- var select_amount = $("#BOM_amount" + company_id).val();
- select_amount = parseInt(select_amount)
- console.log("select_amount: " + select_amount)
- // console.log("typeof(select_amount): " + typeof(select_amount)) // string
- var select_name = $("#" + company_id + "_5").text();
- console.log("select_name: " + select_name)
- var repeat_word = module_amount_list.indexOf(company_id)
- console.log("repeat_word: " + repeat_word)
- if (select_amount != '') {
- if (repeat_word != -1) {
- module_amount_list.splice(repeat_word, 3)
- }
- module_amount_list.push(company_id)
- module_amount_list.push(select_name)
- module_amount_list.push(select_amount)
- // console.log("現有零件: " + module_amount_list)
- alert("零件加入成功 !\n\"" + select_name + "\"×" + select_amount)
- view_component();
- } else if (select_amount == 0) {
- if (repeat_word != -1) {
- module_amount_list.splice(repeat_word, 3)
- }
- view_component();
- } else {
- alert("請輸入零件數量, 且數量為正整數")
- }
- }
- // 輸入完類別後, 流水號自動帶入
- function renewSN() {
- var BOM_accountingsubjects_select = $("#BOM_accountingsubjects").val();
- var BOM_category_select = $("#BOM_category").val();
- $.get('/sn_get/' + BOM_accountingsubjects_select + '/' + BOM_category_select, '', function (res) {
- // console.log(res.new_sn)
- $('#BOM_serialnumber').val(res.new_sn)
- }, 'json');
- }
- // 各資料表←關聯→零件表, 程式
- // function search_relation_insertdata(sql) {
- // 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();
- // 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 != '0000') {
- // 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 search_component_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();
- 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 供應商.供應商 = 零件表.供應商 ' +
- ') ' +
- 'INNER JOIN 規格表 ' +
- 'ON 規格表.內部料號 = 零件表.內部料號 ';
- // 篩選 會計科目/類別/供應商 關鍵字
- if (accountingsubjects_select != '00') {
- AND_list.push('會計科目 = "' + accountingsubjects_select + '"')
- }
- if (category_select != '00') {
- AND_list.push('類別 = "' + category_select + '"')
- }
- if (serialnumber_select != '0000') {
- 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])
- // console.log("res.Component_id[0]:" + res.Component_id[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 += '<th>內部料號</th>';
- data += '<th>會計科目</th>';
- data += '<th>類別</th>';
- data += '<th>流水號</th>';
- data += '<th>供應商</th>';
- data += '<th>名稱</th>';
- data += '<th>原廠料號</th>';
- data += '<th>輸入零件數量</th>';
- data += '<th>加入至新 BOM 表</th>';
- data += '</tr>';
- for (let items = 0; items < res.labels.length; items++) {
- data += '<tr>';
- for (let item = 0; item < res.labels[items].length; 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>';
- }
- };
- // <input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
- data += '<td><input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,\'\').replace(\'.\',\'\')}else{this.value=this.value.replace(/\\D/g,\'\').replace(\'.\',\'\')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,\'\').replace(\'.\',\'\')}else{this.value=this.value.replace(/\\D/g,\'\').replace(\'.\',\'\')}"'
- data += 'id="BOM_amount' + res.labels[items][0] + '" style="height: 25px; width: 90px;"></td>';
- data += '<td><input type="button" class="input-cond-add" value="加入" onclick="insert_module(\'' + res.labels[items][0] + '\')"></td>';
- data += '</tr>';
- };
- data += '</table>';
- }
- var sectorSelect = document.getElementById("result");
- sectorSelect.innerHTML = data;
- }, 'json');
- }
-
- // 查看現有零件
- function view_component() {
- var data = '現有零件: <br>';
- // 網頁顯示用 "內部料號"_"名稱"_"數量"<br>
- for (let i = 0; i < module_amount_list.length; i++) {
- if (i%3 == 0) {
- data += '"' + module_amount_list[i] + '"_'
- } else if (i%3 == 1) {
- data += '"' + module_amount_list[i] + '"_'
- } else if (i%3 == 2) {
- data += '"' + module_amount_list[i] + '"<br>'
- }
- }
-
- // data += 'SQL: <br>' +
- // 'INSERT INTO `' + 'company_id' + '` (`內部料號`, `數量`) ' +
- // 'VALUES ' + module_amount_sqllist.join(', ') + ';';
- var sectorSelect = document.getElementById("view_component_data");
- sectorSelect.innerHTML = data;
- }
- // 新增模組/系統/成品
- function create_module() {
- // 會計科目
- var accountingsubjects_select = $("#BOM_accountingsubjects").val();
- // 類別
- var category_select = $("#BOM_category").val();
- // 流水號 → 從資料庫找到最大的流水號, 然後 +1
- var serialnumber_select = $("#BOM_serialnumber").val();
- // 放到 renewSN 方法內執行
- // 供應商
- var supplier_select = $("#BOM_supplier").val();
- // 零件名稱
- var component_name_select = $("#BOM_module_name_select").val();
- // 內部料號組合
- 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)
- if (accountingsubjects_select == '00' || accountingsubjects_select == '00' || supplier_select == '00' || component_name_select == '') {
- alert("請先輸入 BOM 表會計科目、類別、供應商及名稱\n再新建模組")
- } else {
- // !!! 將模組加入零件表中
- 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("零件表 " + company_id + " 新增成功!")
- // data = '-- 新增成功! --'
- // var sectorSelect = document.getElementById("result");
- // sectorSelect.innerHTML = data;
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("零件表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組零件 thrownError" + thrownError)
- }
- }
- })
- // !!! 將模組加入規格表中 (留下內部料號, 其他 NULL)
- var sql = '';
- sql += 'INSERT INTO 規格表 (`內部料號`)' +
- ' VALUES ("' + company_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("規格表 " + company_id + " 新增成功!")
- // data = '-- 新增成功! --'
- // var sectorSelect = document.getElementById("result");
- // sectorSelect.innerHTML = data;
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("規格表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組零件 thrownError" + thrownError)
- }
- }
- })
- // !!! 建立模組 Table
- var sql = '';
- sql += 'CREATE TABLE `' + company_id + '` ( ' +
- '內部料號 varchar(11) NOT NULL DEFAULT "00", ' +
- '數量 varchar(4) NOT NULL,' +
- '位置 varchar(100) NULL,' +
- '備註 varchar(200) NULL,' +
- '設計原因 varchar(200) NULL,' +
- '填寫人 varchar(20) NULL,' +
- 'PRIMARY KEY (內部料號)' +
- ');';
- 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("資料表 " + company_id + " 建立成功!")
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("資料表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組 Table thrownError" + thrownError)
- }
- }
- })
- // 儲存欲加入的零件 數量_sql 用無名稱注意格式
- var module_amount_sqllist = [];
- // SQL 語法
- var sql_data_list = '';
- for (let i = 0; i < module_amount_list.length; i++) {
- if (i%3 == 0) {
- // 內部料號
- sql_data_list = '("' + module_amount_list[i] + '", '
- }
- if (i%3 == 2) {
- // 數量 + 填寫人
- sql_data_list += '"' + module_amount_list[i] + '", "' + USERNAME + '")'
- module_amount_sqllist.push(sql_data_list)
- }
- }
-
- console.log("module_amount_sqllist: " + module_amount_sqllist)
- // !!! 將所選零件加入模組 Table
- var sql = '';
- sql += 'INSERT INTO `' + company_id + '` (`內部料號`, `數量`, `填寫人`) ' +
- 'VALUES ' + module_amount_sqllist.join(', ') + ';';
- console.log("sql: " + sql)
- var sql_data = { "sql":sql };
-
- if (module_amount_sqllist.length == 0) {
- alert("資料表 " + company_id + ": 加入零件為空, 故此 BOM 表無零件")
- location.reload()
- } else {
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- async:false,
- success:function (res) {
- alert("資料表 " + company_id + ": 零件增加成功!")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("零件加入模組 thrownError" + thrownError)
- }
- }
- })
- }
- }
- }
-
- </script>
- <br>
- <hr>
- <!-- <input type="button" id="view_component" value="查看現有加入零件" onclick="view_component();"> -->
- <div id="view_component_data">現有零件 :</div>
- <br>
- 零件加入完成後, 請按下
- <input type="button" id="create_module" value="新增模組/系統/成品" onclick="create_module();">
-
- <!-- <script>
-
- // 查看現有零件
- function view_component() {
- var data = '現有零件: <br>';
- // 網頁顯示用 "內部料號"_"名稱"_"數量"<br>
- for (let i = 0; i < module_amount_list.length; i++) {
- if (i%3 == 0) {
- data += '"' + module_amount_list[i] + '"_'
- } else if (i%3 == 1) {
- data += '"' + module_amount_list[i] + '"_'
- } else if (i%3 == 2) {
- data += '"' + module_amount_list[i] + '"<br>'
- }
- }
-
- // data += 'SQL: <br>' +
- // 'INSERT INTO `' + 'company_id' + '` (`內部料號`, `數量`) ' +
- // 'VALUES ' + module_amount_sqllist.join(', ') + ';';
- var sectorSelect = document.getElementById("view_component_data");
- sectorSelect.innerHTML = data;
- }
- // 新增模組/系統/成品
- function create_module() {
- // 會計科目
- var accountingsubjects_select = $("#BOM_accountingsubjects").val();
- // 類別
- var category_select = $("#BOM_category").val();
- // 流水號 → 從資料庫找到最大的流水號, 然後 +1
- var serialnumber_select = $("#BOM_serialnumber").val();
- // 放到 renewSN 方法內執行
- // 供應商
- var supplier_select = $("#BOM_supplier").val();
- // 零件名稱
- var component_name_select = $("#BOM_module_name_select").val();
- // 內部料號組合
- 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,
- success:function (res) {
- alert("零件表 " + company_id + " 新增成功!")
- // data = '-- 新增成功! --'
- // var sectorSelect = document.getElementById("result");
- // sectorSelect.innerHTML = data;
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("零件表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組零件 thrownError" + thrownError)
- }
- }
- })
- // !!! 將模組加入規格表中 (留下內部料號, 其他 NULL)
- var sql = '';
- sql += 'INSERT INTO 規格表 (`內部料號`)' +
- 'VALUES ("' + company_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("規格表 " + company_id + " 新增成功!")
- // data = '-- 新增成功! --'
- // var sectorSelect = document.getElementById("result");
- // sectorSelect.innerHTML = data;
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("規格表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組零件 thrownError" + thrownError)
- }
- }
- })
- // !!! 建立模組 Table
- var sql = '';
- sql += 'CREATE TABLE `' + company_id + '` ( ' +
- '內部料號 varchar(11) NOT NULL DEFAULT "00", ' +
- '數量 varchar(4) NOT NULL,' +
- '位置 varchar(100) NULL,' +
- '備註 varchar(200) NULL,' +
- '設計原因 varchar(200) NULL,' +
- '填寫人 varchar(20) NULL,' +
- 'PRIMARY KEY (內部料號)' +
- ');';
- console.log("sql: " + sql)
- var sql_data = { "sql":sql };
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert("資料表 " + company_id + " 建立成功!")
- module_amount_sqllist = [];
- // SQL 語法
- var sql_data_list = '';
- for (let i = 0; i < module_amount_list.length; i++) {
- if (i%3 == 0) {
- sql_data_list = '("' + module_amount_list[i] + '", '
- }
- if (i%3 == 2) {
- sql_data_list += '"' + module_amount_list[i] + '")'
- module_amount_sqllist.push(sql_data_list)
- }
- }
- // !!! 將所選零件加入模組 Table
- var sql = '';
- sql += 'INSERT INTO `' + company_id + '` (`內部料號`, `數量`) ' +
- 'VALUES ' + module_amount_sqllist.join(', ') + ';';
- console.log("sql: " + sql)
- var sql_data = { "sql":sql };
-
- if (module_amount_sqllist.length == 0) {
- alert("資料表 " + company_id + ": 加入零件為空, 故此 BOM 表無零件")
- location.reload()
- } else {
- $.ajax({
- type:"GET",
- url:"/sql_get",
- dataType:"JSON",
- data:sql_data,
- success:function (res) {
- alert("資料表 " + company_id + ": 零件增加成功!")
- location.reload()
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("零件加入模組 thrownError" + thrownError)
- }
- }
- })
- }
- },
- error: function (thrownError) {
- if (thrownError.statusText == "INTERNAL SERVER ERROR") {
- alert("資料表: 內部料號 " + company_id + " 已存在, 請重新輸入")
- } else {
- console.log("新建模組 Table thrownError" + thrownError)
- }
- }
- })
- }
- </script> -->
-
- <br>
- <br>
- <!-- <input type="button" style="width: auto;" class="input-cond-add" value="匯出表單" onclick="export_BOM_table('03030001T01')"> -->
- <!-- <iframe width="100px" src="/plugins/pdfjs-1.4.20/web/viewer.html?file=http://60.250.156.230:3000/rita/ERP/src/1ac36a99cc9721451b4baafd67d98b54bb315bcd/pH_probe.pdf"></iframe> -->
- </body>
- </html>
|