| Server IP : 172.67.216.113 / Your IP : 104.23.243.33 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home2/cp648411/public_html/ilawasia.onnud20.com/CaseList/ |
Upload File : |
<?php
$ck = 'not';
include("../include/checkLogin.php");
include("../include/class.php");
include("../include/table_name.php");
$date = date("Y-m-d H:i:s");
$date_year = date("Y");
$date_month = date("m");
// รับค่า POST อย่างปลอดภัย
$CaseTypeId = isset($_POST["CaseTypeId"]) ? intval($_POST["CaseTypeId"]) : 0;
$CaseDescription = isset($_POST["CaseDescription"]) ? trim($_POST["CaseDescription"]) : "";
$QuotationId = isset($_POST["QuotationId"]) ? intval($_POST["QuotationId"]) : 0;
$IsNoCounting = isset($_POST["IsNoCounting"]) ? intval($_POST["IsNoCounting"]) : 0;
$LocalQuantity = isset($_POST["LocalQuantity"]) ? intval($_POST["LocalQuantity"]) : 0;
$InterQuantity = isset($_POST["InterQuantity"]) ? intval($_POST["InterQuantity"]) : 0;
$ResponseId = isset($_POST["ResponseId"]) ? intval($_POST["ResponseId"]) : 0;
$CustomerCode = isset($_POST["CustomerCode"]) ? trim($_POST["CustomerCode"]) : "";
/*
echo "<pre>";
print_r($_POST);
echo "</pre>";
*/
//exit();
$sql = ['table' => $name_table2, 'count' => 'MAX(CaseId) AS max_id'];
$view_sql = $view_db->view($sql);
$row = $view_db->q($view_sql);
$CaseId = $row['max_id'] ?? 0;
$CaseId = $CaseId + 1;
//echo $CaseId;
// ดึงข้อมูล CaseType
$CaseTypeAbbr = "";
$CountryCode = "";
$sql_mctype = ['table' => $name_table14, 'where' => "CaseTypeId = '$CaseTypeId'"];
$view_sql_mctype = $view_db->view($sql_mctype);
$row_mctype = $view_db->q($view_sql_mctype);
if (!empty($row_mctype)) {
$CaseTypeAbbr = $row_mctype['CaseTypeAbbr'] ?? "";
$CountryId = $row_mctype['CountryId'] ?? 0;
// ดึงข้อมูล Country
$sql_country = ['table' => $name_table10, 'where' => "CountryId = '$CountryId'"];
$view_sql_country = $view_db->view($sql_country);
$row_country = $view_db->q($view_sql_country);
$CountryCode = $row_country['CountryCode'] ?? "";
}
// ดึง CustomerId จาก CustomerCode
$CustomerId = 0;
if (!empty($CustomerCode)) {
$sql_cusId = ['table' => $name_table51, 'where' => "NamesCode = '$CustomerCode'"];
$view_sql_cusId = $view_db->view($sql_cusId);
$row_cusId = $view_db->q($view_sql_cusId);
$CustomerId = $row_cusId['NamesId'] ?? 0;
}
// สร้าง CaseNumber
$CaseNumber = $CustomerCode . '.' . $CaseTypeAbbr . '.' . $CountryCode . str_pad($CaseId, 4, "0", STR_PAD_LEFT);
// เตรียมข้อมูลเพื่อเพิ่ม case
$list = array(
'table' =>$name_table2,
'CaseNumber' =>"'".$CaseNumber."'",
'CustomerId' =>"'".@$CustomerId."'",
'CaseTypeId' =>"'".@$_POST["CaseTypeId"]."'",
'CaseDescription' =>"'".@$_POST["CaseDescription"]."'",
'QuotationId' =>"'".@$_POST["QuotationId"]."'",
'CreateBy' =>"'".@$_SESSION['UserInfo'][0]["UserId"]."'",
'CreateDateTime' =>"'".@$date."'",
'IsNoCounting' =>"'".@$_POST["IsNoCounting"]."'",
'LocalQuantity' =>"'".@$_POST["LocalQuantity"]."'",
'InterQuantity' =>"'".@$_POST["InterQuantity"]."'",
'ResponseId' =>"'".@$_POST["ResponseId"]."'"
);
// เพิ่มข้อมูล
$add = $actiondata_db->add_db($list);
//exit();
if (!empty($add['suc']) && $add['suc'] == 1) {
$_SESSION['Success'] = 'Add case successful';
echo "<script>window.location.href='edit.php?Type=Edit&Id=$CaseId'</script>";
} else {
$_SESSION['Error'] = 'Failed to add case';
echo "<script>window.location.href='index.php'</script>";
}
?>
?>