|
|
@ -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> |