You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

258 lines
8.1 KiB

<?php
// {
// "BillNo": "Z001", //合約單號
// "BillDate": 20210420, //簽約日期
// "TypeId": "SO", //
// "FOrgId": "1000",
// "OrgId": "1000",
// "ModeId": "T", // T汰改 M新梯
// "BizPartnerId": "M0225", //創建人ID
// "CurrId": "TWD",
// "CurrOAmount": 1,
// "CurrLAmount": 1,
// "PersonId": "M0225", //業務人員
// "DueToId": "512", //業務部門
// "TradeConditionId": "",
// "TaxId": "ST005",
// "CreditorCompId": "1000",
// "CreditorOrgId": "1000",
// "CreditorCurrOAmount": 1,
// "CreditorCurrLAmount": 1,
// "CompId": "1000"
// }
// ]
// },
// {
// //salSalesOrderDetail
// "name": "SubOrder",
// "rows": [
// {
// "SupplyCompId": "1001",
// "SupplyOrgId": "1000",
// "TaxId": "ST005",
// "RequirementDate": 20210420, //出貨日期
// "ConsignmentDate": 20210420, //發貨日期
// "DispatchCompId": "1001",
// "DispatchOrgId": "1000",
// "BillNo": "Z001", //合約號
// "RowCode": 1, //全部筆數排列
// "ItemType": 0,
// "MaterialId": "Z001", //作番號
// "SUnitId": "SET",
// "SQuantity": 1, //交易數量
// "SPrice": 1 //交易價格
// }
// ]
// },
// {
// "name": "salOrderStagePay",
// "rows": [
// {
// "BillNo": "",
// "RowCode": "",
// "RowNo": "",
// "PayStage": "ST003", //收款階段
// "PlanPercentage": "Z001", //計劃收款比例(%)
// "PlanPayAmt": 1, //計劃收款金額
// "PlanPayDate": 1, //計劃收款日期 1.第一筆都是簽約日
// "UnWriteOffOAmount": 1 //未核銷金額
// }
// ]
// }
// ]
require_once("../../T8_Authorization_from_bpm.php");
$api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData";
$validation = get_Auth();
$header = [
"CHI_Authorization :" . $validation,
"GroupId:MASADA"
];
$url = "https://erp.masada.com.tw:780/twWebAPI/V1/GLFEEWRITEOFF/DeleteERPData?pkValue=1000,M24020076";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
// 若 API 傳入失敗。
if ($result['Status'] == 'Erroe') {
echo 'API傳入失敗,' . $result['ErrorMsg'];
print_r($result);
} else {
// print_r($result);
print_r($result);
}
print_r($result);
}
curl_close($ch);
exit();
$contract_no = "M24020003";
// $contract_no = "M24010109";
$MainSalesOrder_row = [
"BillNo" => "$contract_no", //合約單號
"BillDate" => 20210420, //簽約日期
"TypeId" => "SO", //
"FOrgId" => "1000",
"OrgId" => "1000",
"ModeId" => "M", // T汰改 M新梯
"BizPartnerId" => "$contract_no", //客戶代碼
"CurrId" => "TWD",
"CurrOAmount" => 1,
"CurrLAmount" => 1,
"PersonId" => "M0177", //業務人員
"DueToId" => "$contract_no", //債務方
"TradeConditionId" => "",
"TaxId" => "ST005",
"CreditorCompId" => "1001",
"CreditorOrgId" => "1000",
"CreatorId" => "M0225"
];
// //salSalesOrderDetail
// $SubOrder_row = [];
for ($i = 0; $i < 3; $i++) {
if ($i == 0) {
$row = [
// "SupplyCompId" => "1001",
// "SupplyOrgId" => "1000",
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
// "DispatchCompId" => "1001",
// "DispatchOrgId" => "1000",
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 100000 //交易價格
];
}
if ($i == 1) {
$row = [
// "SupplyCompId" => "1001",
// "SupplyOrgId" => "1000",
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
// "DispatchCompId" => "1001",
// "DispatchOrgId" => "1000",
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 1,
"MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 650000 //交易價格
];
}
if ($i == 2) {
$row = [
"TaxId" => "ST005",
"RequirementDate" => 20210420, //出貨日期
"ConsignmentDate" => 20210420, //發貨日期
"BillNo" => "$contract_no", //合約號
"RowCode" => $i, //全部筆數排列
"ItemType" => 0,
"MaterialId" => "4MH00669", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番)
"SUnitId" => "SET",
"SQuantity" => 1, //交易數量
"SPrice" => 0 //交易價格
];
}
$SubOrder_row[] = $row;
}
$salOrderStagePay_row = [];
$roww = [
"PayStage" => "簽約", //收款階段
"PlanPercentage" => 0.5, //計劃收款比例(%)
"PlanPayAmt" => 375000, //計劃收款金額
"PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日
"BillNo" => "$contract_no",
"RowCode" => 1,
"RowNo" => 1,
"UnWriteOffOAmount" => 375000 //未核銷金額
];
$roww2 = [
"PayStage" => "貨抵工地",
"PlanPercentage" => 0.5,
"PlanPayAmt" => 375000,
"PlanPayDate" => 20240101,
"BillNo" => "$contract_no",
"RowCode" => 2,
"RowNo" => 2,
"UnWriteOffOAmount" => 375000
];
$salOrderStagePay_row[] = $roww;
$salOrderStagePay_row[] = $roww2;
$MainSalesOrder = [
"name" => "MainSalesOrder",
'rows' => [$MainSalesOrder_row]
];
$SubOrder = [
"name" => "SubOrder",
"rows" => $SubOrder_row
];
$salOrderStagePay = [
"name" => "salOrderStagePay",
"rows" => $salOrderStagePay_row
];
$APIbody = [];
$APIbody[] = $MainSalesOrder;
$APIbody[] = $SubOrder;
$APIbody[] = $salOrderStagePay;
// $data = file_get_contents('test copy.json');
// $arr = json_decode($data, true);
// echo "<pre>";
// print_r($data);
// echo "</pre>";
echo "<pre>";
print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE));
echo "</pre>";
// exit();
$header = [
"CHI_Authorization :" . $validation,
"GroupId:TEST"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($APIbody, JSON_UNESCAPED_UNICODE));
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
// 若 API 傳入失敗。
if ($result['Status'] == 'Erroe') {
echo 'API傳入失敗,' . $result['ErrorMsg'];
print_r($result);
} else {
// print_r($result);
print_r($result);
}
print_r($result);
}
curl_close($ch);