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.
 
 
 
 
 
 

597 lines
32 KiB

<?php
include_once "../header.php";
require_once "../mkt/conn.php";
if(!(isset($_GET['vol_no']) && $_GET['vol_no'] != "")){
echo "<script>alert('非法訪問!');window.history.go(-1);</script>";
}
$vol_no = $_GET['vol_no'];
$sql_str = "SELECT * FROM hope_contract_customer WHERE vol_no = :vol_no";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':vol_no', $vol_no);
$stmt->execute();
$hope_customer = $stmt->fetch(PDO::FETCH_ASSOC);
$sql_str = "SELECT * FROM con_maintance_examine_apply WHERE vol_no = :vol_no ORDER BY create_at DESC LIMIT 1";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':vol_no', $vol_no);
$stmt->execute();
$apply = $stmt->fetch(PDO::FETCH_ASSOC);
if($apply['status'] == 'D'){
echo "<script>alert('非法訪問');window.history.go(-1);</script>";
}
if($apply['status'] == 'YS'){
echo "<script>alert('此單正在審核中!');window.history.go(-1);</script>";
}
if($apply['status'] == 'YY'){
echo "<script>alert('此單已申請過!');window.history.go(-1);</script>";
}
$apply_key = $apply ? $apply['apply_key'] : getApplyKey(date('ym'), 'cmea_apply_key');
$sql_str = "SELECT * FROM con_maintance_examine_clear WHERE apply_key = :apply_key ORDER BY created_at ASC";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$elevators = $stmt->fetchAll(PDO::FETCH_ASSOC);
$hope_elevators = [];
$total_spec = 0;
foreach($elevators as $elevator){
if($elevator['item_no'] > $total_spec){
$total_spec = $elevator['item_no'];
}
if($elevator['cmstatus'] == 'D') continue;
$hope_elevators[] = [
'id'=> $elevator['item_no'],
'spec'=> $elevator['spec'],
'person'=> $elevator['persons'],
'weight'=> $elevator['weight'],
'stop'=> $elevator['stop'],
'speed'=> $elevator['speed'],
'permitNumber'=> $elevator['register_code'],
'brand'=> $elevator['elevator_brand'],
'm1'=> $elevator['is_m1_bundle'],
'months'=> $elevator['maintain_months'],
'cycle'=> $elevator['maintain_period'],
'method'=> $elevator['maintain_method'],
'checkYear'=> $elevator['useful_years'],
'lastDate'=> $elevator['last_check_date'],
'yearCheckFee'=> $elevator['annual_survey_expense'],
'price'=> $elevator['stand_price'],
'qty'=> $elevator['elevator_num'],
'sale_price'=> $elevator['contract_price'],
];
}
$sql_str = "SELECT * FROM pricereview_maintain_item WHERE (mid, item_group) = (:apply_key, 'E') ORDER BY id ASC";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
$otherOptions = [];
$otherOptionKey = 0;
foreach($items as $item){
if($item['item_no'] > $otherOptionKey){
$otherOptionKey = (int)$item['item_no'];
}
$toElevator = $item['option_relate_spec']==0 ? [] : [[
'id'=>$item['option_relate_spec'],
'model'=> array_values(array_filter($hope_elevators, fn($val)=> $val['id'] == $item['option_relate_spec']))[0]['spec'],
]];
$otherOptions[] = [
'id'=> $item['item_no'],
'pr_no'=> $item['price_id'],
'name'=> $item['item_spec'],
'price' => $item['item_unit_price'],
'num'=> $item['item_qty'],
'memo'=> $item['memo'],
'toElevator'=>$toElevator,
];
}
function getApplyKey($p_yyyymm, $seq_name){
if (empty($p_yyyymm) || empty($seq_name)) return null;
global $conn;
$sql_str = "SELECT yyyymm, prefix FROM sequence WHERE seq_name = :seq_name";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':seq_name', $seq_name);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$yyyymm = $result['yyyymm'];
$prefix = $result['prefix'];
if ($p_yyyymm != $yyyymm) {
$sql_str = "UPDATE sequence SET yyyymm = :p_yyyymm, current_val = '10000' WHERE seq_name = :seq_name";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':p_yyyymm', $p_yyyymm);
$stmt->bindParam(':seq_name', $seq_name);
$stmt->execute();
}
$sql_str = "SELECT CONCAT(:prefix, :p_yyyymm, SUBSTRING(appwms.nextval(:seq_name), 2)) AS seq_no";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':prefix', $prefix);
$stmt->bindParam(':p_yyyymm', $p_yyyymm);
$stmt->bindParam(':seq_name', $seq_name);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$seq_no = $result['seq_no'];
return $seq_no;
}
?>
<link rel="stylesheet" href="./css/pricereview.css">
<script src="./js/axios.min.js" integrity="sha512-aoTNnqZcT8B4AmeCFmiSnDlc4Nj/KPaZyB5G7JnOnUEkdNpCZs1LCankiYi01sLTyWy+m2P+W4XM+BuQ3Q4/Dg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer src="./js/alpinejs/cdn.min.js"></script>
<script src="./js/pricereviewAlpine.js"></script>
<div id="pricereviewCreate" x-data=pricereviewCreate()>
<?php
include_once "./window-modal/modalElevaotr.php";
include_once "./window-modal/otherOptionModal.php";
include_once "./window-modal/otherToElevatorModal.php";
?>
<div class="container">
<table class="table" border="1">
<thead >
<tr class="" >
<th scope="col" class="text-center " colspan="8">有望客戶(契約)基本資料</th>
</tr>
</thead>
<tbody>
<tr>
<th>價審單號</th>
<td><input class="form-control" type="text" disabled x-model="apply_key" /></td>
<th>卷號</th>
<td><input class="form-control" type="text" disabled value="<?php echo $hope_customer['vol_no']; ?>" /></td>
<th>現場名稱</th>
<td><input class="form-control" type="text" disabled value="<?php echo $hope_customer['customer']; ?>" /></td>
<th>現場地址</th>
<td><input class="form-control" type="text" disabled value="<?php echo $hope_customer['address']; ?>" /></td>
</tr>
<tr>
<th>電梯品牌</th>
<td><input class="form-control" type="text" disabled x-model="brand" /></td>
<th>電梯數量</th>
<td><input class="form-control" type="number" disabled value="<?php echo $hope_customer['num']; ?>" /></td>
<th>營業員</th>
<td><input class="form-control" type="text" disabled :value="getUsername('<?php echo $hope_customer['salesman']; ?>')" /></td>
<th>當前契約期限結束</th>
<td><input class="form-control" type="date" disabled value="" /></td>
</tr>
</tbody>
</table>
<table class="table" border="1">
<thead >
<tr class="" >
<th scope="col" class="text-center " colspan="10">價格審查(契約)基本資料</th>
</tr>
</thead>
<tbody>
<tr>
<th>契約性質</th>
<td>
<select class="form-control" x-model="contract_status">
<option value="">請選擇</option>
<option value="1">新簽約</option>
<option value="2">免保轉有費</option>
<option value="3">續約</option>
</select>
<span class="errortext" x-cloak data-type="errortext" x-show="contract_status == ''">請選擇契約性質</span>
</td>
<th>付款方式</th>
<td>
<select class="form-control" x-model="pay_method" >
<option value="">請選擇</option>
<option value="A40003">月繳</option>
<option value="A40004">雙月繳</option>
<option value="A40007">季繳</option>
<option value="A40005">半年繳</option>
<option value="A40006">年繳</option>
</select>
<span class="errortext" x-cloak data-type="errortext" x-show="pay_method == ''">請選擇付款方式</span>
</td>
<th>案件名稱</th>
<td>
<input class="form-control" type="text" x-model="case_name" />
<span class="errortext" x-cloak data-type="errortext" x-show="!case_name">請填寫案件名稱</span>
</td>
<th>合約開始日期</th>
<td>
<input type="date" class="form-control" x-model="startDate" />
<span class="errortext" x-cloak data-type="errortext" x-show="!startDate || startDate == '0000-00-00'">請填寫合約開始日期</span>
</td>
<th>合約結束日期</th>
<td>
<input type="date" class="form-control" x-model="endDate" />
<span class="errortext" x-cloak data-type="errortext" x-show="!endDate || endDate == '0000-00-00'">請填寫合約結束日期</span>
</td>
</tr>
</tbody>
</table>
<table class="table" border="1">
<thead >
<tr class="" >
<th scope="col" class="text-center " colspan="8">洽商進度</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=8>
<textarea class="form-control" name="progress" id="progress" cols="20" rows="5" disabled x-html="progress_status"></textarea>
</td>
</tr>
</tbody>
</table>
<table class="table" border="1">
<thead >
<tr class="" >
<th scope="col" class="text-center " colspan="8">電梯詳細資料</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=8>
<textarea class="form-control" name="progress" id="progress" cols="20" rows="6" disabled>注意事項:
1.速度單位是 米/分.
2.標準價格未帶出,請聯係業務部建立該規格報價.
3.無機房速度20~60米 以60米為標準.
</textarea>
</td>
</tr>
</tbody>
</table>
<div class="pricreviewmain container">
<div class="divitem">
<div class="title">
<h4>整機單價</h4>
<button class="addbtn btn" x-ref="addElevatorBtn" @click="openCreateElevatorModal()" >+</button>
</div>
<table class="table" border=1>
<template x-for="(elevator, idx) in elevators" :key="elevator.id">
<tbody>
<tr class="dark" >
<th colspan=1>項次</th>
<th colspan=7 style="text-align: left; padding-left: 15px;" x-text="elevator.id"></th>
<th colspan="2" >
<button class="copyBtn btn btn-secondary" @click="copyElevator(idx)">複製</button>
<button class="btn btn-danger" @click="removeElevator(elevator.id)">刪除</button>
</th>
</tr>
<tr>
<th >電梯</th>
<td>
<select class="form-control" x-model="elevator.spec" @change="getElevatorPrice(idx)">
<option value="">請選擇</option>
<option value="MAE100">MAE100有機房</option>
<option value="MAM200">MAM200無機房</option>
<option value="MAH100">MAH100小電梯</option>
<option value="MAF100">MAF100貨梯(有機房)</option>
</select>
</td>
<th>載重(KG)</th>
<td>
<input type="number" class="form-control" x-model="elevator.weight" @change="getElevatorPrice(idx)" @keyup="getElevatorPrice(idx)" />
</td>
<th>停數</th>
<td>
<input type="number" class="form-control" x-model="elevator.stop" @keyup="getElevatorPrice(idx)" />
</td>
<th>速度(m/min)</th>
<td>
<select name="" id="" class="form-control" style="width:93px" x-model="elevator.speed" @change="getElevatorPrice(idx)" >
<option value="">請選擇</option>
<option value="9">9</option>
<option value="24">24</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="60">60</option>
<option value="90">90</option>
<option value="105">105</option>
<option value="120">120</option>
<option value="150">150</option>
</select>
</td>
<th>人乘</th>
<td>
<select class="form-control" x-model="elevator.person" @change="getElevatorPrice(idx)">
<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>
</tr>
<tr>
<th>電梯許可證號碼</th>
<td colspan=3>
<input type="text" class="form-control" x-model="elevator.permitNumber" />
</td>
<th>品牌</th>
<td>
<select class="form-control" x-model="elevator.brand">
<option value="">請選擇</option>
<option value='永大'>永大</option>
<option value='三菱'>三菱</option>
<option value='崇友'>崇友</option>
<option value='Otis'>Otis</option>
<option value='櫻花'>櫻花</option>
<option value='立路'>立路</option>
<option value='富士達'>富士達</option>
<option value='富士'>富士</option>
<option value='測試品牌'>測試品牌</option>
<option value='sanyo'>sanyo</option>
<option value='測試品牌2'>測試品牌2</option>
<option value='測試品牌4'>測試品牌4</option>
<option value='中升'>中升</option>
<option value='長合'>長合</option>
<option value='宏偉電機工業股份有限公司'>宏偉電機工業股份有限公司</option>
<option value='保速達'>保速達</option>
<option value='東棋'>東棋</option>
<option value='安達'>安達</option>
<option value='百朝'>百朝</option>
<option value='太友'>太友</option>
<option value='永佳捷'>永佳捷</option>
<option value='永勝'>永勝</option>
<option value='其他'>其他</option>
</select>
</td>
<th>竣工檢查年度(民國)</th>
<td>
<input type="number" class="form-control" x-model="elevator.checkYear" />
</td>
<th>上次年檢日期</th>
<td>
<input type="date" class="form-control" x-model="elevator.lastDate" />
</td>
</tr>
<tr>
<th>年檢費用(元)</th>
<td>
<input type="number" class="form-control" x-model="elevator.yearCheckFee" />
</td>
<th>電梯數量</th>
<td>
<input type="number" class="form-control" x-model="elevator.qty" disabled />
</td>
<th>保養週期</th>
<td>
<select name="" id="" class="form-control" x-model="elevator.cycle">
<option value="">請選擇</option>
<option value="1">月保</option>
<option value="2">月保兩次</option>
<option value="3">雙月保</option>
<option value="4">季保</option>
</select>
</td>
<th>保養方式</th>
<td>
<select class="form-control" x-model="elevator.method" @change="getElevatorPrice(idx)">
<option value="">請選擇</option>
<option value="A">全包</option>
<option value="B">半包</option>
<option value="C">清包</option>
</select>
</td>
<th>贈送M1</th>
<td>
<select class="form-control" x-model="elevator.m1" @change="getElevatorPrice(idx)">
<option value="N">否</option>
<option value="Y">是</option>
</select>
</td>
</tr>
<tr>
<th>公司發布價(月)</th>
<td>
<input type="text" class="form-control" disabled x-model="elevator.price.toLocaleString()" />
<span class="errortext" x-show="elevator.price <= 0">公司無提供此規格牌價</span>
</td>
<th>保養月數</th>
<td>
<input type="number" class="form-control" x-model="elevator.months" />
</td>
<th>公司發布價(總價)</th>
<td>
<input type="text" class="form-control" disabled x-model="(elevator.price * elevator.months).toLocaleString()" />
</td>
<th>契約報價(月)</th>
<td>
<input type="number" class="form-control" x-model="elevator.sale_price" />
</td>
<th>契約報價(總價)</th>
<td>
<input type="text" class="form-control" disabled x-model="(elevator.sale_price * elevator.months).toLocaleString()" />
</td>
</tr>
</tbody>
</template>
</table>
</div>
<div class="divitem">
<div class="title">
<h4>除外項目</h4>
<button class="addbtn btn" @click="openCreateOtherOptionFn()" >+</button>
</div>
<table class="table" border=1>
<thead x-show="otherOptions.length > 0">
<tr>
<td>詢價單號</td>
<td>名稱</td>
<td>單價</td>
<td>數量</td>
<td>複價</td>
<td>備註</td>
<td style="width:160px">所屬電梯</td>
<td style="width:220px">功能</td>
</tr>
</thead>
<tbody>
<template x-for="option in otherOptions">
<tr>
<td><input type="text" class="form-control" x-model="option.pr_no"></td>
<td>
<input type="text" class="form-control" x-model="option.name">
<span x-show="option.name==''" class="errortext" x-cloak data-type="errortext">請輸入除外項目名稱</span>
</td>
<td><input type="text" class="form-control" x-model="option.price"></td>
<td>
<input type="number" class="form-control" x-model="option.num" style="width:100px">
<span x-show="!option.num || option.num <= 0 || !Number.isInteger(Number(option.num))" class="errortext" x-cloak data-type="errortext">請輸入正整數</span>
</td>
<td><input type="text" class="form-control" x-model="(option.price * option.num).toLocaleString()" disabled></td>
<td><input type="text" class="form-control" x-model="option.memo" style="min-width:220px" /></td>
<td>
<template x-for="el in option.toElevator">
<p x-html="'<b>' + el.id + '</b>、' + el.model"></p>
</template>
<span x-show="option.toElevator.length <=0" class="errortext" x-cloak data-type="errortext">尚未選擇電梯</span>
</td>
<td>
<div class="d-flex">
<button class="copyBtn btn btn-secondary" @click="copyOtherOption(option.id)">複製</button>
<button class="selectElevator btn btn-danger" @click="addOtherOptionToElevator(option.id)">電梯</button>
<button class="deleteBtn btn btn-danger" @click="removeOtherOption(option.id)">X</button>
</div>
</td>
</tr>
</template>
<tr x-show="otherOptions.length > 0">
<td colspan=3>小計</td>
<td colspan=1 ><input type="text" class="form-control" disabled :value="totalOtherOptionsNum.toLocaleString()" style="width:100px" /></td>
<td colspan=1 ><input type="text" class="form-control" disabled :value="totalOtherOptionsPrice.toLocaleString()" ></td>
<td colspan=3 ></td>
</tr>
</tbody>
</table>
</div>
<div class="divitem" style="margin-top:20px">
<table style="width:800px" class="table noborder" >
<tbody>
<tr>
<th>標準價總額(A)</th>
<th>報價總額(B)</th>
<th>破價總額(B-A)</th>
<th>價率%(B/A)</th>
<th>總台數</th>
<th>服務費(介紹費)</th>
</tr>
<tr>
<td><input type="text" class="form-control" x-model="totalPrice.toLocaleString()" disabled style="width:180px" /></td>
<td><input type="text" class="form-control" x-model="totalSalePrice.toLocaleString()" disabled style="width:180px" /></td>
<td><input type="text" class="form-control" x-model="(totalSalePrice - totalPrice).toLocaleString()" disabled style="width:180px" /></td>
<td>
<input type="text" class="form-control" x-show="totalPrice!=0" x-model="Math.round(totalSalePrice / totalPrice * 100* 10) /10 + '%'" disabled />
<input type="text" class="form-control" x-show="totalPrice==0" value="0" disabled />
</td>
<td><input type="text" class="form-control" x-model="totalElevatorsNum" disabled /></td>
<td><input type="text" class="form-control" x-model="serviceFee" style="width:150px" /></td>
</tr>
<tr>
<th>罰則</th>
<th>訂金保證金(函)%</th>
<th>履約保證金(函)%</th>
<th>保固保證金(函)%</th>
<th></th>
<th></th>
</tr>
<tr>
<td><input type="text" class="form-control" x-model="penalty" /></td>
<td><input type="text" class="form-control" x-model="deposit_rate" /></td>
<td><input type="text" class="form-control" x-model="keep_rate" /></td>
<td><input type="text" class="form-control" x-model="warranty_rate" /></td>
<td></td>
<td></td>
</tr>
<tr>
<th colspan="6">特記事項</th>
</tr>
<tr>
<td colspan="6">
<textarea class="form-control" id="" cols="30" rows="5" x-model="remark"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="filediv">
<label style="font-size:13px">▪️ 營業權限85%以上;85-80%呈至區處長審核;80%以下呈至總經理審核。</label>
<label for="">
<p style="width:120px">報價單</p>
<input type="file" class="form-control" multiple draggable="true" @change="uploadFiles($event, 1)" />
</label>
<label for="">
<p style="width:120px">合約用印申請表</p>
<input type="file" class="form-control" multiple draggable="true" @change="uploadFiles($event, 2)" />
</label>
<label for="">
<?php if(!empty($apply) && $apply['attatch1'] != null): ?>
<a class="btn btn-primary" href="<?php echo $apply['attatch1']; ?>" download="<?php echo $apply['vol_no']; ?>報價單">下載報價單</a>
<?php endif; ?>
<?php if(!empty($apply) && $apply['attatch2'] != null): ?>
<a class="btn btn-primary" style="width:180px" href="<?php echo $apply['attatch2']; ?>" download="<?php echo $apply['vol_no']; ?>合約用印申請表">下載合約用印申請表</a>
<?php endif; ?>
<button class="btn btn-primary" @click="save()">保存</button>
<button class="btn btn-primary" @click="submit()">送審</button>
</label>
</div>
</div>
</div>
</div>
<script>
const body = document.querySelector('body');
const vol_no = '<?php echo $hope_customer['vol_no']; ?>';
const apply_key = '<?php echo $apply_key; ?>';
const customer = '<?php echo $hope_customer['customer']; ?>';
const manager = '<?php echo $hope_customer['manager']; ?>';
const salesman = '<?php echo $hope_customer['salesman'] ?>';
const salesman_name = '<?php echo $hope_customer['salesman_name'] ?>';
const pre_order_date = '<?php echo $hope_customer['pre_order_date']; ?>';
const address = '<?php echo $hope_customer['address']; ?>';
const brand = '<?php echo $hope_customer['brand']; ?>';
const progress_status = '<?php echo $hope_customer['progress_status']; ?>';
const user_id = '<?php echo $user_id ?>';
const user_name = '<?php echo $user_name ?>';
const progress_remark = `<?php echo nl2br($hope_customer['progress_status']); ?>`;
const memo = `<?php echo nl2br($apply['memo']); ?>`;
const contract_kind = '<?php echo $apply ? $apply['contract_kind'] : '' ?>';
const payment_kind = '<?php echo $apply ? $apply['payment_kind'] : '' ?>';
const case_name = '<?php echo $apply ? $apply['case_name'] : '' ?>';
const contract_begin_date = '<?php echo $apply ? $apply['contract_begin_date'] : '' ?>';
const contract_end_date = '<?php echo $apply ? $apply['contract_end_date'] : '' ?>';
const total_spec = '<?php echo $total_spec; ?>';
const hope_elevators = [...<?php echo json_encode($hope_elevators); ?>];
const otherOptionKey = '<?php echo $otherOptionKey; ?>';
const otherOptions = [...<?php echo json_encode($otherOptions); ?>];
const token = '<?php echo $para = "function_name=pricereview&" . $token_link;; ?>';
const penalty = '<?php echo $apply['penalty']; ?>';
const deposit_rate = '<?php echo $apply['deposit_rate']; ?>';
const keep_rate = '<?php echo $apply['keep_rate']; ?>';
const warranty_rate = '<?php echo $apply['warranty_rate']; ?>';
const service_fee = '<?php echo $apply['service_fee']; ?>';
</script>