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.
84 lines
2.8 KiB
84 lines
2.8 KiB
<?php
|
|
include "./header.php";
|
|
$type = $_GET['type'];
|
|
$InvoiceNo = empty($_POST['InvoiceNo']) ? NULL : str_replace('-', '', trim($_POST['InvoiceNo']));
|
|
$InvoiceDate = empty($_POST['InvoiceDate']) ? NULL: $_POST['InvoiceDate'];
|
|
|
|
$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'];
|
|
|
|
if ($type == 'edit') {
|
|
$pay_id = $_POST['pay_id'];
|
|
$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',";
|
|
}
|
|
if($InvoiceDate !== $pay['invoice_date']){
|
|
$sql1.="invoice_date = '$InvoiceDate',";
|
|
}
|
|
if($invoice_amount != $pay['invoice_amount']){
|
|
$sql1.="invoice_amount = $invoice_amount,";
|
|
}
|
|
if($received_amount != $pay['received_amount']){
|
|
$sql1.="received_amount = $received_amount,";
|
|
}
|
|
if($received_date !== $pay['received_date']){
|
|
$sql1.="received_date = '$received_date',";
|
|
}
|
|
if($remark !== $pay['remark']){
|
|
$sql1.="remark = '$remark',";
|
|
}
|
|
$sql1=substr($sql1,0,-1);
|
|
$sql = $sql1 . " WHERE pay_id = $pay_id";
|
|
echo $sql;
|
|
exit();
|
|
} else {
|
|
$BillNo = $_POST['BillNo'];
|
|
$dept_id = $_POST['DeptId'];
|
|
$dept_name = $_POST['DeptName'];
|
|
$manager_name = $_POST['ManagerName'];
|
|
$person_id = $_POST['PersonId'];
|
|
$person_name = $_POST['PersonName'];
|
|
$cust_name = $_POST['CustName'];
|
|
$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)) {
|
|
$sql1 .= ",invoice_no";
|
|
$sql2 .= ",'$InvoiceNo'";
|
|
}
|
|
if (isset($InvoiceDate)) {
|
|
$sql1 .= ",invoice_date";
|
|
$sql2 .= ",'$InvoiceDate'";
|
|
}
|
|
if (!empty($invoice_amount)) {
|
|
$sql1 .= ",invoice_amount";
|
|
$sql2 .= ",$invoice_amount";
|
|
}
|
|
if (!empty($received_amount)) {
|
|
$sql1 .= ",received_amount";
|
|
$sql2 .= ",$received_amount";
|
|
}
|
|
if (isset($received_date)) {
|
|
$sql1 .= ",received_date";
|
|
$sql2 .= ",'$received_date'";
|
|
}
|
|
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>';
|
|
}
|
|
|