297 lines
8.8 KiB
PHP
297 lines
8.8 KiB
PHP
<?php
|
|
|
|
class ServiceCoaMapping extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
echo "Jasa Coa Mapping API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function getListItemJasa()
|
|
{
|
|
try {
|
|
if (!$this->sys_input) {
|
|
throw new Exception("Invalid token");
|
|
}
|
|
$para = $this->sys_input;
|
|
$keyword = "%";
|
|
if ($para['keyword'] != '') {
|
|
$keyword .= $para['keyword'] . "%";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_ItemID,
|
|
M_ItemCode,
|
|
M_ItemDesc
|
|
FROM m_item
|
|
WHERE M_ItemIsActive = 'Y'
|
|
AND M_ItemDesc LIKE ?
|
|
AND M_ItemItem_CategoryID = '4'";
|
|
$que = $this->db->query($sql, [$keyword]);
|
|
if (!$que) {
|
|
throw new Exception('failed to get item jasa', 1);
|
|
}
|
|
$data = $que->result_array();
|
|
|
|
$this->sys_ok($data);
|
|
} catch (Exception $e) {
|
|
$mssg = "[Error] " . $e->getMessage();
|
|
$code = $e->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($mssg);
|
|
} else {
|
|
$this->sys_error_db($mssg);
|
|
}
|
|
exit();
|
|
}
|
|
}
|
|
|
|
public function getListCoa()
|
|
{
|
|
try {
|
|
if (!$this->sys_input) {
|
|
throw new Exception("Invalid token");
|
|
}
|
|
|
|
$para = $this->sys_input;
|
|
$keyword = "%" . $para["keyword"] . "%";
|
|
|
|
$sql = "SELECT
|
|
coaID,
|
|
coaAccountNo,
|
|
coaDescription
|
|
FROM coa
|
|
WHERE coaIsInput = 'Y'
|
|
AND (
|
|
coaDescription LIKE ?
|
|
OR coaAccountNo LIKE ?
|
|
)
|
|
AND coaIsActive = 'Y'
|
|
LIMIT 15";
|
|
$que = $this->db->query($sql, [$keyword, $keyword]);
|
|
if (!$que) {
|
|
throw new Exception("failed to query data coa", 1);
|
|
}
|
|
|
|
$data = $que->result_array();
|
|
$this->sys_ok($data);
|
|
} catch (Exception $e) {
|
|
$mssg = "[Error] " . $e->getMessage();
|
|
$code = $e->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($mssg);
|
|
} else {
|
|
$this->sys_error_db($mssg);
|
|
}
|
|
exit();
|
|
}
|
|
}
|
|
|
|
public function getListServiceMapping()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('invalid token');
|
|
}
|
|
|
|
$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();
|
|
if ($code == 0) {
|
|
$this->sys_error($mssg);
|
|
} 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();
|
|
}
|
|
}
|
|
}
|