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.
206 lines
7.6 KiB
206 lines
7.6 KiB
<?php
|
|
require_once("../../contract/conn.php");
|
|
|
|
if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') {
|
|
if ($_POST['contract_type'] == 'maintainance') {
|
|
try {
|
|
$id = empty($_POST['id']) ? '' : $_POST['id'];
|
|
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
|
|
$amount = empty($_POST['amount']) ? '' : $_POST['amount'];
|
|
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
|
|
$review_at = date("Y-m-d H:i:s");
|
|
$sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
|
|
header("HTTP/1.1 200 success!");
|
|
echo 'Success';
|
|
} catch (PDOException $e) {
|
|
header("HTTP/1.1 404 failed!");
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
} else if ($_POST['contract_type'] == 'new') {
|
|
try {
|
|
$id = empty($_POST['id']) ? '' : $_POST['id'];
|
|
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
|
|
$amount = empty($_POST['amount']) ? '' : $_POST['amount'];
|
|
|
|
header("HTTP/1.1 200 success!");
|
|
echo 'Success';
|
|
} catch (PDOException $e) {
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
// 獎金確認發放,並更新獎金 OR 實際發放時間
|
|
if (!empty($_POST['postType']) && $_POST['postType'] == 'b') {
|
|
try {
|
|
$id = empty($_POST['id']) ? '' : $_POST['id'];
|
|
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
|
|
$bonus_actual = empty($_POST['bonus_actual']) ? '' : $_POST['bonus_actual'];
|
|
$note = empty($_POST['note']) ? '' : $_POST['note'];
|
|
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
|
|
$review_at = date("Y-m-d H:i:s");
|
|
if ($pay_day != '' && $bonus_actual != '') {
|
|
$sql = "UPDATE bonus SET status = 2,review_hr='$user_id',review_at='$review_at',bonus_actual='$bonus_actual',pay_day='$pay_day',note='$note' WHERE id = $id";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
header("HTTP/1.1 200 success!");
|
|
} else {
|
|
header("HTTP/1.1 400");
|
|
echo '請填寫發放時間和實發獎金';
|
|
}
|
|
} catch (PDOException $e) {
|
|
header("HTTP/1.1 404 failed!");
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 獎金暫不發放
|
|
if (!empty($_POST['postType']) && $_POST['postType'] == 'c') {
|
|
// echo 'cccccc';
|
|
try {
|
|
$id = empty($_POST['id']) ? '' : $_POST['id'];
|
|
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
|
|
$bonus_actual = empty($_POST['bonus_issue']) ? '' : $_POST['bonus_issue'];
|
|
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
|
|
$note = empty($_POST['note']) ? '' : $_POST['note'];
|
|
$review_at = date("Y-m-d H:i:s");
|
|
|
|
if ($note != '') {
|
|
$sql = "UPDATE bonus SET status = 4,review_hr='$user_id',review_at='$review_at',pay_day='$pay_day',note='$note' WHERE id = $id";
|
|
echo $sql;
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
header("HTTP/1.1 200 success!");
|
|
} else {
|
|
echo '請填寫備註!!';
|
|
header("HTTP/1.1 400!");
|
|
}
|
|
} catch (PDOException $e) {
|
|
header("HTTP/1.1 404 failed!");
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
if (!empty($_POST['postType']) && $_POST['postType'] == 'd') {
|
|
try {
|
|
$id = empty($_POST['id']) ? '' : $_POST['id'];
|
|
$review_at = date("Y-m-d H:i:s");
|
|
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
|
|
|
|
$sql = "SELECT * FROM bonus WHERE id IN ($id)";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$conn->beginTransaction();
|
|
foreach ($results as $result) {
|
|
// echo '<pre>';
|
|
// print_r($result);
|
|
// echo '</pre>';
|
|
// exit();
|
|
$amount = $result['amount'];
|
|
$id = $result['id'];
|
|
$pay_day = $result['pay_day_due'];
|
|
|
|
$sql = "UPDATE bonus SET status = 5 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day' WHERE id = $id";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
}
|
|
|
|
$conn->commit();
|
|
header("HTTP/1.1 200 success!");
|
|
} catch (PDOException $e) {
|
|
$conn->rollBack();
|
|
header("HTTP/1.1 404 failed!");
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
// echo 'ddddd';
|
|
}
|
|
// 查看T8 是否收款
|
|
if (!empty($_POST['postType']) && $_POST['postType'] == 'e') {
|
|
$sql = "SELECT contract_no FROM bonus WHERE contract_type = 3 AND T8api_status = 1 ";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute();
|
|
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
// echo "<pre>";
|
|
// print_r($results);
|
|
// echo "</pre>";
|
|
foreach ($results as $result) {
|
|
$contract_no = $result['contract_no'];
|
|
$a = isPay($contract_no, $connT8);
|
|
|
|
if ($a == '1') {
|
|
try {
|
|
$sql = "UPDATE bonus SET T8api_status = 2 WHERE contract_no = :contract_no";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bindParam(":contract_no", $contract_no);
|
|
$stmt->execute();
|
|
header("HTTP/1.1 200 success!");
|
|
echo 'Success';
|
|
} catch (PDOException $e) {
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function isPay($contract_no, $connT8)
|
|
{
|
|
// echo $contract_no;
|
|
$sql = "SELECT
|
|
a.BillNo,
|
|
b.OTaxAmt as amount,
|
|
a.CU_EstPayDate as createDate,
|
|
b.PersonId as personId,
|
|
c.BillNo as CBno,
|
|
c.CU_MaterialId as facility
|
|
FROM salIncomeApplyDetail as a
|
|
LEFT JOIN salIncomeApplyMaster as b ON a.BillNo = b.BillNo
|
|
LEFT JOIN (
|
|
SELECT aMaster.BillNo,aMaster.BizPartnerId,aDetail.CU_MaterialId FROM arCheckBill as aMaster
|
|
LEFT JOIN arCheckBillDetail as aDetail ON aMaster.BizPartnerId = aDetail.FromBillNo
|
|
WHERE aMaster.BizPartnerId = '$contract_no' AND aMaster.TypeId = 'RVS'
|
|
) AS c ON a.BillNo = c.BizPartnerId
|
|
WHERE a.BillNo = '$contract_no'
|
|
AND a.RowNo = '1'
|
|
";
|
|
$stmt = $connT8->prepare($sql);
|
|
$stmt->execute();
|
|
$data = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
// $data['amount'] = intval($data['amount']);
|
|
if (!empty($data['CBno']) && $data['CBno'] != '') {
|
|
$checkBillNo = $data['CBno'];
|
|
|
|
$sql = "SELECT
|
|
c.BillDate AS CheckBillDate
|
|
FROM arWriteOffBill AS a
|
|
LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo
|
|
LEFT JOIN
|
|
(SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail
|
|
LEFT JOIN
|
|
(SELECT
|
|
arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo
|
|
FROM arCheckBill
|
|
LEFT JOIN arCheckBillInvInfo
|
|
ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1
|
|
ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c
|
|
ON a.BillNo=c.BillNo
|
|
WHERE c.checkBillNo = '$checkBillNo'
|
|
";
|
|
|
|
$stmt = $connT8->prepare($sql);
|
|
$stmt->execute();
|
|
|
|
return '1';
|
|
} else {
|
|
return '2';
|
|
}
|
|
}
|
|
|