diff --git a/wms/contract/api/getContractData.php b/wms/contract/api/getContractData.php index 9624bb51..c0f3078e 100644 --- a/wms/contract/api/getContractData.php +++ b/wms/contract/api/getContractData.php @@ -49,7 +49,9 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont $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' "; + WHERE a.contractno = :contractno + -- AND a.status != 'YN' + "; $stmt = $conn->prepare($sql_str); $stmt->bindParam(':contractno', $contractno); $stmt->execute(); @@ -73,11 +75,11 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont $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, //設備款 @@ -121,6 +123,7 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont // print_r($pay_arr); // echo ""; + // 計算電梯數 foreach ($elevators_results as $keys) { $contract_elevator_qty += $keys['item_qty']; } @@ -206,32 +209,173 @@ if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['cont } } - -if (isset($_GET['contract_no']) && $_GET['contract_no'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 't') { - $contract_no = $_GET['contract_no']; +// 汰改 +if (isset($_GET['contractno']) && $_GET['contractno'] != '' && isset($_GET['contracttype']) && $_GET['contracttype'] == 't') { try { - $sql = "SELECT * FROM pricereview_main AS a - WHERE a.kind='汰改' AND a.contract_no = :contract_no AND a.status='YY' - "; + $contractno = $_GET['contractno']; + $sql = "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); - $stmt->bindParam(':contract_no', $contract_no); + $stmt->bindParam(':contractno', $contractno); $stmt->execute(); $contract = $stmt->fetch(PDO::FETCH_ASSOC); $id = $contract['id']; + // 查詢 manager and departno + $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']; - $sql = "SELECT * FROM pricerview_pay WHERE mid =: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 =:id"; $stmt = $conn->prepare($sql); $stmt->bindParam(':id', $id); $stmt->execute(); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - $pay_kind = []; - foreach ($result as $result) { - $pay_kind[] = $result; + $pay_amount = $stmt->fetchAll(PDO::FETCH_ASSOC); + // $pay_kind[] = $result; + // $contract['pay_kind'] = $pay_kind; + $pay_arr = [ + 'equipment_total' => 0, //設備款 + 'install_total' => 0, //安裝款 + 'elevotor_pay_detail' => [] + ]; + // echo "
";
+        // print_r($pay_amount);
+        // echo "
"; + $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 = [ + 'pay_kind' => $pay['pay_kind'], + 'pay_scale' => $pay['pay_scale'], + 'pay_period' => $pay['pay_period'], + 'pay_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 = [ + 'pay_kind' => "$a", + 'pay_scale' => $pay['pay_scale'], + 'pay_period' => $pay['pay_period'], + 'pay_amount' => $pay['pay_amount'] + ]; + array_push($pay_arr['elevotor_pay_detail'], $elevotor_pay_detail); + } + } } - $contract['pay_kind'] = $pay_kind; - echo $contract; + + // 計算電梯數 + 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 "
";
+            // print_r($option_arr);
+            // echo "
"; + 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 ='D' AND option_relate_spec = :item_no"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':mid', $mid); + $stmt->bindParam(':item_no', $item_no); + $stmt->execute(); + $dismantle_arr = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (!empty($dismantle_arr)) { + $result['dismantle_price'] = 0; + // 電梯 OPTION 價格分別加到各台電梯 + foreach ($dismantle_arr as $key => $dismantle) { + if ($dismantle['item_qty'] == $result['item_qty']) { + $result['dismantle_price'] += intval($dismantle['item_unit_price']); + } else if ($dismantle['item_qty'] / $result['item_qty'] != 1) { + $item_qty = intval($dismantle['item_qty']) / intval($result['item_qty']); // 總option數量 / 總電梯台數 + $result['dismantle_price'] += intval($dismantle['item_unit_price']) * $item_qty; + } else { + $result['dismantle_price'] += $dismantle['item_unit_price'] * intval($dismantle['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; + // echo "
";
+        // print_r($contract);
+        // echo "
"; + + header('Content-Type: application/json'); + echo json_encode($contract); } catch (PDOException $e) { die("ERROR!!!: " . $e->getMessage()); } diff --git a/wms/contract/api/getFacilityNo.php b/wms/contract/api/getFacilityNo.php index 044d42cd..9d456747 100644 --- a/wms/contract/api/getFacilityNo.php +++ b/wms/contract/api/getFacilityNo.php @@ -404,7 +404,6 @@ class CreateFacilityNo $pdo = $this->connectionDB(); $pdo->exec('SET CHARACTER SET utf8mb4'); $connT8 = $this->connectionDB(); - // $connT8->exec('SET CHARACTER SET utf8mb4'); $sth = $pdo->prepare('SELECT * FROM `worksite` WHERE `facilityno` = ?'); $sth->bindValue(1, $facility_no); @@ -438,7 +437,6 @@ class CreateFacilityNo $pdo = $this->connectionDB(); $pdo->exec('SET CHARACTER SET utf8mb4'); $connT8 = $this->connectionT8DB(); - // $connT8->exec('SET CHARACTER SET utf8mb4'); $status = true; foreach ($facility_no as $row) { $sth = $pdo->prepare('SELECT * FROM `worksite` WHERE `facilityno` = ?'); diff --git a/wms/contract/api/newElevatorT8.php b/wms/contract/api/newElevatorT8.php index 86b1e0f3..e9e44168 100644 --- a/wms/contract/api/newElevatorT8.php +++ b/wms/contract/api/newElevatorT8.php @@ -355,10 +355,11 @@ function T8Insert($data, $facilityno, $connT8) } if (!empty($result) && ($result['Status'] == 'Fails' || $result['Status'] == 'Error')) { $Error_msg = $result['ErrorMsg']; - echo ""; - exit(); + // echo ""; + // exit(); // echo $result['ErrorMsg']; // echo ""; + echo $Error_msg; } } else { echo '資料已新增過,請洽資訊人員'; diff --git a/wms/contract/api/postRenovateContractData.php b/wms/contract/api/postRenovateContractData.php new file mode 100644 index 00000000..352e8f77 --- /dev/null +++ b/wms/contract/api/postRenovateContractData.php @@ -0,0 +1,4 @@ +"; +print_r($_POST); +echo ""; diff --git a/wms/contract/contract-renovate-input.php b/wms/contract/contract-renovate-input.php index 44f1f5be..f965dc75 100644 --- a/wms/contract/contract-renovate-input.php +++ b/wms/contract/contract-renovate-input.php @@ -1,24 +1,31 @@ prepare($sql); -// $stmt->bindParam(':depart_no', $depart_no); +$accounttype = "M"; +$sql_str = "SELECT accountid, name FROM account WHERE accounttype = :accounttype ORDER BY accountid"; +$stmt = $conn->prepare($sql_str); +$stmt->bindParam(":accounttype", $accounttype); $stmt->execute(); -$contractSalesman = $stmt->fetchAll(PDO::FETCH_ASSOC); -// echo '
';
-// print_r($contractSalesman);
-// echo '
'; +$persons = $stmt->fetchAll(PDO::FETCH_ASSOC); +$persons = array_map(function ($person) { + return [ + 'view' => $person['name'] . '-' . $person['accountid'], + 'value' => $person['accountid'], + 'name' => $person['name'] + ]; +}, $persons); ?> + + - +
@@ -43,8 +50,9 @@ $contractSalesman = $stmt->fetchAll(PDO::FETCH_ASSOC); - --> + + + 2、二次款 - + - - + + - + --> + + + + 3、貨到工地款 - + - - + + - + --> + + + + - 安裝 + 5、安裝完畢款 - + - - + + - + --> + + + 6、驗收款 - + - - + + - + --> + + + + 7、其他 - + - - + + - + --> + + + - 合計 + 合計 - + - - + + - + + +
+ + + + - -
- \ No newline at end of file + + + + \ No newline at end of file diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index 7de02def..b3d57efc 100644 --- a/wms/contract/js/alpine.js +++ b/wms/contract/js/alpine.js @@ -808,7 +808,11 @@ const contractDownload = () => { const contractNewInput = () => { return { - init() { }, + init() { + // nextTick(() => { + // $('#renovate_type').select2(); + // }); + }, data: { contractno: 'M24020076', customer: '', @@ -828,7 +832,7 @@ const contractNewInput = () => { pay_arr: [], //電梯付款種類 nums: 0, //電梯數量 area_no: 'T', - contract_arrival_date: '' + contract_arrival_date: '', }, fail_arr: [], step: 1, @@ -1039,7 +1043,8 @@ const contractInput = () => { contract_type: 'new', signing_date: '', token: token, - maintance_manager: '' + maintance_manager: '', + // bonus_verson: 2.1, // manager: '', // regular_contract_manger_id: '', @@ -1609,14 +1614,41 @@ const contractNewApply = () => { const renovateInput = () => { return { + // init() { + // this.initSelect2(); + // }, + // initSelect2() { + // console.log(123); + // $('#renovate_type').select2(); + // }, data: { - contract_no: '', + contract_no: 'T24030025', customer: '', salesman: '', + main_linkman: '', //負責人 + linkman: '', + lm_tel: '', + vat: '', + case_name: '', address: '', - paykind: [0, 0, 0, 0, 0, 0, 0], + area_no: '', + manager: '', + price_total: '', //合約總價 + files: [], + contract_type: '1', + signing_date: '', + elevators: [], //電梯總類 + elevators_detail_arr: [], // 電梯台數 Array payarr: ['', 1, 2, 6, 12], - total: 0, + paykind: [0, 0, 0, 0, 0, 0, 0], //電梯付款種類的分期方式 + scale: [0, 0, 0, 0, 0, 0, 0], + amount: [0, 0, 0, 0, 0, 0, 0], + pay_arr: [], // 電梯付款種類 + total_month: 0, + total_scale: 0, + total_amount: 0, + // disable: false + // options: ['Option 1', 'Option 2', 'Option 3'] // paykindTotal: this.total(), }, step: 1, @@ -1627,22 +1659,116 @@ const renovateInput = () => { this.isLoading = true; this.getContractData(); } else if (this.step == 2) { - console.log('1111'); + if (this.data.nums <= 0) return alert('請填寫電梯數量!') + this.getElevatorsData(); + } else if (this.step == 3) { + this.totalFn(); + this.checkDisableStatus(); + this.step = 4; } // this.step = 3; }, + getContractData() { + axios.get('./api/getContractData.php?contracttype=t&contractno=' + this.data.contract_no).then(res => { + console.log(res.data); + if (!res.data) { + this.step = 2; + this.isLoading = false; + return; + } + this.data.pay_arr = res.data.pay_arr; + for (let i = 0; i < this.data.pay_arr['elevotor_pay_detail'].length; i++) { + let kind = this.data.pay_arr['elevotor_pay_detail'][i].pay_kind - 1; + let amount = this.data.pay_arr['elevotor_pay_detail'][i].pay_amount; + let scale = this.data.pay_arr['elevotor_pay_detail'][i].pay_scale; + console.log(kind); + this.data.amount[kind] = amount; + this.data.scale[kind] = scale; + } + this.data.customer = res.data.company + this.data.main_linkman = res.data.manager + this.data.vat = res.data.uscc + this.data.case_name = res.data.case_name + this.data.linkman = res.data.linkman + this.data.lm_tel = res.data.lm_tel + this.data.address = res.data.address + this.data.salesman = res.data.person + // this.data.qc = res.data.qc; + this.data.price_total = res.data.price_total; + this.data.elevators = res.data.elevators; + this.data.elevators_detail_arr = res.data.elevators_detail_arr; + this.data.nums = res.data.nums; + this.data.contract_arrival_date = res.data.facilitok_date; + this.step = 2; + this.isLoading = false; + }).catch(err => { + console.log(err); + this.isLoading = false; + }) + }, + getElevatorsData() { + if (this.step == 2) { + for (let i = 0; i < this.data.nums; i++) { + // this.initSelect2(i); + // console.log(this.data.elevators_detail_arr[i]); + this.data.elevators_detail_arr[i].warehouseid = ''; // 公務部門負責人 + this.data.elevators_detail_arr[i].latitude = ''; // 經度 + this.data.elevators_detail_arr[i].longitude = ''; // 緯度 + this.data.elevators_detail_arr[i].manage = ''; // 工地負責人 + this.data.elevators_detail_arr[i].qc = 'QO'; // QC和官檢 + this.data.elevators_detail_arr[i].contract_arrival_date = this.data.contract_arrival_date; //合約交期(到工地) + this.data.elevators_detail_arr[i].selectedItems = ''; + // this.data.elevators_detail_arr[i].area_no = ''; //區域 + } + this.step = 3; + this.isLoading = false; + } else if (this.step == 3) { + console.log(this.data.elevators_detail_arr); + // this.step = 4; + // this.isLoading = false; + } + }, + cons() { + console.log(this.data.elevators_detail_arr); + }, // 計算總共分期月數 totalFn() { - let total = 0 + let total_month = 0 for (let i = 0; i < this.data.paykind.length; i++) { if (this.data.paykind[i] != '0') { - total += Number(this.data.paykind[i]); + total_month += Number(this.data.paykind[i]); + } + } + this.data.total_month = total_month; + + let total_scale = 0 + for (let i = 0; i < this.data.scale.length; i++) { + if (this.data.scale[i] != '0') { + total_scale += Number(this.data.scale[i]); + } + } + let total_amount = 0 + for (let i = 0; i < this.data.scale.length; i++) { + if (this.data.scale[i] != '0') { + total_amount += Number(this.data.amount[i]); } } // console.log(123); - this.data.total = total; + this.data.total_month = total_month; + this.data.total_scale = total_scale; + this.data.total_amount = total_amount; + }, + checkDisableStatus() { + for (let i = 0; i < this.data.amount.length; i++) { + if (this.data.amount[i] == 0) { + this.data.disable = true; + } + } }, + // initSelect2(idx) { + // this.data.elevators_detail_arr[idx].selectedItems = $('#renovate_type' + idx).select2().val(); + // }, nextStepKeyupFn(e) { if (e.keyCode != 13) return if (this.step == 1) { @@ -1654,20 +1780,32 @@ const renovateInput = () => { this.step -= 1; console.log(this.step); }, - getContractData() { - axios.get('../api/getContractData.php?contracttype=t&contract_no=' + this.data.contract_no, (res) => { - console.log(res.data); - }) - }, save() { + console.log(this.data); + const form = new FormData(); + form.append('contractno', this.data.contract_no); + form.append('customer', this.data.customer); + form.append('manager', this.data.main_linkman); + form.append('vat', this.data.vat); + form.append('area_no', this.data.area_no); + form.append('case_name', this.data.case_name); + form.append('linkman', this.data.linkman); + form.append('lm_tel', this.data.lm_tel); + form.append('address', this.data.address); + form.append('salesman', this.data.salesman); + form.append('signing_date', this.data.signing_date); + form.append('nums', this.data.nums); + form.append('price_total', this.data.price_total); + form.append('contract_type', this.data.contract_type); + form.append('elevators_detail_arr', JSON.stringify(this.data.elevators_detail_arr)); + form.append('elevators', JSON.stringify(this.data.elevators)); + form.append('pay_arr', JSON.stringify(this.data.pay_arr)); + form.append('scale', JSON.stringify(this.data.scale)); + form.append('contracttype', 'm'); + form.append('user_id', user_id); + axios.post('./api/postRenovateContractData.php', form).then(res => { - }, - getContractData() { - this.step = 2; - this.isLoading = false; - console.log(this.step); - + }) } - } } \ No newline at end of file