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.
 
 
 
 
 
 

484 lines
22 KiB

<?php
include "./header.php";
// Load Composer's autoloader
// require_once 'C:\xampp\htdocs\wms\excel\vendor\autoload.php';
require_once dirname(__DIR__) . '/common/composer/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as xls;
//use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
$rib_id = isset($_GET['id']) ? $_GET['id'] : die('ERROR:Rib_id is not found.');
$state = isset($_GET['state']) ? $_GET['state'] : die('ERROR: state is not found');
if ($state == 1) {
// 要寫到費用報銷單的資料
$totalVoucher = 0;
$FeeNotes = "";
//取得暫存的表頭資料
$rib_query = "SELECT * FROM rib WHERE rib_id = $rib_id";
$rib = mysqli_query($link, $rib_query);
$rib = mysqli_fetch_assoc($rib);
$OAmountWithTax = 0;
// 取得部門代碼
// $dept = "";
// $sql_depid = "SELECT DISTINCT department_id, name from department";
// $dept_query = mysqli_query($link, $sql_depid);
// $deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC);
// foreach ($deptype as $key => $value) {
// if ($value['department_id'] == $rib['DeptId']) {
// $dept = $value['name'];
// }
// }
try {
$conn = new PDO("sqlsrv:Server=60.244.87.101;Database=T8MASADA", "masada", "ZXCVasdf1234");
if ($conn) {
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//取得部門代碼
$sql_department = "SELECT DeptId,DeptName FROM comDepartment WHERE DeptId!='0001'";
$deptype = $conn->query($sql_department);
foreach ($deptype as $department) {
if ($department['DeptId'] == $rib['DeptId']) {
$dept = $department['DeptName'];
}
}
$conn = null;
}
} catch (PDOException $e) {
echo "fail";
echo $e->getMessage();
}
// 爬蟲--匯率
function htmlContentGet($url)
{
$opts = [
"http" => [
"method" => "GET",
"header" => "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\r\n"
]
];
return file_get_contents($url, false, stream_context_create($opts));
}
$week = date("w");
$currency_day = date("Y-m-d", strtotime("-1 day"));
if ($week == 1) {
$currency_day = date("Y-m-d", strtotime("-3 day"));
} elseif ($week == 0) {
$currency_day = date("Y-m-d", strtotime("-2 day"));
}
$X = htmlContentGet('https://rate.bot.com.tw/xrt/all/' . $currency_day);
$string = strip_tags($X); // 先清掉 html tag, 以免 html tag 被破壞
//美金
$USD = explode(' ', stristr($string, '美金'))[298];
//人民幣
$RMB = explode(' ', stristr($string, '人民幣'))[298];
//歐元
$EUR = explode(' ', stristr($string, '歐元'))[298];
//港幣
$HKD = explode(' ', stristr($string, '港幣'))[298];
//整理要變更的數據 -表身
$CurrLAmount = 1;
if ($rib['CurrId'] == "CNY") {
$CurrLAmount = $RMB;
} elseif ($rib['CurrId'] == "EUR") {
$CurrLAmount = $EUR;
} elseif ($rib['CurrId'] == "HKD") {
$CurrLAmount = $HKD;
} elseif ($rib['CurrId'] == "USD") {
$CurrLAmount = $USD;
}
//取得暫存的表身資料
$ribsub_query = "SELECT * FROM rib_sub WHERE rib_id = $rib_id";
$ribsub_data = mysqli_query($link, $ribsub_query);
$OTax = 0;
$LTax = 0;
$OAmount = 0;
$IsCounteract = 0;
$WriteOffAmount = 0;
$count = 0;
while ($ribsub = mysqli_fetch_assoc($ribsub_data)) {
$count += 1;
$OAmountWithTax += $ribsub['OAmount'];
$LAmount = $ribsub['OAmount'] * $CurrLAmount;
$OAmountUnWithTax = $ribsub['OAmount'] / (1 + $ribsub['TaxRate']);
$LAmountUnWithTax = $OAmountUnWithTax * $CurrLAmount;
$sub_WriteOffAmount = $ribsub['OAmount'];
$sub_OTax = $ribsub['OAmount'] - $OAmountUnWithTax;
$OTax += $sub_OTax;
$sub_LTax = $LAmount - $LAmountUnWithTax;
$LTax += $sub_LTax;
$WriteOffAmount += $ribsub['OAmount'];
$OAmount += $OAmountUnWithTax;
$ribsub_id = $ribsub['ribsub_id'];
$FeeNotes .= "\n" . $count . ". ";
if (isset($ribsub['ProjectId']) && (isset($ribsub['CU_MaterialId']))) {
$FeeNotes .= "合約號:" . $ribsub['ProjectId'] . "\n 作番號:" . $ribsub['CU_MaterialId'] . "\n ";
} elseif (isset($ribsub['ProjectId']) && (!isset($ribsub['CU_MaterialId']))) {
$FeeNotes .= "合約號:" . $ribsub['ProjectId'] . "\n ";
} elseif (!isset($ribsub['ProjectId']) && (isset($ribsub['CU_MaterialId']))) {
$FeeNotes .= "作番號:" . $ribsub['CU_MaterialId'] . "\n ";
}
$FeeNotes .= "費用說明:" . $ribsub['FeeNoteShow'] . "\n";
if ($ribsub['TaxId'] == "ST005" || $ribsub['TaxId'] == "ST101") {
$IsCounteract = 1;
}
$totalVoucher += $ribsub['VoucherCount'];
$sql_sub = "UPDATE rib_sub SET CurrentLAmount=$CurrLAmount,OAmountUnWithTax=$OAmountUnWithTax,
LAmountUnWithTax=$LAmountUnWithTax, FeeBalance=$LAmountUnWithTax,LAmount=$LAmount, OTax=$sub_OTax,
LTax=$sub_LTax, WriteOffAmount=$sub_WriteOffAmount WHERE ribsub_id = $ribsub_id";
// 上傳資料庫__表身
mysqli_query($link, $sql_sub);
}
$UnPayOAmount = $WriteOffAmount;
$UnPayLAmount = $UnPayOAmount * $CurrLAmount;
$LAmountWithTax = $OAmountWithTax * $CurrLAmount;
$LAmount = $OAmount * $CurrLAmount;
// 更新表頭資料
$BillDate = intval(date('Ymd'));
$sql_rib = "UPDATE rib SET BillDate=$BillDate,CurrentState=1,PermitState=1, OAmountWithTax=$OAmountWithTax, LAmountWithTax= $LAmountWithTax, LAmount=$LAmount,
OAmount =$OAmount, UnPayOAmount=$UnPayOAmount, Balance = $OAmountWithTax, LBalance= $UnPayLAmount ,UnPaymentLAmt=$UnPayLAmount,
UnPayLAmount=$UnPayLAmount, OTax=$OTax, LTax=$LTax, WriteOffAmount=$WriteOffAmount, CreatorId='$user_id' WHERE rib_id = $rib_id";
mysqli_query($link, $sql_rib);
if (mysqli_affected_rows($link) > 0) {
echo '<script>alert("已進入審核流程")</script>';
} else {
echo $sql_rib;
echo '<script>alert("操作失敗")</script>';
}
//紀錄繳交資料
$SQL1 = str_replace("'", '', $sql_rib);
$sql_submit = "UPDATE rib SET UserSubmit='$SQL1' WHERE rib_id=$rib_id";
mysqli_query($link, $sql_submit);
//產生費用報銷單excel
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load("reimburse-sample.xlsx");
$printday = date("Y-m-d");
$print = "列印日期:" . $printday;
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('H3', $rib['BillNo']);
$sheet->setCellValue('H5', $rib['BillDate']);
$sheet->setCellValue('H6', $dept);
$sheet->setCellValue('G2', $print);
if ($rib['WriteOffType'] == 1) {
$sheet->setCellValue('H8', '■ 廠商 □ 員工');
} elseif ($rib['WriteOffType'] == 2) {
$sheet->setCellValue('H8', '■ 員工 □ 廠商');
}
if ($rib['pay_type'] == 0) {
$sheet->setCellValue('H9', ' ■ 現金
□ 銀行轉帳
□ 沖帳及金額
( )
預付款申請單號
NO.');
} elseif ($rib['pay_type'] == 1) {
$sheet->setCellValue('H9', '□ 現金
■ 銀行轉帳
□ 沖帳及金額
( )
預付款申請單號
NO.');
}
$sheet->setCellValue('H10', $WriteOffAmount);
$sheet->setCellValue('H11', $totalVoucher);
$sheet->setCellValue('G13', $FeeNotes);
$writer = new Xls($spreadsheet);
$writer->save('WriteOff.xlsx');
?>
<script>
var link = document.createElement('a');
console.log(window.location.origin + "/wms/WriteOff.xlsx");
link.setAttribute('href', window.location.origin + "/wms/WriteOff.xlsx");
link.setAttribute('download', '費用報銷單.xlsx');
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
</script>
<?php
$content = "需要審核的費用報銷單為:";
$notice_rib_sql = "SELECT BillNo FROM rib WHERE CurrentState = 1";
$notice_rib = mysqli_query($link, $notice_rib_sql);
foreach ($notice_rib as $notice_content) {
$name = $notice_content['BillNo'];
$content .= "$name" . "、";
}
$notice_rib_num = mysqli_num_rows($notice_rib);
$notice_rib = mysqli_fetch_row($notice_rib);
$notice_sql = "SELECT * FROM notice WHERE related_id = 810";
$notice_num = mysqli_query($link, $notice_sql);
$notice_num = mysqli_num_rows($notice_num);
$title = "有" . $notice_rib_num . "個費用報銷單待審核";
if ($notice_num == 0) {
$insert_notice_sql = "INSERT INTO notice (kind, related_id, title, content, haveread, permission, creater) VALUES(1,810,'$title','$content',1,'M0056','system')";
} else {
$insert_notice_sql = "UPDATE notice SET title= '$title', content='$content',permission='M0056' WHERE related_id=810";
}
mysqli_query($link, $insert_notice_sql);
} elseif ($state == 2) {
//取得表頭資料
$rib_query = "SELECT * FROM rib WHERE rib_id = $rib_id";
$rib = mysqli_query($link, $rib_query);
$rib = mysqli_fetch_assoc($rib);
// 產生mysql單據編號
// $MaxBillNo = 0;
// $curreny_date = date('ym');
// $query_rib = array();
// $sqlname = $rib['TransactId'];
// $sqlname .= $curreny_date;
// $BillNo = $sqlname;
// $date_sql = "SELECT BillNo from rib WHERE (BillNo LIKE '$sqlname%') &&CurrentState==2";
// $query_rib = mysqli_query($link, $date_sql);
// $myNo = mysqli_fetch_all($query_rib);
// foreach ($myNo as $thisMyNo) {
// $thisMyNo = (int)substr($thisMyNo[0], -2);
// if ($thisMyNo > $MaxBillNo) {
// $MaxBillNo = $thisMyNo;
// }
// }
// 連線T8MASADA 取得單據編號
// try {
// $conn = new PDO("sqlsrv:Server=60.244.87.101;Database=T8TEST", "masada", "ZXCVasdf1234");
// if ($conn) {
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $sql = "SELECT BillNo FROM glFeeWriteOff WHERE (BillNo LIKE '$sqlname%')";
// $Noo = $conn->query($sql);
// foreach ($Noo as $maxMs) {
// $thisMsMax = (int)substr($maxMs['BillNo'], -2);
// if ($thisMsMax > $MaxBillNo) {
// $MaxBillNo = $thisMsMax;
// }
// }
// }
// } catch (PDOException $e) {
// echo "fail";
// echo $e->getMessage();
// }
// $MaxBillNo += 1;
// if ($MaxBillNo < 10) {
// $BillNo .= "0" . strval($MaxBillNo);
// } else {
// $BillNo .= strval($MaxBillNo);
// }
$BillNo = $rib['BillNo'];
//連線T8資料庫
try {
$conn = new PDO("sqlsrv:Server=60.244.87.101;Database=T8MASADA", "masada", "ZXCVasdf1234");
if ($conn) {
// // 表頭
$BillDate = $rib['BillDate'];
$TypeId = $rib['TypeId'];
$CurrId = ($rib['CurrId'] == "CNY") ? "RMB" : $rib['CurrId'];
$TransactId = $rib['TransactId'];
$WriteOffType = $rib['WriteOffType'];
$WriteOffId = $rib['WriteOffId'];
$WriteOffDescribe = empty($rib['WriteOffDescribe']) ? null : $rib['WriteOffDescribe'];
$DeptId = $rib['DeptId'];
$CostCenterId = empty($rib['CostCenterId']) ? Null : $rib['CostCenterId'];
$HadPayOAmount = $rib['HadPayOAmount'];
$HadPayLAmount = $rib['HadPayLAmount'];
$UnPayOAmount = $rib['UnPayOAmount'];
$UnPayLAmount = $rib['UnPayLAmount'];
$PaymentState = $rib['PaymentState'];
$Balance = $rib['Balance'];
$LBalance = $rib['LBalance'];
$GatheringPersonId = $rib['GatheringPersonId'];
$GatheringPersonDescribe = empty($rib['GatheringPersonDescribe']) ? Null : $rib['GatheringPersonDescribe'];
$BankId = empty($rib['BankId']) ? Null : $rib['BankId'];
$BankName = empty($rib['BankName']) ? Null : $rib['BankName'];
if (isset($BankId) && isset($BankName)) {
$totalBankName = $BankId . $BankName;
}
$BankAccount = empty($rib['BankAccount']) ? Null : $rib['BankAccount'];
$BankAccountName = empty($rib['BankAccountName']) ? Null : $rib['BankAccountName'];
$IsTaxBill = $rib['IsTaxBill'];
$OAmount = $rib['OAmount'];
$LAmount = $rib['LAmount'];
$OTax = $rib['OTax'];
$LTax = $rib['LTax'];
$LAmountWithTax = $rib['LAmountWithTax'];
$OAmountWithTax = $rib['OAmountWithTax'];
$IsContainTax = $rib['IsContainTax'];
$AdvanceOAmount = $rib['AdvanceOAmount'];
$AdvanceLAmount = $rib['AdvanceLAmount'];
$PrePayWriteOffAmount = $rib['PrePayWriteOffAmount'];
$WriteOffAmount = $rib['WriteOffAmount'];
$TelNo = empty($rib['TelNo']) ? Null : $rib['TelNo'];
$UnPaymentLAmt = empty($rib['UnPaymentLAmt']) ? null : $rib['UnPaymentLAmt'];
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO glFeeWriteOff(BillNo, BillDate, OrgId,FOrgId,TypeId,PayOrgId,
CurrId,TransactId,WriteOffType,BizOrgId,WriteOffId,DeptId,
HadPayOAmount,HadPayLAmount,UnPayOAmount,UnPayLAmount,PaymentState,Balance,LBalance,
FillUp,GatheringBizOrgId, GatheringPersonId, IsTaxBill, OAmount,LAmount,OTax,LTax,LAmountWithTax,OAmountWithTax,
IsContainTax,AdvanceOAmount,AdvanceLAmount,PrePayWriteOffAmount,WriteOffAmount,
CompId,UnPaymentOAmt,UnPaymentLAmt,IsPayment, CurrentState,PermitState";
$sql2 = ") VALUES ('$BillNo',$BillDate,'1000','1000','$TypeId','1000',
'$CurrId','$TransactId',$WriteOffType,'1000','$WriteOffId','$DeptId',
$HadPayOAmount,$HadPayLAmount,$UnPayOAmount,$UnPayLAmount,$PaymentState,$Balance,$LBalance,
0,'1000','$GatheringPersonId',$IsTaxBill,$OAmount,$LAmount,$OTax,$LTax,$LAmountWithTax,$OAmountWithTax,
$IsContainTax,$AdvanceOAmount,$AdvanceLAmount,$PrePayWriteOffAmount,$WriteOffAmount,
'1001',$WriteOffAmount,$UnPaymentLAmt,0,2,2";
$sql .= empty($CostCenterId) ? "" : ",CostCenterId";
$sql2 .= empty($CostCenterId) ? "" : ",'" . $CostCenterId . "'";
$sql .= empty($WriteOffDescribe) ? "" : ",WriteOffDescribe";
$sql2 .= empty($WriteOffDescribe) ? "" : ",'" . $WriteOffDescribe . "'";
$sql .= empty($GatheringPersonDescribe) ? "" : ",GatheringPersonDescribe";
$sql2 .= empty($GatheringPersonDescribe) ? "" : ",'" . $GatheringPersonDescribe . "'";
$sql .= empty($totalBankName) ? "" : ",BankName";
$sql2 .= empty($totalBankName) ? "" : ",'" . $totalBankName . "'";
$sql .= empty($BankAccount) ? "" : ",BankAccount";
$sql2 .= empty($BankAccount) ? "" : ",'" . $BankAccount . "'";
$sql .= empty($BankAccountName) ? "" : ",BankAccountName";
$sql2 .= empty($BankAccountName) ? "" : ",'" . $BankAccountName . "'";
$sql .= empty($TelNo) ? "" : ",TelNo";
$sql2 .= empty($TelNo) ? "" : ",'" . $TelNo . "'";
$sql .= $sql2;
$sql .= ")";
$result = $conn->query($sql);
// 更改WMS RIB狀態
$rib_sql = "UPDATE rib SET BillNo='$BillNo',CurrentState=2, PermitState=2 WHERE rib_id =$rib_id";
mysqli_query($link, $rib_sql);
//取得表身資料
$ribsub_query = "SELECT * FROM rib_sub WHERE rib_id = $rib_id";
$ribsub_data = mysqli_query($link, $ribsub_query);
$RowCode = 0;
while ($ribsub = mysqli_fetch_assoc($ribsub_data)) {
$RowCode += 1;
$RowNo = $ribsub['RowNo'];
$FeeDate = $ribsub['FeeDate'];
$FeeTypeId = $ribsub['FeeTypeId'];
$WriteOffType = $ribsub['WriteOffType'];
$WriteOffId = $ribsub['WriteOffId'];
$WriteOffDescribe = empty($ribsub['WriteOffDescribe']) ? Null : $ribsub['WriteOffDescribe'];
$FeeDeptId = $ribsub['FeeDeptId'];
$CostCenterId = empty($ribsub['CostCenterId']) ? Null : $ribsub['CostCenterId'];
$UnitId = $ribsub['UnitId'];
$Quantity = $ribsub['Quantity'];
$Price = $ribsub['Price'];
$CurrOAmount = $ribsub['CurrOAmount'];
$CurrLAmount = $ribsub['CurrentLAmount'];
$TaxId = $ribsub['TaxId'];
$TaxRate = $ribsub['TaxRate'];
$OTax = $ribsub['OTax'];
$LTax = $ribsub['LTax'];
$LAmountUnWithTax = $ribsub['LAmountUnWithTax'];
$OAmountUnWithTax = $ribsub['OAmountUnWithTax'];
$OAmount = $ribsub['OAmount'];
$LAmount = $ribsub['LAmount'];
$FeeBalance = $ribsub['FeeBalance'];
$VoucherCount = $ribsub['VoucherCount'];
$FeeNoteShow = empty($ribsub['FeeNoteShow']) ? Null : $ribsub['FeeNoteShow'];
$ProjectId = empty($ribsub['ProjectId']) ? null : $ribsub['ProjectId'];
$InvoiceNo = empty($ribsub['InvoiceNo']) ? null : $ribsub['InvoiceNo'];
$InvoiceNo = trim($InvoiceNo);
$InvoiceNo = str_replace('-', '', $InvoiceNo);
$comSupplierId = empty($ribsub['comSupplierId']) ? null : $ribsub['comSupplierId'];
$VoucherType = empty($ribsub['VoucherType']) ? null : $ribsub['VoucherType'];
$InvoiceId = empty($ribsub['InvoiceId']) ? null : $ribsub['InvoiceId'];
$CurrId = ($ribsub['CurrId'] == "CNY") ? "RMB" : $rib['CurrId'];
$WriteOffAmount = $ribsub['WriteOffAmount'];
$IsCounteract = $ribsub['IsCounteract'];
$CU_MaterialId = empty($ribsub['CU_MaterialId']) ? null : $ribsub['CU_MaterialId'];
$TaxNo = empty($ribsub['TaxNo']) ? null : $ribsub['TaxNo'];
$sqlsub = "INSERT INTO glFeeWriteOffSub (BillNo, RowCode,RowNo,FeeDate,FeeTypeId, WriteOffType,
BizOrgId, WriteOffId, FeeOrgId, FeeDeptId, FeeCompanyId, UnitId ,
Quantity, Price, CurrOAmount,CurrLAmount,TaxId,TaxRate,OTax,LTax,LAmountUnWithTax
,OAmountUnWithTax,OAmount,LAmount,FeeBalance,VoucherCount,CurrId,WriteOffAmount,SupplyOrgId,IsCounteract,IsKeyByFeeInfo
";
$sqlsub2 = ") VALUES ('$BillNo',$RowCode, $RowNo,$FeeDate,'$FeeTypeId',$WriteOffType,
'1000','$WriteOffId','1000','$FeeDeptId','1000','$UnitId',
$Quantity, $Price, $CurrOAmount, $CurrLAmount,'$TaxId',$TaxRate,$OTax,$LTax,$LAmountUnWithTax
,$OAmountUnWithTax,$OAmount,$LAmount,$FeeBalance,$VoucherCount,'$CurrId',$WriteOffAmount,'1000',$IsCounteract,0
";
$sqlsub .= empty($WriteOffDescribe) ? "" : ",WriteOffDescribe";
$sqlsub2 .= empty($WriteOffDescribe) ? "" : ",'" . $WriteOffDescribe . "'";
$sqlsub .= empty($CostCenterId) ? "" : ",CostCenterId";
$sqlsub2 .= empty($CostCenterId) ? "" : ",'" . $CostCenterId . "'";
$sqlsub .= empty($FeeNoteShow) ? "" : ",FeeNoteShow";
$sqlsub2 .= empty($FeeNoteShow) ? "" : ",'" . $FeeNoteShow . "'";
$sqlsub .= empty($ProjectId) ? "" : ",ProjectId";
$sqlsub2 .= empty($ProjectId) ? "" : ",'" . $ProjectId . "'";
$sqlsub .= empty($InvoiceNo) ? "" : ",InvoiceNo";
$sqlsub2 .= empty($InvoiceNo) ? "" : ",'" . $InvoiceNo . "'";
$sqlsub .= empty($CU_MaterialId) ? "" : ",CU_MaterialId";
$sqlsub2 .= empty($CU_MaterialId) ? "" : ",'" . $CU_MaterialId . "'";
$sqlsub .= empty($comSupplierId) ? "" : ",comSupplierId";
$sqlsub2 .= empty($comSupplierId) ? "" : ",'" . $comSupplierId . "'";
$sqlsub .= empty($VoucherType) ? "" : ",VoucherType";
$sqlsub2 .= empty($VoucherType) ? "" : ",'" . $VoucherType . "'";
$sqlsub .= empty($InvoiceId) ? "" : ",InvoiceId";
$sqlsub2 .= empty($InvoiceId) ? "" : ",'" . $InvoiceId . "'";
$sqlsub .= empty($TaxNo) ? "" : ",TaxNo";
$sqlsub2 .= empty($TaxNo) ? "" : ",'" . $TaxNo . "'";
$sqlsub .= $sqlsub2;
$sqlsub .= ")";
$result2 = $conn->query($sqlsub);
}
}
} catch (PDOException $e) {
echo "fail";
echo $e->getMessage();
}
$content = "需要審核的費用報銷單為:";
$notice_rib_sql = "SELECT BillNo FROM rib WHERE CurrentState = 1";
$notice_rib = mysqli_query($link, $notice_rib_sql);
foreach ($notice_rib as $notice_content) {
$name = $notice_content['BillNo'];
$content .= "$name" . "、";
}
$notice_rib_num = mysqli_num_rows($notice_rib);
$notice_rib = mysqli_fetch_row($notice_rib);
$notice_sql = "SELECT * FROM notice WHERE related_id = 810";
$notice_num = mysqli_query($link, $notice_sql);
$notice_num = mysqli_num_rows($notice_num);
$title = "有" . $notice_rib_num . "個費用報銷單待審核";
if ($notice_rib_num > 0) {
if ($notice_num == 0) {
$insert_notice_sql = "INSERT INTO notice (kind, related_id, title, content, haveread, permission, creater) VALUES(1,810,'$title','$content',1,'M0056','system')";
} else {
$insert_notice_sql = "UPDATE notice SET title= '$title', content='$content',permission='M0056' WHERE related_id=810";
}
mysqli_query($link, $insert_notice_sql);
} else {
if ($notice_num != 0) {
$insert_notice_sql = "DELETE FROM notice WHERE related_id = 810";
}
mysqli_query($link, $insert_notice_sql);
}
}
?>
<script>
window.location.href = "rib01-index.php?<?= $token_link ?>";
</script>