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.
 
 
 
 
 
 

549 lines
25 KiB

<?php
require_once "database.php";
include "header.php";
$data = array();
?>
<script>
function commafy(num) {
num = num + "";
var re = /(-?\d+)(\d{3})/
while (re.test(num)) {
num = num.replace(re, "$1,$2")
}
return num;
}
function dataFormat() {
var amtAll = 0;
$("input[name='item_price_bp']").each(function(){
amtAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#amt').val(commafy(amtAll));
$('#price_lowest').val(commafy(amtAll));
$('#price_total_broken').val(commafy($('#price_total').val().replace(/[,]+/g,"")-$('#price_lowest').val().replace(/[,]+/g,"")));
var qt = parseInt($('#qty_total').val().replace(/[,]+/g,"")) || 0;
if (qt) {
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/qt).toFixed(2)));
}
$('#price_rate').val((($('#price_total').val().replace(/[,]+/g,"")/$('#price_lowest').val().replace(/[,]+/g,""))*100).toFixed(2));
}
function selFacil(o) {
var fp = o.parent().parent();
var f1 = fp.find('select[name=fp_kind]').val();
var f2 = fp.find('select[name=fp_seat]').val();
var f3 = fp.find('input[name=fp_numberofstop]').val();
var f4 = fp.find('select[name=fp_speed]').val();
var f5 = fp.find('input[name=item_qty]').val();
if (f1 !== '' && f2 !== '' && f3 !== '' && f4 !== '' && f5 !== '') {
let fAry = [f1, f2, f3, f4, f5];
//console.log(fAry);
var formdata = new FormData();
formdata.append('fval', fAry);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
data = JSON.parse(this.responseText);
if (data.st == 'err') {
alert(data.err);
fp.find('input[name=item_price_bp]').val(0);
dataFormat();
return false;
}
fp.find('input[name=item_price_bp]').val(commafy(data.amt));
fp.find('input[name=fp_id]').val(data.id);
fp.find('input[name=item_spec]').val(data.model);
fp.find('input[name=item_group]').val(data.group);
var cntAll = 0;
$("input[name='item_qty']").each(function(){
cntAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#cnt').val(commafy(cntAll));
$('#qty_total').val(commafy(cntAll));
var pl = parseInt($('#price_lowest').val().replace(/[,]+/g,"")) || 0;
if (pl) {
$('#price_rate').val(commafy((($('#price_total').val().replace(/[,]+/g,"")/pl)*100).toFixed(2)));
}
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/$('#qty_total').val()).toFixed(2)));
dataFormat();
/*
var amtAll = 0;
$("input[name='item_price_bp']").each(function(){
amtAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#amt').val(commafy(amtAll));
$('#price_lowest').val(commafy(amtAll));
$('#price_total_broken').val(commafy($('#price_total').val().replace(/[,]+/g,"")-$('#price_lowest').val().replace(/[,]+/g,"")));
var qt = parseInt($('#qty_total').val().replace(/[,]+/g,"")) || 0;
if (qt) {
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/qt).toFixed(2)));
}
$('#price_rate').val((($('#price_total').val().replace(/[,]+/g,"")/$('#price_lowest').val().replace(/[,]+/g,""))*100).toFixed(2));
*/
}
}
xhr.open('POST','/mkt/pricereview-facility.php',true);
xhr.send(formdata);
}
}
function tt(){
$("input[name='item_price_bp']").keyup(function(){
dataFormat();
/*
var amtAll = 0;
$("input[name='item_price_bp']").each(function(){
amtAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#amt').val(commafy(amtAll));
$('#price_lowest').val(commafy(amtAll));
$('#price_total_broken').val(commafy($('#price_total').val().replace(/[,]+/g,"")-$('#price_lowest').val().replace(/[,]+/g,"")));
var qt = parseInt($('#qty_total').val().replace(/[,]+/g,"")) || 0;
if (qt) {
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/qt).toFixed(2)));
}
$('#price_rate').val((($('#price_total').val().replace(/[,]+/g,"")/$('#price_lowest').val().replace(/[,]+/g,""))*100).toFixed(2));
*/
});
}
$(function(){
$('#tb1').on('click', 'input[name=fp_numberofstop], input[name=item_qty]', function(){
//$("input[name=item_qty]").unbind().keyup(function(){
$(this).unbind().keyup(function(){
selFacil($(this));
/*
var fp = $(this).parent().parent();
var f1 = fp.find('select[name=fp_kind]').val();
var f2 = fp.find('select[name=fp_seat]').val();
var f3 = fp.find('input[name=fp_numberofstop]').val();
var f4 = fp.find('select[name=fp_speed]').val();
var f5 = fp.find('input[name=item_qty]').val();
if (f1 !== '' && f2 !== '' && f3 !== '' && f4 !== '' && f5 !== '') {
let fAry = [f1, f2, f3, f4, f5];
var formdata = new FormData();
formdata.append('fval', fAry);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
data = JSON.parse(this.responseText);
if (data.st == 'err') {
alert(data.err);
return false;
}
fp.find('input[name=item_price_bp]').val(commafy(data.amt));
fp.find('input[name=fp_id]').val(data.id);
fp.find('input[name=item_spec]').val(data.model);
fp.find('input[name=item_group]').val(data.group);
var cntAll = 0;
$("input[name='item_qty']").each(function(){
cntAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#cnt').val(commafy(cntAll));
$('#qty_total').val(commafy(cntAll));
var pl = parseInt($('#price_lowest').val().replace(/[,]+/g,"")) || 0;
if (pl) {
$('#price_rate').val(commafy((($('#price_total').val().replace(/[,]+/g,"")/pl)*100).toFixed(2)));
}
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/$('#qty_total').val()).toFixed(2)));
dataFormat();
}
}
xhr.open('POST','/mkt/pricereview-facility.php',true);
xhr.send(formdata);
}
*/
});
});
$('#tb1').on('click', 'select[name=fp_kind], select[name=fp_seat], select[name=fp_speed]', function(){
$(this).unbind().change(function(){
selFacil($(this));
});
});
$('#deposit_rate').keyup(function(){ $(this).val($(this).val().replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')); });
$('#keep_rate').keyup(function(){ $(this).val($(this).val().replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')); });
$('#warranty_rate').keyup(function(){ $(this).val($(this).val().replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')); });
/*
// for 動態表格的作法:event delegation
$('#tb1').on('click', $("input[name='item_qty']"), function(){
$("input[name='item_qty']").keyup(function(){
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
var cntAll = 0;
//$(this).parent().next().find('input').val(commafy($(this).val()*Number($(this).parent().next().find('input').val().replace(/[,]+/g,""))));
$("input[name='item_qty']").each(function(){
cntAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#cnt').val(commafy(cntAll));
$('#qty_total').val(commafy(cntAll));
// $(this).parent().next().find('input[name=item_price_bp]').val($(this).parent().parent().find('input[name=item_price_bp_base').val()*$(this).val());
var amtAll = 0;
$("input[name='item_price_bp']").each(function(){
amtAll += Number($(this).val().replace(/[,]+/g,""));
});
$('#amt').val(commafy(amtAll));
$('#price_lowest').val(commafy(amtAll));
var pl = parseInt($('#price_lowest').val().replace(/[,]+/g,"")) || 0;
if (pl) {
$('#price_rate').val(commafy((($('#price_total').val().replace(/[,]+/g,"")/pl)*100).toFixed(2)));
}
$('#price_broken').val(commafy(($('#price_total_broken').val().replace(/[,]+/g,"")/$('#qty_total').val()).toFixed(2)));
});
});
*/
// $('#tb1').on('click', tt);
$('#tb1').on('keyup', 'input[name=item_price_bp]', function(){
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
dataFormat();
});
$('#tb1').on('keyup', 'input[name=fp_numberofstop], input[name=item_qty], input[name=item_price]', function(){
//$("input[name='item_price']").keyup(function(){
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
//});
});
$('#tb1').on('keyup', 'input[name=pv_rate]', function(){
$(this).val($(this).val().replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1'));
});
$("#price_total").on("input", function(){
var pt = parseInt($(this).val().replace(/[,]+/g,"")) || 0;
$(this).val($(this).val().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
//var pl = ('NaN'==$('#price_lowest').val() || ''==$('#price_lowest').val().trim())?0:parseInt($('#price_lowest').val());
var pl = parseInt($('#price_lowest').val().replace(/[,]+/g,"")) || 0;
$('#price_total_broken').val(commafy(pt-pl));
if (pl) {
$('#price_rate').val(((pt/pl)*100).toFixed(2));
}
var qt = parseInt($('#qty_total').val().replace(/[,]+/g,"")) || 0;
if (qt) {
$('#price_broken').val(commafy((parseInt($('#price_total_broken').val().replace(/[,]+/g,""))/qt).toFixed(0)));
}
$('#pay1').html(commafy((pt*0.2).toFixed(0)));
$('#pay2').html(commafy((pt*0.4).toFixed(0)));
$('#pay3').html(commafy((pt*0.2).toFixed(0)));
$('#pay4').html(commafy((pt*0.1).toFixed(0)));
$('#pay5').html(commafy((pt*0.1).toFixed(0)));
});
$('#btnadd').click(function(){
/*
var facilTemp = '';
facilTemp+= '<tr name="facil_templ">';
facilTemp+= '<td>'+($('tr[name=facil_templ]').length+1)+'</td>';
facilTemp+= '<td>';
facilTemp+= '<?php include_once "facility_price.php"; ?>';
facilTemp+= '</td>';
facilTemp+= '<td><input type="text" name="item_spec"></td>';
facilTemp+= '<td><input type="text" name="item_qty"></td>';
facilTemp+= '<td><input type="text" name="item_price_bp"></td>';
facilTemp+= '<td><input type="text" name="item_price"></td>';
facilTemp+= '<td><input type="text" name="pv_rate"></td>';
facilTemp+= '<td colspan="2"><input type="text" name="note"><input type="hidden" name="item_group" value="A"><input type="hidden" name="item_price_bp_base"></td>';
facilTemp+= '</tr>';
$('#tb1 tr:last').prev().after(facilTemp);
*/
$('#tb1 tr:last').prev().after($("tr[name='facil_templ']").eq(0).clone().find('input').val('').end());
$('#tb1 tr:last').prev().find('td').first().html($("tr[name='facil_templ']").length);
//$("tr[name=facil_templ]").eq($("tr[name=facil_templ]").length-1).find('td').eq(0).html($("tr[name=facil_templ]").length);
//$('#facil_templ').clone(true).insertAfter($('#tb1 tr:last').prev());
});
$('#submit').click(function(){
var itemFpidArr = [];
$("input[name='fp_id']").each(function(){ itemFpidArr.push($(this).val()); })
$('#fp_id_all').val(itemFpidArr);
var itemSpecArr = [];
$("input[name='item_spec']").each(function(){ itemSpecArr.push($(this).val()); })
$('#item_spec_all').val(itemSpecArr);
var itemGroupArr = [];
$("input[name='item_group']").each(function(){ itemGroupArr.push($(this).val()); })
$('#item_group_all').val(itemGroupArr);
var itemQtyArr = [];
$("input[name='item_qty']").each(function(){ itemQtyArr.push($(this).val().replace(/[,]+/g,"")); })
$('#item_qty_all').val(itemQtyArr);
var itemPriceBpArr = [];
$("input[name='item_price_bp']").each(function(){ itemPriceBpArr.push($(this).val().replace(/[,]+/g,"")); })
$('#item_price_bp_all').val(itemPriceBpArr);
var itemPriceArr = [];
$("input[name='item_price']").each(function(){ itemPriceArr.push($(this).val().replace(/[,]+/g,"")); })
$('#item_price_all').val(itemPriceArr);
var pvRateArr = [];
$("input[name='pv_rate']").each(function(){ pvRateArr.push($(this).val()); })
$('#pv_rate_all').val(pvRateArr);
var noteArr = [];
$("input[name='note']").each(function(){ noteArr.push($(this).val()); })
$('#note_all').val(noteArr);
//console.log(itemNameArr);
//return false;
});
});
</script>
<div class="container">
<?php
include "pricereview-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">卷號</label>
<input type="text" name="contractno" id="contractno" maxlength="7" required>
</div>
<div>
<label for="person">營業員</label>
<input type="text" name="person" id="person">
</div>
<div>
<label for="company">客戶名稱</label>
<input type="text" name="company" id="company" required>
</div>
<div>
<label for="case_name">案件名稱</label>
<input type="text" name="case_name" id="case_name" required>
</div>
<div>
<label for="address">工地地址</label>
<input type="text" name="address" id="address" required>
</div>
<div>
<label for="compete">競爭對手</label>
<input type="text" name="compete" id="compete">
</div>
<div>
<label for="price_lowest">底價總額</label>
<input type="text" name="price_lowest" id="price_lowest" style="background-color:#eee5e5" readonly>
</div>
<div>
<label for="price_total">售價總額</label>
<input type="text" name="price_total" id="price_total" required>
</div>
<div>
<label for="price_total_broken">破價總額</label>
<input type="text" name="price_total_broken" id="price_total_broken" style="background-color:#eee5e5" readonly>
</div>
<div>
<label for="price_rate">價率%</label>
<input type="text" name="price_rate" id="price_rate" style="background-color:#eee5e5" readonly>
</div>
<div>
<label for="qty_total">總台數</label>
<input type="text" name="qty_total" id="qty_total" style="background-color:#eee5e5" readonly>
</div>
<div>
<label for="inquire_no">詢價單號</label>
<input type="text" name="inquire_no" id="inquire_no">
</div>
<div>
<label for="price_broken">破價(台)</label>
<input type="text" name="price_broken" id="price_broken" style="background-color:#eee5e5" readonly>
</div>
<div>
<label for="predeal_date">預定成交日</label><br>
<input type="date" name="predeal_date" id="predeal_date" required>
</div>
<div>
<label for="facilitok_date">預定交期</label><br>
<input type="date" name="facilitok_date" id="facilitok_date" required>
</div>
<div>
<label for="penalty">罰則</label>
<input type="text" name="penalty" id="penalty">
</div>
<div>
<label for="deposit_rate">訂金保證金(函)%</label>
<input type="text" name="deposit_rate" id="deposit_rate">
</div>
<div>
<label for="keep_rate">履約保證金(函)%</label>
<input type="text" name="keep_rate" id="keep_rate">
</div>
<div>
<label for="warranty_rate">保固保證金(函)%</label>
<input type="text" name="warranty_rate" id="warranty_rate">
</div>
<div class="table-responsive" style="width:100%;margin-top:10px;">
<table class="table">
<thead>
<tr>
<th><label for="memo">說明</label></th>
</tr>
</thead>
<tbody>
<tr>
<td><textarea name="memo" id="memo" rows="10"></textarea></td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive">
<table id="tb1" class="table table-bordered">
<thead>
<tr>
<th nowrap>項次</th>
<th style="width:13%">電梯</th>
<th style="width:11%">人乘</th>
<th>停數</th>
<th style="width:11%">速度</th>
<th>數量</th>
<th style="width:11%">B/P(含稅)</th>
<th style="width:11%">金額(含稅)</th>
<th>價審%</th>
<th nowrap>備註</th>
<th><button type="button" id="btnadd" class="btn btn-primary btn-sm">新增</button></th>
</tr>
</thead>
<tbody>
<tr name="facil_templ">
<td>1</td>
<td>
<select name="fp_kind">
<option value="">請選擇</option>
<option value="MAE100">MAE100</option>
<option value="MAM200">MAM200</option>
<option value="MAH100">MAH100</option>
<option value="MAQ100">MAQ100</option>
<!--<option value="MAF100">MAF100</option>
<option value="MAZ100">MAZ100</option>-->
</select>
</td>
<td>
<select name="fp_seat">
<option value="">請選擇</option>
<option value="6">6</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="15">15</option>
<option value="17">17</option>
<option value="20">20</option>
<option value="24">24</option>
</select>
</td>
<td style="padding-top:0px;">
<input type="text" name="fp_numberofstop">
</td>
<td>
<select name="fp_speed">
<option value="">請選擇</option>
<option value="30">30m/min</option>
<option value="45">45m/min</option>
<option value="60">60m/min</option>
<option value="90">90m/min</option>
<option value="105">105m/min</option>
<option value="120">120m/min</option>
<option value="150">150m/min</option>
</select>
</td>
<td style="padding-top:0px;"><input type="text" name="item_qty" maxlength="2"></td>
<td style="padding-top:0px;"><input type="text" name="item_price_bp"></td>
<td style="padding-top:0px;"><input type="text" name="item_price"></td>
<td style="padding-top:0px;"><input type="text" name="pv_rate"></td>
<td style="padding-top:0px;" colspan="2"><input type="text" name="note"><input type="hidden" name="item_group" value="A"><input type="hidden" name="fp_id"><input type="hidden" name="item_spec"></td>
</tr>
<tr>
<td></td>
<td colspan="5"><input type="text" name="item_spec" placeholder="OPTION合計"></td>
<td><input type="text" name="item_price_bp"></td>
<td><input type="text" name="item_price"></td>
<td><input type="text" name="pv_rate"></td>
<td colspan="2"><input type="text" name="note"><input type="hidden" name="item_group" value="B"></td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="4">合計</th>
</tr>
</thead>
<tbody>
<tr>
<td><label>數量</label></td>
<td><input type="text" id="cnt" style="background-color:#eee5e5" readonly></td>
<td><label>B/P(含稅)</label></td>
<td><input type="text" id="amt" style="background-color:#eee5e5" readonly></td>
</tr>
</tbody>
</table>
<table class="table table-bordered">
<thead>
<tr>
<th colspan="4">付款辦法</th>
</tr>
</thead>
<tbody>
<tr>
<td>1、訂金</td>
<td>20%</td>
<td id="pay1"></td>
<td>30天期票,簽約後30日內兌現</td>
</tr>
<tr>
<td>2、二次款</td>
<td>40%</td>
<td id="pay2"></td>
<td>30天期票,電梯出貨前兌現</td>
</tr>
<tr>
<td>3、貨到付款</td>
<td>20%</td>
<td id="pay3"></td>
<td>30天期票,電梯使用前兌現</td>
</tr>
<tr>
<td>4、安裝完畢款</td>
<td>10%</td>
<td id="pay4"></td>
<td>30天期票,電梯交車前兌現</td>
</tr>
<tr>
<td>5、尾款</td>
<td>10%</td>
<td id="pay5"></td>
<td>30天期票,取得許可函後30日內兌現</td>
</tr>
</tbody>
</table>
<button type="submit" name="submit" id="submit">儲存</button>
</div>
<input type="hidden" name="fp_id_all" id="fp_id_all">
<input type="hidden" name="item_spec_all" id="item_spec_all">
<input type="hidden" name="item_group_all" id="item_group_all">
<input type="hidden" name="item_qty_all" id="item_qty_all">
<input type="hidden" name="item_price_bp_all" id="item_price_bp_all">
<input type="hidden" name="item_price_all" id="item_price_all">
<input type="hidden" name="pv_rate_all" id="pv_rate_all">
<input type="hidden" name="note_all" id="note_all">
</form>
</div>
<?php
//mysqli_free_result($res);
mysqli_close($link);
include "footer.php";
?>