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">
-
- {% 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>
- </tr>
-
-
- <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_remark_0" value="備註" style="height: 25px; width: 90px; margin-right: 20px;">
- <input type="button" value="新增下一筆" onclick="table_add_rows()">
- </td>
- </tr>
- <script>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function PR_change() {
-
- 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 += '</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>
- 請購 :
-
-
- <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 };
-
- function create_PR_table(PR_conpany_id) {
- console.log("create_PR_table PR_conpany_id: " + PR_conpany_id)
-
- 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);
- }
- console.log("PR_insert_items: " + PR_insert_items)
-
- 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(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(', ');
- 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', '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);
-
-
- 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) {
-
- 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: 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)
-
- 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>
|