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.
180 lines
5.7 KiB
180 lines
5.7 KiB
<?php
|
|
include "./header.php";
|
|
|
|
$account_id = "M0122";
|
|
$password = "90493119";
|
|
$GroupId = 'TEST';
|
|
$validation = get_Auth($GroupId, $account_id, $password);
|
|
|
|
|
|
function get_Auth($groupId, $accountId, $password)
|
|
{
|
|
$user_id = $accountId;
|
|
$user_password = $password;
|
|
$api_key = "A21181F1EE4966D3";
|
|
$GroupId = $groupId;
|
|
|
|
// 伺服器時間扣兩分鐘會比較穩定
|
|
// $now = gmdate("YmdHis");
|
|
$now = gmdate("YmdHis", strtotime("-2 minutes"));
|
|
|
|
$data = "$user_id." . $now;
|
|
$sign = hash_hmac('SHA256', $data, $api_key, false);
|
|
|
|
// 各種API連線網址
|
|
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
|
|
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
|
|
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
|
|
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
|
|
|
|
$headerParam = [
|
|
"UserId: $user_id",
|
|
"Pwd: $user_password",
|
|
"TimestampUTC: $now",
|
|
"Sign: $sign",
|
|
"GroupId: $GroupId"
|
|
];
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $apiurl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam);
|
|
|
|
$response = curl_exec($ch);
|
|
if ($response === false) {
|
|
echo 'Curl error: ' . curl_error($ch);
|
|
} else {
|
|
$result = json_decode($response, true);
|
|
if ($result['Status'] == 'Success')
|
|
return $result['Data']['CHI_Authorization'];
|
|
if ($result['Status'] == 'Error')
|
|
return $result['ErrorMsg'];
|
|
|
|
print_r($result);
|
|
}
|
|
|
|
curl_close($ch);
|
|
}
|
|
|
|
|
|
function get_purchaseApply_index($conn,$add_sql)
|
|
{
|
|
$sql_purchaseApply = "SELECT main.BillNo,
|
|
main.BillDate,
|
|
main.BizPartnerId,
|
|
COALESCE(Biz.BizPartnerName, '') AS BizPartnerName,
|
|
main.IsPriceWithTax,
|
|
main.OAmountWithTax,
|
|
main.TaxId,
|
|
COALESCE(comTaxNo.TaxName, '') AS TaxName,
|
|
main.TaxRate,
|
|
main.CurrId,
|
|
main.PersonId,
|
|
COALESCE(Person.PersonName, '') AS PersonName,
|
|
main.DeptId,
|
|
COALESCE(Dept.DeptName, '') AS DeptName,
|
|
main.CU_ReimbursementNo AS rib_NillNo
|
|
FROM purCharge AS main
|
|
LEFT JOIN comBusinessPartner AS Biz ON Biz.BizPartnerId = main.BizPartnerId
|
|
LEFT JOIN comTaxNo ON comTaxNo.TaxId = main.TaxId
|
|
LEFT JOIN comGroupPerson AS Person ON Person.PersonId = main.PersonId
|
|
LEFT JOIN comDepartment AS Dept ON Dept.DeptId = main.DeptId
|
|
WHERE 1=1 ";
|
|
$sql_purchaseApply .= $add_sql." ORDER BY main.BillDate DESC";
|
|
try {
|
|
$query_purchaseApply = $conn->prepare($sql_purchaseApply);
|
|
$query_purchaseApply->execute();
|
|
$result = $query_purchaseApply->fetchAll();
|
|
return $result;
|
|
} catch (PDOException $ex) {
|
|
trigger_error($ex->getMessage(), E_USER_WARNING);
|
|
return array();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//費用申請單API 不能用
|
|
function get_purchase_apply($validation, $GroupId, $BillNo)
|
|
{
|
|
if (is_null($validation) || is_null($GroupId) || is_null($BillNo)) {
|
|
return "參數錯誤";
|
|
}
|
|
$apiurl = "http://60.244.87.101:880//twWebAPI/V1/PURFEEAPPLY/GetERPData?pkValue=$BillNo";
|
|
$headerParam = [
|
|
'CHI_Authorization: ' . $validation,
|
|
'GroupId:' . $GroupId
|
|
];
|
|
$ch = curl_init();
|
|
if (!$ch) {
|
|
throw new Exception("Could not init cURL");
|
|
}
|
|
curl_setopt($ch, CURLOPT_URL, $apiurl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
|
|
$response = curl_exec($ch);
|
|
if ($response === false) {
|
|
$error = curl_error($ch);
|
|
curl_close($ch);
|
|
if (is_null($error)) {
|
|
throw new Exception("Curl error: Unknown error");
|
|
} else {
|
|
throw new Exception("Curl error: " . $error);
|
|
}
|
|
}
|
|
|
|
$result = json_decode($response, true);
|
|
if (is_null($result)) {
|
|
throw new Exception("Failed to decode JSON data");
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
|
|
function transanction_purchase_apply($validation, $GroupId, $BillNo)
|
|
{
|
|
date_default_timezone_set("Asia/Taipei");
|
|
$host = getenv('DB_HOST');
|
|
$dbuser = getenv('DB_USERNAME');
|
|
$dbpassword = getenv('DB_PASSWORD');
|
|
$dbname = getenv('DB_DATABASE');
|
|
$sqlsrv = getenv('sqlsrv');
|
|
$Database = getenv('Database');
|
|
$Account = getenv('Account');
|
|
$Password = getenv('Password');
|
|
|
|
try {
|
|
$mysqlConn = new PDO("mysql:host=$host;dbname=$dbname", $dbuser, $dbpassword);
|
|
$mysqlConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$mssqlConn = new PDO("sqlsrv:Server=$sqlsrv;Database=$Database", $Account, $Password);
|
|
$mssqlConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$mysqlConn->beginTransaction();
|
|
$mssqlConn->beginTransaction();
|
|
|
|
// 在MySQL数据库中执行插入操作
|
|
$mysqlInsertQuery = "INSERT INTO your_mysql_table (column1, column2) VALUES (:value1, :value2)";
|
|
$mysqlStatement = $mysqlConn->prepare($mysqlInsertQuery);
|
|
$mysqlStatement->execute(array(':value1' => 'value1', ':value2' => 'value2'));
|
|
|
|
// 在MSSQL数据库中执行插入操作
|
|
$mssqlInsertQuery = "INSERT INTO your_mssql_table (column1, column2) VALUES (?, ?)";
|
|
$mssqlStatement = $mssqlConn->prepare($mssqlInsertQuery);
|
|
$mssqlStatement->execute(array('value1', 'value2'));
|
|
|
|
// 提交事务
|
|
$mysqlConn->commit();
|
|
$mssqlConn->commit();
|
|
|
|
echo "Transaction successfully committed.";
|
|
} catch (PDOException $e) {
|
|
// 如果有异常发生,则回滚事务
|
|
$mysqlConn->rollBack();
|
|
$mssqlConn->rollBack();
|
|
echo "Transaction failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
|