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.
 
 
 
 
 
 

227 lines
9.9 KiB

<?php
ini_set('display_errors', 'on');
include "./header.php";
// 設置一個空陣列來放資料
$data = array();
// sql語法存在變數中
$sql = "select * from rib ";
// 是否為會計 阿娥
if (($user_id == "M0056" || $user_id == "M0209")) {
$sql .= "WHERE ((CurrentState =1) or (TransactId= '$user_id') or (WriteOffId='$user_id') or (GatheringPersonId='$user_id'))";
$data = mysqli_query($link, $sql);
} else {
// 找下屬
$follower = [];
$follower = find_follow('$user_id');
if (count($follower) > 0) {
echo "有下屬";
$column_str = "('$user_id'" . ",'";
$column_str .= implode("','", $follower);
$column_str .= "')";
$sql .= "WHERE ((TransactId in $column_str) or (WriteOffId in $column_str) or (GatheringPersonId in $column_str))";
} else {
$sql .= "WHERE ((TransactId= '$user_id') or (WriteOffId='$user_id') or (GatheringPersonId='$user_id'))";
};
$data = mysqli_query($link, $sql);
}
// 取得部門代碼
$sql_depid = "SELECT department_id, name from department";
$dept_query = mysqli_query($link, $sql_depid);
$deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC);
?>
<!--
新增單據 -->
<p>
<a href="rib01-create.php?<?php echo $token_link; ?>" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-plus"></span>
</a>
</p>
<?php
if ($data) :
?>
<style>
table {
table-layout: fixed;
width: 100%;
}
td {
word-wrap: break-word;
}
img {
width: 125px;
}
.width_style_1 {
width: 125px;
}
table {
width: 100%;
}
#table_index_filter {
float: right;
}
#table_index_paginate {
float: right;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
</style>
<div style="width:98% ;margin: 1%">
<table id="table_index" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>單據編號</th>
<th>單據日期</th>
<th>付款方式</th>
<th>經辦人</th>
<th>報銷部門</th>
<th>報銷人</th>
<th>幣別</th>
<?php
if (($user_id == "M0056" || $user_id == "M0209")) { ?>
<th>報銷金額</th>
<?php } ?>
<th style="width: 8%;">狀態</th>
<th style="width: 7%;">功能</th>
</tr>
</thead>
<tbody>
<?php
if (is_iterable($data)) {
foreach ($data as $data) : ?>
<tr>
<td><?php echo $data['BillNo']; ?></td>
<td><?php echo substr($data['BillDate'], 0, 10); ?></td>
<td><?php if ($data['pay_type'] == 0) {
echo "現金";
} elseif ($data['pay_type'] == 1) {
echo "銀行轉帳";
}; ?></td>
<td><?php echo accountidToName($data['TransactId']); ?></td>
<td><?php
if (is_iterable($deptype)) {
foreach ($deptype as $dept) {
if ($data["DeptId"] == $dept['department_id']) {
echo $dept['name'];
break;
}
}
} ?></td>
<td><?php echo accountidToName($data['WriteOffId']); ?></td>
<td><?php if ($data['CurrId'] == "USD") : echo "美金";
elseif ($data['CurrId'] == "TWD") : echo "台幣";
elseif ($data['CurrId'] == "CNY") : echo "人民幣";
elseif ($data['CurrId'] == "HKD") : echo "港幣";
elseif ($data['CurrId'] == "EUR") : echo "歐元";
endif; ?> </td>
<?php
if (($user_id == "M0056" || $user_id == "M0209")) { ?>
<td><?php echo $data['OAmountWithTax']; ?> </td>
<?php } ?>
<td><?php if ($data['CurrentState'] == 0) : echo "草稿";
elseif ($data['CurrentState'] == 1) : echo "審核中";
elseif ($data['CurrentState'] == 2) : echo "通過";
elseif ($data['CurrentState'] == 3) : echo "作廢";
elseif ($data['CurrentState'] == 5) : echo "退回";
else : echo "結案";
endif ?>
</td>
<td>
<p>
<?php if (($user_id == "M0056" || $user_id == "M0209") && $data['CurrentState'] == 1) {
?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=1&<?= $token_link ?>" class="btn btn-success btn-sm">
<span class="glyphicon glyphicon-pawn"></span>
</a>
<?php
} else { ?>
<?php if ($data['CurrentState'] == 0) : ?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=0&<?= $token_link ?>" class="btn btn-warning btn-sm">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<?php elseif ($data['CurrentState'] == 1) : ?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=1&<?= $token_link ?>" class="btn btn-primary btn-sm">
<span class=" glyphicon glyphicon-search"></span>
</a>
<button type="button" onclick="download(<?= $data['rib_id'] ?>)" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-download-alt"></span></button>
<!-- <a href="rib03-download.php?id=<?php echo $data['rib_id'] ?>&<?= $token_link ?>" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-download-alt"></span>
</a> -->
<?php elseif ($data['CurrentState'] == 2) : ?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=2&<?= $token_link ?>" class="btn btn-info btn-sm">
<span class=" glyphicon glyphicon-ok"></span>
</a>
<?php elseif ($data['CurrentState'] == 3) : ?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=2&<?= $token_link ?>" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-search"></span>
</a>
<?php elseif ($data['CurrentState'] == 5) : ?>
<a href="rib01-check.php?id=<?php echo $data['rib_id'] ?>&state=2&<?= $token_link ?>" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-search"></span>
</a>
<?php endif;
} ?>
</p>
</td>
</tr>
<?php endforeach;
} ?>
</tbody>
</table>
</div>
<script>
function download(ribid) {
var xhr = new XMLHttpRequest();
var url = window.location.origin + "/wms/rib03-download.php?ribid=" + ribid + "&<?= $token_link ?>";
xhr.open('GET', url, true);
xhr.send();
xhr.responseType = 'text';
xhr.onload = function() {
if (xhr.status === 200) {
console.log("ok");
var file_path = xhr.responseText;
var link = document.createElement('a');
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);
// window.open('rib-test.php','-----');
}
};
}
// function openpdf(ribid){
// window.open('rib-test.php','-----');
// }
</script>
<?php
else :
echo "<h2>There is no record!</h2>";
endif;
include "./footer.php";
?>