|
|
@ -16,7 +16,7 @@ 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"]; |
|
|
@ -28,7 +28,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$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']; |
|
|
@ -42,21 +41,21 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$files_id = null; |
|
|
|
|
|
|
|
$fail_arr = []; |
|
|
|
// if (empty($contractno)) $fail_arr[] = '合約號為必填'; |
|
|
|
// if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; |
|
|
|
// if (empty($manager)) $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(); |
|
|
|
// } |
|
|
|
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 = [ |
|
|
@ -76,16 +75,18 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$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(); |
|
|
|
} |
|
|
|
// $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(); |
|
|
|
// 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,24 +182,24 @@ 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(); |
|
|
|
} |
|
|
|
} |
|
|
|
// $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(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -263,7 +265,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$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)"; |
|
|
|
$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); |
|
|
@ -278,7 +280,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
$stmt->bindParam(":files_id", $files_id); |
|
|
|
$stmt->bindParam(":created_at", $created_at); |
|
|
|
$stmt->bindParam(":created_by", $created_by); |
|
|
|
$stmt->bindParam(":qc", $qc); |
|
|
|
// $stmt->bindParam(":qc", $qc); |
|
|
|
$stmt->execute(); |
|
|
|
|
|
|
|
|
|
|
@ -286,6 +288,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
if ($result) { |
|
|
|
header("HTTP/1.1 201 Created"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (PDOException $e) { |
|
|
|
$conn->rollback(); |
|
|
|
header("HTTP/1.1 500 Internal Server Error"); |
|
|
@ -295,7 +298,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c |
|
|
|
|
|
|
|
function T8Insert($data, $facilityno, $connT8) |
|
|
|
{ |
|
|
|
try { |
|
|
|
// try { |
|
|
|
// 引入銷售訂單 API |
|
|
|
require_once("./T8API.php"); |
|
|
|
|
|
|
@ -345,6 +348,7 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
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')"; |
|
|
@ -363,10 +367,9 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$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')"; |
|
|
|
(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')"; |
|
|
@ -379,10 +382,11 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$stmt->bindParam(':CreateTime', $createTime); |
|
|
|
$stmt->execute(); |
|
|
|
} else { |
|
|
|
// // 若客戶資料不為空,更新該客戶資訊。 |
|
|
|
// 若客戶資料不為空,更新該客戶資訊。 |
|
|
|
$sql = "UPDATE comCustomer SET |
|
|
|
PersonId=:PersonId, |
|
|
|
ConditionId='0008', |
|
|
|
CurrId='TWD', |
|
|
|
InvoiceAddress=:InvoiceAddress, |
|
|
|
LastOperatorId=:LastOperatorId, |
|
|
|
LastOperateTime=:LastOperateTime |
|
|
@ -441,13 +445,20 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$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)"; |
|
|
@ -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,6 +505,7 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
$stmt->bindParam(':CreatorId', $user_id); |
|
|
|
$stmt->bindParam(':CreateTime', $createTime); |
|
|
|
$stmt->execute(); |
|
|
|
} |
|
|
|
// 階段收款資訊 |
|
|
|
$salOrderStagePay_row = []; |
|
|
|
$equipment_total = 0; |
|
|
@ -626,24 +637,27 @@ function T8Insert($data, $facilityno, $connT8) |
|
|
|
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 = "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 ($result['Status'] == 'Fails' || $result['Status'] == 'Error') { |
|
|
|
echo "<pre>"; |
|
|
|
print_r($result); |
|
|
|
echo "</pre>"; |
|
|
|
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()); |
|
|
|
} |
|
|
|
// } 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, |
|
|
|