Browse Source

應收帳款(新梯)

gary
Ellin 1 year ago
parent
commit
f74d72e66c
  1. 88
      wms/account-receivable-check.php
  2. 47
      wms/account-receivable-index.php
  3. 5
      wms/account-receivable-received-create.php
  4. 21
      wms/account-receivable-received-edit.php
  5. 74
      wms/account-receivable-received-submit.php

88
wms/account-receivable-check.php

@ -1,17 +1,34 @@
<?php
include "./header.php";
//企業名稱 統一編號 聯絡地址
$Bill = $_POST['Bill'];
$Bill = json_decode($Bill, true);
$sql_received = "SELECT * from account_received where BillNo = '$Bill[0]' ORDER BY `pay_id` ASC";
$pay_received = mysqli_query($link, $sql_received);
$had_received = 0;
if (mysqli_num_rows($pay_received) == 0) {
$had_received_amount = intval(0);
$had_invoice_amount=intval(0);
$status_summary = intval(0);
if (mysqli_num_rows($pay_received) > 0) {
foreach ($pay_received as $received) {
$had_received += $received['received_amount'];
$had_received_amount += intval($received['received_amount']);
$had_invoice_amount += intval($received['invoice_amount']);
if(in_array(intval($received['status']),array(0,4,5,99))){
$tem_status = intval(0);
}else{
$tem_status = intval($received['status']);
}
if($status_summary < $tem_status){
$status_summary = $tem_status;
}
}
}
$unreceived = $Bill[12] - $had_received;
$unreceived_amount = intval($Bill[12]) - intval($had_received_amount);
$uninvoice_amount = intval($Bill[12]) - intval($had_invoice_amount);
$Bill[19] =$had_invoice_amount;
$Bill[20] =$had_received_amount;
$Bill[21] =$uninvoice_amount;
$Bill[22] =$unreceived_amount;
$Bill[23] =$status_summary;
$data = json_encode($Bill);
?>
<style>
@ -135,7 +152,7 @@ include "./footer.php";
?>
<?php
if ($user_id == "M0122") {
if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) {
?>
<button type="button" onclick="create('create',0)" class="btn btn-primary btn-sm pull-right" style="margin-right: 10%;margin-bottom: 10px;">
新增收款紀錄<span class=" glyphicon glyphicon-plus"></span></button>
@ -148,10 +165,15 @@ if ($user_id == "M0122") {
<tr>
<th>發票日期</th>
<th>發票金額</th>
<th>發票號碼</th>
<th>收款日期</th>
<th>收款金額</th>
<th>說明</th>
<th style="width: 10%;">功能</th>
<th>備註</th>
<th>狀態</th>
<?php if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) { ?>
<th style="width: 10%;">功能</th>
<?php } ?>
</tr>
</thead>
<tbody>
@ -160,17 +182,47 @@ if ($user_id == "M0122") {
<tr>
<td><?= $received['invoice_date'] ?></td>
<td><?= number_format($received['invoice_amount']) ?></td>
<td><?= $received['invoice_no'] ?></td>
<td><?= $received['received_date'] ?></td>
<td><?= number_format($received['received_amount']) ?></td>
<td><?= $received['remark'] ?></td>
<td><?php if (in_array(accountidToDepartId($user_id), array('220', '210'))) { ?>
<td style="text-align: center;">
<?php
switch ($received['status']) {
case 0:
echo "<span style='color:blue;'>進行中</span>";
break;
case 1:
echo "<span style='color:brown;'>催收</span>";
break;
case 2:
echo "<span style='color:red;'>法務件 (發函)</span>";
break;
case 3:
echo "<span style='color:red;'>法務件 (訴訟)</span>";
break;
case 4:
echo "折讓";
break;
case 5:
echo "壞帳";
break;
case 99:
echo "完成";
break;
}
?></td>
<?php if ((accountidToDepartId($user_id) == '220') || ($user_id == "M0209")) { ?>
<td>
<button type="button" onclick="create('edit',<?= $received['pay_id'] ?>)" class="btn btn-warning btn-sm pull-right" style="margin-right: 10%;margin-bottom: 10px;">
<span class="glyphicon glyphicon-pencil"></span></button>
<a href="account-receivable-received-delete.php?id=<?php echo $received['pay_id'] ?>&<?= $token_link ?>" class="btn btn-danger btn-sm">
<!-- <a href="account-receivable-received-delete.php?id=<?php echo $received['pay_id'] ?>&<?= $token_link ?>" class="btn btn-danger btn-sm">
<span class=" glyphicon glyphicon-trash"></span>
</a>
<?php } ?>
</td>
</a> -->
</td>
<?php } ?>
</tr>
<?php }
} ?>
@ -178,16 +230,16 @@ if ($user_id == "M0122") {
</table>
</div>
<script>
function create(type,pay_id) {
function create(type, pay_id) {
var BillData = <?= $data ?>;
var form = document.createElement("form");
form.method = 'POST';
if(type === 'create'){
if (type === 'create') {
form.action = "account-receivable-received-create.php?<?= $token_link ?>";
}else{
form.action = "account-receivable-received-edit.php?pay_id="+pay_id+"&<?= $token_link ?>";
} else {
form.action = "account-receivable-received-edit.php?pay_id=" + pay_id + "&<?= $token_link ?>";
}
var input = document.createElement("input");
input.type = "hidden";
input.name = "Bill";

47
wms/account-receivable-index.php

@ -35,6 +35,8 @@ if (!(in_array(accountidToDepartId($user_id), array('220', '210')))) {
}
$contract = $conn->query($sql_contract);
// 取收款資料 account_received
$received_data = mysqli_query($link, $sql_received);
foreach ($received_data as $received) {
if ($received['BillNo'] == 'SO20230801001') {
@ -47,9 +49,14 @@ foreach ($received_data as $received) {
if (isset($received_array[$BillNo])) {
$received_array[$BillNo][0] += $received['invoice_amount'];
$received_array[$BillNo][1] += $received['received_amount'];
$received['status'] = (intval($received['status']) < 4) ? intval($received['status']) : 0;
if ($received_array[$BillNo][2] < intval($received['status'])) {
$received_array[$BillNo][2] = intval($received['status']);
}
} else {
$received_array[$BillNo][0] = $received['invoice_amount'];
$received_array[$BillNo][1] = $received['received_amount'];
$received_array[$BillNo][2] = (intval($received['status']) < 4) ? intval($received['status']) : 0;
}
}
foreach ($contract as $cont) {
@ -213,25 +220,37 @@ ON d.department_id = tmp2.department_id";
if (isset($received_array[$key][0])) {
$uninvoice_budget = $receivable_budget - $received_array[$key][0];
$received_invoice = $received_array[$key][0];
}else{
} else {
$uninvoice_budget = $receivable_budget;
}
if (isset($received_array[$key][1])) {
$unreceived_budget = $receivable_budget - $received_array[$key][1];
$received_budget = $received_array[$key][1];
}else{
} else {
$unreceived_budget = $receivable_budget;
}
if (isset($received_array[$key][2])) {
$status = $received_array[$key][2];
} else {
$status = 0;
}
}
if (isset($value[0]) && ($value[0] != 0)) {
$receivable_array[$key] = [$key, $value[0], $value[1], $value[2], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[9],
$value[10], $receivable_budget, $facitities, $value[13], $value[14], $value[15], $value[16], $value[17], $received_invoice, $received_budget,
$uninvoice_budget, $unreceived_budget];
if (isset($key)) {
$receivable_array[$key] = [
$key, $value[0], $value[1], $value[2], $value[3], $value[4], $value[5], $value[6], $value[7], $value[8], $value[9],
$value[10], $receivable_budget, $facitities, $value[13], $value[14], $value[15], $value[16], $value[17], $received_invoice, $received_budget,
$uninvoice_budget, $unreceived_budget, $status
];
}
}
$data = json_encode($receivable_array);
//0 合約號; 1 部門; 2 經理; 3 營業員; 4 客戶名稱; 5 簽約款; 6 二次款; 7 貨底工地款; 8 安裝款; 9 式車款; 10 官檢款;
//11 交車款; 12 目前應收; 13 作番狀態; 14 抬頭; 15 統一編號; 16 聯絡地址; 17 部門id; 18 營業員id; 19 已開發票金額; 20 已收金額;
//21 未開發票金額; 22 未收金額; 23 狀態
// echo "合約號;部門;經理;營業員;客戶名稱;簽約款;二次款;貨抵工地款;安裝款;試車款;官檢款;交車款;目前應收;總作番數;貨抵;安裝試車;官檢;移交數;狀態</br>";
?>
<style>
table {
@ -289,7 +308,8 @@ $data = json_encode($receivable_array);
<th style="width: 100px;">目前應收</th>
<th style="width: 150px;">未開發票金額</th>
<th style="width: 100px;">未收金額</th>
<th>狀態</th>
<th>作番狀態</th>
<th style="width: 100px;">收款狀態</th>
<th style="width: 100px;">操作</th>
</tr>
</thead>
@ -314,6 +334,15 @@ $data = json_encode($receivable_array);
<td style="text-align: end;"><?= number_format(round($contract[21])) ?></td>
<td style="text-align: end;"><?= number_format(round($contract[22])) ?></td>
<td style="text-align: start;"><?= $contract[13] ?></td>
<td style="text-align: start;"><?php
if (in_array($contract[23], array(0, 4, 5))) {
echo "正常";
} elseif ($contract[23] == 1) {
echo "<span style='color:blue'>催收</span>";
} else {
echo "<span style='color:red'>法務件</span>";
}
?></td>
<td><button type="button" onclick="sendData('<?= $contract[0] ?>')" class="btn btn-primary btn-sm"><span class=" glyphicon glyphicon-search"></span></button>
</td>
</tr>
@ -328,8 +357,6 @@ $data = json_encode($receivable_array);
console.log(BillNo);
var BillData = <?= $data ?>;
var Bill = BillData[BillNo];
console.log(Bill);
console.log(typeof(Bill));
var form = document.createElement("form");
form.method = 'POST';
form.action = "account-receivable-check.php?<?= $token_link ?>";

5
wms/account-receivable-received-create.php

@ -81,6 +81,7 @@ $BillData = json_decode($Bill, true);
<input type="hidden" name="DeptId" value="<?= $BillData[17] ?>">
<input type="hidden" name="PersonId" value="<?= $BillData[18] ?>">
<input type="hidden" name="CustName" value="<?= $BillData[4] ?>">
<input type="hidden" name="Bill" id="Bill" value="">
</div>
<div class="form-group">
<div class="col-md-3">
@ -115,7 +116,9 @@ $BillData = json_decode($Bill, true);
$("#DeptName").prop("disabled", false);
$("#ManagerName").prop("disabled", false);
$("#PersonName").prop("disabled", false);
var Bill = <?= $Bill ?>;
Bill = JSON.stringify(Bill);
$("#Bill").val(Bill);
$("#pay_received").submit();
}
</script>

21
wms/account-receivable-received-edit.php

@ -16,6 +16,8 @@ $pay = mysqli_fetch_assoc($pay);
<button type="button" onclick="backToIndex()" class="btn btn-outline-primary btn-lg"><span class="glyphicon glyphicon-menu-left"></span></button>
</div>
</div>
<div class="container">
<div class="text-center">
<h3><strong><?= $BillData[4] ?></strong></h3>
@ -83,9 +85,24 @@ $pay = mysqli_fetch_assoc($pay);
<input type="text" class="form-control" id="remark" name="remark" value="<?= $pay['remark'] ?>">
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label for="status" style="color: red;">狀態</label>
<select id="status" name="status">
<option value=0 <?php if($pay['status'] == 0) echo "selected" ?>>進行中</option>
<option value=1 <?php if($pay['status'] == 1) echo "selected" ?>>催收</option>
<option value=2 <?php if($pay['status'] == 2) echo "selected" ?>>法務件 (發函)</option>
<option value=3 <?php if($pay['status'] == 3) echo "selected" ?>>法務件 (訴訟)</option>
<option value=4 <?php if($pay['status'] == 4) echo "selected" ?>>折讓</option>
<option value=5 <?php if($pay['status'] == 5) echo "selected" ?>>壞帳</option>
<option value=99 <?php if($pay['status'] == 99) echo "selected" ?>>完成</option>
</select>
</div>
</div>
<input type="hidden" name="pay_id" value="<?= $pay['pay_id'] ?>">
<input type="hidden" name="Bill" id="Bill" value="">
</div>
<div class="form-group">
<div class="col-md-3">
@ -99,6 +116,7 @@ $pay = mysqli_fetch_assoc($pay);
<script>
function backToIndex() {
var Bill = <?= $Bill ?>;
@ -116,6 +134,9 @@ $pay = mysqli_fetch_assoc($pay);
function send() {
event.preventDefault();
var Bill = <?= $Bill ?>;
Bill = JSON.stringify(Bill);
$("#Bill").val(Bill);
$("#pay_received").submit();
}
</script>

74
wms/account-receivable-received-submit.php

@ -1,43 +1,47 @@
<?php
include "./header.php";
$type = $_GET['type'];
$InvoiceNo = empty($_POST['InvoiceNo']) ? NULL : str_replace('-', '', trim($_POST['InvoiceNo']));
$InvoiceDate = empty($_POST['InvoiceDate']) ? NULL: $_POST['InvoiceDate'];
$InvoiceNo = empty($_POST['InvoiceNo']) ? '' : str_replace('-', '', trim($_POST['InvoiceNo']));
$InvoiceDate = isset($_POST['InvoiceDate']) ? $_POST['InvoiceDate'] : '';
$Bill = $_POST['Bill'];
$invoice_amount = empty($_POST['InvoiceAmount']) ? 0 : $_POST['InvoiceAmount'];
$received_amount = empty($_POST['ReceivedAmount']) ? 0 : $_POST['ReceivedAmount'];
$received_date = empty($_POST['ReceivedDate']) ? NULL : $_POST['ReceivedDate'];
$remark = empty($_POST['remark']) ? '' : $_POST['remark'];
$received_date = isset($_POST['ReceivedDate']) ? $_POST['ReceivedDate'] : '';
$remark = isset($_POST['remark']) ? $_POST['remark'] : '';
if ($type == 'edit') {
$pay_id = $_POST['pay_id'];
$status = $_POST['status'];
$sql_query_pay = "SELECT * from account_received where pay_id = $pay_id";
$pay = mysqli_query($link, $sql_query_pay);
$pay = mysqli_fetch_assoc($pay);
$sql1 = "UPDATE account_received SET ";
if ($InvoiceNo !== $pay['invoice_no']) {
$sql1.="invoice_no = '$InvoiceNo',";
$sql1 .= "invoice_no = '$InvoiceNo',";
}
if($InvoiceDate !== $pay['invoice_date']){
$sql1.="invoice_date = '$InvoiceDate',";
if ($InvoiceDate != $pay['invoice_date']) {
$sql1 .= "invoice_date = '$InvoiceDate',";
}
if ($invoice_amount != $pay['invoice_amount']) {
$sql1 .= "invoice_amount = $invoice_amount,";
}
if($invoice_amount != $pay['invoice_amount']){
$sql1.="invoice_amount = $invoice_amount,";
if ($received_amount != $pay['received_amount']) {
$sql1 .= "received_amount = $received_amount,";
}
if($received_amount != $pay['received_amount']){
$sql1.="received_amount = $received_amount,";
if ($received_date != $pay['received_date']) {
$sql1 .= "received_date = '$received_date',";
}
if($received_date !== $pay['received_date']){
$sql1.="received_date = '$received_date',";
if ($remark != $pay['remark']) {
$sql1 .= "remark = '$remark',";
}
if($remark !== $pay['remark']){
$sql1.="remark = '$remark',";
if ($status != $pay['status']) {
$sql1 .= "status = $status,";
}
$sql1=substr($sql1,0,-1);
$sql = $sql1 . " WHERE pay_id = $pay_id";
echo $sql;
exit();
// $sql1 = substr($sql1, 0, -1);
$sql = $sql1 . "LastOperatorId = '$user_id' WHERE pay_id = $pay_id";
} else {
$BillNo = $_POST['BillNo'];
$dept_id = $_POST['DeptId'];
@ -49,36 +53,44 @@ if ($type == 'edit') {
$sql1 = "INSERT INTO account_received (
BillNo,dept_id,dept_name,manager_name,person_id,person_name,cust_name";
$sql2 = ",CreatorId) VALUES ('$BillNo','$dept_id','$dept_name','$manager_name','$person_id','$person_name','$cust_name'";
if (!empty($InvoiceNo)) {
if (isset($InvoiceNo)) {
$sql1 .= ",invoice_no";
$sql2 .= ",'$InvoiceNo'";
}
if (isset($InvoiceDate)) {
if ((!empty($InvoiceDate))) {
$sql1 .= ",invoice_date";
$sql2 .= ",'$InvoiceDate'";
}
if (!empty($invoice_amount)) {
if (isset($invoice_amount)) {
$sql1 .= ",invoice_amount";
$sql2 .= ",$invoice_amount";
}
if (!empty($received_amount)) {
if (isset($received_amount)) {
$sql1 .= ",received_amount";
$sql2 .= ",$received_amount";
}
if (isset($received_date)) {
if (!(empty($received_date))) {
$sql1 .= ",received_date";
$sql2 .= ",'$received_date'";
}
if (!empty($remark)) {
if (!(empty($remark))) {
$sql1 .= ",remark";
$sql2 .= ",'$remark'";
}
$sql = $sql1 . $sql2 . ",'$user_id')";
}
mysqli_query($link, $sql);
if (mysqli_affected_rows($link)) {
echo '<script>alert("新增/更新 成功")</script>';
echo $sql;
} else {
echo '<script>alert("新增/更新 失敗")</script>';
}
?>
<script>
var Bill = <?= $Bill ?>;
var form = document.createElement("form");
form.method = 'POST';
form.action = "account-receivable-check.php?<?= $token_link ?>";
var input = document.createElement("input");
input.type = "hidden";
input.name = "Bill";
input.value = JSON.stringify(Bill);
form.appendChild(input);
document.body.appendChild(form);
form.submit();
</script>
Loading…
Cancel
Save