diff --git a/.gitignore b/.gitignore index 44e45c2f..39c6cbea 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ wms/chinese.php phpinfo.php wms/account_receivable_sql_file.sql wms/account_receivable_maintainance_sql.sql +wms/account-receivable-contract.xlsx +wms/account-receivable-maintainance.xlsx +wms/account_receivable_renovate_sql.sql diff --git a/wms/account-receivable-contract.xlsx b/wms/account-receivable-contract.xlsx index 571e77f7..503566a8 100644 Binary files a/wms/account-receivable-contract.xlsx and b/wms/account-receivable-contract.xlsx differ diff --git a/wms/account-receivable-excel.php b/wms/account-receivable-excel.php index 17ea668d..39af3bb4 100644 --- a/wms/account-receivable-excel.php +++ b/wms/account-receivable-excel.php @@ -36,7 +36,7 @@ if ($type == 'newContract') { '尾款催收金額', '尾款催收次數' ]; - file_put_contents('account-receivable.txt', json_encode($Bill, JSON_UNESCAPED_UNICODE)); + // file_put_contents('account-receivable.txt', json_encode($Bill, JSON_UNESCAPED_UNICODE)); $sheet->fromArray($colomnHeader, NULL, 'A2'); $rowIndex = 3; foreach ($Bill as $key => $value) { @@ -59,79 +59,61 @@ if ($type == 'newContract') { } $writer = new Xlsx($spreadsheet); $excelFileName = 'account-receivable-contract.xlsx'; - $writer->save($excelFileName); -} elseif ($type == 'facility') { +} elseif ($type == 'maintainance') { + $sheet->mergeCells('A1:H1'); + $sheet->setTitle('保養催收統整'); + $sheet->setCellValue('A1', '保養催收統整'); + $sheet->getStyle('A1')->getFont()->setBold(true); + $sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + $sheet->getStyle('A1')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); + $sheet->getStyle('A1')->getFont()->setSize(14); + $sheet->getRowDimension('1')->setRowHeight(38); $colomnHeader = [ - 'T8單據日期', '作番號', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭', - '訂金名稱', '訂金合約金額', '訂金應收日期', '訂金目前應收金額', '訂金已開金額', '訂金未開金額', '訂金已收金額', '訂金催收金額', '訂金催收次數', - '二次款名稱', '二次款合約金額', '二次款應收日期', '二次款目前應收金額', '二次款已開金額', '二次款未開金額', '二次款已收金額', '二次款催收金額', '二次款催收次數', - '貨抵工地款名稱', '貨抵工地款合約金額', '貨抵工地款應收日期', '貨抵工地款目前應收金額', '貨抵工地款已開金額', '貨抵工地款未開金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款催收次數', - '安裝款名稱', '安裝款合約金額', '安裝款應收日期', '安裝款目前應收金額', '安裝款已開金額', '安裝款未開金額', '安裝款已收金額', '安裝款催收金額', '安裝款催收次數', - '試車款名稱', '試車款合約金額', '試車款應收日期', '試車款目前應收金額', '試車款已開金額', '試車款未開金額', '試車款已收金額', '試車款催收金額', '試車款催收次數', - '官檢款名稱', '官檢款合約金額', '官檢款應收日期', '官檢款目前應收金額', '官檢款已開金額', '官檢款未開金額', '官檢款已收金額', '官檢款催收金額', '官檢款催收次數', - '交車款名稱', '交車款合約金額', '交車款應收日期', '交車款目前應收金額', '交車款已開金額', '交車款未開金額', '交車款已收金額', '交車款催收金額', '交車款催收次數', - '尾款名稱', '尾款金額', '尾款應收日期', '尾款應收金額', '尾款已開金額', '尾款未開金額', '尾款已收金額', '尾款催收金額', '尾款催收次數', - '作番狀態', '合約-設備金額', '合約-安裝金額', '作番合約總金額', '作番總應收金額' + '合約號','序號','作番號','部門','契約員','客戶','金額','催收次數' ]; - $sheet->fromArray($colomnHeader, NULL, 'A1'); - $rowIndex = 2; + + // file_put_contents('account-receivable.txt', json_encode($Bill, JSON_UNESCAPED_UNICODE)); + $sheet->fromArray($colomnHeader, NULL, 'A2'); + $rowIndex = 3; foreach ($Bill as $key => $value) { $sheet->fromArray($value, NULL, 'A' . $rowIndex); $column = [ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', - 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BK' + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' ]; - foreach ($column as $col) { - $sheet->getColumnDimension($col)->setAutoSize(true); - } - $rowIndex++; } $writer = new Xlsx($spreadsheet); - $excelFileName = 'account-receivable-facility.xlsx'; - $writer->save($excelFileName); -} else { + $excelFileName = 'account-receivable-contract.xlsx'; + +}elseif ($type == 'renovate') { + $sheet->mergeCells('A1:K1'); + $sheet->setTitle('汰改催收統整'); + $sheet->setCellValue('A1', '汰改催收統整'); + $sheet->getStyle('A1')->getFont()->setBold(true); + $sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + $sheet->getStyle('A1')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); + $sheet->getStyle('A1')->getFont()->setSize(14); + $sheet->getRowDimension('1')->setRowHeight(38); $colomnHeader = [ - 'T8單據日期', '合約號', '部門', '經理', '營業員', '客戶名稱', '統一編號', '聯絡地址', '抬頭', - '訂金', '訂金目前應收', '訂金已開票金額', '訂金未開票金額', '訂金已收金額', '訂金催收金額', '訂金最大催收次數', '訂金最小催收次數', - '二次款', '二次款目前應收', '二次款已開票金額', '二次款未開票金額', '二次款已收金額', '二次款催收金額', '二次款最大催收次數', '二次款最小催收次數', - '貨抵工地款', '貨抵工地款目前應收', '貨抵工地款已開票金額', '貨抵工地款未開票金額', '貨抵工地款已收金額', '貨抵工地款催收金額', '貨抵工地款最大催收次數', '貨抵工地款最小催收次數', - '安裝款', '安裝款目前應收', '安裝款已開票金額', '安裝款未開票金額', '安裝款已收金額', '安裝款催收金額', '安裝款最大催收次數', '安裝款最小催收次數', - '試車款', '試車款目前應收', '試車款已開票金額', '試車款未開票金額', '試車款已收金額', '試車款催收金額', '試車款最大催收次數', '試車款最小催收次數', - '官檢款', '官檢款目前應收', '官檢款已開票金額', '官檢款未開票金額', '官檢款已收金額', '官檢款催收金額', '官檢款最大催收次數', '官檢款最小催收次數', - '交車款', '交車款目前應收', '交車款已開票金額', '交車款未開票金額', '交車款已收金額', '交車款催收金額', '交車款最大催收次數', '交車款最小催收次數', - '尾款', '尾款目前應收', '尾款已開票金額', '尾款未開票金額', '尾款已收金額', '尾款催收金額', '尾款最大催收次數', '尾款最小催收次數', - '合約設備金額', '合約安裝金額', '合約總金額', '目前應收', '已開發票金額', '已收金額', '作番總數', '作番狀態' + '合約號','作番號','部門','營業員','客戶','收款階段名稱','應收日期','金額','已收金額','催收金額','催收次數' ]; - $sheet->fromArray($colomnHeader, NULL, 'A1'); - $rowIndex = 2; + // file_put_contents('account-receivable.txt', json_encode($Bill, JSON_UNESCAPED_UNICODE)); + $sheet->fromArray($colomnHeader, NULL, 'A2'); + $rowIndex = 3; foreach ($Bill as $key => $value) { + $sheet->fromArray($value, NULL, 'A' . $rowIndex); $column = [ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', - 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', - 'CA', 'CB', 'CC', 'CD' + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I','J','K' ]; - foreach ($column as $col) { - if ($col == 'CC') { - $sheet->getColumnDimension('CC')->setWidth(40); - $sheet->getStyle('CC')->getAlignment()->setWrapText(true); - } else { - $sheet->getColumnDimension($col)->setAutoSize(true); - } - } - - $rowIndex++; } $writer = new Xlsx($spreadsheet); - $excelFileName = 'account-receivable-test.xlsx'; - $writer->save($excelFileName); + $excelFileName = 'account-receivable-renovate.xlsx'; } +$writer->save($excelFileName); echo $excelFileName; ?> +

應收帳款(保養)

@@ -347,17 +368,17 @@ include "./footer.php"; 合約號 - 序號 - 作番號 - 部門 + 序號 + 作番號 + 部門 契約員 - 客戶名稱 + 客戶名稱 應收日期 是否應收 款別金額 - 是否收齊 + 是否收齊 催收次數 @@ -372,13 +393,13 @@ include "./footer.php"; " . $row['PersonName']; ?> " . $row['BizPartnerName']; ?> - + - - + + @@ -400,29 +421,6 @@ include "./footer.php"; } } } - // function downloadData() { - // var xhr = new XMLHttpRequest(); - // var url = window.location.origin + "/wms/account-receivable-renovate-excel.php?type=all&"; - // xhr.open('POST', url, true); - // xhr.setRequestHeader('Content-Type', 'application/json'); - // xhr.onreadystatechange = function() { - // if (xhr.readyState === 4 && xhr.status === 200) { - // var file_path = xhr.responseText; - // var link = document.createElement('a'); - // var name = "汰改應收帳款" + "" + ".xlsx"; - // link.setAttribute('href', window.location.origin + "/wms/account-receivable-renovate.xlsx"); - // link.setAttribute('download', name); - // link.style.display = 'none'; - // document.body.appendChild(link); - // link.click(); - // document.body.removeChild(link); - // } - // } - // xhr.send(JSON.stringify({ - // Bill: - // })); - - // } function searchFront(area) { var term = 'search_' + area; @@ -510,8 +508,28 @@ include "./footer.php"; } } - function check(searchname) { - console.log(searchname); + function downloadData() { + var BillData = ; + var filename = "保養催收帳款" + "" + ".xlsx"; + var xhr = new XMLHttpRequest(); + var url = window.location.origin + "/wms/account-receivable-excel.php?type=maintainance&"; + xhr.open('POST', url, true); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === 200) { + var link = document.createElement('a'); + link.setAttribute('href', window.location.origin + "/wms/account-receivable-contract.xlsx"); + link.setAttribute('download', filename); + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + } + xhr.send(JSON.stringify({ + Bill: BillData + })); + } \ No newline at end of file diff --git a/wms/account-receivable-new-index.php b/wms/account-receivable-new-index.php index 712c8647..4c7e38b9 100644 --- a/wms/account-receivable-new-index.php +++ b/wms/account-receivable-new-index.php @@ -794,7 +794,6 @@ foreach ($final_paystage as $key => &$value) { } } - //合約資料填回arrayData foreach ($final_paystage as $key => $value) { for ($sequence = 1; $sequence <= count($value); $sequence++) { @@ -811,9 +810,6 @@ foreach ($final_paystage as $key => $value) { $arvalue['receivable_budget'] += $value[$sequence]['PlanPayAmt']; $arrayData[$key]['receivable_budget'] += $value[$sequence]['PlanPayAmt']; } - // else { - // $arvalue['receivable_budget'] = 0; - // } if ($arvalue['collect_month'] < $value[$sequence]['collect_month']) { $arvalue['collect_month'] = $value[$sequence]['collect_month']; } @@ -837,7 +833,7 @@ foreach ($final_paystage as $key => $value) { $sum_received_budget += $value[$sequence]['received_budget']; $sum_invoice_budget += $value[$sequence]['invoice_budget']; } - if ($value[$sequence]['collect_month'] > $arrayData[$key]['collect_month']) { + if ((round($arvalue['receivable_budget'] - $arvalue['received_budget']) >2)&&($value[$sequence]['collect_month'] > $arrayData[$key]['collect_month'])) { $arrayData[$key]['collect_month'] = $value[$sequence]['collect_month']; } } @@ -914,34 +910,34 @@ foreach ($arrayData as $key => &$value) { $excel_contract_all_array[$key][5] = $excel_contract_array[$key][19]; $excel_contract_all_array[$key][6] = $excel_contract_array[$key][20]; $excel_contract_all_array[$key][7] = $excel_contract_array[$key][17]; - $total_collect_budget += $excel_contract_all_array[$key][6]; - $total_collect_facility += $excel_contract_all_array[$key][4]; + $total_collect_budget += $excel_contract_all_array[$key][7]; + $total_collect_facility += $excel_contract_all_array[$key][5]; $isBoga = 0; if (stristr($value['PayStage'][1]['PayStage'], '寶佳')) { $isBoga = 1; $excel_contract_boga_array[$key] = array_fill(0, 24, ''); $excel_contract_boga_array[$key][0] = $excel_contract_array[$key][0]; $excel_contract_boga_array[$key][1] = $excel_contract_array[$key][3]; - $excel_contract_boga_array[$key][2] = $excel_contract_array[$key][8]; - $excel_contract_boga_array[$key][3] = $excel_contract_array[$key][11]; - $excel_contract_boga_array[$key][4] = $excel_contract_array[$key][19]; - $excel_contract_boga_array[$key][5] = $excel_contract_array[$key][20]; - $excel_contract_boga_array[$key][6] = $excel_contract_array[$key][17]; - $excel_contract_boga_array[$key][7] = $excel_contract_array[$key][18]; - $boga_collect_budget += $excel_contract_boga_array[$key][6]; - $boga_collect_facility += $excel_contract_boga_array[$key][4]; + $excel_contract_boga_array[$key][2] = $excel_contract_array[$key][6]; + $excel_contract_boga_array[$key][3] = $excel_contract_array[$key][8]; + $excel_contract_boga_array[$key][4] = $excel_contract_array[$key][11]; + $excel_contract_boga_array[$key][5] = $excel_contract_array[$key][19]; + $excel_contract_boga_array[$key][6] = $excel_contract_array[$key][20]; + $excel_contract_boga_array[$key][7] = $excel_contract_array[$key][17]; + $boga_collect_budget += $excel_contract_boga_array[$key][7]; + $boga_collect_facility += $excel_contract_boga_array[$key][5]; } else { $excel_contract_noboga_array[$key] = array_fill(0, 24, ''); $excel_contract_noboga_array[$key][0] = $excel_contract_array[$key][0]; $excel_contract_noboga_array[$key][1] = $excel_contract_array[$key][3]; - $excel_contract_noboga_array[$key][2] = $excel_contract_array[$key][8]; - $excel_contract_noboga_array[$key][3] = $excel_contract_array[$key][11]; - $excel_contract_noboga_array[$key][4] = $excel_contract_array[$key][19]; - $excel_contract_noboga_array[$key][5] = $excel_contract_array[$key][20]; - $excel_contract_noboga_array[$key][6] = $excel_contract_array[$key][17]; - $excel_contract_noboga_array[$key][7] = $excel_contract_array[$key][18]; - $noboga_collect_budget += $excel_contract_noboga_array[$key][6]; - $noboga_collect_facility += $excel_contract_noboga_array[$key][4]; + $excel_contract_noboga_array[$key][2] = $excel_contract_array[$key][6]; + $excel_contract_noboga_array[$key][3] = $excel_contract_array[$key][8]; + $excel_contract_noboga_array[$key][4] = $excel_contract_array[$key][11]; + $excel_contract_noboga_array[$key][5] = $excel_contract_array[$key][19]; + $excel_contract_noboga_array[$key][6] = $excel_contract_array[$key][20]; + $excel_contract_noboga_array[$key][7] = $excel_contract_array[$key][17]; + $noboga_collect_budget += $excel_contract_noboga_array[$key][7]; + $noboga_collect_facility += $excel_contract_noboga_array[$key][5]; } } @@ -1138,9 +1134,9 @@ foreach ($arrayData as $key => &$value) { } } // $excel_contract_all_array['last']= $excel_contract_boga_array['last'] = $excel_contract_noboga_array['last'] = array_fill(0, 23, ''); -$excel_contract_all_array['last']= ['合計', '', '', '', $total_collect_facility, '', $total_collect_budget, '', $total_sign_collect_budget, '', $total_second_collect_budget, '', $total_arrival_collect_budget, '', $total_install_collect_budget, '', $total_tryrun_collect_budget, '', $total_check_collect_budget, '', $total_delivery_collect_budget, '', $total_final_collect_budget, '']; -$excel_contract_boga_array['last']= ['合計', '', '', '', $boga_collect_facility, '', $boga_collect_budget, '', $boga_sign_collect_budget, '', $boga_second_collect_budget, '', $boga_arrival_collect_budget, '', $boga_install_collect_budget, '', $boga_tryrun_collect_budget, '', $boga_check_collect_budget, '', $boga_delivery_collect_budget, '', $boga_final_collect_budget, '']; -$excel_contract_noboga_array['last']= ['合計', '', '', '', $noboga_collect_facility, '', $noboga_collect_budget, '', $noboga_sign_collect_budget, '', $noboga_second_collect_budget, '', $noboga_arrival_collect_budget, '', $noboga_install_collect_budget, '', $noboga_tryrun_collect_budget, '', $noboga_check_collect_budget, '', $noboga_delivery_collect_budget, '', $noboga_final_collect_budget, '']; +$excel_contract_all_array['last']= ['合計', '', '', '','', $total_collect_facility, '', $total_collect_budget, $total_sign_collect_budget, '', $total_second_collect_budget, '', $total_arrival_collect_budget, '', $total_install_collect_budget, '', $total_tryrun_collect_budget, '', $total_check_collect_budget, '', $total_delivery_collect_budget, '', $total_final_collect_budget, '']; +$excel_contract_boga_array['last']= ['合計', '', '', '','', $boga_collect_facility, '', $boga_collect_budget, $boga_sign_collect_budget, '', $boga_second_collect_budget, '', $boga_arrival_collect_budget, '', $boga_install_collect_budget, '', $boga_tryrun_collect_budget, '', $boga_check_collect_budget, '', $boga_delivery_collect_budget, '', $boga_final_collect_budget, '']; +$excel_contract_noboga_array['last']= ['合計', '', '', '','', $noboga_collect_facility, '', $noboga_collect_budget, $noboga_sign_collect_budget, '', $noboga_second_collect_budget, '', $noboga_arrival_collect_budget, '', $noboga_install_collect_budget, '', $noboga_tryrun_collect_budget, '', $noboga_check_collect_budget, '', $noboga_delivery_collect_budget, '', $noboga_final_collect_budget, '']; // print_r($excel_contract_array['M230064']); // echo "
---------------------------------------------------------
"; @@ -1342,7 +1338,7 @@ $testtotal = 0;
- +
@@ -1362,9 +1358,9 @@ $testtotal = 0; 合約催收次數 - + ≤ 催收次數 ≤ - + @@ -1416,7 +1412,10 @@ $testtotal = 0; - +
+ + +
@@ -1603,6 +1602,20 @@ include "./footer.php"; "; + // exit(); + // echo $result['ErrorMsg']; + // echo ""; + echo $Error_msg; + } + } else { + echo '資料已新增過,請洽資訊人員'; + // exit(); + } + // $connT8->commit(); + // } catch (PDOException $e) { + // $connT8->rollback(); + // header("HTTP/1.1 500 Internal Server Error"); + // die('Error!:' . $e->getMessage()); + // } +} diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 296d7144..328e5e89 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -1,7 +1,6 @@ makeBFacilityNo("T", $facility_arr, (int)$num); + echo json_encode($facilityno); + // exit(); // if ($user_id == 'M0225') { // echo '
';
@@ -79,7 +79,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
         //     exit();
         // }
         $fail_arr = [];
-        // if ($contractno === '') return $fail_arr[] = '合約號為必填';
+        if ($contractno === '') return $fail_arr[] = '合約號為必填';
         if ($total_price == '')  $fail_arr[] = '合約總價為必填';
         if ($salesman == '')  $fail_arr[] = '營業員為必填';
         if ($contract_begin_date == '')  $fail_arr[] = '合約開始時間為必填';
@@ -108,11 +108,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
             echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE);
             exit();
         }
-        exit();
-        T8insert($_POST, $facilityno, $depId, $connT8);
-        exit();
+        // T8insert($_POST, $facilityno, $depId, $connT8);
         /// 獎金計算
         $aaa = bonusCreate($_POST, $facilityno, $conn);
+        exit();
         if (!empty($aaa) && $aaa['status'] == 2) {
             header("HTTP/1.1 422 Unprocessable Entity");
             echo $aaa['data'];
@@ -292,7 +291,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
             }
 
 
-            // $regular_contract_manger_id = $elevators[$idx]['regular_contract_manger_id'];
+            $regular_contract_manger_id = $elevators[$idx]['regular_contract_manger_id'];
             // $sql = "SELECT * FROM account WHERE accountid = '' ";
             $sql = "SELECT * FROM account WHERE accountid = '$maintance_manager' ";
             $stmt = $conn->prepare($sql);
@@ -306,17 +305,15 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
             //         南部 : M0077
             // 保養組長之後調整
             $mail_title = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-請安排此作番的保養人員";
-            $mail_content = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-請安排此作番的保養人員  點我";
+            $mail_content = "保養計畫 : 合約號:" . $contractno . "作番號:" . $no . "-請安排此作番的保養人員  點我";
             // exit();
             $mail->sendx(
                 $mail_title,
                 $mail_content,
                 [
-                    // [$user_id, $user_detail['email']],
+                    [$user_id, $user_detail['email']],
                     // [$maintance_manager, $maintance_manager_detail['email']],
-                    // ['M0012', 'Yingying@masada.com.tw']
-                    // [$regular_contract_manger_id, $regular_contract_manger_mail['mail']],
-                    ['M0225', 'lkmd555@masada.com.tw']
+                    // ['M0225', 'lkmd555@masada.com.tw']
                     // ['M0012', 'Yingying@masada.com.tw']
                 ],
                 "永佳捷科技"
@@ -400,10 +397,17 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
         } else {
             $files = null;
         }
-        $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, repairman, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by,signing_date) 
-                VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :repairman, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by,:signing_date)";
+        $kind = [
+            'new' => '1',
+            'free_to_charge' => '2',
+            'renew_priceissue' => '3',
+            'longcontract_m1_free_charge' => '4'
+        ];
+        $sql_str = "INSERT INTO contract_b_signed_back (contract_no,contract_kind, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price,payType, customer_phone, customer_email, maintance_manager, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, created_at, created_by,signing_date) 
+                VALUES (:contract_no, :contract_type,:contract_kind, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :payType ,:customer_phone, :customer_email, :maintance_manager, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :created_at, :created_by,:signing_date)";
         $stmt = $conn->prepare($sql_str);
         $stmt->bindParam(":contract_no", $contractno);
+        $stmt->bindParam(":contract_kind", $kind[$contract_type]);
         $stmt->bindParam(":contract_type", $contract_type);
         $stmt->bindParam(":company", $company);
         $stmt->bindParam(":customer_no", $customer_no);
@@ -413,8 +417,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
         $stmt->bindParam(":total_price", $total_price);
         $stmt->bindParam(":customer_phone", $customer_phone);
         $stmt->bindParam(":customer_email", $customer_email);
-        $stmt->bindParam(":repairman", $repairman);
-        // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。
+        $stmt->bindParam(":maintance_manager", $maintance_manager);
         $stmt->bindParam(":contact_person", $contact_person);
         $stmt->bindParam(":contact_address", $contact_address);
         $stmt->bindParam(":contact_phone", $contact_phone);
@@ -423,13 +426,13 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c
         $stmt->bindParam(":area", $area);
         $stmt->bindParam(":address", $address);
         $stmt->bindParam(":files_id", $files_id);
-        $stmt->bindParam(":bonus", $bonus);
-        $stmt->bindParam(":max_bonus", $max_bonus);
         $stmt->bindParam(":created_at", $created_at);
         $stmt->bindParam(":created_by", $user_id);
         $stmt->bindParam(':payType', $payType);
         $stmt->bindParam(':signing_date', $signing_date);
-
+        // $stmt->bindParam(":cycle", $cycle); // 保養頻率在做番上,這邊不 insert。
+        // $stmt->bindParam(":bonus", $bonus);
+        // $stmt->bindParam(":max_bonus", $max_bonus);
         $stmt->execute();
 
         // T8insert($_POST, $facilityno);
@@ -471,6 +474,7 @@ function T8insert($data, $facilityno, $depId, $connT8)
     $invoice = !empty($_POST['invoice']) ? $_POST['invoice'] : '';
     $invoice_address = !empty($_POST['invoice_address']) ? $_POST['invoice_address'] : '';
     $total_price = !empty($_POST['total_price']) ? intval($_POST['total_price']) : 0;
+
     // $email = !empty($data['email']) ? $data['email'] : null;
     // $partyAaddress = !empty($data['partyAaddress']) ? $data['partyAaddress'] : null; // 業務聯絡人地址
     // $num = !empty($data['num']) ? $data['num'] : null; // 電梯數量
@@ -566,6 +570,7 @@ function T8insert($data, $facilityno, $depId, $connT8)
     // echo '
';
     // print_r($elevators['maintainance']);
     // echo '
'; + foreach ($elevators as $index => $elevator) { $maintainance_type = $elevator['maintainance']; if ($maintainance_type == 'A') { @@ -581,16 +586,17 @@ function T8insert($data, $facilityno, $depId, $connT8) $stmt->bindParam(':ProjectId', $contractno); $stmt->execute(); $resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (empty($resultProject)) { //新增於 comProject。合約 table - $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,ValidityFromDate,ValidityToDate,CreateTime,CreatorId,IsInUsed) - VALUES(:ProjectId,:ProjectName,:TypeId,:ValidityFromDate,:ValidityToDate,:CreateTime,:CreatorId,1)"; + $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed) + VALUES(:ProjectId,:ProjectName,:TypeId,:CreateTime,:CreatorId,1)"; $stmt = $connT8->prepare($sql); $stmt->bindParam(':ProjectId', $contractno); $stmt->bindParam(':ProjectName', $customer); $stmt->bindParam(':TypeId', $type); - $stmt->bindParam(':ValidityFromDate', $beginDate); - $stmt->bindParam(':ValidityToDate', $endDate); + // $stmt->bindParam(':ValidityFromDate', $beginDate); + // $stmt->bindParam(':ValidityToDate', $endDate); $stmt->bindParam(':CreateTime', $createTime); $stmt->bindParam(':CreatorId', $user_id); $stmt->execute(); @@ -598,7 +604,6 @@ function T8insert($data, $facilityno, $depId, $connT8) $row = 0; // // 新增電梯數 foreach ($elevators as $index => $elevator) { - $facility_no = $facilityno[$index]; $sql = "INSERT INTO comMaterial (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime) @@ -638,14 +643,11 @@ function T8insert($data, $facilityno, $depId, $connT8) ]; // 幾年 // $SQuantityYear = $elevator['maintain_months'] / 12; - // 單台電梯契約報價 $price_of_month = intval($elevator['sold_price']); - print_r($price_of_month); - exit; + //分幾期 () => 總共保養月 / 分期月 $SQuantitya = $elevator['maintain_months'] / $IncomeId[$payType]; $SQuantity = $IncomeId[$payType]; - $date_1 = getNext25thDate($contract_begin_date); // 依每台電梯去加入各個的付款項 @@ -673,11 +675,13 @@ function T8insert($data, $facilityno, $depId, $connT8) } } $count_rows_data = COUNT($salIncomeApplyDetail_rows); - $T8total = $price_of_month * $count_rows_data; + $T8total = $price_of_month * $elevator['maintain_months']; // echo "
";
-    // print_r($salIncomeApplyDetail_rows);
+    // print_r($T8total);
     // echo "
"; + // exit; if ($T8total != $total_price) { + echo '1'; $difference = $T8total - $total_price; $salIncomeApplyDetail_rows[$count_rows_data - 1]['SPrice'] = $salIncomeApplyDetail_rows[$count_rows_data - 1]['SPrice'] - $difference; } @@ -706,7 +710,8 @@ function T8insert($data, $facilityno, $depId, $connT8) "DeptId" => "$depId", "IsPriceWithTax" => 1, "CU_ContractStart" => intval($beginDate), - "CU_ContractEnd" => intval($endDate) + "CU_ContractEnd" => intval($endDate), + "AddrId" => "$invoice_address" ]; $salIncomeApplyMaster = [ @@ -724,14 +729,12 @@ function T8insert($data, $facilityno, $depId, $connT8) echo '
';
     print_r(json_encode($API_body));
     echo '
'; - // exit(); // $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; //正式區 $api_url = "http://60.244.87.101:880/twWebAPI/V1/SALINCOMEAPPLY/PostERPData"; //測試區 $result = T8salIncomeApply($API_body, $api_url); // echo '
';
     // print_r($result);
     // echo '
'; - // exit(); if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { http_response_code(404); die('Error!:' . $result['ErrorMsg']); @@ -741,143 +744,142 @@ function T8insert($data, $facilityno, $depId, $connT8) function bonusCreate($data, $facilityno, $conn) { - try { - - require_once("../../bonus/maintance/maintaenance_contract_bonus.php"); - // require_once("../../bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); - - $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; - $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; - $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; - $payType = !empty($data['payType']) ? $data['payType'] : ''; - $contract_type = $data['contract_type']; //合約類別 - $status = 1; - $bonus_json = []; - $create_id = $data['user_id']; - $create_at = date('Y-m-d H:i:s'); - $contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; - $contract_kind = 3; - - $payment = [ - 'A40006' => 'annually', //年繳 - 'A40007' => 'quarterly', //季繳 - 'A40004' => 'bimonthly', // 雙月繳 - 'A40005' => 'semiannually', // 半年繳 - 'A40003' => 'monthly' //月繳 - ]; + // try { + + require_once("../../bonus/maintance/maintaenance_contract_bonus.php"); + // require_once("../../bonus/other/maintenance_longterm_contract_m1_free_charge_bonus_v2_1_1.php"); + + $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; + $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; + $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; + $payType = !empty($data['payType']) ? $data['payType'] : ''; + $contract_type = $data['contract_type']; //合約類別 + $status = 1; + $bonus_json = []; + $create_id = $data['user_id']; + $create_at = date('Y-m-d H:i:s'); + $contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; + $contract_kind = 3; + + $payment = [ + 'A40006' => 'annually', //年繳 + 'A40007' => 'quarterly', //季繳 + 'A40004' => 'bimonthly', // 雙月繳 + 'A40005' => 'semiannually', // 半年繳 + 'A40003' => 'monthly' //月繳 + ]; - $fail_arr = []; - $payDay = getNext25thDate($contract_begin_date); - foreach ($elevators as $key => $elevator) { - $facility_no = $facilityno[$key]; - $ver = $elevator['bonus_verson']; //獎金版本 - $payment_period = $payment[$payType]; //付款方式 - $elevator_list_price = !empty(($elevator['stand_price'])) ? intval($elevator['stand_price']) : ''; //牌價 - $fee_per_st = !empty($elevator['sold_price']) ? intval(round($elevator['sold_price'] / 1.05, 2)) : ''; //作翻契約金額 (不含稅) - $commission_fee = !empty($elevator['service_expense']) ? $elevator['service_expense'] : ''; //服務費(月/台) - $receivable_date_due = $payDay; //第一筆保養款項收回日 - $sales_id = $salesman; //營業人員 - $discount = $elevator['discount'] / 100; - $region_director_id = $elevator['manager']; - $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; - $maintain_months = intval($elevator['maintain_months']); - $years = $maintain_months / 12; - // echo $years; - if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; - if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; - if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; - if ($region_director_id == '') $fail_arr[] = '區處長為必填'; - if ($sales_id == '') $fail_arr[] = "契約人為必填"; - - if (COUNT($fail_arr) > 0) { - return $fail_arr; - break; - } - $renew_priceissue_bonus = []; - // $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; - ///////////////////////////////// - // 如果保養合約 大於一年 2.0版本 - // if (!empty($maintain_months)) { - // if ($ver == '2.1') { - // if ($maintain_months > 12 && $contract_type == 'new') { - // // 第一年為 "新簽約" - // $results = maintenance_contract_bonus_v2_1( - // $ver, - // $contract_type, - // $payment_period, - // $elevator_list_price, - // $fee_per_st, - // $commission_fee, - // $receivable_date_due, - // $sales_id, - // $region_director_id, - // $regular_contract_manger_id - // ); - // for ($i = 1; $i <= $years - 1; $i++) { - // $contract_type = 'renew_priceissue'; - // $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year")); - // // 第二年以上改 "續約" - // $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( - // $ver, - // $contract_type, - // $payment_period, - // $elevator_list_price, - // $fee_per_st, - // $commission_fee, - // $receivable_date_due_renew, - // $sales_id, - // $region_director_id, - // $regular_contract_manger_id - // ); - // } - // } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { - // // 超過一年的 "續約" - // for ($i = 0; $i < $years; $i++) { - // $contract_type = 'renew_priceissue'; - // $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( - // $ver, - // $contract_type, - // $payment_period, - // $elevator_list_price, - // $fee_per_st, - // $commission_fee, - // $receivable_date_due, - // $sales_id, - // $region_director_id, - // $regular_contract_manger_id - // ); - // } - // } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') { - // // 五年以上長約 - // $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( - // $ver, - // $contract_type, - // $payment_period, - // $maintain_months, - // $elevator_list_price, - // $fee_per_st, - // $commission_fee, - // $receivable_date_due, - // $sales_id, - // $region_director_id, - // $regular_contract_manger_id - // ); - // } else { - // $results = maintenance_contract_bonus_v2_1( - // $ver, - // $contract_type, - // $payment_period, - // $elevator_list_price, - // $fee_per_st, - // $commission_fee, - // $receivable_date_due, - // $sales_id, - // $region_director_id, - // $regular_contract_manger_id - // ); - // } - // } else - if ($ver == '2.0') { + $fail_arr = []; + $payDay = getNext25thDate($contract_begin_date); + foreach ($elevators as $key => $elevator) { + $facility_no = $facilityno[$key]; + $ver = $elevator['bonus_verson']; //獎金版本 + $payment_period = $payment[$payType]; //付款方式 + $elevator_list_price = !empty(($elevator['stand_price'])) ? intval($elevator['stand_price']) : 0; //牌價 + $fee_per_st = !empty($elevator['sold_price']) ? intval(round($elevator['sold_price'] / 1.05, 2)) : 0; //作翻契約金額 (不含稅) + $commission_fee = !empty($elevator['service_expense']) ? intval($elevator['service_expense']) : 0; //服務費(月/台) + $receivable_date_due = $payDay; //第一筆保養款項收回日 + $sales_id = $salesman; //營業人員 + $discount = $elevator['discount'] / 100; + $region_director_id = $elevator['manager']; + $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; + $maintain_months = intval($elevator['maintain_months']); + $years = $maintain_months / 12; + // echo $years; + if ($maintain_months == '') $fail_arr[] = "保養月費為必填"; + if ($fee_per_st == '') $fail_arr[] = "契約金額為必填"; + if ($elevator_list_price == '') $fail_arr[] = "牌價為必填"; + if ($region_director_id == '') $fail_arr[] = '區處長為必填'; + if ($sales_id == '') $fail_arr[] = "契約人為必填"; + + if (COUNT($fail_arr) > 0) { + return $fail_arr; + break; + } + $renew_priceissue_bonus = []; + $years = ($maintain_months % 12) == 0 ? $maintain_months / 12 : ''; + /////////////////////////////// + // 如果保養合約 大於一年 2.0版本 + if (!empty($maintain_months)) { + if ($ver == '2.1') { + if ($maintain_months > 12 && $contract_type == 'new') { + // 第一年為 "新簽約" + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + for ($i = 1; $i <= $years - 1; $i++) { + $contract_type = 'renew_priceissue'; + $receivable_date_due_renew = date("Y-m-d", strtotime("$receivable_date_due + $i year")); + // 第二年以上改 "續約" + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due_renew, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months > 12 && $contract_type == 'renew_priceissue') { + // 超過一年的 "續約" + for ($i = 0; $i < $years; $i++) { + $contract_type = 'renew_priceissue'; + $renew_priceissue_bonus[] = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($maintain_months >= 60 && $contract_type = 'longcontract_m1_free_charge') { + // 五年以上長約 + $results = maintenance_longterm_contract_m1_free_charge_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $maintain_months, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } else { + $results = maintenance_contract_bonus_v2_1( + $ver, + $contract_type, + $payment_period, + $elevator_list_price, + $fee_per_st, + $commission_fee, + $receivable_date_due, + $sales_id, + $region_director_id, + $regular_contract_manger_id + ); + } + } else if ($ver == '2.0') { $contract_years = $years > 2 ? 'above_two' : 'one'; // echo $contract_years; @@ -896,9 +898,9 @@ function bonusCreate($data, $facilityno, $conn) } // } ///////////////////////////////// - // echo "
";
-            // print_r($results);
-            // echo "
"; + echo "
";
+            print_r($results);
+            echo "
"; ///////////////////////////////// $bonus_json = [ 'contract_type' => $contract_type, @@ -943,26 +945,27 @@ function bonusCreate($data, $facilityno, $conn) $stmt->execute(); } } + $request = [ + "status" => "1", + "data" => "Success" + ]; + } else { + $request = [ + "status" => "2", + "data" => "create_bonus_error" + ]; } - $request = [ - "status" => "1", - "data" => "Success" - ]; - } else { - $request = [ - "status" => "2", - "data" => "create_bonus_error" - ]; } - // exit(); } - return $request; - // exit(); - } catch (PDOException $e) { - http_response_code(404); - echo $e->getMessage(); - die('Error!:' . $e->getMessage()); } + return $request; + // exit(); + // } catch (PDOException $e) { + // http_response_code(404); + // echo $e->getMessage(); + // die('Error!:' . $e->getMessage()); + // } + } // 計算保養開始日期的當月25號 diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php index 359cbbb0..d52f6bb3 100644 --- a/wms/contract/api/postNewContractData.php +++ b/wms/contract/api/postNewContractData.php @@ -8,6 +8,8 @@ require_once("../conn.php"); include_once("./getFacilityNo.php"); include_once("./getComboNo.php"); include_once("./upload_chk.php"); +include_once("./newElevatorBonus.php"); +include_once("./newElevatorT8.php"); ini_set('date.timezone', 'Asia/Taipei'); @@ -33,10 +35,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $area_no = $_POST['area_no']; $elevators = json_decode($_POST['elevators'], JSON_UNESCAPED_UNICODE); $elevators_detail_arr = json_decode($_POST['elevators_detail_arr'], JSON_UNESCAPED_UNICODE); - // echo "
";
-  // print_r($elevators_detail_arr);
-  // echo "
"; - // exit(); + + $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files_id = null; @@ -44,13 +44,14 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c if (empty($contractno)) $fail_arr[] = '合約號為必填'; if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; if (empty($manager)) $fail_arr[] = '負責人為必填'; - // if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; if (empty($case_name)) $fail_arr[] = '案名為必填'; if (empty($linkman)) $fail_arr[] = '聯絡人為必填'; if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; if (empty($address)) $fail_arr[] = '地址為必填'; if (empty($salesman)) $fail_arr[] = '營業員為必填'; // if (empty($elevators_detail_arr['qc'])) $fail_arr[] = '請選擇QC或官檢'; + // if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; + if (count($fail_arr) > 0) { header("HTTP/1.1 422 Unprocessable Entity"); echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); @@ -76,7 +77,10 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c echo json_encode($facilityno); // $bonus_result = BounsCount($_POST, $conn, $facilityno); - + // echo "
";
+  // print_r($bonus_result);
+  // echo "
"; + // exit(); // if (!empty($bonus_result) && $bonus_result['status'] == "2") { // $fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員'; // // header("HTTP/1.1 422 Unprocessable Entity"); @@ -85,7 +89,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c // } T8Insert($_POST, $facilityno, $connT8); - // exit(); + exit(); try { $conn->beginTransaction(); @@ -296,515 +300,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c } } -function T8Insert($data, $facilityno, $connT8) -{ - // try { - // 引入銷售訂單 API - require_once("./T8API.php"); - - $contractno = $data['contractno']; - $partyA = $data['customer']; - $phone = $data['lm_tel']; - $vat = $data['vat']; - $partyAaddress = $data['address']; - $user_id = $data['user_id']; - $salesman = $data['salesman']; - $createAt = date("Y-m-dH-i-s"); - - - $elevators = !empty($data['elevators_detail_arr']) ? json_decode($data['elevators_detail_arr'], true) : []; //電梯 - $pay_arr = !empty($data['pay_arr']) ? json_decode($data['pay_arr'], true) : []; //電梯 - - $createTime = str_replace('-', '', $createAt); - $signing_date = intval(str_replace("-", '', $data['signing_date'])); //簽訂日期 - // echo - // $pay_kind = [ - // '1' => '簽約', - // '2' => '二次款', - // '3' => '貨抵工地', - // '4' => '材料其他', - // '5' => '試車完工', //安裝完畢 - // '6' => '交車' //交車 - // ]; - - $pay_kind = [ - '1' => '簽約', - '2' => '二次款', - '3' => '貨抵工地', - '4' => '材料其他', - '5' => '試車完工', //安裝完畢 - '6' => '交車' //交車 - ]; - - $sql = "SELECT * FROM comCustomer - WHERE BizPartnerId = :BizPartnerId - "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - - // 新增客戶 table - if (empty($result)) { - // 若 客戶資料為空,新增一筆到 comCustomer - // 新增客戶資料 - - $sql = "INSERT INTO comBusinessPartner - (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId) - VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:CreatorId,:CreateTime,'10')"; - // $sql = "INSERT INTO comBusinessPartner - // (BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,CreatorId,CreateTime,BizPartnerTypeId) - // VALUES('$contractno','$partyA',1,'TW','$phone',99999999,'$vat', '$partyA','$partyAaddress','$user_id',$createTime,'10')"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->bindParam(':BizPartnerName', $partyA); //客戶名稱 - $stmt->bindParam(':WorkTelNo', $phone); - $stmt->bindParam(':TaxNo', $vat); - $stmt->bindParam(':EnterpriseName', $partyA); //企業名稱 - $stmt->bindParam(':ContactAddress', $partyAaddress); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - - - $sql = "INSERT INTO comCustomer - (OrgId,BizPartnerTypeId,ConditionId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId)VALUES - ('1000','10','0008','TWD',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime,'35')"; - // $sql = "INSERT INTO comCustomer - // (OrgId,BizPartnerTypeId,CurrId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime,InvoiceId) - // VALUES('1000','10','TWD','$contractno','$salesman','$user_id',1,'$partyAaddress','$createTime','35')"; - $stmt = $connT8->prepare($sql); - - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->bindParam(':PersonId', $salesman); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':InvoiceAddress', $partyAaddress); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - } else { - // 若客戶資料不為空,更新該客戶資訊。 - $sql = "UPDATE comCustomer SET - PersonId=:PersonId, - ConditionId='0008', - CurrId='TWD', - InvoiceAddress=:InvoiceAddress, - LastOperatorId=:LastOperatorId, - LastOperateTime=:LastOperateTime - WHERE BizPartnerId=:BizPartnerId - "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':PersonId', $salesman); - $stmt->bindParam(':InvoiceAddress', $partyAaddress); - $stmt->bindParam(':LastOperatorId', $user_id); - $stmt->bindParam(':LastOperateTime', $createTime); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); - - - $sql = "UPDATE comBusinessPartner SET - BizPartnerName=:BizPartnerName, - WorkTelNo=:WorkTelNo, - TaxNo=:TaxNo, - EnterpriseName=:EnterpriseName, - ContactAddress=:ContactAddress, - LastOperatorId=:LastOperatorId, - LastOperateTime=:LastOperateTime - WHERE BizPartnerId = :BizPartnerId - "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':BizPartnerName', $partyA); - $stmt->bindParam(':WorkTelNo', $phone); - $stmt->bindParam(':TaxNo', $vat); - $stmt->bindParam(':EnterpriseName', $partyA); - $stmt->bindParam(':ContactAddress', $partyAaddress); - // $stmt->bindParam(':EMail', $email); - $stmt->bindParam(':LastOperatorId', $user_id); - $stmt->bindParam(':LastOperateTime', $createTime); - $stmt->bindParam(':BizPartnerId', $contractno); - $stmt->execute(); - } - - $sql = "SELECT * FROM comProject WHERE ProjectId = :ProjectId"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':ProjectId', $contractno); - $stmt->execute(); - $resultProject = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (empty($resultProject)) { - //新增於 comProject。合約 table - $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,CreateTime,CreatorId,IsInUsed) - VALUES(:ProjectId,:ProjectName,'C0',:CreateTime,:CreatorId,1)"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':ProjectId', $contractno); - $stmt->bindParam(':ProjectName', $partyA); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->execute(); - } - $sql = "SELECT * FROM salSalesOrder WHERE BillNo = :BillNo"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':BillNo', $contractno); - $contractT8 = $stmt->fetch(PDO::FETCH_ASSOC); - if (empty($contractT8)) { - - foreach ($elevators as $index => $elevator) { - - $count = 1; - // 產品集成維護 - $facility_no = $facilityno[$index]; - $MaterialName = "$partyA($facility_no)"; - $contract_arrival_a = $elevator['contract_arrival_date']; - $sql = "SELECT * FROM comMaterial WHERE MaterialId = '$facility_no'"; - $stmt = $connT8->prepare($sql); - $stmt->execute(); - $MaterialisIt = $stmt->fetch(PDO::FETCH_ASSOC); - if (empty($MaterialisIt)) { - $sql = "INSERT INTO comMaterial - (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime,IsInUsed) - VALUES ('1000',:MaterialId,'10','A',:CreatorId,:CreateTime,1)"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facility_no); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - $sql = "INSERT INTO comMaterialGroup - (MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,IsInUsed,UnitId,CreatorId,CreateTime) - VALUES ('10',:MaterialId,:MaterialName,'A',1,'SET',:CreatorId,:CreateTime)"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facility_no); - $stmt->bindParam(':MaterialName', $MaterialName); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - - $sql = "INSERT INTO comMaterialPurchases - (Orgid,MaterialTypeId,MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime) - VALUES ('1000','10',:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)"; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facility_no); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - - $sql = "INSERT INTO plsMaterialPlanData - (PlanRangeId,MaterialId,FOrgId,MaterialTypeId,CreatorId,CreateTime,DefaultDemandOrg) VALUES - (1000,:MaterialId,1000,10,:CreatorId,:CreateTime,1000) - "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facility_no); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - - $sql = "INSERT INTO comMaterialSales - (OrgId,MAterialTypeId,MaterialId,CurrId,SUnitId,SupplyOrgId,CreatorId,CreateTime,IsInUsed) VALUES - (1000,10,:MaterialId,'TWD','SET',1000,:CreatorId,:CreateTime,1) - "; - $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facility_no); - $stmt->bindParam(':CreatorId', $user_id); - $stmt->bindParam(':CreateTime', $createTime); - $stmt->execute(); - } - // 階段收款資訊 - $salOrderStagePay_row = []; - $equipment_total = 0; - $install_total = 0; - $equipment_total = $pay_arr['equipment_total']; - $install_total = $pay_arr['install_total']; - $count_a = 0; - $count_month = 1; - foreach ($pay_arr['elevotor_pay_detail'] as $key => $detail) { - if ($detail['kind'] == 3) { - $PlanPayDate = $contract_arrival_a; - } else if ($detail['kind'] > 3) { - $PlanPayDate = date("Y-m-d", strtotime($contract_arrival_a . '+' . $count_month . ' month')); - $count_month++; - } else { - $PlanPayDate = $signing_date; - $count_a++; - if ($count_a == 1) { - $PlanPayDate = date("Y-m-d", strtotime($signing_date . '+' . $count_a . ' month')); - } - } - - $contract_arrival_date = intval(str_replace("-", '', $PlanPayDate)); //貨到工地日 - - $PayStage = $pay_kind[$detail['kind']]; - $PlanPercentage = intval($detail['pay_scale']) / 100; - $rows = [ - "PayStage" => "$PayStage", //收款階段 - "PlanPercentage" => $PlanPercentage, //計劃收款比例(%) - "PlanPayAmt" => $detail['amount'], //計劃收款金額 - "PlanPayDate" => $contract_arrival_date, //計劃收款日期 1.第一筆都是簽約日 - "BillNo" => "$contractno", - "RowCode" => $key + 1, - "RowNo" => $key + 1, - "UnWriteOffOAmount" => $detail['amount'] //未核銷金額 - ]; - $salOrderStagePay_row[] = $rows; - } - - // 設備 - $row1 = [ - "TaxId" => "ST005", - "RequirementDate" => $signing_date, //出貨日期 - "ConsignmentDate" => $signing_date, //發貨日期 - "BillNo" => "$contractno", //合約號 - "RowCode" => $count, //全部筆數排列 - "ItemType" => 1, - "MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) - "SUnitId" => "SET", - "SQuantity" => 1, //交易數量 - "SPrice" => $equipment_total, //交易價格 - "CU_MaterialId" => $facility_no - ]; - $count++; - // 安裝 - $row2 = [ - "TaxId" => "ST005", - "RequirementDate" => $signing_date, //出貨日期 - "ConsignmentDate" => $signing_date, //發貨日期 - "BillNo" => "$contractno", //合約號 - "RowCode" => $count, //全部筆數排列 - "ItemType" => 1, - "MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) - "SUnitId" => "SET", - "SQuantity" => 1, //交易數量 - "SPrice" => $install_total, //交易價格 - "CU_MaterialId" => $facility_no - ]; - $count++; - // 產品(作番) - $row3 = [ - "TaxId" => "ST005", - "RequirementDate" => $signing_date, //出貨日期 - "ConsignmentDate" => $signing_date, //發貨日期 - "BillNo" => "$contractno", //合約號 - "RowCode" => $count, //全部筆數排列 - "ItemType" => 0, - "MaterialId" => "$facility_no", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) - "SUnitId" => "SET", - "SQuantity" => 1, //交易數量 - "SPrice" => 0, //交易價格 - "CU_MaterialId" => $facility_no // 歸屬作番號 - ]; - $count++; - $SubOrder_row[] = $row1; - $SubOrder_row[] = $row2; - $SubOrder_row[] = $row3; - $count++; - } - $MainSalesOrder_row = [ - "BillNo" => "$contractno", //合約單號 - "BillDate" => $signing_date, //簽約日期 - "TypeId" => "SO", // - "FOrgId" => "1000", - "OrgId" => "1000", - "ModeId" => "M", // T汰改 M新梯 - "BizPartnerId" => "$contractno", //客戶代碼 - "CurrId" => "TWD", - "CurrOAmount" => 1, - "CurrLAmount" => 1, - "PersonId" => "$salesman", //業務人員 - "DueToId" => "$contractno", //債務方 - "TradeConditionId" => "", - "TaxId" => "ST005", - "CreditorCompId" => "1001", - "CreditorOrgId" => "1000", - "CreatorId" => "$user_id" - // "CompId" => "1001", - // "CreditorCurrOAmount" => 1, - // "CreditorCurrLAmount" => 1 - ]; - $MainSalesOrder = [ - "name" => "MainSalesOrder", - 'rows' => [$MainSalesOrder_row] - ]; - $SubOrder = [ - "name" => "SubOrder", - "rows" => $SubOrder_row - ]; - $salOrderStagePay = [ - "name" => "salOrderStagePay", - "rows" => $salOrderStagePay_row - ]; - - $API_body = []; - $API_body[] = $MainSalesOrder; - $API_body[] = $SubOrder; - $API_body[] = $salOrderStagePay; - echo "
";
-    print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE));
-    echo "
"; - // $api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData"; - // $api_url = "http://127.0.0.1:880/twWebAPI/V1/SALSALESORDER/PostERPData"; - $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALSALESORDER/PostERPData'; - - $result = T8salIncomeApply($API_body, $api_url); - echo "
";
-    print_r($result);
-    echo "
"; - if (!empty($result) && ($result['Status'] == 'Fails' || $result['Status'] == 'Error')) { - echo $result['ErrorMsg']; - } - } else { - echo '資料已新增過,請洽資訊人員'; - // exit(); - } - $connT8->commit(); - // } catch (PDOException $e) { - // $connT8->rollback(); - // header("HTTP/1.1 500 Internal Server Error"); - // die('Error!:' . $e->getMessage()); - // } -} - - -function BounsCount($data, $conn, $facilityno) -{ - try { - require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); - $dailyNecessities = [ - 'MAE100' => 'passenger', //小機房 - 'MAM200' => 'passenger', //無機房 - 'MAH100' => 'dumbwaiter', //小電梯 - 'MAQ100' => 'positive_drive', //強趨梯 - 'MAF100' => 'cargo', //貨梯 - 'MAP100' => 'flatbase', // 平台踢 - ]; - $contractType = [ - '1' => 'strategy_customer', - '2' => 'general_customer' - ]; - $signing_date = $data['signing_date']; - $bonus_v1_0_date = '2024-01-02'; - $bonus_v2_0_date = '2024-01-03'; - $contract_type = $data['contract_type']; - $total = $data['price_total']; - $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 - // $elevator_knockdown_price = $data['price_total']; //受價總額 - $elevators = json_decode($data['elevators_detail_arr'], true); - $contract_no = $data['contractno']; - $salesman = $data['salesman']; - $manager = $data['manager']; - $contract_kind = 1; - $create_id = $data['user_id']; - $create_at = date("Y-m-d H:i:s"); - $status = 1; - - - - - - $result_bonus = []; - $result_bonus_arr = []; - if ($signing_date <= $bonus_v1_0_date) { - $ver = '1.0'; - foreach ($elevators as $key => $elevator) { - - $elevator_knockdown_price = $elevator['elevator_price']; // 單台電梯售價 - $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price']; //牌價 - $result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); - $facility_no = $facilityno[$key]; - $bonus_json = [ - 'contract_type' => $type, - 'total' => $elevator_list_price, - 'fee_per_st' => $elevator_knockdown_price - ]; - if (!empty($result_bonus)) { - if ($result_bonus['result_status'] != "error") { - foreach ($result_bonus['bonus_array'] as $i => $result) { - $bonus_type = explode('-', $result['bonus_type']); - $pay_man_type = $bonus_type[0]; //發放類別 - $bonus_kind = $bonus_type[1]; - $amount = $result['bonus_amount']; //獎金水庫 - $bonus_receiver = $result['bonus_receiver']; //發放人員 - $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; - $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; - $bonus_json['bonus_kind'] = $bonus_kind; - $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); - $sql = "INSERT INTO bonus - (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES - ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') - "; - $stmt = $conn->prepare($sql); - $stmt->execute(); - } - $request = [ - "status" => "1", - "data" => "Success" - ]; - return $request; - } - $request = [ - "status" => "2", - "data" => "create_bonus_error" - ]; - return $request; - } - } - } else if ($signing_date >= $bonus_v2_0_date) { - $ver = '2.0'; - foreach ($elevators as $key => $elevator) { - $option_other_price = !empty($elevator['option_other_price']) ? intval($elevator['option_other_price']) : 0; - $elevator_type = $dailyNecessities[$elevator['spec']]; - $elevator_list_price = $option_other_price + $elevator['option_price'] + $elevator['elevator_price']; - $elevator_knockdown_price = $elevator['elevator_price']; - $commission_fee = $elevator['commission_fee']; - $result_bonus = elevator_new_deal_bonus_v2_0( - $ver, - $type, - $elevator_type, - $elevator_list_price, - $elevator_knockdown_price, - $salesman, - $manager - ); - $facility_no = $facilityno[$key]; - $bonus_json = [ - 'contract_type' => $type, - 'total' => $elevator_list_price, - 'fee_per_st' => $elevator_knockdown_price - ]; - if (!empty($result_bonus)) { - if ($result_bonus['result_status'] != "error") { - foreach ($result_bonus['bonus_array'] as $i => $result) { - $bonus_type = explode('-', $result['bonus_type']); - $pay_man_type = $bonus_type[0]; //發放類別 - $bonus_kind = $bonus_type[1]; - $amount = $result['bonus_amount']; //獎金水庫 - $bonus_receiver = $result['bonus_receiver']; //發放人員 - $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; - $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; - $bonus_json['bonus_kind'] = $bonus_kind; - $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); - $sql = "INSERT INTO bonus - (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES - ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') - "; - $stmt = $conn->prepare($sql); - $stmt->execute(); - } - } - $request = [ - "status" => "1", - "data" => "Success" - ]; - } else { - $request = [ - "status" => "2", - "data" => "create_bonus_error" - ]; - } - } - } - return $request; - } catch (PDOException $e) { - header("HTTP/1.1 500 Internal Server Error"); - die('Error!:' . $e->getMessage()); - } -} function do_wws_assign1($user_id, $form_id, $flow_code, $conn) { 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/api/test copy.json b/wms/contract/api/test copy.json index 7ef01c22..e5a503b1 100644 --- a/wms/contract/api/test copy.json +++ b/wms/contract/api/test copy.json @@ -1,43 +1,115 @@ [ { - "apply_key": "11111111", - "register_code": "B32510261185", - "elevator_brand": "1", - "elevator_kind": "E", - "spec": "MAH100", - "weight": "450", - "speed": "45.00", - "stop": "3", - "floors": "3", - "persons": "6", - "elevator_num": "0", - "useful_years": "106", - "last_check_date": "1", - "speed_governors_check_expense": "0", - "maintain_times": "1", - "is_m1_bundle": "N", - "maintainance": "B", - "maintain_months": "12", - "maintain_period": "1", - "stand_price": "1250.00", - "contract_price": "1250.00", - "sold_price": 1250, - "commission_expense": null, - "management_expense": null, - "annual_survey_expense": "0.00", - "service_expense": 0, - "cmstatus": "Y", - "updated_at": null, - "creater": null, - "created_at": "2024-02-26 15:24:23", - "discount": 100, - "latitude": "112", - "longitude": "11", - "takecertificatedate": "112", - "opendoor": "2PCO", - "useful_date": "113-01-01", - "bonus_verson": "2.0", - "manager": "M0029", - "regular_contract_manger_id": "M0054" + "name": "MainSalesOrder", + "rows": [ + { + "BillNo": "M24020076", + "BillDate": 20240306, + "TypeId": "SO", + "FOrgId": "1000", + "OrgId": "1000", + "ModeId": "M", + "BizPartnerId": "M24020076", + "CurrId": "TWD", + "CurrOAmount": 1, + "CurrLAmount": 1, + "PersonId": "M0073", + "DueToId": "M24020076", + "TradeConditionId": "", + "TaxId": "ST005", + "CreditorCompId": "1001", + "CreditorOrgId": "1000", + "CreatorId": "M0225" + } + ] + }, + { + "name": "SubOrder", + "rows": [ + { + "TaxId": "ST005", + "RequirementDate": 20240306, + "ConsignmentDate": 20240306, + "BillNo": "M24020076", + "RowCode": 1, + "ItemType": 1, + "MaterialId": "A40001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 910000, + "CU_MaterialId": "4MW00001" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240306, + "ConsignmentDate": 20240306, + "BillNo": "M24020076", + "RowCode": 2, + "ItemType": 1, + "MaterialId": "A40008", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 390000, + "CU_MaterialId": "4MW00001" + }, + { + "TaxId": "ST005", + "RequirementDate": 20240306, + "ConsignmentDate": 20240306, + "BillNo": "M24020076", + "RowCode": 3, + "ItemType": 0, + "MaterialId": "4MW00001", + "SUnitId": "SET", + "SQuantity": 1, + "SPrice": 0, + "CU_MaterialId": "4MW00001" + } + ] + }, + { + "name": "salOrderStagePay", + "rows": [ + { + "PayStage": "簽約", + "PlanPercentage": 0.2, + "PlanPayAmt": 260000, + "PlanPayDate": 20240406, + "BillNo": "M24020076", + "RowCode": 1, + "RowNo": 1, + "UnWriteOffOAmount": 260000 + }, + { + "PayStage": "貨抵工地", + "PlanPercentage": 0.5, + "PlanPayAmt": 650000, + "PlanPayDate": 20240306, + "BillNo": "M24020076", + "RowCode": 2, + "RowNo": 2, + "UnWriteOffOAmount": 650000 + }, + { + "PayStage": "試車完工", + "PlanPercentage": 0.2, + "PlanPayAmt": 260000, + "PlanPayDate": 20240306, + "BillNo": "M24020076", + "RowCode": 3, + "RowNo": 3, + "UnWriteOffOAmount": 260000 + }, + { + "PayStage": "交車", + "PlanPercentage": 0.1, + "PlanPayAmt": 130000, + "PlanPayDate": 20240306, + "BillNo": "M24020076", + "RowCode": 4, + "RowNo": 4, + "UnWriteOffOAmount": 130000 + } + ] } ] \ No newline at end of file diff --git a/wms/contract/conn.php b/wms/contract/conn.php index 5ac49515..3c94b8d1 100644 --- a/wms/contract/conn.php +++ b/wms/contract/conn.php @@ -34,11 +34,10 @@ try { //設定主動以警告的形式報錯 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8TEST", "M0225", "IFFBU1E="); // $connT8 = new PDO("sqlsrv:Server=10.10.145.2;Database=T8MASADA", "masada", "@m222222"); // $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8MASADA", "masada", "@m222222"); - + $connT8 = new PDO("sqlsrv:Server=220.130.203.251;Database=T8TEST", "M0225", "IFFBU1E="); if ($connT8) { $connT8->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 48d61379..0c5d4eb2 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -119,7 +119,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -134,7 +134,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - +
簽約日 - +

未填寫

合約開始時間契約成交價契約成交價(月)

未填寫

@@ -143,8 +143,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
發票抬頭 - - + + 統一編號/身分證 @@ -217,7 +217,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); 保養經理 - diff --git a/wms/contract/contract-renovate-input.php b/wms/contract/contract-renovate-input.php new file mode 100644 index 00000000..f965dc75 --- /dev/null +++ b/wms/contract/contract-renovate-input.php @@ -0,0 +1,471 @@ +prepare($sql_str); +$stmt->bindParam(":accounttype", $accounttype); +$stmt->execute(); +$persons = $stmt->fetchAll(PDO::FETCH_ASSOC); +$persons = array_map(function ($person) { + return [ + 'view' => $person['name'] . '-' . $person['accountid'], + 'value' => $person['accountid'], + 'name' => $person['name'] + ]; +}, $persons); +?> + + + + + + + + + + + + +
+
+ +
+ + + + + + + + + + + + + + + +
+

汰改合約入力

+
+ + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/wms/contract/js/alpine.js b/wms/contract/js/alpine.js index b493f514..e78edf69 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, @@ -841,7 +845,7 @@ const contractNewInput = () => { this.getContractDate(); } else if (this.step == 2) { if (this.data.nums <= 0) return alert('請填寫電梯數量!') - checkInput(); + // checkInput(); this.getElevatorsData(); } else if (this.step == 3) { this.getElevatorsData(); @@ -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: '', @@ -1227,7 +1232,6 @@ const contractInput = () => { form.append('phone', this.data.phone); form.append('email', this.data.email); form.append('mworker', this.data.mworker); - // form.append('mcycle', this.data.mcycle); form.append('salesman', this.data.salesman); form.append('contract_begin_date', this.data.contract_begin_date); form.append('contract_end_date', this.data.contract_end_date); @@ -1248,6 +1252,8 @@ const contractInput = () => { form.append('contract_type', this.data.contract_type); form.append('signing_date', this.data.signing_date); form.append('maintance_manager', this.data.maintance_manager); + form.append('invoice', this.data.invoice); + form.append('invoice_address', this.data.invoice_address); // 如果有附件檔案,可以逐一加入 for (var i = 0; i < this.data.files.length; i++) { @@ -1604,4 +1610,202 @@ const contractNewApply = () => { } } +} + +const renovateInput = () => { + return { + // init() { + // this.initSelect2(); + // }, + // initSelect2() { + // console.log(123); + // $('#renovate_type').select2(); + // }, + data: { + contract_no: 'T24030025', + customer: '', + salesman: '', + main_linkman: '', //負責人 + linkman: '', + lm_tel: '', + vat: '', + case_name: '', + address: '', + area_no: '', + manager: '', + price_total: '', //合約總價 + files: [], + contract_type: '1', + signing_date: '', + elevators: [], //電梯總類 + elevators_detail_arr: [], // 電梯台數 Array + payarr: ['', 1, 2, 6, 12], + 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, + isLoading: false, + nextStepFn() { + if (this.step == 1) { + if (this.data.contract_no == '') return alert('請輸入合約號'); + this.isLoading = true; + this.getContractData(); + } else if (this.step == 2) { + 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_month = 0 + for (let i = 0; i < this.data.paykind.length; i++) { + if (this.data.paykind[i] != '0') { + 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_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) { + this.getContractData(); + // console.log(this.step); + } + }, + preStepFn() { + this.step -= 1; + console.log(this.step); + }, + 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 => { + + }) + } + } } \ No newline at end of file