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.
 
 
 
 
 
 

662 lines
29 KiB

<?php
require_once('./conn.php');
include "../header.php";
if(isset($_POST['list'])){
if($_POST['prviewType'] == 1){
$isStand = ($_POST['buystandard']=="true") ? 1 : 0;
}else{
$isStand = $_POST['installstandard']=="true" ? 1 : 0;
}
$type = $_POST['prviewType']=='1' ? "電梯買賣合約書" : "電梯安裝合約書";
$list = json_decode($_POST['list']);
$standardList = json_decode($_POST['standardList']);
$illustrate = $_POST['illustrate'];
$updatedIllustrate = false;
$standardIllustrate = $_POST['standardIllustrate'];
$partyA = $_POST['partyA'];
$partyAcontractno = $_POST['partyAcontractno'];
$total_price = $_POST['total_price'];
$person = $_POST['person'];
$personid = $_POST['personid'];
$delivery_term = $_POST['delivery_term'];
$install_period = $_POST['install_period'];
$free_maintainance = $_POST['free_maintainance'];
// $originArr = array_filter(json_decode(json_encode($list), true), fn($item)=> $item['origin'] == 1);
$standardArr = json_decode(json_encode($standardList), true);
$nostandardArr = json_decode(json_encode($list), true);
$newlist = array_values(array_filter($list, fn($item)=> $item->deleted == 0));
foreach($nostandardArr as $idx=>&$item){
if($item['origin'] === 1){
if(strip_tags($item['text']) != strip_tags($standardArr[$item['id']]['text'])){
$item['updated'] = 1;
}else{
$item['updated'] = 0;
}
}
}
unset($item);
if(strip_tags($illustrate) != strip_tags($standardIllustrate)){
$updatedIllustrate = true;
}
$sql_str = "SELECT * FROM hope_elevator_customer WHERE vol_no = :vol_no";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':vol_no', $partyAcontractno);
$stmt->execute();
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
if(count($customer) <= 0 ){
echo "<script>
alert('資料不齊或合約書已生成過。');
window.history.back();
</script>";
}
function numberToChinese($num) {
$chineseNumbers = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九','十'];
$units = ['', '十', '百', '千', '万'];
if ($num <= 10) {
return $chineseNumbers[$num];
} elseif ($num < 20) {
return $units[1] . $chineseNumbers[$num % 10];
} elseif ($num < 100) {
return $chineseNumbers[intval($num / 10)] . $units[1] . ($num % 10 > 0 ? $chineseNumbers[$num % 10] : '');
} else {
// 处理大于 99 的数字
$result = '';
$strNum = strval($num);
$length = strlen($strNum);
for ($i = 0; $i < $length; $i++) {
$currentDigit = intval($strNum[$i]);
if ($currentDigit > 0) {
$result .= $chineseNumbers[$currentDigit] . $units[$length - $i - 1];
} else {
$result .= $chineseNumbers[$currentDigit];
}
}
return $result;
}
}
function removeTrailingBr($string) {
//使用正則表達式刪除字串尾巴的<br>或<br />
return preg_replace('/(<br\s*\/?>)+$/', '', $string);
}
?>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.5.0/axios.min.js" integrity="sha512-aoTNnqZcT8B4AmeCFmiSnDlc4Nj/KPaZyB5G7JnOnUEkdNpCZs1LCankiYi01sLTyWy+m2P+W4XM+BuQ3Q4/Dg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.3/purify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.3/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js" integrity="sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
.container{
background-color: transparent !important;
width: 100% !important;
}
.prview, .footer{
width: 800px;
border:1px #ccc solid;
padding: 20px;
font-family:'標楷體';
}
.prview.none{
display: none;
}
.prview h2{
font-size: 18pt;
text-align: center;
}
.prview p{
font-size: 12pt;
margin:0;
padding: 0;
}
td tr table th{
border:none !important;
background-color: #fff !important;
}
tr:nth-child(even){
background-color: #fff !important;
}
.colorDiv{
display: flex;
margin: 10px 0;
}
.colorDiv .block{
width: 18px;
height: 18px;
}
.colorDiv span{
font-size: 15px;
margin:0 5px 0 2px;
font-weight: 600;
}
.colorDiv .block.gray{
background-color: #DDDDDD;
}
.colorDiv .block.green{
background-color: #00B900;
}
.colorDiv .block.red{
background-color: #D11919;
}
#btn, .pre{
background-color : #0D559D ;
color:#fff;
outline: none;
border:none;
border:1px #ccc solid;
width: 100px;
height: 32px;
font-weight: 600;
border-radius: 6px;
margin-right: 5px;
}
.pre{
background-color: #40C474;
}
</style>
<div class="container" x-data="{
css:'',
random:'',
init(){
const characters = '012345678901234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const charactersLength = characters.length;
let randomString = '';
const length = 15;
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charactersLength);
randomString += characters.charAt(randomIndex);
}
this.random = randomString
},
exportFn(){
const now = new Date();
// 獲取年、月、日、小時、分鐘、秒
const year = now.getFullYear();
const month = now.getMonth() + 1; // 月份是從0開始的,所以要加1
const day = now.getDate();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
// 格式化日期和時間
const formattedDate = `${year}${month}${day}${hours}${minutes}${seconds}`;
let token = formattedDate + '<?php echo $partyAcontractno; ?><?php echo $partyA; ?>永佳捷<?php echo $total_price; ?>'
let newtoken = formattedDate + '-' + CryptoJS.MD5(CryptoJS.SHA256(CryptoJS.SHA256(CryptoJS.MD5(token).toString()).toString() + this.random).toString()).toString()
console.log(newtoken);
let html = this.$refs.prview.innerHTML
let footer = this.$refs.footer.innerHTML
let affix1 = this.$refs.affix1.innerHTML
// html = this.$refs.footer.innerHTML
// axios.post('./export-pdf.php', {'html':html}).then(res=>{
// console.log(res);
// })
const form = new FormData();
form.append('html', html);
form.append('footer', footer);
form.append('affix1', affix1);
form.append('css',this.css);
form.append('user_name', '<?php echo $user_name; ?>');
form.append('contract_no', '<?php echo $partyAcontractno; ?>');
form.append('party_a', '<?php echo $partyA; ?>');
form.append('total_price', '<?php echo $total_price; ?>');
form.append('person', '<?php echo $person; ?>');
form.append('token', newtoken);
form.append('formattedDate', formattedDate);
axiosClient({
method:'post',
responseType:'blob',
url:'./export-pdf.php',
data:form
}).then(response=>{
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', formattedDate + '.pdf'); // 指定下载的文件名
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.store(newtoken, formattedDate)
})
},
store(newtoken, formattedDate){
const form = new FormData();
form.append('contract_id', '<?php echo $partyAcontractno; ?>')
form.append('uscc', '<?php echo $customer['uscc']; ?>')
form.append('ekind', '新梯')
form.append('new_elevator', '<?php $_POST['prviewType']=='1' ? "買賣" : "安裝"; ?>')
form.append('party_a', '<?php echo $partyA; ?>')
form.append('total_price', <?php echo (int)$total_price; ?>)
form.append('accound_id', '<?php echo $personid; ?>')
form.append('times', 1)
form.append('random', this.random)
form.append('hash', newtoken)
form.append('url', formattedDate+'.pdf' );
form.append('created_by', '<?php echo $user_id; ?>')
form.append('delivery_term', '<?php echo $delivery_term; ?>')
form.append('install_period', '<?php echo $install_period; ?>')
form.append('free_maintainance', '<?php echo $free_maintainance; ?>')
axiosClient({
method:'post',
url:'./store-contract.php',
data:form
}).then(res=>{
console.log(res);
})
},
}">
<button @click="history.go(-1)" class="pre">回前頁</button>
<button id="btn" @click="exportFn()">點我下載</button>
<?php if($isStand == 0){ ?>
<div class="colorDiv">
<div class="block gray"></div>
<span>修改的條列</span>
<div class="block green"></div>
<span>新增的條列</span>
<div class="block red"></div>
<span>刪除的條列</span>
</div>
<?php } ?>
<div class="prview" id="prview" x-ref="prview" style="font-family:'標楷體'" x-show="false" >
<h2 style="text-align:center;font-size:18pt;"><?php echo $type; ?></h2>
<p style="font-size: 12pt;">合約書編號:<?php echo $_POST['partyAcontractno'] ?></p>
<table>
<tr>
<td style="width:100px"></td>
<td style="width:200px"><?php echo $_POST['partyA'] ?></td>
<td>(即買方,以下簡稱為甲方)</td>
</tr>
</table>
<p style="font-size: 12pt;">立合約書人</p>
<table>
<tr>
<td style="width:100px"></td>
<td style="width:200px">永佳捷科技股份有限公司</td>
<td>(即賣方,以下簡稱為乙方)</td>
</tr>
</table>
<p style="font-size: 12pt;width:440px"><?php echo $illustrate; ?></p>
<table style="width:100%">
<?php foreach($newlist as $idx=>$item){
?>
<tr style="display:block;">
<td style="width:60px;">第<?php echo numberToChinese($idx+1);?>條</td>
<td style="width:445px;"><?php echo nl2br(removeTrailingBr(json_decode(json_encode($item), true)['text'])); ?></td>
</tr>
<?php } ?>
</table>
</div>
<section style="display:flex;justify-content:center;">
<div class="prview" style="font-family:'標楷體';background-color:#fff;" >
<h2 style="text-align:center;font-size:18pt;"><?php echo $type; ?></h2>
<p style="font-size: 12pt;">合約書編號:<?php echo $_POST['partyAcontractno'] ?></p>
<table style="border:none">
<tr style="border:none;">
<td style="border:none;width:100px;"></td>
<td style="border:none;width:200px"><?php echo $_POST['partyA'] ?></td>
<td style="border:none">(即買方,以下簡稱為甲方)</td>
</tr>
</table>
<p style="font-size: 12pt;">立合約書人</p>
<table style="border:none">
<tr style="border:none;">
<td style="border:none;width:100px"></td>
<td style="border:none;width:200px">永佳捷科技股份有限公司</td>
<td style="border:none">(即賣方,以下簡稱為乙方)</td>
</tr>
</table>
<p style="font-size: 12pt;width:800px"><?php echo $standardIllustrate; ?></p>
<table style="width:100%;border:none">
<?php foreach($standardList as $idx=>$item){
?>
<tr style="margin-bottom:10px;display:block;border:none">
<td style="width:100px;border:none">第<?php echo numberToChinese($idx+1);?>條</td>
<td style="border:none"><?php echo nl2br(json_decode(json_encode($item), true)['text']); ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php if($isStand == 0){ ?>
<div class="prview nostandard" style="font-family:'標楷體'" x-ref="nostandard">
<h2 style="text-align:center;font-size:18pt;"><?php echo $type; ?></h2>
<p style="font-size: 12pt;">合約書編號:<?php echo $_POST['partyAcontractno'] ?></p>
<table style="border:none">
<tr style="border:none;">
<td style="border:none;width:100px;"></td>
<td style="border:none;width:200px"><?php echo $_POST['partyA'] ?></td>
<td style="border:none">(即買方,以下簡稱為甲方)</td>
</tr>
</table>
<p style="font-size: 12pt;">立合約書人</p>
<table style="border:none">
<tr style="border:none;">
<td style="border:none;width:100px"></td>
<td style="border:none;width:200px">永佳捷科技股份有限公司</td>
<td style="border:none">(即賣方,以下簡稱為乙方)</td>
</tr>
</table>
<p style="font-size: 12pt;width:800px;<?php if($updatedIllustrate){ echo 'background-color:#ddd'; } ?>"><?php echo $illustrate; ?></p>
<table style="width:100%;border:none">
<?php foreach($nostandardArr as $idx=>$item){
?>
<tr style="margin-bottom:10px;display:block;border:none">
<td style="width:100px;border:none">第<?php echo numberToChinese($idx+1);?>條</td>
<?php if($item['updated'] == 1){ ?>
<td style="border:none;background-color:#ddd;"><?php echo nl2br(json_decode(json_encode($item), true)['text']); ?></td>
<?php }elseif($item['deleted'] == 1){ ?>
<td style="border:none;background-color:#D11919;text-decoration:line-through"><?php echo nl2br(json_decode(json_encode($item), true)['text']); ?></td>
<?php }elseif($item['id']>15){ ?>
<td style="border:none;background-color:#00B900;"><?php echo nl2br(json_decode(json_encode($item), true)['text']); ?></td>
<?php }else{ ?>
<td style="border:none"><?php echo nl2br(removeTrailingBr(json_decode(json_encode($item), true)['text'])); ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
</section>
<div class="footer" x-ref="footer" x-show="false">
<br />
<p> 立合約書人:</p>
<table>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:30px;border:none">甲</td>
<td style="width:30px;border:none;text-align:right">方</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
</td>
<td style="border:none">&nbsp;<?php echo $_POST['partyA']; ?></td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:20px;border:none;">代</td>
<td style="width:20px;border:none;text-align:center">表</td>
<td style="width:20px;border:none;text-align:right">人</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
<td style="border:none">&nbsp;<?php echo $customer['manager']; ?></td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:15px;border:none;">統</td>
<td style="width:15px;border:none;text-align:center">一</td>
<td style="width:15px;border:none;text-align:center">編</td>
<td style="width:15px;border:none;text-align:right">號</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
<td style="border:none">&nbsp;<?php echo $customer['uscc']; ?></td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:30px;border:none;">地</td>
<td style="width:30px;border:none;text-align:right">址</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
<td style="border:none">&nbsp;<?php echo $customer['address']; ?></td>
</tr>
</table>
<p style="line-height:0.1">&nbsp;</p>
<table>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:30px;border:none">乙</td>
<td style="width:30px;border:none;text-align:right">方</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
</td>
<td style="border:none">&nbsp;永佳捷科技股份有限公司</td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:20px;border:none;">總</td>
<td style="width:20px;border:none;text-align:center">經</td>
<td style="width:20px;border:none;text-align:right">理</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
</td>
<td style="border:none">&nbsp;蔡定憲</td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:15px;border:none;">統</td>
<td style="width:15px;border:none;text-align:center">一</td>
<td style="width:15px;border:none;text-align:center">編</td>
<td style="width:15px;border:none;text-align:right">號</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
</td>
<td style="border:none">&nbsp;90493119</td>
</tr>
<tr style="line-height:2">
<td style="width:100px;border:none">
<table>
<tr>
<td style="width:30px;border:none;">地</td>
<td style="width:30px;border:none;text-align:right">址</td>
<td style="width:10px;border:none;text-align:right">:</td>
</tr>
</table>
</td>
<td style="border:none">&nbsp;臺北市中山區敬業一路128巷39號3樓之1</td>
</tr>
</table>
<p>&nbsp;</p>
<!-- <table>
<tr>
<td style="width:200px;border:none;text-align:justify">中華民國</td>
<td style="width:100px;border:none;text-align:right">年</td>
<td style="width:100px;border:none;text-align:right">月</td>
<td style="width:100px;border:none;text-align:right">日</td>
</tr>
</table> -->
</div>
<div class="affix1" x-ref="affix1" x-show="false">
<h1 style="text-align:center">升降設備除外工程表</h1>
<table>
<tr>
<td style="width:40px">一、</td>
<td>機械室之建造,含預留出入口、通風照明、自動閉鎖裝置,及天花板上之保養用吊鉤。</td>
</tr>
<tr>
<td style="width:40px">二、</td>
<td style="width:460px">通往機械室之樓梯及加護欄杆工程。</td>
</tr>
<tr>
<td style="width:40px">三、</td>
<td style="width:460px">機械室基礎台需用防濕之瀝青鐵筋混凝土及地板防塵工事。</td>
</tr>
<tr>
<td style="width:40px">四、</td>
<td style="width:460px">機械室及升降路中間之橫樑或工字樑之安裝工程。</td>
</tr>
<tr>
<td style="width:40px">五、</td>
<td style="width:460px">自屋外至機械室之動力及照明用配線電源開關插座,及接地線等電路工程。</td>
</tr>
<tr>
<td style="width:40px">六、</td>
<td style="width:460px">升降路及機械室以外監視盤、電鈴、電話之配管與配線工程。</td>
</tr>
<tr>
<td style="width:40px">七、</td>
<td style="width:460px">升降路之建造及底部之防水工程及緩衝器水泥台工程。</td>
</tr>
<tr>
<td style="width:40px">八、</td>
<td style="width:460px">機坑照明保養用之開關及插座,鐵爬梯。</td>
</tr>
<tr>
<td style="width:40px">九、</td>
<td style="width:460px">各樓按鈕開關之留洞工程及安裝後之固定與週邊裝飾工程。</td>
</tr>
<tr>
<td style="width:40px">十、</td>
<td style="width:460px">升降路內甲方不得裝設有任何與升降設備無關之配線、電線配管、水管、風管等設備。</td>
</tr>
<tr>
<td style="width:40px">十一、</td>
<td style="width:460px">安裝所需水泥、砂石、水電與供試車用動力電源。</td>
</tr>
<tr>
<td style="width:40px">十二、</td>
<td style="width:460px">升降路及機房之建造,電源設備之容量及位置等,需符合國家標準(CNS-2866)及建築法規等規定。</td>
</tr>
<tr>
<td style="width:40px">十三、</td>
<td style="width:460px">機械運抵工地後供給儲存倉庫。</td>
</tr>
<tr>
<td colspan="2">備註:CNS-2866國家標準建築物電梯有關之法規: </td>
</tr>
<tr>
<td style="width:25px">1.</td>
<td style="width:475px">機械室內應設有照明及通風設備,以利管理檢查,照明應在100LUX(米一燭光)以上,通風設備應能使室內溫度保持在攝氏40度以下。</td>
</tr>
<tr>
<td style="width:25px">2.</td>
<td style="width:475px">機械室之出入口應加鎖,其裝置應良好。 </td>
</tr>
<tr>
<td style="width:25px">3.</td>
<td style="width:475px">由機械室至走廊,樓梯間應便於通行,樓梯應加裝扶手,其與水平面之傾斜角度,應不超過60度。 </td>
</tr>
<tr>
<td style="width:25px">4.</td>
<td style="width:475px">機械室出入門之構造,應有下述裝置: <br>
A:能自動關閉者。 <br>
B:有彈簧鎖或其類似裝置,以便室內不用鎖匙,而能開門。 <br>
C:除屋頂開口部份以外,機械式牆壁,應能耐火。(二小時防火時效)
</td>
</tr>
<tr>
<td style="width:25px">5.</td>
<td style="width:475px">升降路內不得設置與升降機無關之配管及配線。 </td>
</tr>
<tr>
<td style="width:25px">6.</td>
<td style="width:475px">任一升降路下部之任何部份,供人使用或類似使用時配重側比照車廂,同樣必須裝設緊急安全裝置。</td>
</tr>
<tr>
<td style="width:25px">7.</td>
<td style="width:475px">若有火警受信總機時,甲方需提供"火警受信總機"檢出信號及通往升降道內之配管配線(0.75MM² × 3) </td>
</tr>
</table>
</div>
</div>
<script>
const axiosClient = axios.create({
baseURL : ``,
});
axiosClient.interceptors.request.use( (config)=> {
config.headers.Authorization = `Bearer ${123}`
return config;
}, (error)=> {
return Promise.reject(error);
});
axiosClient.interceptors.response.use( (response)=> {
return response;
}, (error)=>{
if(error.response.status === 401){
// store.commit('setToken', null)
// sessionStorage.removeItem('TOKEN')
// router.push({name:'login'})
}
throw error;
});
createFloatWater()
function createFloatWater(){
}
const btn =document.getElementById('btn')
// btn.addEventListener('click', exportFn)
// exportFn();
function exportFn(){
const now = new Date();
// 獲取年、月、日、小時、分鐘、秒
const year = now.getFullYear();
const month = now.getMonth() + 1; // 月份是從0開始的,所以要加1
const day = now.getDate();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
// 格式化日期和時間
const formattedDate = `${year}${month}${day}${hours}${minutes}${seconds}`;
let html = document.getElementById('prview').innerHTML
let footer = document.getElementById('prview').innerHTML
console.log(html);
// axios.post('./export-pdf.php', {'html':html}).then(res=>{
// console.log(res);
// })
const form = new FormData();
form.append('html', html);
form.append('css','');
axiosClient({
method:'post',
responseType:'blob',
url:'./export-pdf.php',
data:form
}).then(response=>{
const url = window.URL.createObjectURL(new Blob([response.data]));
console.log(url);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', formattedDate + '.pdf'); // 指定下载的文件名
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
}
</script>
<?php
}else{
echo "<script>alert('非法訪問!');history.back() </script>";
}
?>