|
|
@ -16,76 +16,77 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST') { |
|
|
|
} |
|
|
|
//新梯簽回 |
|
|
|
if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'm') { |
|
|
|
try { |
|
|
|
$created_at = date('Y-m-d H:i:s'); |
|
|
|
$created_by = $_POST["user_id"]; |
|
|
|
$contractno = $_POST["contractno"]; |
|
|
|
$customer = $_POST["customer"]; |
|
|
|
$manager = $_POST["manager"]; |
|
|
|
$vat = $_POST["vat"]; |
|
|
|
$case_name = $_POST["case_name"]; |
|
|
|
$linkman = $_POST["linkman"]; |
|
|
|
$lm_tel = $_POST["lm_tel"]; |
|
|
|
$address = $_POST["address"]; |
|
|
|
$salesman = $_POST["salesman"]; |
|
|
|
$qc = $_POST["qc"]; |
|
|
|
$contracttype = $_POST["contracttype"]; |
|
|
|
$elevators_nums = $_POST['nums']; |
|
|
|
$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 "<pre>"; |
|
|
|
// print_r($elevators_detail_arr); |
|
|
|
// echo "</pre>"; |
|
|
|
// exit(); |
|
|
|
$files = !empty($_FILES['files']) ? $_FILES['files'] : null; |
|
|
|
$files_id = null; |
|
|
|
|
|
|
|
$fail_arr = []; |
|
|
|
// 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($qc)) $fail_arr[] = '請選擇QC或官檢'; |
|
|
|
// if (count($fail_arr) > 0) { |
|
|
|
// header("HTTP/1.1 422 Unprocessable Entity"); |
|
|
|
// echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); |
|
|
|
// exit(); |
|
|
|
// } |
|
|
|
//create facility table |
|
|
|
$createFacilityNo = new CreateFacilityNo(); |
|
|
|
$dailyNecessities = [ |
|
|
|
'MAE100' => 'X', //小機房客梯 |
|
|
|
'MAM200' => 'W', //無機房客梯 |
|
|
|
'MAH100' => 'H', //小電梯 |
|
|
|
'MAQ100' => 'Z', //強趨梯 |
|
|
|
'MAF100' => 'F', //貨梯 |
|
|
|
'MAP100' => 'B', //平台梯 |
|
|
|
]; |
|
|
|
$arr = []; |
|
|
|
// 建立作番號 |
|
|
|
foreach ($elevators_detail_arr as $elevator) { |
|
|
|
// $spec = explode('-', $elevator['item_spec']); |
|
|
|
$arr[] = $dailyNecessities[$elevator['spec']]; |
|
|
|
} |
|
|
|
$facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); |
|
|
|
echo json_encode($facilityno); |
|
|
|
|
|
|
|
$bonus_result = BounsCount($_POST, $conn, $facilityno); |
|
|
|
if (!empty($bonus_result) && $bonus_result['status'] == "2") { |
|
|
|
$fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員'; |
|
|
|
// header("HTTP/1.1 422 Unprocessable Entity"); |
|
|
|
echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); |
|
|
|
exit(); |
|
|
|
} |
|
|
|
|
|
|
|
T8Insert($_POST, $facilityno, $connT8); |
|
|
|
$created_at = date('Y-m-d H:i:s'); |
|
|
|
$created_by = $_POST["user_id"]; |
|
|
|
$contractno = $_POST["contractno"]; |
|
|
|
$customer = $_POST["customer"]; |
|
|
|
$manager = $_POST["manager"]; |
|
|
|
$vat = $_POST["vat"]; |
|
|
|
$case_name = $_POST["case_name"]; |
|
|
|
$linkman = $_POST["linkman"]; |
|
|
|
$lm_tel = $_POST["lm_tel"]; |
|
|
|
$address = $_POST["address"]; |
|
|
|
$salesman = $_POST["salesman"]; |
|
|
|
$contracttype = $_POST["contracttype"]; |
|
|
|
$elevators_nums = $_POST['nums']; |
|
|
|
$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 "<pre>"; |
|
|
|
// print_r($elevators_detail_arr); |
|
|
|
// echo "</pre>"; |
|
|
|
// exit(); |
|
|
|
$files = !empty($_FILES['files']) ? $_FILES['files'] : null; |
|
|
|
$files_id = null; |
|
|
|
|
|
|
|
$fail_arr = []; |
|
|
|
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 (count($fail_arr) > 0) { |
|
|
|
header("HTTP/1.1 422 Unprocessable Entity"); |
|
|
|
echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); |
|
|
|
exit(); |
|
|
|
} |
|
|
|
//create facility table |
|
|
|
$createFacilityNo = new CreateFacilityNo(); |
|
|
|
$dailyNecessities = [ |
|
|
|
'MAE100' => 'X', //小機房客梯 |
|
|
|
'MAM200' => 'W', //無機房客梯 |
|
|
|
'MAH100' => 'H', //小電梯 |
|
|
|
'MAQ100' => 'Z', //強趨梯 |
|
|
|
'MAF100' => 'F', //貨梯 |
|
|
|
'MAP100' => 'B', //平台梯 |
|
|
|
]; |
|
|
|
$arr = []; |
|
|
|
// 建立作番號 |
|
|
|
foreach ($elevators_detail_arr as $elevator) { |
|
|
|
// $spec = explode('-', $elevator['item_spec']); |
|
|
|
$arr[] = $dailyNecessities[$elevator['spec']]; |
|
|
|
} |
|
|
|
$facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); |
|
|
|
echo json_encode($facilityno); |
|
|
|
|
|
|
|
// $bonus_result = BounsCount($_POST, $conn, $facilityno); |
|
|
|
|
|
|
|
// if (!empty($bonus_result) && $bonus_result['status'] == "2") { |
|
|
|
// $fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員'; |
|
|
|
// // header("HTTP/1.1 422 Unprocessable Entity"); |
|
|
|
// echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); |
|
|
|
// exit(); |
|
|
|
// } |
|
|
|
|
|
|
|
T8Insert($_POST, $facilityno, $connT8); |
|
|
|
// exit(); |
|
|
|
try { |
|
|
|
$conn->beginTransaction(); |
|
|
|
|
|
|
|
//create account table |
|
|
@ -122,8 +123,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$site_manager = $value['manage']; |
|
|
|
$warehouseid = $value['warehouseid']; |
|
|
|
$sql = "INSERT INTO Wipwholestatus |
|
|
|
(contract_type,contractno,salesid,custom,accountid,site_manager,warehouseid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,area_no,address,contract_arrival_date,real_contract_arrival_date,qc_official_type,creater,create_at) VALUES |
|
|
|
('A',:contractno,:salesid,:custom,:accountid,:site_manager,:warehouseid,:facilityno,:weight,:numberofpassenger,:numberoffloor,:opentype,:speed,:facility_kind,:area_no,:address,:contract_arrival_date,:real_contract_arrival_date,:qc_official_type,:creater,:create_at)"; |
|
|
|
(contract_type,contractno,salesid,custom,accountid,site_manager,warehouseid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,area_no,address,contract_arrival_date,real_contract_arrival_date,qc_official_type,creater,create_at,desin_spec_verify) VALUES |
|
|
|
('A',:contractno,:salesid,:custom,:accountid,:site_manager,:warehouseid,:facilityno,:weight,:numberofpassenger,:numberoffloor,:opentype,:speed,:facility_kind,:area_no,:address,:contract_arrival_date,:real_contract_arrival_date,:qc_official_type,:creater,:create_at,1)"; |
|
|
|
// $sql = "INSERT INTO Wipwholestatus |
|
|
|
// (contract_type,contractno,salesid,custom,accountid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,address,contract_arrival_date,qc_official_type,creater,create_at) VALUES |
|
|
|
// ('A','$contractno','$salesman','$customer','$customer','$facilityno','$weight','$person','$floor','$open','$speed','$facility_kind','$address','$contract_arrival_date','$qc','$created_by','$created_at')"; |
|
|
@ -153,6 +154,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
// echo "<pre>"; |
|
|
|
// print_r($lastId); |
|
|
|
// echo "</pre>"; |
|
|
|
// exit; |
|
|
|
if (!empty($lastId)) { |
|
|
|
echo '123'; |
|
|
|
// 寫入待簽程狀態 A (營業) |
|
|
@ -180,111 +182,112 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$stmt->execute(); |
|
|
|
|
|
|
|
// create table schedule |
|
|
|
$contract_begin_date = ''; |
|
|
|
$contract_end_date = ''; // 一年 |
|
|
|
$comboNo = new CreateComboNo('em', $contract_begin_date, $contract_end_date); |
|
|
|
$comboArr = json_decode($comboNo->getComboNo(), true); |
|
|
|
foreach ($comboArr as $combo) { |
|
|
|
$sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)'; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(':contractno', $contractno); |
|
|
|
$stmt->bindParam(':facilityno', $facility_no); |
|
|
|
$stmt->bindParam(':combono', $combo[0]); |
|
|
|
$stmt->bindParam(':repairerid', $repairerid); |
|
|
|
$stmt->bindParam(':repairername', $repairername); |
|
|
|
$stmt->bindParam(':duedate', $combo[1]); |
|
|
|
$stmt->bindParam(':creater', $creater); |
|
|
|
$stmt->bindParam(':create_at', $create_at); |
|
|
|
$result = $stmt->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(":accountid", $salesman); |
|
|
|
$stmt->execute(); |
|
|
|
$saleman = $stmt->fetch(PDO::FETCH_ASSOC); |
|
|
|
$salesman_name = $saleman['name']; |
|
|
|
if (!empty($files)) { |
|
|
|
$englisharr = range('a', 'z'); |
|
|
|
$files = $_FILES['files']; |
|
|
|
$newfiles = []; |
|
|
|
foreach ($files as $file) { |
|
|
|
$i = 0; //新陣列的索引編號 |
|
|
|
foreach ($file as $key => $val) { |
|
|
|
$newfiles[$i]['name'] = $files['name'][$key]; |
|
|
|
$newfiles[$i]['type'] = $files['type'][$key]; |
|
|
|
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; |
|
|
|
$newfiles[$i]['error'] = $files['error'][$key]; |
|
|
|
$newfiles[$i]['size'] = $files['size'][$key]; |
|
|
|
$i++; |
|
|
|
} //foreach 第2層 end |
|
|
|
} |
|
|
|
$max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) |
|
|
|
$allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 |
|
|
|
$path = '../images/contracts/'; |
|
|
|
if (!file_exists($path)) { |
|
|
|
mkdir($path); |
|
|
|
} |
|
|
|
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 |
|
|
|
$datetime = (string)date('YmdHis'); |
|
|
|
$files_id = 'm' . $datetime; // 保養=>b + 日期時間 |
|
|
|
foreach ($newfiles as $key => $file) { |
|
|
|
$randNum = rand(1000, 9999); |
|
|
|
$randEnglish = $englisharr[rand(0, 25)]; |
|
|
|
$file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; |
|
|
|
$msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); |
|
|
|
if ($msg == 1) { |
|
|
|
$msg = '檔案傳送成功!'; |
|
|
|
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(':files_id', $files_id); |
|
|
|
$stmt->bindParam(':file_name', $file_name); |
|
|
|
$stmt->bindParam(':file_mime', $file['type']); |
|
|
|
$stmt->bindParam(':file_size', $file['size']); |
|
|
|
$stmt->bindParam(':created_at', $created_at); |
|
|
|
$stmt->bindParam(':created_by', $created_by); |
|
|
|
$stmt->execute(); |
|
|
|
} else { |
|
|
|
throw new PDOException('檔案上傳失敗:' . $msg); |
|
|
|
// $contract_begin_date = ''; |
|
|
|
// $contract_end_date = ''; // 一年 |
|
|
|
// $comboNo = new CreateComboNo('em', $contract_begin_date, $contract_end_date); |
|
|
|
// $comboArr = json_decode($comboNo->getComboNo(), true); |
|
|
|
// foreach ($comboArr as $combo) { |
|
|
|
// $sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)'; |
|
|
|
// $stmt = $conn->prepare($sql_str); |
|
|
|
// $stmt->bindParam(':contractno', $contractno); |
|
|
|
// $stmt->bindParam(':facilityno', $facility_no); |
|
|
|
// $stmt->bindParam(':combono', $combo[0]); |
|
|
|
// $stmt->bindParam(':repairerid', $repairerid); |
|
|
|
// $stmt->bindParam(':repairername', $repairername); |
|
|
|
// $stmt->bindParam(':duedate', $combo[1]); |
|
|
|
// $stmt->bindParam(':creater', $creater); |
|
|
|
// $stmt->bindParam(':create_at', $create_at); |
|
|
|
// $result = $stmt->execute(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(":accountid", $salesman); |
|
|
|
$stmt->execute(); |
|
|
|
$saleman = $stmt->fetch(PDO::FETCH_ASSOC); |
|
|
|
$salesman_name = $saleman['name']; |
|
|
|
if (!empty($files)) { |
|
|
|
$englisharr = range('a', 'z'); |
|
|
|
$files = $_FILES['files']; |
|
|
|
$newfiles = []; |
|
|
|
foreach ($files as $file) { |
|
|
|
$i = 0; //新陣列的索引編號 |
|
|
|
foreach ($file as $key => $val) { |
|
|
|
$newfiles[$i]['name'] = $files['name'][$key]; |
|
|
|
$newfiles[$i]['type'] = $files['type'][$key]; |
|
|
|
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; |
|
|
|
$newfiles[$i]['error'] = $files['error'][$key]; |
|
|
|
$newfiles[$i]['size'] = $files['size'][$key]; |
|
|
|
$i++; |
|
|
|
} //foreach 第2層 end |
|
|
|
} |
|
|
|
$msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '<br/>'; |
|
|
|
$src_name = $path . $file['name']; |
|
|
|
if (file_exists($src_name)) { |
|
|
|
//副檔名 |
|
|
|
$extname = pathinfo($src_name, PATHINFO_EXTENSION); |
|
|
|
//主檔名 |
|
|
|
$basename = basename($src_name, '.' . $extname); |
|
|
|
$max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) |
|
|
|
$allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 |
|
|
|
$path = '../images/contracts/'; |
|
|
|
if (!file_exists($path)) { |
|
|
|
mkdir($path); |
|
|
|
} |
|
|
|
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 |
|
|
|
$datetime = (string)date('YmdHis'); |
|
|
|
$files_id = 'm' . $datetime; // 保養=>b + 日期時間 |
|
|
|
foreach ($newfiles as $key => $file) { |
|
|
|
$randNum = rand(1000, 9999); |
|
|
|
$randEnglish = $englisharr[rand(0, 25)]; |
|
|
|
$file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; |
|
|
|
$msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); |
|
|
|
if ($msg == 1) { |
|
|
|
$msg = '檔案傳送成功!'; |
|
|
|
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(':files_id', $files_id); |
|
|
|
$stmt->bindParam(':file_name', $file_name); |
|
|
|
$stmt->bindParam(':file_mime', $file['type']); |
|
|
|
$stmt->bindParam(':file_size', $file['size']); |
|
|
|
$stmt->bindParam(':created_at', $created_at); |
|
|
|
$stmt->bindParam(':created_by', $created_by); |
|
|
|
$stmt->execute(); |
|
|
|
} else { |
|
|
|
throw new PDOException('檔案上傳失敗:' . $msg); |
|
|
|
} |
|
|
|
$msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '<br/>'; |
|
|
|
$src_name = $path . $file['name']; |
|
|
|
if (file_exists($src_name)) { |
|
|
|
//副檔名 |
|
|
|
$extname = pathinfo($src_name, PATHINFO_EXTENSION); |
|
|
|
//主檔名 |
|
|
|
$basename = basename($src_name, '.' . $extname); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
$files = null; |
|
|
|
} |
|
|
|
} else { |
|
|
|
$files = null; |
|
|
|
} |
|
|
|
|
|
|
|
$sql_str = "INSERT INTO contract_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by, qc_official_type) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by, :qc)"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(":contract_no", $contractno); |
|
|
|
$stmt->bindParam(":customer", $customer); |
|
|
|
$stmt->bindParam(":manager", $manager); |
|
|
|
$stmt->bindParam(":vat", $vat); |
|
|
|
$stmt->bindParam(":case_name", $case_name); |
|
|
|
$stmt->bindParam(":linkman", $linkman); |
|
|
|
$stmt->bindParam(":lm_tel", $lm_tel); |
|
|
|
$stmt->bindParam(":address", $address); |
|
|
|
$stmt->bindParam(":salesman", $salesman); |
|
|
|
$stmt->bindParam(":salesman_name", $salesman_name); |
|
|
|
$stmt->bindParam(":files_id", $files_id); |
|
|
|
$stmt->bindParam(":created_at", $created_at); |
|
|
|
$stmt->bindParam(":created_by", $created_by); |
|
|
|
$stmt->bindParam(":qc", $qc); |
|
|
|
$stmt->execute(); |
|
|
|
$sql_str = "INSERT INTO contract_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by)"; |
|
|
|
$stmt = $conn->prepare($sql_str); |
|
|
|
$stmt->bindParam(":contract_no", $contractno); |
|
|
|
$stmt->bindParam(":customer", $customer); |
|
|
|
$stmt->bindParam(":manager", $manager); |
|
|
|
$stmt->bindParam(":vat", $vat); |
|
|
|
$stmt->bindParam(":case_name", $case_name); |
|
|
|
$stmt->bindParam(":linkman", $linkman); |
|
|
|
$stmt->bindParam(":lm_tel", $lm_tel); |
|
|
|
$stmt->bindParam(":address", $address); |
|
|
|
$stmt->bindParam(":salesman", $salesman); |
|
|
|
$stmt->bindParam(":salesman_name", $salesman_name); |
|
|
|
$stmt->bindParam(":files_id", $files_id); |
|
|
|
$stmt->bindParam(":created_at", $created_at); |
|
|
|
$stmt->bindParam(":created_by", $created_by); |
|
|
|
// $stmt->bindParam(":qc", $qc); |
|
|
|
$stmt->execute(); |
|
|
|
|
|
|
|
|
|
|
|
$result = $conn->commit(); |
|
|
|
if ($result) { |
|
|
|
header("HTTP/1.1 201 Created"); |
|
|
|
$result = $conn->commit(); |
|
|
|
if ($result) { |
|
|
|
header("HTTP/1.1 201 Created"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (PDOException $e) { |
|
|
|
$conn->rollback(); |
|
|
@ -295,109 +298,110 @@ 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 |
|
|
|
// 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); |
|
|
|
$stmt = $connT8->prepare($sql); |
|
|
|
$stmt->bindParam(':BizPartnerId', $contractno); |
|
|
|
$stmt->execute(); |
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC); |
|
|
|
|
|
|
|
// 新增客戶 table |
|
|
|
if (empty($result)) { |
|
|
|
// 若 客戶資料為空,新增一筆到 comCustomer |
|
|
|
// 新增客戶資料 |
|
|
|
|
|
|
|
// 新增客戶 table |
|
|
|
if (empty($result)) { |
|
|
|
// 若 客戶資料為空,新增一筆到 comCustomer |
|
|
|
// 新增客戶資料 |
|
|
|
$sql = "INSERT INTO comBusinessPartner |
|
|
|
$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 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','TWD','0008',: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); |
|
|
|
$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 |
|
|
|
$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(); |
|
|
|
$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 |
|
|
|
$sql = "UPDATE comBusinessPartner SET |
|
|
|
BizPartnerName=:BizPartnerName, |
|
|
|
WorkTelNo=:WorkTelNo, |
|
|
|
TaxNo=:TaxNo, |
|
|
@ -407,47 +411,54 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
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(); |
|
|
|
} |
|
|
|
$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"; |
|
|
|
$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(); |
|
|
|
$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)"; |
|
|
|
} |
|
|
|
$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->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']; |
|
|
|
|
|
|
|
$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)"; |
|
|
@ -456,7 +467,6 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$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)"; |
|
|
@ -495,155 +505,159 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$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')); |
|
|
|
} |
|
|
|
} |
|
|
|
// 階段收款資訊 |
|
|
|
$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 // 歸屬作番號 |
|
|
|
$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'] //未核銷金額 |
|
|
|
]; |
|
|
|
$count++; |
|
|
|
$SubOrder_row[] = $row1; |
|
|
|
$SubOrder_row[] = $row2; |
|
|
|
$SubOrder_row[] = $row3; |
|
|
|
$count++; |
|
|
|
$salOrderStagePay_row[] = $rows; |
|
|
|
} |
|
|
|
$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" => "", |
|
|
|
|
|
|
|
// 設備 |
|
|
|
$row1 = [ |
|
|
|
"TaxId" => "ST005", |
|
|
|
"CreditorCompId" => "1001", |
|
|
|
"CreditorOrgId" => "1000", |
|
|
|
"CreatorId" => "$user_id" |
|
|
|
// "CompId" => "1001", |
|
|
|
// "CreditorCurrOAmount" => 1, |
|
|
|
// "CreditorCurrLAmount" => 1 |
|
|
|
]; |
|
|
|
$MainSalesOrder = [ |
|
|
|
"name" => "MainSalesOrder", |
|
|
|
'rows' => [$MainSalesOrder_row] |
|
|
|
"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 |
|
|
|
]; |
|
|
|
$SubOrder = [ |
|
|
|
"name" => "SubOrder", |
|
|
|
"rows" => $SubOrder_row |
|
|
|
$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 |
|
|
|
]; |
|
|
|
$salOrderStagePay = [ |
|
|
|
"name" => "salOrderStagePay", |
|
|
|
"rows" => $salOrderStagePay_row |
|
|
|
$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 "<pre>"; |
|
|
|
print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE)); |
|
|
|
echo "</pre>"; |
|
|
|
$api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData"; |
|
|
|
|
|
|
|
$result = T8salIncomeApply($API_body, $api_url); |
|
|
|
// echo "<pre>"; |
|
|
|
// print_r($result); |
|
|
|
// echo "</pre>"; |
|
|
|
if ($result['Status'] == 'Fails' || $result['Status'] == 'Error') { |
|
|
|
echo $result['ErrorMsg']; |
|
|
|
} |
|
|
|
} else { |
|
|
|
echo '資料已新增過,請洽資訊人員'; |
|
|
|
$API_body = []; |
|
|
|
$API_body[] = $MainSalesOrder; |
|
|
|
$API_body[] = $SubOrder; |
|
|
|
$API_body[] = $salOrderStagePay; |
|
|
|
echo "<pre>"; |
|
|
|
print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE)); |
|
|
|
echo "</pre>"; |
|
|
|
// $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 "<pre>"; |
|
|
|
print_r($result); |
|
|
|
echo "</pre>"; |
|
|
|
if (!empty($result) && ($result['Status'] == 'Fails' || $result['Status'] == 'Error')) { |
|
|
|
echo $result['ErrorMsg']; |
|
|
|
} |
|
|
|
$connT8->commit(); |
|
|
|
} catch (PDOException $e) { |
|
|
|
$connT8->rollback(); |
|
|
|
header("HTTP/1.1 500 Internal Server Error"); |
|
|
|
die('Error!:' . $e->getMessage()); |
|
|
|
} else { |
|
|
|
echo '資料已新增過,請洽資訊人員'; |
|
|
|
// exit(); |
|
|
|
} |
|
|
|
$connT8->commit(); |
|
|
|
// } catch (PDOException $e) { |
|
|
|
// $connT8->rollback(); |
|
|
|
// header("HTTP/1.1 500 Internal Server Error"); |
|
|
|
// die('Error!:' . $e->getMessage()); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -698,7 +712,6 @@ function BounsCount($data, $conn, $facilityno) |
|
|
|
'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) { |
|
|
@ -748,9 +761,6 @@ function BounsCount($data, $conn, $facilityno) |
|
|
|
$salesman, |
|
|
|
$manager |
|
|
|
); |
|
|
|
// echo '<pre>'; |
|
|
|
// print_r($result_bonus); |
|
|
|
// echo '</pre>'; |
|
|
|
$facility_no = $facilityno[$key]; |
|
|
|
$bonus_json = [ |
|
|
|
'contract_type' => $type, |
|
|
|