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.
 
 
 
 
 
 

229 lines
10 KiB

<?php
require_once('../conn.php');
// 保養
if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'b') {
try {
$contractno = $_GET['contractno'];
$sql_str = "SELECT con_maintance_examine_apply.*, con_maintance_examine_clear.* FROM con_maintance_examine_apply
JOIN con_maintance_examine_clear on con_maintance_examine_apply.apply_key=con_maintance_examine_clear.apply_key
WHERE con_maintance_examine_apply.vol_no = :vol_no ;";
$sql_str = "SELECT * FROM con_maintance_examine_apply WHERE vol_no = :vol_no ORDER BY create_at DESC;";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':vol_no', $contractno);
$stmt->execute();
$contract = $stmt->fetch(PDO::FETCH_ASSOC);
if (empty($contract)) {
echo false;
exit;
}
$apply_key = $contract['apply_key'];
$sql_str = "SELECT * FROM con_maintance_examine_clear WHERE apply_key = :apply_key";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':apply_key', $apply_key);
$stmt->execute();
$elevators = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = COUNT($elevators);
foreach ($elevators as $key => $elevator) {
$elevator['discount'] = round(($elevator['sold_price'] / $elevator['stand_price']), 2);
}
$contract['elevators'] = $elevators;
$contract['num'] = $count;
$contractResponse = json_encode($contract);
// 設定回應標頭為 JSON
header('Content-Type: application/json');
// 將 JSON 回應返回給客戶端
echo $contractResponse;
// echo json_encode($contractResponse);
} catch (PDOException $e) {
die("ERROR!!!: " . $e->getMessage());
}
}
// 新梯
if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'm') {
try {
$contractno = $_GET['contractno'];
$sql_str = "SELECT a.*,b.lm_tel,b.uscc,b.manager,b.linkman FROM pricereview_main AS a
LEFT JOIN hope_elevator_customer AS b ON a.contractno = b.vol_no
WHERE a.contractno = :contractno AND a.status != 'YN' ";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':contractno', $contractno);
$stmt->execute();
$contract = $stmt->fetch(PDO::FETCH_ASSOC);
$salesman = $contract['person'];
$sql = "SELECT * FROM account WHERE accountid = :accountid ";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':accountid', $salesman);
$stmt->execute();
$account_detail = $stmt->fetch(PDO::FETCH_ASSOC);
$contract['manager'] = $account_detail['manager'];
$contract['salesman_departno'] = $account_detail['department_id'];
$mid = $contract['id'];
$sql = "SELECT * FROM pricereview_item WHERE mid = :mid AND item_group = 'A' ";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->execute();
$elevators_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$elevators_detail_arr = [];
$contract_elevator_qty = 0;
$sql = "SELECT * FROM pricereview_pay WHERE mid = :mid";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->execute();
$pay_amount = $stmt->fetchAll(PDO::FETCH_ASSOC);
$pay_arr = [
'equipment_total' => 0, //設備款
'install_total' => 0, //安裝款
'elevotor_pay_detail' => []
];
$elevotor_pay_detail = [];
foreach ($pay_amount as $i => $pay) {
if ($pay['pay_kind'] <= 4) {
// 設備款總價
$pay_arr['equipment_total'] += $pay['pay_amount'];
if ($pay['pay_scale'] > 0) {
$elevotor_pay_detail = [
'kind' => $pay['pay_kind'],
'pay_scale' => $pay['pay_scale'],
'pay_period' => $pay['pay_period'],
'amount' => $pay['pay_amount']
];
// $elevotor_pay_detail['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period'];
// $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount'];
array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail);
}
} else {
$pay_arr['install_total'] += $pay['pay_amount'];
if ($pay['pay_scale'] > 0) {
$a = $pay['pay_kind'];
$elevotor_pay_detail = [
'kind' => "$a",
'pay_scale' => $pay['pay_scale'],
'pay_period' => $pay['pay_period'],
'amount' => $pay['pay_amount']
];
array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail);
// $elevotor_pay_detail[] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['kind'] = $pay['pay_kind'];
// $pay_arr['elevotor_pay_detail']['pay_scale'] = $pay['pay_scale'];
// $pay_arr['elevotor_pay_detail']['pay_period'] = $pay['pay_period'];
// $pay_arr['elevotor_pay_detail']['amount'] = $pay['pay_amount'];
}
}
}
// echo "<pre>";
// print_r($pay_arr);
// echo "</pre>";
foreach ($elevators_results as $keys) {
$contract_elevator_qty += $keys['item_qty'];
}
foreach ($elevators_results as $keys => $result) {
$item_no = $result['item_no']; //電梯項次
// 電梯 OPTION
$sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='B' AND option_relate_spec = :item_no";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->bindParam(':item_no', $item_no);
$stmt->execute();
$option_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$option_arr[] = $option_results;
// echo "<pre>";
// print_r($option_arr);
// echo "</pre>";
if (!empty($option_results)) {
$result['option_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯
foreach ($option_results as $key => $option) {
if ($option['item_qty'] == $result['item_qty']) {
$result['option_price'] += intval($option['item_unit_price']);
} else if ($option['item_qty'] / $result['item_qty'] != 1) {
$item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數
$result['option_price'] += intval($option['item_unit_price']) * $item_qty;
} else {
$result['option_price'] += $option['item_unit_price'] * intval($option['item_qty']);
}
}
}
// 查詢保固延長
$sql = "SELECT * FROM pricereview_item WHERE mid =:mid AND item_group ='E' AND option_relate_spec = :item_no";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':mid', $mid);
$stmt->bindParam(':item_no', $item_no);
$stmt->execute();
$other_option_arr = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($other_option_arr)) {
$result['option_other_price'] = 0;
// 電梯 OPTION 價格分別加到各台電梯
foreach ($other_option_arr as $key => $option) {
if ($option['item_qty'] == $result['item_qty']) {
$result['option_other_price'] += intval($option['item_unit_price']);
} else if ($option['item_qty'] / $result['item_qty'] != 1) {
$item_qty = intval($option['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數
$result['option_other_price'] += intval($option['item_unit_price']) * $item_qty;
} else {
$result['option_other_price'] += $option['item_unit_price'] * intval($option['item_qty']);
}
}
}
$note = explode(',', $result['note']);
$result['spec'] = $note[0]; //型號
$result['person'] = $note[1]; // 人承
$result['floor'] = $note[2]; // 樓層
$result['speed'] = $note[3]; // 速度
$count_qty = $result['item_qty'];
for ($i = 0; $i < $count_qty; $i++) {
$result['elevator_price'] = round($result['item_price_ct'] / $result['item_qty']); //合約單台電提價格
$result['commission_fee'] = round($contract['special_fee']) / $contract_elevator_qty;
$result['item_no'] = $i + 1;
$result['item_qty'] = 1;
array_push($elevators_detail_arr, $result);
}
}
$count = COUNT($elevators_detail_arr);
$contract['elevators'] = $elevators_results;
$contract['elevators_detail_arr'] = $elevators_detail_arr;
$contract['pay_arr'] = $pay_arr;
$contract['nums'] = $count;
$contractResponse = json_encode($contract);
// 設定回應標頭為 JSON
header('Content-Type: application/json');
// 將 JSON 回應返回給客戶端
echo $contractResponse;
} catch (PDOException $e) {
die("ERROR!!!: " . $e->getMessage());
}
}
if (!empty($_GET['contracttype']) && $_GET['contracttype'] == 'accountManger' && !empty($_GET['salesman'])) {
try {
$salesman = $_GET['salesman'];
$sql = "SELECT manager FROM account WHERE accountid = :accountid";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':accountid', $salesman);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
header('Content-Type:application/json');
echo json_encode($result);
} catch (PDOException $e) {
die("ERROR!!!:" . $e->getMessage());
}
}