You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

581 lines
24 KiB

<?php
include "../header.php";
require_once '../cont/wf_common.php';
// 報價單編號
$repair_no_a = date("Ymd");
$sql = "select max(repair_no) from pricereview_repair_main where SUBSTRING(repair_no, 1, 8) = '$repair_no_a'";
$res = mysqli_query($link, $sql);
$row = mysqli_fetch_row($res);
if (empty($row[0])) $serial = "001";
else $serial = str_pad(substr($row[0] + 1, -3), 3, 0, STR_PAD_LEFT);
$repair_no = $repair_no_a . $serial;
// 公司站點
$maddr_arr = [];
$sql = "select code_name, content, remark from code where field_name = 'masada_addr' order by code_name";
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_row($res)) {
$maddr_arr[$row[0]] = $row[2] . "(" . $row[1] . ")";
}
mysqli_free_result($res);
// 保養人員
$repairer_arr = [];
// 申請人測試 accounttype = 'E' -> 管理人員。 原本是 'B'
$sql = "select accountid, name from account where accounttype = 'B' and accountid not in ('B000000001', 'M0008') order by accountid";
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_row($res)) {
$repairer_arr[$row[0]] = $row[1];
}
mysqli_free_result($res);
// 備品項目
$item_arr = [];
$sql = "SELECT * FROM supplies WHERE ver = '20231103'";
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($res)) {
$item_arr[$row["id"]]["title"] = $row["title"];
$item_arr[$row["id"]]["stype"] = $row["stype"];
$item_arr[$row["id"]]["unit"] = $row["unit"];
$item_arr[$row["id"]]["price"] = $row["price"];
$item_arr[$row["id"]]["memo"] = $row["memo"];
}
mysqli_free_result($res);
$item_str = '<table id="table_index2" class="table table-striped table-bordered" style="width:100%">';
$item_str .= '<thead>
<tr class="kind-col">
<th scope="col" nowrap>序號</th>
<th scope="col" nowrap>名稱</th>
<th scope="col" nowrap>類別</th>
<th scope="col" nowrap>單位</th>
<th scope="col" nowrap>售價</th>
<th scope="col" nowrap>備註</th>
</tr></thead><tbody>';
foreach ($item_arr as $k => $v) {
$item_str .= "<tr>";
$item_str .= "<td>" . $k . "</td>";
$item_str .= "<td>" . $v["title"] . "</td>";
$item_str .= "<td>" . $v["stype"] . "</td>";
$item_str .= "<td>" . $v["unit"] . "</td>";
$item_str .= "<td>" . number_format($v["price"]) . "</td>";
$item_str .= "<td>" . $v["memo"] . "</td>";
$item_str .= "</tr>";
}
$item_str .= "</tbody></table>";
/*
#獲取簽核意見
$assign_opinions = Assign::get_records($form_key);
$assigner = $wf->getAssignerList();
$assign_status = $wf->getAssignStatus($assigner);
*/
$assign_status = '<option value="FH">指派</option>'
?>
<style>
#btnadd,
a[name=btndel] {
margin-left: 4px;
}
.nextline {
width: 100%;
height: 0;
}
input[type=submit],
input[type=button] {
width: 100%;
background-color: #1E74FD;
color: white;
padding: 14px 20px;
margin: 8px 2px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.kind-col {
color: brown;
}
.modal-dialog {
width: 1200px;
}
.modal-content {
height: 660px;
}
#itemModal .modal-body {
height: 540px;
overflow-y: auto;
}
#table_index2_filter label {
width: 30%;
}
#table_index2 {
cursor: pointer;
}
.row .form_row_header {
background-color: #6d9eeb;
line-height: 30px;
font-size: 16px;
}
.dollar-right {
text-align: right;
}
.star {
color: red;
}
</style>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
// 加千分位
function commafy(num) {
num = num + "";
var re = /(-?\d+)(\d{3})/
while (re.test(num)) {
num = num.replace(re, "$1,$2")
}
return num;
}
function getCont(o) {
var fp = o.parent().parent();
//console.log(fp.html());
var pa = fp.find('input[name=contractno]').val().trim();
if (pa !== '') {
var formdata = new FormData();
formdata.append('pa', pa);
var xhr = new XMLHttpRequest();
var str = '';
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
data = JSON.parse(this.responseText);
if (data.st == 'err') {
//alert(data.err);
alert('查無資料,請自行輸入資料!');
fp.find('input[name=company]').val('');
fp.find('input[name=invoice]').val('');
fp.find('input[name=address]').val('');
fp.find('select[name=repairerid]').val('');
fp.find('select[name=taxid]').val('');
fp.find('select[name=invoice]').val('');
fp.find('textarea[name=memo]').val('');
fp.find('input[name=facilityno]').val('');
fp.find('select[name=facilityno]').html('<option value=""></option>');
fp.find('select[name=facilityno]').removeAttr("required");
fp.find('select[name=facilityno]').hide();
fp.find('input[name=facilityno]').prop('required', true);
fp.find('input[name=facilityno]').show();
return false;
}
fp.find('input[name=company]').val(data.company);
fp.find('input[name=invoice]').val(data.company);
fp.find('input[name=contractno]').val(data.contractno);
fp.find('input[name=address]').val(data.address);
fp.find('select[name=repairerid]').val(data.repairerid);
Object.keys(data.faci).forEach(function(k) {
str += '<option value="' + data.faci[k] + '">' + data.faci[k] + '</option>';
});
fp.find('input[name=facilityno]').removeAttr("required");
fp.find('input[name=facilityno]').hide();
fp.find('select[name=facilityno]').append(str);
fp.find('select[name=facilityno]').prop('required', true);
fp.find('select[name=facilityno]').show();
}
}
xhr.open('POST', 'pricereview_contractno-api.php', true);
xhr.send(formdata);
}
}
function dataFormat() {
var amtAll = 0;
$("input[name='item_price_bp']").each(function() {
amtAll += Number($(this).val().replace(/[,]+/g, ""));
});
var service = Number($("input[name='service_charge']").val().replace(/[,]+/g, ""));
var tax = Math.round(amtAll * 0.05);
$('#sales_tax').val(commafy(tax));
$('#total_price').val(commafy(amtAll + tax + service));
}
function cacl(o) {
// console.log(o.parent().parent());
var fp = o.parent().parent();
fp.find('input[name=item_price_bp]').val(commafy(fp.find('input[name=item_unit_price]').val().replace(/[,]+/g, "") * o.val().replace(/[,]+/g, "")));
dataFormat();
}
$(function() {
//$('#assign_status').change(function() {
$("#next_users").empty();
//var _selected_status = $(this).children('option:selected').val(); //獲取被選擇的狀態
var _option_tmp = ""; //獲取下拉列表
/*for (a in assigner) { //遍曆assigner
if (assigner[a][0] == _selected_status) {
_tmp = assigner[a][1].split(',');
for (var b in _tmp) {
if (_tmp[b] == '') {
continue;
}
_uname = _tmp[b].split('-')[1];
_uid = _tmp[b].split('-')[0];
_option_tmp += '<option value=' + _uid + '>' + _tmp[b] + '</option>';
}
}
}*/
_option_tmp = '<option value=""></option>';
_option_tmp += '<option value="M0026">M0026-張莉凱</option>';
_option_tmp += '<option value="M0033">M0033-吳育宗</option>';
_option_tmp += '<option value="M0054">M0054-陳志文</option>';
_option_tmp += '<option value="M0086">M0086-李烘銘</option>';
_option_tmp += '<option value="M0137">M0137-劉永德</option>';
$("#next_users").append(_option_tmp);
//});
$('#table_index2').DataTable({
"language": {
"zeroRecords": "沒有符合的結果",
"search": "查詢",
},
"searching": true,
"pageLength": 300,
});
$('#table_index2_length').hide();
$("#table_index2_paginate").hide();
/*$("#repair_no").prop("disabled", true);
$("#sales_tax").prop("disabled", true);
$("#total_price").prop("disabled", true);
*/
$("select[name=facilityno]").hide();
$("select[name=facilityno]").removeAttr("required");
$("input[name=item_unit_price], input[name=item_price_bp]").each(function() {
//$(this).prop("disabled", true);
});
$('#query').click(function() {
getCont($(this));
});
$('#btnadd').click(function() {
// console.log('123');
$('#tb1 tr:last').prev().prev().prev().after($("tr[name='main_templ']").last().clone().find('input').val('').end());
$('#tb1 tr:last').prev().prev().prev().find('td a[name=item_href]').html('點選');
});
// 點擊服務費會出現 or 消失 input 框
// $('#btnadd-sc').click(function() {
// $('#service_charge_tr').toggle();
// // 若消失清空 input 的值
// $('#service_charge').val('');
// // 並且重新計算總價(total)
// dataFormat();
// });
$('#tb1').on('click', 'a[name=btndel]', function() {
if ($('tr[name=main_templ]').length > 1) {
$(this).closest('tr').remove();
dataFormat();
}
});
// 關閉modal時
$("#itemModal").on("hidden.bs.modal", function() {
$('#table_index2_filter input').val(''); // 清空search
$('#table_index2_filter input').keyup(); // 恢復search前狀態
});
$('#tb1').on('focus', 'tr[name=main_templ] a[name=item_href]', function() {
$("#itemModal").modal('show');
var jobj = $(this); // 父視窗
$("#itemModal .modal-body td").unbind().click(function() {
var pobj = $(this).closest('td').parent();
var jTitle = pobj.find('td').eq(1).html();
var re = /主龬索 調速機/;
var found = jTitle.match(re);
//console.log(found);return;
jobj.html(jTitle);
jobj.closest('td').parent().find('input[name=item_qty]').val('');
jobj.closest('td').parent().find('input[name=item_unit_price]').val('');
jobj.closest('td').parent().find('input[name=item_memo]').val('');
jobj.closest('td').parent().find('input[name=item_price_bp]').val('');
jobj.closest('td').parent().find('input[name=item_unit_price]').val(pobj.find('td').eq(4).html());
jobj.closest('td').parent().find('input[name=supplies_id]').val(pobj.find('td').eq(0).html());
jobj.closest('td').parent().find('input[name=item_title_txt]').val(jTitle);
$("#itemModal").modal('hide');
});
});
$('#tb1').on('click', 'input[name=item_qty]', function() {
// console.log(this);
$(this).unbind().keyup(function() {
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
cacl($(this));
});
});
// 服務費 ++
$('#tb1').on('click', 'input[name=service_charge]', function() {
// console.log(this);
$(this).unbind().keyup(function() {
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
dataFormat();
// cacl($(this));
});
});
$('input[name=submit]').click(function() {
var itemTitleArr = [];
$("input[name=item_title_txt]").each(function() {
if ($(this).val() != '') itemTitleArr.push($(this).val());
})
$('#item_title_all').val(itemTitleArr);
var itemQtyArr = [];
$("input[name=item_qty]").each(function() {
if ($(this).val() != '') itemQtyArr.push($(this).val().replace(/[,]+/g, ""));
})
$('#item_qty_all').val(itemQtyArr);
var itemUnitPriceArr = [];
$("input[name=item_unit_price]").each(function() {
if ($(this).val() != '') itemUnitPriceArr.push($(this).val().replace(/[,]+/g, ""));
})
$('#item_unit_price_all').val(itemUnitPriceArr);
var itemPriceBpArr = [];
$("input[name=item_price_bp]").each(function() {
if ($(this).val() != '') itemPriceBpArr.push($(this).val().replace(/[,]+/g, ""));
})
$('#item_price_bp_all').val(itemPriceBpArr);
var itemMemoArr = [];
$("input[name=item_memo]").each(function() {
if ($(this).val() != '') itemMemoArr.push($(this).val() + "@@");
})
$('#item_memo_all').val(itemMemoArr);
if ($("#sales_tax").val() == "" || $("#total_price").val() == "") {
alert("請新增報價項目!");
return false;
}
});
});
</script>
<!--子窗:備品項目-->
<div class="modal fade" id="itemModal" tabindex="-1" role="dialog" aria-labelledby="itemModalTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="itemModalTitle">供應商備品備料</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<?php echo $item_str; ?>
</div>
</div>
</div>
</div>
<div class="container">
<?php
include "pricereview_repair-record-submit.php";
/*
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["id"]) && empty($_POST["expert_id"]) && empty($_POST["personal_id"])){
echo "<p class='error'>Please fill up the required field!</p>";
} else {
echo "<p class='success'>Record has added successfully</p>";
}
}
*/
?>
<form class="form-inline" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
<div>
<label for="contractno">客戶合約號<span class="star">*</span></label>
<input type="text" name="contractno" id="contractno" required>
</div>
<div>
<br>
<input type="button" name="query" id="query" value="查詢">
</div>
<div class="nextline"></div>
<div>
<label for="repair_no">報價單編號<span class="star">*</span></label>
<input type="text" name="repair_no" id="repair_no" value="<?php echo $repair_no; ?>" readonly>
</div>
<div class="nextline"></div>
<div>
<label for="sign_date">簽訂日期<span class="star">*</span></label><br>
<input type="date" name="sign_date" id="sign_date" value="<?php echo date('Y-m-d'); ?>" required>
</div>
<div>
<label for="company">公司地址<span class="star">*</span></label>
<select name="masada_addr" id="masada_addr" required>
<option value=""></option>
<?php
foreach ($maddr_arr as $k => $v) {
echo "<option value=\"" . $k . "\">" . $v . "</option>";
}
?>
</select>
</div>
<div>
<label for="company">客戶名稱<span class="star">*</span></label>
<input type="text" name="company" id="company" size="30" required>
</div>
<div>
<label for="facilityno">電梯編號<span class="star">*</span></label>
<input type="text" name="facilityno" required>
<select name="facilityno" required>
<option value=""></option>
</select>
</div>
<div class="nextline"></div>
<div>
<label for="address">工程地址<span class="star">*</span></label>
<input type="text" name="address" id="address" size="50" required>
</div>
<div>
<label for="taxid">客戶統一編號<span></span></label>
<input type="text" name="taxid" id="taxid" maxlength="8">
</div>
<div>
<label for="invoice">客戶發票抬頭<span class="star">*</span></label>
<input type="text" name="invoice" id="invoice" size="30" required>
</div>
<div>
<label for="repairerid">申請人<span class="star">*</span></label>
<select name="repairerid" id="repairerid" required>
<option value=""></option>
<?php
foreach ($repairer_arr as $k => $v) {
echo "<option value=\"" . $k . "\">" . $v . "</option>";
}
?>
</select>
</div>
<div class="nextline"></div>
<div>
<label for="memo">備註</label><br>
<textarea name="memo" id="memo" cols="60" rows="4"></textarea>
</div>
<div class="nextline"></div>
<br>
<div class="table-responsive">
<table id="tb1" class="table table-bordered">
<thead>
<tr>
<th colspan="5"><a href="javascript:void(0);" id="btnadd" class="btn btn-primary btn-sm">新增備品</a> <span class="star">*</span></th>
<!-- <th colspan="5"><a href="javascript:void(0);" id="btnadd-sc" class="btn btn-primary btn-sm">服務費</a></th> -->
</tr>
<tr>
<th nowrap>名稱</th>
<th>數量</th>
<th>單價</th>
<th>合計</th>
<th>備註</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr name="main_templ">
<td name="item_title" nowrap>
<a href="" name="item_href" data-toggle="modal">點選</a>
</td>
<td>
<input type="text" name="item_qty" class="form-control dollar-right" size="4">
</td>
<td>
<input type="text" name="item_unit_price" class="form-control dollar-right" size="8" readonly>
</td>
<td>
<input type="text" name="item_price_bp" class="form-control dollar-right" size="10" readonly>
</td>
<td>
<input type="text" name="item_memo" class="form-control">
</td>
<td>
<input type="hidden" name="supplies_id">
<input type="hidden" name="item_title_txt">
<a href="javascript:void(0);" name="btndel" class="btn btn-danger btn-sm">X</a>
</td>
</tr>
<tr id='service_charge_tr'>
<td colspan="3">
<h5>服務費</h5>
</td>
<td>
<input type="text" name="service_charge" id="service_charge" value="0" class="dollar-right" size="8" ">
</td>
<td colspan=" 2">
</td>
</tr>
<tr>
<td colspan="3">
<h5>營業稅</h5>
</td>
<td>
<input type="text" name="sales_tax" id="sales_tax" class="dollar-right" size="8" readonly>
</td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="3">
<h5>總價</h5>
</td>
<td>
<input type="text" name="total_price" id="total_price" class="dollar-right" size="8" readonly>
</td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
</div>
<div class="nextline"></div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="10">簽核操作<span class="star">*</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><b style='float:right'>簽核狀態</b></td>
<td>
<select name="assign_status" id="assign_status" required class="form-control form-control form-control-sm">
<?php echo $assign_status; ?>
</select>
</td>
<td><b>下位簽核者</b></td>
<td>
<select name="next_users" id="next_users" class="form-control form-control-sm" required></select>
</td>
<td>
<input type="submit" name="submit" id="submit" value="提交">
</td>
</tr>
</tbody>
</table>
</div>
<!--<div><input type="submit" name="submit" id="submit" value="提交"></div>-->
<input type="hidden" name="item_title_all" id="item_title_all">
<input type="hidden" name="item_qty_all" id="item_qty_all">
<input type="hidden" name="item_unit_price_all" id="item_unit_price_all">
<input type="hidden" name="item_price_bp_all" id="item_price_bp_all">
<input type="hidden" name="item_memo_all" id="item_memo_all">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
</div>
<?php
include "../footer.php";
?>