add sql collection and update endpoint mapping service coa
This commit is contained in:
@@ -47,6 +47,7 @@ class ServiceCoaMapping extends MY_Controller
|
||||
} else {
|
||||
$this->sys_error_db($mssg);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,16 +56,61 @@ class ServiceCoaMapping extends MY_Controller
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
throw new Exception('invalid token');
|
||||
|
||||
$sql = "";
|
||||
$que = $this->db->query($sql);
|
||||
if (!$que) {
|
||||
throw new Exception('failed to query service coa mapping', 1);
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$keyword = "%" . $para['search'] . "%";
|
||||
|
||||
$offset = 0;
|
||||
$limit = 10;
|
||||
if ($para['pages'] > 0) {
|
||||
$offset = ($para['pages'] - 1) * $limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
ServiceCoaMappingID,
|
||||
ServiceCoaMappingM_ItemID,
|
||||
M_ItemDesc,
|
||||
ServiceCoaMappingCoaJasaID,
|
||||
coaJasa.coaAccountNo,
|
||||
coaJasa.coaDescription,
|
||||
ServiceCoaMappingCoaHutangID
|
||||
coaDebt.coaAccountNo,
|
||||
coaDebt.coaDescription
|
||||
FROM service_coa_mapping
|
||||
JOIN m_item ON M_ItemID = ServiceCoaMappingM_ItemID
|
||||
AND M_ItemDesc LIKE ?
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN coa AS coaJasa
|
||||
ON coaJasa.coaID = ServiceCoaMappingCoaJasaID
|
||||
LEFT JOIN coa AS coaDebt
|
||||
ON coaDebt.coaID = ServiceCoaMappingCoaHutangID
|
||||
WHERE ServiceCoaMappingIsActive = 'Y'";
|
||||
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$que_total = $this->db->query($sql_total, [$keyword]);
|
||||
if (!$que_total) {
|
||||
throw new Exception('failed query total data', 1);
|
||||
}
|
||||
$total = $que_total->row_array()['total'];
|
||||
|
||||
$sql_data = $sql . " LIMIT ? OFFSET ? ";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$keyword,
|
||||
$limit,
|
||||
$offset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
throw new Exception('failed to query data', 1);
|
||||
}
|
||||
$data = $que_data->result_array();
|
||||
|
||||
$output = [
|
||||
'records' => $data,
|
||||
'total' => $total
|
||||
];
|
||||
|
||||
$this->sys_ok($output);
|
||||
} catch (Exception $e) {
|
||||
$mssg = "[Error] " . $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
@@ -73,6 +119,136 @@ class ServiceCoaMapping extends MY_Controller
|
||||
} else {
|
||||
$this->sys_error_db($mssg);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function insertJasaCoaMapping()
|
||||
{
|
||||
try {
|
||||
if (!$this->sys_input) {
|
||||
throw new Exception("Invalid token");
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql = "INSERT INTO service_coa_mapping (
|
||||
ServiceCoaMappingM_ItemID,
|
||||
ServiceCoaMappingCoaJasaID,
|
||||
ServiceCoaMappingCoaHutangID,
|
||||
ServiceCoaMappingIsActive,
|
||||
ServiceCoaMappingUserID
|
||||
) VALUES (?, ?, ?, 'Y', ?)";
|
||||
$que = $this->db->query($sql, [
|
||||
$para['M_ItemID'],
|
||||
$para['CoaJasaID'],
|
||||
$para['CoaHutangID'],
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$que) {
|
||||
throw new Exception('failed insert coa mapping jasa', 1);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] insert coa mapping jasa");
|
||||
} catch (Exception $e) {
|
||||
$this->db->trans_rollback();
|
||||
$mssg = "[Error] " . $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
if ($code == 0) {
|
||||
$this->sys_error($mssg);
|
||||
} else {
|
||||
$this->sys_error_db($mssg);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateJasaCoaMapping()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
throw new Exception('invalid token');
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql = "UPDATE service_coa_mapping
|
||||
SET
|
||||
ServiceCoaMappingM_ItemID = ?,
|
||||
ServiceCoaMappingCoaJasaID = ?,
|
||||
ServiceCoaMappingCoaHutangID = ?,
|
||||
ServiceCoaMappingUserID = ?
|
||||
WHERE ServiceCoaMappingID = ?";
|
||||
$que = $this->db->query($sql, [
|
||||
$para['M_ItemID'],
|
||||
$para['CoaJasaID'],
|
||||
$para['CoaHutangID'],
|
||||
$user['M_UserID'],
|
||||
$para['ServiceCoaMappingID']
|
||||
]);
|
||||
if (!$que) {
|
||||
throw new Exception('failed update coa mapping jasa', 1);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[success] update coa mapping jasa");
|
||||
} catch (Exception $e) {
|
||||
$this->db->trans_rollback();
|
||||
$mssg = "[Error] " . $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
if ($code == 0) {
|
||||
$this->sys_error($mssg);
|
||||
} else {
|
||||
$this->sys_error_db($mssg);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteJasaCoaMapping()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
throw new Exception('invalid token', 1);
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql = "UPDATE service_coa_mapping
|
||||
SET
|
||||
ServiceCoaMappingIsActive = 'N',
|
||||
ServiceCoaMappingUserID = ?
|
||||
WHERE ServiceCoaMappingID = ?";
|
||||
$que = $this->db->query($sql, [
|
||||
$user['M_UserID'],
|
||||
$para['ServiceCoaMappingID']
|
||||
]);
|
||||
if (!$que) {
|
||||
throw new Exception('failed soft delete coa mapping jasa', 1);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[success] soft delete coa mapping jasa");
|
||||
} catch (Exception $e) {
|
||||
$this->db->trans_rollback();
|
||||
$mssg = "[Error] " . $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
if ($code == 0) {
|
||||
$this->sys_error($mssg);
|
||||
} else {
|
||||
$this->sys_error_db($mssg);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user