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.
 
 
 
 
 
 

337 lines
16 KiB

<?php
include "./header.php";
$rib_id = isset($_GET['id']) ? $_GET['id'] : die('ERROR:Rib_id is not found.');
$state = isset($_GET['state']) ? $_GET['state'] : 0;
$db_query = "SELECT * from rib where rib_id='$rib_id'";
$res = mysqli_query($link, $db_query);
// 找出使用者的部門
// 取得部門代碼
//取得人員名單
// 連線T8MASADA
try {
$conn = new PDO("sqlsrv:Server=60.244.87.101;Database=T8MASADA", "masada", "@m222222");
if ($conn) {
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$member = array();
//取得人員名單與使用者的部門
$sql_mydept = "SELECT UserId, Username FROM capMembership";
$deptmem = $conn->query($sql_mydept);
foreach ($deptmem as $mem) {
$userid = $mem['UserId'];
$username = $mem['Username'];
$member["$userid"] = [$username];
};
$sql_dept = "SELECT DeptId, PersonId FROM comPerson WHERE DeptId!='0001'";
$allpeople = $conn->query($sql_dept);
foreach ($allpeople as $man) {
if ($man['PersonId'] == $user_id) {
$mydepart = $man['DeptId'];
}
$personid = $man['PersonId'];
$depart = $man['DeptId'];
if(isset($member["$personid"])){
array_push($member["$personid"], "$depart");}
}
//取得部門代碼
$sql_department = "SELECT DeptId,DeptName FROM comDepartment WHERE DeptId!='0001'";
$deptype = $conn->query($sql_department);
}
} catch (PDOException $e) {
echo "fail";
echo $e->getMessage();
}
//取得 rib_sub的資料
$pay_data = array();
$pay_sql = "select * from rib_sub where rib_id = $rib_id";
$pay_data = mysqli_query($link, $pay_sql);
$totalOAmount = 0;
$CurrLAmount = 0;
if ($pay_data) {
foreach ($pay_data as $pdat) {
$totalOAmount += $pdat['OAmount'];
$CurrLAmount = $pdat['CurrentLAmount'];
}
}
?>
<div style="width: 90%;">
<div style="padding-left: 2rem; padding-bottom: 1rem;">
<a href="rib01-index.php?<?php echo $token_link; ?>" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-home"></span>
</a>
</div>
</div>
<div class="container" id="ribedit">
<div class="text-center">
<h3>報銷單據</h3>
</div>
<form class="form-horizontal" name="ribeditfrom" id="ribeditform" method="POST" action="rib01-submit.php?submit=edit&state=<?= $state ?>&<?= $token_link ?>" enctype="multipart/form-data">
<?php
foreach ($res as $data) :; ?>
<div class="form-group">
<div class="col-md-3">
<label for="BillNo">單據編號</label>
<input class="form-control" type="text" name="BillNo" id="BillNo" value="<?php echo $data['BillNo'] ?>" disabled>
</div>
<div class="col-md-3">
<label for="BillDate" style="color: red;">單據日期</label>
<input class="form-control" type="number" name="BillDate" id="BillDate" value=<?= date('Ymd') ?> disabled>
</div>
<div class="col-md-3">
<label for="CurrId" style="color: red;">幣別</label>
<select name="CurrId" id="CurrId" class="form-control" <?php if ($state == 1) {
echo "disabled";
} ?>>
<option value="TWD" <?php if ($data['CurrId'] === "TWD") {
echo "selected";
} ?>>台幣</option>
<option value="CNY" <?php if ($data['CurrId'] === "CNY") {
echo "selected";
} ?>>人民幣</option>
<option value="EUR" <?php if ($data['CurrId'] === "EUR") {
echo "selected";
} ?>>歐元</option>
<option value="HKD" <?php if ($data['CurrId'] === "HKD") {
echo "selected";
} ?>>港幣</option>
<option value="USD" <?php if ($data['CurrId'] === "USD") {
echo "selected";
} ?>>美元</option>
</select>
</div>
<div class="col-md-3">
<label for="TransactId" style="color: red;">經辦人</label>
<select name="TransactId" id="TransactId" class="form-control" <?php if ($state == 1) {
echo "disabled";
} ?>>
<option value="<?php echo $user_id; ?>"> <?php echo $user_name; ?> </option>
</select>
</div>
</div>
<div class="form-group">
<!-- <div class="col-md-3">
<label for="WriteOffType">報銷人類型</label>
<select name="WriteOffType" id="WriteOffType" class="form-control">
<option value=0 <?php if ($data['WriteOffType'] == 0) {
echo "selected";
} ?>>客戶</option>
<option value=1 <?php if ($data['WriteOffType'] == 1) {
echo "selected";
} ?>>廠商</option>
<option value=2 <?php if ($data['WriteOffType'] == 2) {
echo "selected";
} ?>>員工</option>
<option value=3 <?php if ($data['WriteOffType'] == 3) {
echo "selected";
} ?>>其他</option>
<option value=4 <?php if ($data['WriteOffType'] == 4) {
echo "selected";
} ?>>公司</option>
</select>
</div> -->
<div class="col-md-3">
<label for="DeptId" style="color: red;">報銷單位</label>
<select name="DeptId" id="DeptId" class="form-control" required>
<?php
foreach ($deptype as $dept) { ?>
<option value="<?php echo $dept['DeptId']; ?>" <?php
if ($dept['DeptId'] == $data['DeptId']) {
echo "selected";
} ?>><?php echo $dept['DeptName']; ?></option>
<?php };
?>
</select>
</div>
<div class="col-md-3">
<label for="WriteOffId" style="color: red;">報銷人</label>
<select name="WriteOffId" id="WriteOffId" class="form-control" required>
<option value="" id="WriteOffOption">請選擇報銷人</option>
<?php
foreach ($member as $key => $value) { ?>
<option value="<?php echo $key; ?>" id="<?= 'WriteOff' . $value[1] . $value[0] ?>" <?php if ($key == $data['WriteOffId']) {
echo "selected";
} ?>> <?php echo $value[0]; ?> </option>
<?php }
?>
</select>
</div>
<div class="col-md-3">
<label for="pay_type">付款方式</label>
<select name="pay_type" id="pay_type" class="form-control" required <?php if ($state == 1) {
echo "disabled";
} ?>>
<option value=0 <?php if ($data['pay_type'] == 0) {
echo "selected";
} ?>>現金</option>
<option value=1 <?php if ($data['pay_type'] == 1) {
echo "selected";
} ?>>銀行轉帳</option>
</select>
</div>
<div class="col-md-3">
<label for="GatheringPersonId" style="color: red;">收款人</label>
<select name="GatheringPersonId" id="GatheringPersonId" class="form-control" required <?php if ($state == 1) {
echo "disabled";
} ?>>
<?php
foreach ($member as $key => $value) {
?>
<option value="<?php echo $key; ?>" id="<?= 'Gathering' . $value[1].$value[0] ?>" <?php if ($key == $data['GatheringPersonId']) {
echo "selected";
} ?>> <?php echo $value[0]; ?> </option>
<?php }; ?>
</select>
</div>
</div>
<div class="form-group">
</div>
<div class="form-group">
<?php
if ($user_id == "M0056" && $state == 1) { ?>
<div class="form-group">
<div class="col-md-3">
<label for="WriteOffAmount">報銷金額 (原幣)</label>
<input name="WriteOffAmount" id="WriteOffAmount" class="form-control" type="number" value="<?= round($data['WriteOffAmount']) ?>" disabled>
</div>
<div class="col-md-3">
<label for="OAmount">未稅報銷金額 (原幣)</label>
<input name="OAmount" id="OAmount" class="form-control" value="<?= round($data['OAmount']) ?>" disabled>
</div>
<div class="col-md-3">
<label for="OTax">稅金 (原幣)</label>
<input name="OTax" id="OTax" class="form-control" value="<?= round($data['OTax']) ?>" disabled>
</div>
<div class="col-md-3">
<label for="CurrentLAmount">匯率</label>
<input name="CurrentLAmount" id="CurrentLAmount" class="form-control" value="<?= round($CurrLAmount) ?>" disabled>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label for="LAmountWithTax">本幣報銷金額</label>
<input name="LAmountWithTax" id="LAmountWithTax" class="form-control" type="number" value="<?= round($data['LAmountWithTax']) ?>" disabled>
</div>
<div class="col-md-3">
<label for="LAmount">本幣未稅報銷金額</label>
<input name="LAmount" id="LAmount" class="form-control" value="<?= round($data['LAmount']) ?>" disabled>
</div>
<div class="col-md-3">
<label for="LTax">本幣稅金</label>
<input name="LTax" id="LTax" class="form-control" value="<?= round($data['LTax']) ?>" disabled>
</div>
</div>
<?php
} else { ?>
<div class="form-group">
<div class="col-md-3">
<label for="totalOAmount">報銷金額 (原幣)</label>
<input name="totalOAmount" id="totalOAmount" class="form-control" type="number" value="<?= round($totalOAmount) ?>" disabled>
</div>
</div>
<?php
} ?>
<div class="form-group">
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="hidden" name="type" id="type" value="rib">
<input type="hidden" name="rib_id" id="rib_id" value="<?= $rib_id ?>">
</div>
<?php
endforeach
?>
<div class="form-group">
<div class="col-md-7">
</div>
<div class="col-md-5">
<button onclick="sendedit()" type="button" class="btn btn-primary btn-lg pull-right">暫存報銷單據</button>
</div>
</div>
</form>
</div>
<script>
$(function() {
$('#DeptId').change(function() {
changeWriteOffId($('#DeptId').val());
})
})
function changeWriteOffId(SelectedDept) {
var GatheringSelectDeptId = 'Gathering' + SelectedDept;
var SelectDeptId = 'WriteOff' + SelectedDept;
for (var i = 0; i < WriteOffId.options.length; i++) {
WriteOffId.options[i].selected = false;
let thisid = WriteOffId.options[i].id
if (thisid.search(SelectDeptId) === 0) {
WriteOffId.options[i].style['display'] = '';
} else {
WriteOffId.options[i].style['display'] = 'none';
};
};
for (var j = 0; j < GatheringPersonId.options.length; j++) {
let Gatherid = GatheringPersonId.options[j].id
if (Gatherid.search(GatheringSelectDeptId) === 0 || GatheringPersonId.options[j].value === "<?= $user_id ?>") {
GatheringPersonId.options[j].style['display'] = '';
} else {
GatheringPersonId.options[j].style['display'] = 'none';
};
}
};
function sendedit() {
$("#BillNo").prop("disabled", false);
$("#CurrId").prop("disabled", false);
$("#TransactId").prop("disabled", false);
$("#WriteOffType").prop("disabled", false);
$("#DeptId").prop("disabled", false);
$("#WriteOffId").prop("disabled", false);
$("#pay_type").prop("disabled", false);
$("#GatheringPersonId").prop("disabled", false);
$("#TelNo").prop("disabled", false);
$("#BankId").prop("disabled", false);
$("#BankAccount").prop("disabled", false);
$("#BankAccountName").prop("disabled", false);
$("#WriteOffAmount").prop("disabled", false);
$("#OAmount").prop("disabled", false);
$("#OTax").prop("disabled", false);
$("#CurrentLAmount").prop("disabled", false);
$("#LAmountWithTax").prop("disabled", false);
$("#LAmount").prop("disabled", false);
$("#LTax").prop("disabled", false);
$("#totalOAmount").prop("disabled", false);
$('#ribeditform').submit();
}
</script>
<?php
include "./footer.php";