123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- <!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>
|