add more BE file from server
This commit is contained in:
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
class Approvelevel extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "APPROVE LEVEL API";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_count = "SELECT count(*) as total
|
||||
FROM m_approve_level
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND (M_ApproveLevelName LIKE ?)";
|
||||
$qry_count = $this->db->query($sql_count, [$search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_count) {
|
||||
$tot_count = $qry_count->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
M_ApproveLevelStartTotal,
|
||||
M_ApproveLevelEndTotal
|
||||
FROM m_approve_level
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND (M_ApproveLevelName LIKE ?)
|
||||
ORDER BY M_ApproveLevelID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve list error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$rows[$key]['rownumber'] = $key + 1;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['name']) || trim($prm['name']) == "") {
|
||||
$this->sys_error("Approve level name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$name = trim($prm['name']);
|
||||
$startTotal = trim($prm['startTotal']);
|
||||
$endTotal = trim($prm['endTotal']);
|
||||
|
||||
// Check for existing approve with same name
|
||||
$sql_check = "SELECT COUNT(*) as total FROM m_approve_level
|
||||
WHERE M_ApproveLevelName = ? AND M_ApproveLevelIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$name]);
|
||||
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Nama approve level sudah ada");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO m_approve_level(
|
||||
M_ApproveLevelName,
|
||||
M_ApproveLevelStartTotal,
|
||||
M_ApproveLevelEndTotal,
|
||||
M_ApproveLevelIsActive,
|
||||
M_ApproveLevelUserID,
|
||||
M_ApproveLevelCreated) VALUES(?,?,?,'Y',?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$name,
|
||||
$startTotal,
|
||||
$endTotal,
|
||||
$userId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve level insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM m_approve_level WHERE M_ApproveLevelName = '{$name}' AND M_ApproveLevelIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['approveId']) || !is_numeric($prm['approveId'])) {
|
||||
$this->sys_error("Approve level ID is required");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['name']) || trim($prm['name']) == "") {
|
||||
$this->sys_error("Approve level name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$approveId = $prm['approveId'];
|
||||
$name = trim($prm['name']);
|
||||
$startTotal = trim($prm['startTotal']);
|
||||
$endTotal = trim($prm['endTotal']);
|
||||
|
||||
// Check if department exists
|
||||
$sql_exist = "SELECT COUNT(*) as total FROM m_approve_level
|
||||
WHERE M_ApproveLevelID = ? AND M_ApproveLevelIsActive = 'Y'";
|
||||
$qry_exist = $this->db->query($sql_exist, [$approveId]);
|
||||
if ($qry_exist && $qry_exist->result_array()[0]['total'] == 0) {
|
||||
$this->sys_error("Approve level not found");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check for existing department with same name (excluding current department)
|
||||
$sql_check = "SELECT COUNT(*) as total FROM m_approve_level
|
||||
WHERE M_ApproveLevelName = ? AND M_ApproveLevelID != ?
|
||||
AND M_ApproveLevelIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$name, $approveId]);
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Nama Approve level sudah ada");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update department
|
||||
$sql = "UPDATE m_approve_level SET
|
||||
M_ApproveLevelName = ?,
|
||||
M_ApproveLevelStartTotal = ?,
|
||||
M_ApproveLevelEndTotal = ?,
|
||||
M_ApproveLevelUserID = ?,
|
||||
M_ApproveLevelLastUpdated = NOW()
|
||||
WHERE M_ApproveLevelID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$name,
|
||||
$startTotal,
|
||||
$endTotal,
|
||||
$userId,
|
||||
$approveId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Approve level update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
// Get updated record
|
||||
$sql_get = "SELECT * FROM m_approve_level WHERE M_ApproveLevelID = ? AND M_ApproveLevelIsActive = 'Y'";
|
||||
$records = $this->db->query($sql_get, [$approveId])->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['approveId']) || !is_numeric($prm['approveId'])) {
|
||||
$this->sys_error("Approve level ID is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$approveId = $prm['approveId'];
|
||||
|
||||
// Check if approve exists and is active
|
||||
$sql_exist = "SELECT COUNT(*) as total FROM m_approve_level
|
||||
WHERE M_ApproveLevelID = ? AND M_ApproveLevelIsActive = 'Y'";
|
||||
$qry_exist = $this->db->query($sql_exist, [$approveId]);
|
||||
if ($qry_exist && $qry_exist->result_array()[0]['total'] == 0) {
|
||||
$this->sys_error("Approve level not found");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Soft delete by updating IsActive to 'N'
|
||||
$sql = "UPDATE m_approve_level SET
|
||||
M_ApproveLevelIsActive = 'N',
|
||||
M_ApproveLevelUserID = ?,
|
||||
M_ApproveLevelLastUpdated = NOW()
|
||||
WHERE M_ApproveLevelID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userId,
|
||||
$approveId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"message" => "Approve level deleted successfully",
|
||||
"approveId" => $approveId
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUser()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$approveId = $prm["approveId"];
|
||||
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_count = "SELECT count(*) as total
|
||||
FROM m_user
|
||||
JOIN m_staff ON M_UserM_StaffID = M_StaffID AND M_StaffIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserM_ApproveLevelID = ?
|
||||
AND (M_UserFullName LIKE ? OR M_StaffName LIKE ?)";
|
||||
$qry_count = $this->db->query($sql_count, [$approveId, $search, $search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_count) {
|
||||
$tot_count = $qry_count->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
M_UserID,
|
||||
M_UserM_BranchID,
|
||||
M_UserS_RegionalID,
|
||||
M_UserM_UserGroupID,
|
||||
M_UserR_ReportGroupID,
|
||||
M_UserM_StaffID,
|
||||
M_UserUsername,
|
||||
M_UserFullName,
|
||||
M_UserIsCoordinator,
|
||||
M_StaffName,
|
||||
M_StaffPhone
|
||||
FROM m_user
|
||||
JOIN m_staff ON M_UserM_StaffID = M_StaffID AND M_StaffIsActive = 'Y'
|
||||
WHERE M_UserIsActive = 'Y'
|
||||
AND M_UserM_ApproveLevelID = ?
|
||||
AND (M_UserFullName LIKE ? OR M_StaffName LIKE ?)
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$approveId, $search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_user list error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
386
application/controllers/mockup/masterdata/accounting/Bankcoa.php
Normal file
386
application/controllers/mockup/masterdata/accounting/Bankcoa.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
class Bankcoa extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "MAPPING BANK COA API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$sql = "SELECT S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
ORDER BY S_RegionalName ASC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = $prm["regionalId"];
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$regionalId = $prm['regionalId'];
|
||||
// $filterregional = "";
|
||||
// if (intval($regionalId) > 0) {
|
||||
// $filterregional .= " AND S_RegionalID = {$regionalId}";
|
||||
// }
|
||||
|
||||
$branchCode = $prm['branchCode'];
|
||||
$filterbranch = "";
|
||||
if ($branchCode != "") {
|
||||
$filterbranch .= " AND MapBank_BranchCode = '{$branchCode}'";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
MapBank_ID,
|
||||
MapBank_BranchCode,
|
||||
MapBank_NatBankID,
|
||||
MapBank_NatBankCode,
|
||||
MapBank_NatBankName,
|
||||
MapBank_NatBankIsEDC,
|
||||
MapBank_BankAccountNo,
|
||||
MapBank_CoaID,
|
||||
MapBank_CoaAccountNo,
|
||||
MapBank_CoaDescription,
|
||||
MapBank_EDC_CoaID,
|
||||
MapBank_EDC_CoaAccountNo,
|
||||
MapBank_EDC_CoaDescription,
|
||||
MapBank_IsActive
|
||||
FROM map_bank_coa
|
||||
JOIN m_branch ON MapBank_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = {$regionalId}
|
||||
WHERE MapBank_IsActive = 'Y'
|
||||
AND (MapBank_NatBankName LIKE '{$search}' OR MapBank_NatBankCode LIKE '{$search}' OR MapBank_BankAccountNo LIKE '{$search}')
|
||||
$filterbranch
|
||||
";
|
||||
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total, []);
|
||||
|
||||
// print_r($this->db->last_query());
|
||||
// exit;
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$total_count = 0;
|
||||
$total_page = 0;
|
||||
if ($qry_total) {
|
||||
$total_count = $qry_total->result_array()[0]["total"];
|
||||
$total_page = ceil($total_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select count bank coa count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_bank = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
$qry_bank = $this->db->query($sql_bank, []);
|
||||
if ($qry_bank) {
|
||||
$rows = $qry_bank->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select bank coa count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $total_page,
|
||||
"total_filter" => $total_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchCoaBank()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$search_name = '%' . $search . '%';
|
||||
$search_account = "$search%";
|
||||
|
||||
$number_limit = 10;
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
CONCAT(coaAccountNo, ' - ', coaDescription) as accountNoDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (coaDescription LIKE '{$search_name}' OR coaAccountNo LIKE '{$search_account}')
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, array($number_limit));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total_filter" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchCoaEDC()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$search_name = '%' . $search . '%';
|
||||
$search_account = "$search%";
|
||||
|
||||
$number_limit = 10;
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
CONCAT(coaAccountNo, ' - ', coaDescription) as accountNoDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (coaDescription LIKE '{$search_name}' OR coaAccountNo LIKE '{$search_account}')
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, array($number_limit));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total_filter" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveupdate()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$isEdc = $prm["isEdc"];
|
||||
$coaBankId = $prm["coaBankId"];
|
||||
$coaBankAccountNo = $prm["coaBankAccountNo"];
|
||||
$coaBankDescription = $prm["coaBankDescription"];
|
||||
$edcCoaId = $prm["edcCoaId"];
|
||||
$edcCoaAccountNo = $prm["edcCoaAccountNo"];
|
||||
$edcCoaDescription = $prm["edcCoaDescription"];
|
||||
$mapBankId = $prm["mapBankId"];
|
||||
|
||||
$sql = "UPDATE map_bank_coa SET
|
||||
MapBank_NatBankIsEDC = ?,
|
||||
MapBank_CoaID = ?,
|
||||
MapBank_CoaAccountNo = ?,
|
||||
MapBank_CoaDescription = ?,
|
||||
MapBank_EDC_CoaID = ?,
|
||||
MapBank_EDC_CoaAccountNo = ?,
|
||||
MapBank_EDC_CoaDescription = ?,
|
||||
MapBank_LastUpdatedAt = NOW()
|
||||
WHERE MapBank_ID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$isEdc,
|
||||
$coaBankId,
|
||||
$coaBankAccountNo,
|
||||
$coaBankDescription,
|
||||
$edcCoaId,
|
||||
$edcCoaAccountNo,
|
||||
$edcCoaDescription,
|
||||
$mapBankId
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update map bank coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletebankcoa()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$mapBankId = $prm["mapBankId"];
|
||||
|
||||
$sql = "UPDATE map_bank_coa SET
|
||||
MapBank_IsActive = 'N',
|
||||
MapBank_LastUpdatedAt = NOW()
|
||||
WHERE MapBank_ID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$mapBankId
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete map bank coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
<?php
|
||||
|
||||
class Beginingbalance extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "COA API";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function getPeriode()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeName as name,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d-%m-%Y'), ' - ',DATE_FORMAT(periodeEndDate, '%d-%m-%Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
// $data = array(
|
||||
// array("id" => "1", "name" => "Periode Januari", "periode" => '01-01-2024 - 31-01-2024'),
|
||||
// array("id" => "2", "name" => "Periode Februari", "periode" => '01-02-2024 - 31-02-2024'),
|
||||
// array("id" => "3", "name" => "Periode Maret", "periode" => '01-03-2024 - 31-03-2024'),
|
||||
// );
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function cek()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT COUNT(*) as total FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array()[0]['total'];
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function save()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$periode = $prm['periode'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "SELECT COUNT(*) as total FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$total = $qry->result_array()[0]['total'];
|
||||
if (intval($total) > 0) {
|
||||
$sql = "DELETE FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$cekData = $data[$i];
|
||||
if (!array_key_exists('Number', $cekData)) {
|
||||
$this->sys_error("Kolom Number tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Keterangan', $cekData)) {
|
||||
$this->sys_error("Kolom Keterangan tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Debit', $cekData)) {
|
||||
$this->sys_error("Kolom Debit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Kredit', $cekData)) {
|
||||
$this->sys_error("Kolom Kredit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (floatval($cekData['Debit']) > 0 && floatval($cekData['Kredit']) > 0) {
|
||||
$this->sys_error("Jumlah debit dan credit keduanya lebih besar dari 0");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT coaID FROM coa
|
||||
WHERE coaAccountNo = ?
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$cekData['Number']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("cek coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->result_array();
|
||||
if (count($cek) == 0) {
|
||||
$this->sys_error_db("{$cekData['Number']} tidak ada di coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$data[$i]['coaID'] = $cek[0]['coaID'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$dataCoa = $data[$i];
|
||||
$debit = $dataCoa['Debit'];
|
||||
$credit = $dataCoa['Kredit'];
|
||||
$type = 'DB';
|
||||
if (floatval($dataCoa['Kredit']) > 0) {
|
||||
$type = 'CR';
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO t_beginningbalance(
|
||||
T_BeginningBalancePeriodeID,
|
||||
T_BeginningBalanceCoaID,
|
||||
T_BeginningBalanceCoaAccountNo,
|
||||
T_BeginningBalanceDescription,
|
||||
T_BeginningBalanceType,
|
||||
T_BeginningBalanceStatus,
|
||||
T_BeginningBalanceDebit,
|
||||
T_BeginningBalanceCredit,
|
||||
T_BeginningBalanceCreatedUserID,
|
||||
T_BeginningBalanceCreated)
|
||||
VALUES(?,?,?,?,?,?,?,?,?, NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$periode['id'],
|
||||
$dataCoa['coaID'],
|
||||
$dataCoa['Number'],
|
||||
$dataCoa['Keterangan'],
|
||||
$type,
|
||||
'N',
|
||||
$debit,
|
||||
$credit,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error insert beginning balance", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok("OK");
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
function addData()
|
||||
{
|
||||
// $this->sys_error_db("error msg");
|
||||
// $this->sys_error("error msg");
|
||||
// exit;
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$periode = $prm['periode'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$cekData = $data[$i];
|
||||
if (!array_key_exists('Number', $cekData)) {
|
||||
$this->sys_error("Kolom Number tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Keterangan', $cekData)) {
|
||||
$this->sys_error("Kolom Keterangan tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Debit', $cekData)) {
|
||||
$this->sys_error("Kolom Debit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Kredit', $cekData)) {
|
||||
$this->sys_error("Kolom Kredit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (floatval($cekData['Debit']) > 0 && floatval($cekData['Kredit']) > 0) {
|
||||
$this->sys_error("Jumlah debit dan credit keduanya lebih besar dari 0");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT coaID FROM coa
|
||||
WHERE coaAccountNo = ?
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$cekData['Number']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("cek coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->result_array();
|
||||
if (count($cek) == 0) {
|
||||
$this->sys_error_db("{$cekData['Number']} tidak ada di coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$data[$i]['coaID'] = $cek[0]['coaID'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$dataCoa = $data[$i];
|
||||
$debit = $dataCoa['Debit'];
|
||||
$credit = $dataCoa['Kredit'];
|
||||
$type = 'DB';
|
||||
if (floatval($dataCoa['Kredit']) > 0) {
|
||||
$type = 'CR';
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO t_beginningbalance(
|
||||
T_BeginningBalancePeriodeID,
|
||||
T_BeginningBalanceCoaID,
|
||||
T_BeginningBalanceCoaAccountNo,
|
||||
T_BeginningBalanceDescription,
|
||||
T_BeginningBalanceType,
|
||||
T_BeginningBalanceStatus,
|
||||
T_BeginningBalanceDebit,
|
||||
T_BeginningBalanceCredit,
|
||||
T_BeginningBalanceCreatedUserID,
|
||||
T_BeginningBalanceCreated)
|
||||
VALUES(?,?,?,?,?,?,?,?,?, NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$periode['id'],
|
||||
$dataCoa['coaID'],
|
||||
$dataCoa['Number'],
|
||||
$dataCoa['Keterangan'],
|
||||
$type,
|
||||
'N',
|
||||
$debit,
|
||||
$credit,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error insert beginning balance", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok("OK");
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$dt_user = $this->sys_user;
|
||||
$branch = $dt_user['M_BranchID'];
|
||||
$branch_code = '';
|
||||
if(intval($branch) > 0){
|
||||
|
||||
$sql = "SELECT * FROM m_branch WHERE branchID = ?";
|
||||
$qry = $this->db->query($sql, [$branch]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$branch = $qry->result_array()[0];
|
||||
$branch_code = $branch['M_BranchCode'];
|
||||
}
|
||||
|
||||
$pt_loginID = $dt_user['M_BranchCompanyID'];
|
||||
$regionalID = $dt_user['S_RegionalID'];
|
||||
|
||||
$sql = "SELECT
|
||||
T_BeginningBalanceID as id,
|
||||
T_BeginningBalanceCoaID as coaID,
|
||||
T_BeginningBalancePeriodeID as periodeID,
|
||||
T_BeginningBalanceCoaAccountNo as number,
|
||||
T_BeginningBalanceDescription as keterangan,
|
||||
T_BeginningBalanceType as type,
|
||||
T_BeginningBalanceStatus as status,
|
||||
CASE
|
||||
WHEN T_BeginningBalanceType = 'DB' THEN T_BeginningBalanceDebit
|
||||
WHEN T_BeginningBalanceType = 'CR' THEN T_BeginningBalanceCredit
|
||||
END as value
|
||||
FROM t_beginningbalance
|
||||
WHERE
|
||||
T_BeginningBalanceM_BranchCompanyID = ?
|
||||
AND T_BeginningBalanceS_RegionalID = ?
|
||||
AND T_BeginningBalanceM_BranchCode = ?";
|
||||
$qry = $this->db->query($sql, [$pt_loginID, $regionalID, $branch_code]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$totalDebit = 0;
|
||||
$totalCredit = 0;
|
||||
$totalBalance = 0;
|
||||
$status = 'N';
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$dataCek = $data[$i];
|
||||
if ($dataCek['type'] == 'DB') {
|
||||
$totalDebit = $totalDebit + floatval($dataCek['value']);
|
||||
}
|
||||
if ($dataCek['type'] == 'CR') {
|
||||
$totalCredit = $totalCredit + floatval($dataCek['value']);
|
||||
}
|
||||
}
|
||||
$totalBalance = $totalDebit - $totalCredit;
|
||||
$periode = array();
|
||||
if (count($data) > 0) {
|
||||
if ($data[0]['status'] == 'P') {
|
||||
$status = 'P';
|
||||
}
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeName as name,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d-%m-%Y'), ' - ',DATE_FORMAT(periodeEndDate, '%d-%m-%Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeID = ?";
|
||||
$qry = $this->db->query($sql, [$data[0]['periodeID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$periode = $qry->result_array()[0];
|
||||
}
|
||||
|
||||
$rst = array(
|
||||
'data' => $data,
|
||||
'periode' => $periode,
|
||||
'status' => $status,
|
||||
'total' => array(
|
||||
'debit' => $totalDebit,
|
||||
'credit' => $totalCredit,
|
||||
'balance' => $totalBalance
|
||||
)
|
||||
);
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function updateData()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$debit = 0;
|
||||
$credit = 0;
|
||||
$type = $data['type'];
|
||||
if ($type == 'DB') {
|
||||
$debit = $data['value'];
|
||||
$credit = 0;
|
||||
}
|
||||
if ($type == 'CR') {
|
||||
$credit = $data['value'];
|
||||
$debit = 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE t_beginningbalance
|
||||
SET T_BeginningBalanceDebit = ?,
|
||||
T_BeginningBalanceCredit = ?,
|
||||
T_BeginningBalanceType = ?,
|
||||
T_BeginningBalanceLastUpdatedUserID = ?
|
||||
WHERE T_BeginningBalanceID = ?";
|
||||
$qry = $this->db->query($sql, [$debit, $credit, $type, $userid, $data['id']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$retval = array(
|
||||
"debit" => $debit,
|
||||
"type" => $type,
|
||||
"credit" => $credit,
|
||||
"last_qry" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($retval);
|
||||
}
|
||||
function postData()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
|
||||
$sql = "UPDATE t_beginningbalance
|
||||
SET T_BeginningBalanceStatus = 'P',
|
||||
T_BeginningBalanceLastUpdatedUserID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$userid]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function delete()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$sql = "DELETE FROM t_beginningbalance WHERE T_BeginningBalanceID = ?";
|
||||
$qry = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function searchCoa()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$sql = "SELECT
|
||||
T_BeginningBalanceID ,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, '-' ,coaDescription) as display
|
||||
FROM coa
|
||||
LEFT JOIN t_beginningbalance
|
||||
ON coaID = T_BeginningBalanceCoaID
|
||||
WHERE
|
||||
coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'
|
||||
AND T_BeginningBalanceID IS NULL
|
||||
AND (coaAccountNo LIKE ? OR coaDescription LIKE ?)
|
||||
";
|
||||
$qry = $this->db->query($sql, [$search, $search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Branchacc extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Branch API";
|
||||
}
|
||||
|
||||
public function getBranch()
|
||||
{
|
||||
$sql = "SELECT M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND S_RegionalID IN (6)";
|
||||
$query = $this->db->query($sql);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Tidak menemukan data branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
public function validateDateRange($startDate, $endDate)
|
||||
{
|
||||
// Validasi input kosong
|
||||
if (!$startDate || !$endDate) {
|
||||
$this->sys_error("Parameter startdate dan enddate wajib diisi.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Konversi ke timestamp
|
||||
$startTimestamp = strtotime($startDate);
|
||||
$endTimestamp = strtotime($endDate);
|
||||
$today = date('Y-m-d');
|
||||
$hMinus2Timestamp = strtotime('-2 days'); // H-2 dari hari ini
|
||||
|
||||
// Validasi startdate harus sebelum atau sama dengan H-2
|
||||
if ($startTimestamp > $hMinus2Timestamp) {
|
||||
$this->sys_error("startdate harus sebelum atau sama dengan H-2 dari hari ini (" . date('Y-m-d', $hMinus2Timestamp) . ")");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validasi jika enddate sebelum startdate
|
||||
if ($endTimestamp < $startTimestamp) {
|
||||
$this->sys_error("enddate tidak boleh lebih awal dari startdate.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Jika validasi lolos
|
||||
$result = array(
|
||||
"startdate" => $startDate,
|
||||
"enddate" => $endDate
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
class Departement extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "DEPARTEMEN API";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_count = "SELECT count(*) as total
|
||||
FROM m_department
|
||||
WHERE M_DepartmentIsActive = 'Y'
|
||||
AND (M_DepartmentCode LIKE ? OR M_DepartmentName LIKE ?)";
|
||||
$qry_count = $this->db->query($sql_count, [$search, $search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_count) {
|
||||
$tot_count = $qry_count->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("department count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_DepartmentID,
|
||||
M_DepartmentCode,
|
||||
M_DepartmentName,
|
||||
M_DepartmentCreated,
|
||||
M_DepartmentLastUpdated,
|
||||
'' as rownumber
|
||||
FROM m_department
|
||||
WHERE M_DepartmentIsActive = 'Y'
|
||||
AND (M_DepartmentCode LIKE ? OR M_DepartmentName LIKE ?)
|
||||
ORDER BY M_DepartmentID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("department list error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$rows[$key]['rownumber'] = $key + 1;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['nameDepartment']) || trim($prm['nameDepartment']) == "") {
|
||||
$this->sys_error("Department name is required");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['codeDepartment']) || trim($prm['codeDepartment']) == "") {
|
||||
$this->sys_error("Code name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$nameDepartment = trim($prm['nameDepartment']);
|
||||
$codeDepartment = trim($prm['codeDepartment']);
|
||||
|
||||
// Check for existing department with same name
|
||||
$sql_check = "SELECT COUNT(*) as total FROM m_department
|
||||
WHERE M_DepartmentName = ? AND M_DepartmentIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$nameDepartment]);
|
||||
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Nama department sudah ada");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO m_department(
|
||||
M_DepartmentCode,
|
||||
M_DepartmentName,
|
||||
M_DepartmentIsActive,
|
||||
M_DepartmentUserID,
|
||||
M_DepartmentCreated
|
||||
) VALUES(?,?,'Y',?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$codeDepartment,
|
||||
$nameDepartment,
|
||||
$userId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("department insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM m_department WHERE M_DepartmentCode = '{$codeDepartment}' AND M_DepartmentIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['departmentId']) || !is_numeric($prm['departmentId'])) {
|
||||
$this->sys_error("Department ID is required");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['nameDepartment']) || trim($prm['nameDepartment']) == "") {
|
||||
$this->sys_error("Department name is required");
|
||||
exit;
|
||||
}
|
||||
if (!isset($prm['codeDepartment']) || trim($prm['codeDepartment']) == "") {
|
||||
$this->sys_error("Code name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$departmentId = $prm['departmentId'];
|
||||
$nameDepartment = trim($prm['nameDepartment']);
|
||||
$codeDepartment = trim($prm['codeDepartment']);
|
||||
|
||||
// Check if department exists
|
||||
$sql_exist = "SELECT COUNT(*) as total FROM m_department
|
||||
WHERE M_DepartmentID = ? AND M_DepartmentIsActive = 'Y'";
|
||||
$qry_exist = $this->db->query($sql_exist, [$departmentId]);
|
||||
if ($qry_exist && $qry_exist->result_array()[0]['total'] == 0) {
|
||||
$this->sys_error("Department not found");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check for existing department with same name (excluding current department)
|
||||
$sql_check = "SELECT COUNT(*) as total FROM m_department
|
||||
WHERE M_DepartmentName = ? AND M_DepartmentID != ?
|
||||
AND M_DepartmentIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$nameDepartment, $departmentId]);
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Nama department sudah ada");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update department
|
||||
$sql = "UPDATE m_department SET
|
||||
M_DepartmentCode = ?,
|
||||
M_DepartmentName = ?,
|
||||
M_DepartmentUserID = ?,
|
||||
M_DepartmentLastUpdated = NOW()
|
||||
WHERE M_DepartmentID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$codeDepartment,
|
||||
$nameDepartment,
|
||||
$userId,
|
||||
$departmentId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("department update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
// Get updated record
|
||||
$sql_get = "SELECT * FROM m_department WHERE M_DepartmentID = ? AND M_DepartmentIsActive = 'Y'";
|
||||
$records = $this->db->query($sql_get, [$departmentId])->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['departmentId']) || !is_numeric($prm['departmentId'])) {
|
||||
$this->sys_error("Department ID is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$departmentId = $prm['departmentId'];
|
||||
|
||||
// Check if department exists and is active
|
||||
$sql_exist = "SELECT COUNT(*) as total FROM m_department
|
||||
WHERE M_DepartmentID = ? AND M_DepartmentIsActive = 'Y'";
|
||||
$qry_exist = $this->db->query($sql_exist, [$departmentId]);
|
||||
if ($qry_exist && $qry_exist->result_array()[0]['total'] == 0) {
|
||||
$this->sys_error("Department not found");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Soft delete by updating IsActive to 'N'
|
||||
$sql = "UPDATE m_department SET
|
||||
M_DepartmentIsActive = 'N',
|
||||
M_DepartmentUserID = ?,
|
||||
M_DepartmentLastUpdated = NOW()
|
||||
WHERE M_DepartmentID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userId,
|
||||
$departmentId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("department delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"message" => "Department deleted successfully",
|
||||
"departmentId" => $departmentId
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
314
application/controllers/mockup/masterdata/accounting/Divisi.php
Normal file
314
application/controllers/mockup/masterdata/accounting/Divisi.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
class Divisi extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Training Playground";
|
||||
echo "<br>";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$sql_data = "";
|
||||
$sql_filter = "";
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
|
||||
// sort
|
||||
$sortBy = $prm['sortBy'];
|
||||
$sortStatus = $prm['sortStatus'];
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy . " " . $sortStatus;
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
// $number_limit = 1;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
|
||||
// $sql_filter .= "select count(distinct ItemUnitID, ItemUnitCode,
|
||||
// ItemUnitName)
|
||||
// as total
|
||||
// from itemunit
|
||||
// where ItemUnitIsActive = 'Y'
|
||||
// AND (
|
||||
// ItemUnitCode like ?
|
||||
// OR ItemUnitName like ?
|
||||
// )";
|
||||
|
||||
|
||||
$sql_filter .= "
|
||||
select count(*) as total from division where DivisionIsActive = 'Y' AND ( DivisionName like ? OR DivisionCode like ?)";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $search]);
|
||||
// echo $this->db->last_query();
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
// $tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_count = $qry_filter->row()->total;
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("itemunit count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_data .= "select
|
||||
distinct
|
||||
DivisionCode as code,
|
||||
DivisionName as name,
|
||||
DivisionID as id,
|
||||
DivisionKodeSurat
|
||||
from division
|
||||
where DivisionIsActive = 'Y'
|
||||
AND (
|
||||
DivisionCode like ?
|
||||
OR DivisionName like ?
|
||||
)
|
||||
$q_sort
|
||||
limit ? offset ?";
|
||||
|
||||
$qry_data = $this->db->query($sql_data, [
|
||||
$search,
|
||||
$search,
|
||||
$number_limit,
|
||||
$number_offset
|
||||
]);
|
||||
|
||||
// var_dump($this->db->last_query());
|
||||
|
||||
if ($qry_data) {
|
||||
$rows = $qry_data->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("division select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"qry" => $sql_data
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function add()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 3;
|
||||
|
||||
$divisi_name = $prm['name'];
|
||||
$lettercode = $prm['lettercode'];
|
||||
|
||||
if($divisi_name != ""){
|
||||
$sql = "SELECT COUNT(*) as exist
|
||||
FROM division
|
||||
WHERE DivisionIsActive = 'Y'
|
||||
AND (DivisionName = ? OR DivisionKodeSurat = ?)";
|
||||
$query_count = $this->db->query($sql,[$divisi_name, $lettercode]);
|
||||
$get_count = $query_count->row_array();
|
||||
if($get_count['exist'] != 0){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division name already exist");
|
||||
exit;
|
||||
}
|
||||
$sql = "INSERT INTO division (
|
||||
DivisionCode,
|
||||
DivisionName,
|
||||
DivisionKodeSurat,
|
||||
DivisionIsActive,
|
||||
DivisionCreated,
|
||||
DivisionCreatedUserID
|
||||
) VALUES (fn_numbering('DV'), ?, ?, 'Y', NOW(), ?)";
|
||||
$query_insert = $this->db->query($sql,[$divisi_name, $lettercode, $userid]);
|
||||
if(!$query_insert){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division insert");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$divisi_id = $this->db->insert_id();
|
||||
$sql = "SELECT
|
||||
DivisionID as id,
|
||||
DivisionCode as code,
|
||||
DivisionName as name ,
|
||||
DivisionKodeSurat
|
||||
FROM division
|
||||
WHERE DivisionIsActive = 'Y' AND DivisionID = ?";
|
||||
$query_select = $this->db->query($sql,[$divisi_id]);
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $query_select->row_array()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edit()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 1;
|
||||
$id = $prm['id'];
|
||||
$divisi_name = $prm['name'];
|
||||
$lettercode = $prm['lettercode'];
|
||||
|
||||
if($divisi_name != "" && $id != "" && $id != 0){
|
||||
$sql = "SELECT COUNT(*) as exist
|
||||
FROM division
|
||||
WHERE DivisionIsActive = 'Y'
|
||||
AND (DivisionName = ? OR DivisionKodeSurat = ?)
|
||||
AND DivisionID != ?";
|
||||
$query_count = $this->db->query($sql,[$divisi_name, $lettercode, $id]);
|
||||
$get_count = $query_count->row_array();
|
||||
if($get_count['exist'] != 0){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division name already exist");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE division SET
|
||||
DivisionName = ?,
|
||||
DivisionKodeSurat = ?,
|
||||
DivisionLastUpdated = now(),
|
||||
DivisionLastUpdatedUserID = ?
|
||||
WHERE DivisionID = ?";
|
||||
$query_update = $this->db->query($sql,[$divisi_name, $lettercode, $userid, $id]);
|
||||
if(!$query_update){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division update");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$sql = "SELECT
|
||||
DivisionID as id,
|
||||
DivisionCode as code,
|
||||
DivisionName as name,
|
||||
DivisionKodeSurat
|
||||
FROM division
|
||||
WHERE DivisionIsActive = 'Y' AND DivisionID = ?";
|
||||
$query_select = $this->db->query($sql,[$id]);
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $query_select->row_array()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 1;
|
||||
if($id != "" && $id != 0){
|
||||
$sql = "UPDATE division SET DivisionIsActive = 'N', DivisionDeleted = now(), DivisionDeletedUserID = ? WHERE DivisionID = ?";
|
||||
$query_update = $this->db->query($sql,[$userid, $id]);
|
||||
if(!$query_update){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("division delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
class GatewayAutoJurnal extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
private $host;
|
||||
private $endpointTypes = [
|
||||
'SALES' => 'insertSales',
|
||||
'AR' => 'insertAr',
|
||||
'ARPAYMENT' => 'insertArPayment',
|
||||
'RKTAGIHAN' => 'insertRkTagihan',
|
||||
'RKPELUNASAN' => 'insertRkPelunasan'
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$this->host = $protocol . '://' . $_SERVER['HTTP_HOST'] . '/one-api/mockup/masterdata/accounting/Mediajurnalauto';
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "GATEWAY INJECT AUTO COUNT MEDIA JURNAL CABANG PER TANGGAL";
|
||||
}
|
||||
|
||||
/**
|
||||
* API endpoint to inject data based on POST parameters
|
||||
*/
|
||||
public function inject($branchCode, $startDate, $endDate, $autoJurnalType) {
|
||||
// Validate required fields
|
||||
$requiredFields = ['branchCode' => $branchCode, 'startDate' => $startDate, 'endDate' => $endDate, 'autoJurnalType' => $autoJurnalType];
|
||||
foreach ($requiredFields as $field => $value) {
|
||||
if (empty($value)) {
|
||||
$this->sys_error("Missing required parameter: {$field}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Process the request
|
||||
$result = $this->injectData(
|
||||
$startDate,
|
||||
$endDate,
|
||||
$branchCode,
|
||||
$autoJurnalType
|
||||
);
|
||||
|
||||
// Send response
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
public function injectData($startDate, $endDate, $branchCode, $endpointType = 'ALL', $verbose = false) {
|
||||
// Validate inputs
|
||||
if (!$this->validateDate($startDate) || !$this->validateDate($endDate)) {
|
||||
$this->sys_error("Invalid date format. Use Y-m-d format.");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($branchCode)) {
|
||||
$this->sys_error("Branch code is required.");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strtotime($startDate) > strtotime($endDate)) {
|
||||
$this->sys_error("Start date cannot be greater than end date.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Define endpoints to use based on type
|
||||
$selectedEndpoints = [];
|
||||
|
||||
// Process single or multiple endpoint types
|
||||
$typesToProcess = is_array($endpointType) ? $endpointType : [$endpointType];
|
||||
|
||||
foreach ($typesToProcess as $type) {
|
||||
$type = strtoupper($type);
|
||||
|
||||
// If 'ALL' is specified, use all endpoints
|
||||
if ($type === 'ALL') {
|
||||
foreach ($this->endpointTypes as $key => $endpoint) {
|
||||
$selectedEndpoints[$endpoint] = "{$this->host}/{$endpoint}/{$branchCode}/%s";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if the specified type exists
|
||||
if (isset($this->endpointTypes[$type])) {
|
||||
$endpointName = $this->endpointTypes[$type];
|
||||
$selectedEndpoints[$endpointName] = "{$this->host}/{$endpointName}/{$branchCode}/%s";
|
||||
}
|
||||
}
|
||||
|
||||
// If no valid endpoint types were provided
|
||||
if (empty($selectedEndpoints)) {
|
||||
$this->sys_error("Invalid endpoint type specified. Valid types are: " . implode(', ', array_keys($this->endpointTypes)) . ", or ALL");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Convert dates to DateTime objects for iteration
|
||||
$currentDate = new DateTime($startDate);
|
||||
$end = new DateTime($endDate);
|
||||
|
||||
$results = [];
|
||||
|
||||
// Loop through each day in the range
|
||||
while ($currentDate <= $end) {
|
||||
$dateStr = $currentDate->format('Y-m-d');
|
||||
|
||||
// Call each selected endpoint for the current date
|
||||
foreach ($selectedEndpoints as $endpointName => $endpointUrl) {
|
||||
$url = sprintf($endpointUrl, $dateStr);
|
||||
$response = $this->curlGet($url);
|
||||
|
||||
$results[$dateStr][$endpointName] = $response;
|
||||
|
||||
// Optional: Add delay to prevent overwhelming the API
|
||||
usleep(100000); // 0.1 second delay
|
||||
}
|
||||
|
||||
// Move to next day
|
||||
$currentDate->modify('+1 day');
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'data' => $results,
|
||||
'summary' => [
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
'branchCode' => $branchCode,
|
||||
'endpointTypes' => $typesToProcess,
|
||||
'totalDays' => count($results)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function curlGet($url) {
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_CONNECTTIMEOUT => 30
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($error) {
|
||||
return [
|
||||
'success' => false,
|
||||
'code' => 0,
|
||||
'message' => $error
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => ($httpCode >= 200 && $httpCode < 300),
|
||||
'code' => $httpCode,
|
||||
'response' => $response
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate date format
|
||||
*
|
||||
* @param string $date Date to validate
|
||||
* @return bool Whether the date is valid
|
||||
*/
|
||||
private function validateDate($date) {
|
||||
$d = DateTime::createFromFormat('Y-m-d', $date);
|
||||
return $d && $d->format('Y-m-d') === $date;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
<?php
|
||||
class Itemregional extends MY_Controller{
|
||||
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "AUTH API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
// search
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? trim($prm["search"]) : '';
|
||||
$search = ($search !== '') ? "%$search%" : "%%";
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0;
|
||||
|
||||
$sql = "SELECT
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
M_ItemItem_CategoryID,
|
||||
M_ItemInventoryCode,
|
||||
M_ItemNat_GroupID,
|
||||
M_ItemNat_SubGroupID,
|
||||
M_ItemFa_ClassID,
|
||||
|
||||
-- Data item regional
|
||||
M_ItemRegionalID,
|
||||
M_ItemRegionalS_RegionalID,
|
||||
M_ItemRegionalMinQty,
|
||||
M_ItemRegionalItemUnitID,
|
||||
|
||||
-- Data Satuan
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
|
||||
-- Regional
|
||||
S_RegionalID,
|
||||
S_RegionalName
|
||||
|
||||
|
||||
FROM m_itemregional
|
||||
JOIN m_item ON M_ItemID = M_ItemRegionalM_ItemID
|
||||
JOIN s_regional ON S_RegionalID = M_ItemRegionalS_RegionalID
|
||||
JOIN itemunit ON ItemUnitID = M_ItemRegionalItemUnitID
|
||||
|
||||
|
||||
WHERE M_ItemRegionalIsActive = 'Y'
|
||||
AND (
|
||||
M_ItemDesc LIKE CONCAT('%', '$search', '%')
|
||||
OR S_RegionalName LIKE CONCAT('%', '$search', '%')
|
||||
)
|
||||
ORDER BY M_ItemRegionalID DESC";
|
||||
|
||||
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db_onedev->query($sql_total);
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("select m_itemregional count error", $this->db_onedev);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
|
||||
$qry = $this->db_onedev->query($sql_select);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db_onedev->trans_rollback();
|
||||
$this->sys_error_db("select m_itemregional error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$response = [
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
];
|
||||
|
||||
$this->sys_ok($response);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getItem()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm['search'];
|
||||
// $where_search = "%%";
|
||||
$where_search_desc = '%'.$search.'%';
|
||||
$where_search_acc = "$search%";
|
||||
|
||||
$sql = "SELECT
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
M_ItemItem_CategoryID,
|
||||
M_ItemInventoryCode,
|
||||
M_ItemNat_GroupID,
|
||||
M_ItemNat_SubGroupID,
|
||||
M_ItemM_InventarisGolID,
|
||||
M_ItemPurchaseUOM,
|
||||
M_ItemBaseUOM,
|
||||
M_ItemItem_UnitID
|
||||
FROM m_item
|
||||
WHERE M_ItemIsActive = 'Y'
|
||||
AND
|
||||
(
|
||||
M_ItemDesc LIKE '$where_search_desc'
|
||||
OR M_ItemCode LIKE '$where_search_acc'
|
||||
)";
|
||||
|
||||
// echo $sql;
|
||||
// die();
|
||||
$qry = $this->db_onedev->query($sql, array());
|
||||
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get coa pendapatan");
|
||||
exit;
|
||||
}
|
||||
$result = $qry->result_array();
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm['search'];
|
||||
// $where_search = "%%";
|
||||
$where_search_desc = '%'.$search.'%';
|
||||
$where_search_acc = "$search%";
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND
|
||||
S_RegionalName LIKE '$where_search_acc'";
|
||||
|
||||
// echo $sql;
|
||||
// die();
|
||||
$qry = $this->db_onedev->query($sql, array());
|
||||
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get coa pendapatan");
|
||||
exit;
|
||||
}
|
||||
$result = $qry->result_array();
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUnit()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm['search'];
|
||||
// $where_search = "%%";
|
||||
$where_search_desc = '%'.$search.'%';
|
||||
$where_search_acc = "$search%";
|
||||
|
||||
$sql = "SELECT
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND
|
||||
(
|
||||
ItemUnitName LIKE '$where_search_desc'
|
||||
OR ItemUnitCode LIKE '$where_search_acc'
|
||||
)";
|
||||
|
||||
// echo $sql;
|
||||
// die();
|
||||
$qry = $this->db_onedev->query($sql, array());
|
||||
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get unit");
|
||||
exit;
|
||||
}
|
||||
$result = $qry->result_array();
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// addData
|
||||
function addData()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
|
||||
|
||||
// Extract input parameters
|
||||
$M_ItemRegionalS_RegionalID = isset($prm['M_ItemRegionalS_RegionalID']) ? $prm['M_ItemRegionalS_RegionalID'] : 0;
|
||||
$M_ItemRegionalM_ItemID = isset($prm['M_ItemRegionalM_ItemID']) ? $prm['M_ItemRegionalM_ItemID'] : 0;
|
||||
$M_ItemRegionalQty = isset($prm['M_ItemRegionalQty']) ? $prm['M_ItemRegionalQty'] : 0;
|
||||
$M_ItemRegionalItemUnitID = isset($prm['M_ItemRegionalItemUnitID']) ? $prm['M_ItemRegionalItemUnitID'] : 0;
|
||||
|
||||
// Construct SQL query
|
||||
$sql = "INSERT INTO m_itemregional (
|
||||
M_ItemRegionalM_ItemID,
|
||||
M_ItemRegionalS_RegionalID,
|
||||
M_ItemRegionalMinQty,
|
||||
M_ItemRegionalItemUnitID,
|
||||
M_ItemRegionalUserID,
|
||||
M_ItemRegionalCreated,
|
||||
M_ItemRegionalLastUpdated
|
||||
) VALUES (
|
||||
'$M_ItemRegionalM_ItemID',
|
||||
'$M_ItemRegionalS_RegionalID',
|
||||
'$M_ItemRegionalQty',
|
||||
'$M_ItemRegionalItemUnitID',
|
||||
'$userid',
|
||||
NOW(),
|
||||
NOW()
|
||||
)";
|
||||
|
||||
// Execute query
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db_onedev->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get_by_id
|
||||
function get_by_id()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
// m_itemregional
|
||||
$M_ItemRegionalID = isset($prm['M_ItemRegionalID']) ? $prm['M_ItemRegionalID'] : 0;
|
||||
|
||||
$sql_m = "SELECT * FROM m_itemregional where M_ItemRegionalID = '$M_ItemRegionalID'";
|
||||
|
||||
$qry_m = $this->db_onedev->query($sql_m);
|
||||
if (!$qry_m) {
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_m = $qry_m->result_array();
|
||||
|
||||
// coa start
|
||||
$M_ItemRegionalCoaID = isset($prm['M_ItemRegionalCoaID']) ? $prm['M_ItemRegionalCoaID'] : 0;
|
||||
$sql_u = "SELECT * FROM coa where coaID = '$M_ItemRegionalCoaID'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'
|
||||
";
|
||||
|
||||
$qry_u = $this->db_onedev->query($sql_u);
|
||||
if (!$qry_u) {
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_u = $qry_u->result_array();
|
||||
|
||||
// empty $rows_u
|
||||
if (empty($rows_u)) {
|
||||
$rows_u = [[
|
||||
"coaID" => 0,
|
||||
"coaAccountNo" => '',
|
||||
"coaDescription" => '',
|
||||
"coaSubDescription" => '',
|
||||
"coaAccountType" => '',
|
||||
"coaSpecialAccountType" => '',
|
||||
"coaIsInput" => 'N',
|
||||
"coaReportSchedule" => '',
|
||||
"coaCurrencyCode" => '',
|
||||
"coaCashFlowCategory" => '',
|
||||
"coaCreated" => '',
|
||||
"coaLastUpdated" => '',
|
||||
"coaIsActive" => 'Y',
|
||||
"coaLevel" => 1
|
||||
]];
|
||||
}
|
||||
|
||||
// coa end
|
||||
|
||||
// accum depre start
|
||||
$M_ItemRegionalAccumDepreCoaID = $prm['M_ItemRegionalAccumDepreCoaID'];
|
||||
$sql_h = "SELECT * FROM coa where coaID = '$M_ItemRegionalAccumDepreCoaID'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'";
|
||||
|
||||
$qry_h = $this->db_onedev->query($sql_h);
|
||||
if (!$qry_h) {
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_h = $qry_h->result_array();
|
||||
// empty $rows_h
|
||||
if (empty($rows_h)) {
|
||||
$rows_h = [[
|
||||
"coaID" => 0,
|
||||
"coaAccountNo" => '',
|
||||
"coaDescription" => '',
|
||||
"coaSubDescription" => '',
|
||||
"coaAccountType" => '',
|
||||
"coaSpecialAccountType" => '',
|
||||
"coaIsInput" => 'N',
|
||||
"coaReportSchedule" => '',
|
||||
"coaCurrencyCode" => '',
|
||||
"coaCashFlowCategory" => '',
|
||||
"coaCreated" => '',
|
||||
"coaLastUpdated" => '',
|
||||
"coaIsActive" => 'Y',
|
||||
"coaLevel" => 1
|
||||
]];
|
||||
}
|
||||
// accum depre end
|
||||
|
||||
|
||||
|
||||
$response = [
|
||||
"record_m_itemregional" => $rows_m,
|
||||
"records_coa" => $rows_u,
|
||||
"records_accum_depre" => $rows_h,
|
||||
"sql" => $this->db_onedev->last_query()
|
||||
];
|
||||
|
||||
$this->sys_ok($response);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// editData
|
||||
function editData()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$M_ItemRegionalID = $prm['M_ItemRegionalID'];
|
||||
$M_ItemRegionalS_RegionalID = isset($prm['M_ItemRegionalS_RegionalID']) ? $prm['M_ItemRegionalS_RegionalID'] : 0;
|
||||
$M_ItemRegionalM_ItemID = isset($prm['M_ItemRegionalM_ItemID']) ? $prm['M_ItemRegionalM_ItemID'] : 0;
|
||||
$M_ItemRegionalQty = isset($prm['M_ItemRegionalQty']) ? $prm['M_ItemRegionalQty'] : 0;
|
||||
$M_ItemRegionalItemUnitID = isset($prm['M_ItemRegionalItemUnitID']) ? $prm['M_ItemRegionalItemUnitID'] : 0;
|
||||
|
||||
$sql = "UPDATE m_itemregional SET
|
||||
M_ItemRegionalS_RegionalID = '{$M_ItemRegionalS_RegionalID}',
|
||||
M_ItemRegionalM_ItemID = '{$M_ItemRegionalM_ItemID}',
|
||||
M_ItemRegionalMinQty = '{$M_ItemRegionalQty}',
|
||||
M_ItemRegionalItemUnitID = '{$M_ItemRegionalItemUnitID}',
|
||||
M_ItemRegionalUserID = '{$userid}',
|
||||
M_ItemRegionalLastUpdated = now()
|
||||
WHERE M_ItemRegionalID = '$M_ItemRegionalID'
|
||||
";
|
||||
|
||||
|
||||
// echo $sql;
|
||||
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db_onedev->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
// "sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// deleteData
|
||||
function deleteData()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$M_ItemRegionalID = $prm['M_ItemRegionalID'];
|
||||
|
||||
|
||||
$sql = "UPDATE m_itemregional
|
||||
SET
|
||||
M_ItemRegionalIsActive = 'N',
|
||||
M_ItemRegionalLastUpdated = now(),
|
||||
M_ItemRegionalUserID = '$userid'
|
||||
WHERE M_ItemRegionalID = '$M_ItemRegionalID'";
|
||||
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
$this->db_onedev->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db_onedev->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,702 @@
|
||||
<?php
|
||||
class Itemunit extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Training Playground";
|
||||
echo "<br>";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$sql_data = "";
|
||||
$sql_filter = "";
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if ($all == 'N') {
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
|
||||
// sort
|
||||
$sortBy = $prm['sortBy'];
|
||||
$sortStatus = $prm['sortStatus'];
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy . " " . $sortStatus;
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
// $number_limit = 1;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
// $number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
|
||||
// $sql_filter .= "select count(distinct ItemUnitID, ItemUnitCode,
|
||||
// ItemUnitName)
|
||||
// as total
|
||||
// from itemunit
|
||||
// where ItemUnitIsActive = 'Y'
|
||||
// AND (
|
||||
// ItemUnitCode like ?
|
||||
// OR ItemUnitName like ?
|
||||
// )";
|
||||
|
||||
|
||||
$sql_filter .= "
|
||||
select count(*) as total from (
|
||||
select distinct ItemUnitID, ItemUnitCode,
|
||||
ItemUnitName
|
||||
from itemunit
|
||||
where ItemUnitIsActive = 'Y'
|
||||
AND (
|
||||
ItemUnitCode like ?
|
||||
OR ItemUnitName like ?)
|
||||
) x";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $search]);
|
||||
// echo $this->db->last_query();
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
// $tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_count = $qry_filter->row()->total;
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("itemunit count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_data .= "select
|
||||
distinct ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCode as code,
|
||||
ItemUnitName as name,
|
||||
ItemUnitID as id
|
||||
from itemunit
|
||||
where ItemUnitIsActive = 'Y'
|
||||
AND (
|
||||
ItemUnitCode like ?
|
||||
OR ItemUnitName like ?
|
||||
)
|
||||
$q_sort
|
||||
limit ? offset ?";
|
||||
|
||||
$qry_data = $this->db->query($sql_data, [
|
||||
$search,
|
||||
$search,
|
||||
$number_limit,
|
||||
$number_offset
|
||||
]);
|
||||
|
||||
// var_dump($this->db->last_query());
|
||||
|
||||
if ($qry_data) {
|
||||
$rows = $qry_data->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("itemunit select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_filter" => count($rows),
|
||||
"records" => $rows,
|
||||
"qry" => $sql_data
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function add()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 3;
|
||||
|
||||
$unit_name_search = "";
|
||||
$unit_name = "";
|
||||
if (isset($prm['unit_name'])) {
|
||||
$unit_name_search = trim($prm["unit_name"]);
|
||||
$unit_name = trim($prm['unit_name']);
|
||||
if ($unit_name_search != "") {
|
||||
$unit_name_search = $prm['unit_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql_count = "SELECT COUNT(*) as exist
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName = ?";
|
||||
$query_count = $this->db->query($sql_count, [
|
||||
$unit_name_search
|
||||
]);
|
||||
|
||||
$last_query_count = $this->db->last_query();
|
||||
|
||||
if (!$query_count) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit search & count by name");
|
||||
exit;
|
||||
} else {
|
||||
// substring date
|
||||
// $date = date('Y');
|
||||
// $substring_date = substr($date,-2);
|
||||
|
||||
// var_dump($substring_date);
|
||||
|
||||
$unit_code_generate = "UI";
|
||||
|
||||
$get_count = $query_count->row_array();
|
||||
if ($get_count['exist'] == 0) {
|
||||
// call fungsi untuk generate code
|
||||
$sql_generate_code = "select fn_numbering(?) as code";
|
||||
$query_generate_code = $this->db->query(
|
||||
$sql_generate_code,
|
||||
[
|
||||
$unit_code_generate
|
||||
]
|
||||
);
|
||||
|
||||
if (!$query_generate_code) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit call sp");
|
||||
exit;
|
||||
}
|
||||
|
||||
$get_unit_code = $query_generate_code->row_array();
|
||||
$unit_code = $get_unit_code['code'];
|
||||
|
||||
// query insert
|
||||
$sql_insert = "INSERT INTO itemunit
|
||||
(
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCreated,
|
||||
ItemUnitLastUpdated,
|
||||
ItemUnitUserID
|
||||
)
|
||||
VALUES (?, ?, now(), now(), ?)";
|
||||
|
||||
$query_insert = $this->db->query($sql_insert, [
|
||||
$unit_code,
|
||||
$unit_name,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$query_insert) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
// var_dump($this->db->affected_rows());
|
||||
$insert_id = $this->db->insert_id();
|
||||
// print_r($insert_id);
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$insert_id
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit select json");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
// print_r($json_after_log);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.itemunit_log(
|
||||
ItemUnitLogItemUnitID,
|
||||
ItemUnitLogStatus,
|
||||
ItemUnitLogJSONBefore,
|
||||
ItemUnitLogJSONAfter,
|
||||
ItemUnitLogUserID,
|
||||
ItemUnitLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'ADD',
|
||||
null,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$insert_id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit insert log");
|
||||
exit;
|
||||
}
|
||||
|
||||
// sukses
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($get_count['exist'] != 0) {
|
||||
array_push($errors, array(
|
||||
'field' => 'name',
|
||||
'msg' => 'Nama sudah ada'
|
||||
));
|
||||
}
|
||||
|
||||
$insert_id = $this->db->insert_id();
|
||||
// print_r($insert_id);
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$insert_id
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit select json");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
// print_r($json_after_log);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.itemunit_log(
|
||||
ItemUnitLogItemUnitID,
|
||||
ItemUnitLogStatus,
|
||||
ItemUnitLogJSONBefore,
|
||||
ItemUnitLogJSONAfter,
|
||||
ItemUnitLogUserID,
|
||||
ItemUnitLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'DELETE',
|
||||
null,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$insert_id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit insert log");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// sukses
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edit()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 1;
|
||||
$id = $prm['id'];
|
||||
|
||||
$unit_name_search = "";
|
||||
$unit_name = "";
|
||||
if (isset($prm['unit_name'])) {
|
||||
$unit_name_search = trim($prm["unit_name"]);
|
||||
$unit_name = trim($prm['unit_name']);
|
||||
if ($unit_name_search != "") {
|
||||
$unit_name_search = $prm['unit_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql_count = "SELECT COUNT(*) as exist
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName = ?";
|
||||
$query_count = $this->db->query($sql_count, [
|
||||
$unit_name_search
|
||||
]);
|
||||
|
||||
$last_query_count = $this->db->last_query();
|
||||
|
||||
if (!$query_count) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit search & count by name");
|
||||
exit;
|
||||
} else {
|
||||
// substring date
|
||||
// $date = date('Y');
|
||||
// $substring_date = substr($date,-2);
|
||||
|
||||
// var_dump($substring_date);
|
||||
|
||||
// $unit_code_generate = "UI";
|
||||
|
||||
$get_count = $query_count->row_array();
|
||||
// if($get_count['exist'] == 0)
|
||||
// {
|
||||
// call fungsi untuk generate code
|
||||
// $sql_generate_code = "select fn_numbering(?) as code";
|
||||
// $query_generate_code = $this->db->query($sql_generate_code,
|
||||
// [
|
||||
// $unit_code_generate
|
||||
// ]);
|
||||
|
||||
// if(!$query_generate_code){
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db("itemunit call sp");
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $get_unit_code = $query_generate_code->row_array();
|
||||
// $unit_code = $get_unit_code['code'];
|
||||
|
||||
// json before
|
||||
$sql_json_before = "SELECT *
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$id
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit select json before");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before_log = json_encode($data_before_by_id);
|
||||
|
||||
// print_r($json_before_log);
|
||||
|
||||
// query update
|
||||
$sql_update = "UPDATE itemunit
|
||||
set
|
||||
ItemUnitName = ?,
|
||||
ItemUnitLastUpdated = now(),
|
||||
ItemUnitUserID = ?
|
||||
WHERE ItemUnitID = ?";
|
||||
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$unit_name,
|
||||
$userid,
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$query_update) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($json_before_log);
|
||||
|
||||
// print_r($query_data);
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitID = ?";
|
||||
|
||||
$qry_json_after = $this->db->query(
|
||||
$sql_json_after,
|
||||
[
|
||||
$id
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_after) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit select json after");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_after_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after_log = json_encode($data_after_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.itemunit_log(
|
||||
ItemUnitLogItemUnitID,
|
||||
ItemUnitLogStatus,
|
||||
ItemUnitLogJSONBefore,
|
||||
ItemUnitLogJSONAfter,
|
||||
ItemUnitLogUserID,
|
||||
ItemUnitLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'EDIT',
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$id,
|
||||
$json_before_log,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit edit log");
|
||||
exit;
|
||||
}
|
||||
|
||||
// sukses
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $errors = array();
|
||||
// if($get_count['exist'] != 0){
|
||||
// array_push($errors,array(
|
||||
// 'field'=>'name',
|
||||
// 'msg'=>'Nama sudah ada'
|
||||
// ));
|
||||
// }
|
||||
|
||||
// $result = array (
|
||||
// "total" => -1,
|
||||
// "errors" => $errors,
|
||||
// "records" => 0);
|
||||
// $this->sys_ok($result);
|
||||
// }
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//begin transaction
|
||||
$this->db->trans_begin();
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
// $userid = 1;
|
||||
|
||||
$sql_delete = "UPDATE itemunit
|
||||
SET ItemUnitIsActive = 'N',
|
||||
ItemUnitLastUpdated = now(),
|
||||
ItemUnitUserID = ?
|
||||
WHERE ItemUnitID = ?";
|
||||
|
||||
$query_delete = $this->db->query($sql_delete, [
|
||||
$userid,
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$query_delete) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
// var_dump($this->db->affected_rows());
|
||||
// print_r($insert_id);
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'N'
|
||||
AND ItemUnitID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query(
|
||||
$sql_json_before,
|
||||
[
|
||||
$id
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit select json");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
// print_r($json_after_log);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.itemunit_log(
|
||||
ItemUnitLogItemUnitID,
|
||||
ItemUnitLogStatus,
|
||||
ItemUnitLogJSONBefore,
|
||||
ItemUnitLogJSONAfter,
|
||||
ItemUnitLogUserID,
|
||||
ItemUnitLogCreated
|
||||
) VALUES (
|
||||
?,
|
||||
'DELETE',
|
||||
null,
|
||||
?,
|
||||
?,
|
||||
now()
|
||||
)";
|
||||
|
||||
$qry_insert_log = $this->db->query(
|
||||
$sql_insert_log,
|
||||
[
|
||||
$id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]
|
||||
);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunit delete log");
|
||||
exit;
|
||||
}
|
||||
|
||||
// sukses
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
// sukses
|
||||
// $this->db->trans_commit();
|
||||
// $result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
// $this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
<?php
|
||||
|
||||
class JournalItemOut extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PAYMENT VOUCHER API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = $prm['regionalId'] ?? null;
|
||||
$branchCode = $prm['branchCode'] ?? null;
|
||||
$periodeid = $prm['periodeid'] ?? null;
|
||||
$xdate = $prm['xdate'] ?? null;
|
||||
$search = $prm['search'] ?? '';
|
||||
$search = '%' . trim($search) . '%';
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?"
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOITEMOUT'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int)($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, array($value["jurnalID"]));
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row['JurnalErr_Msg'] = json_decode($row['JurnalErr_Msg'], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = 'Y';
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = 'N';
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'AUTOITEMOUT')
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, array($value["jurnalID"]));
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'total' => $totalPage,
|
||||
'totalfilter' => $totalCount,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm['regionalId'] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r['S_RegionalID'] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => ""
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r['M_BranchCode'] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
class JournalItemUsage extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "ITEM USAGE API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOITEMUSAGE'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'AUTOITEMUSAGE')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
AND M_ApproveLevelIsActive = 'Y'
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTOITEMUSAGE'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = "";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$para["periodeID"],
|
||||
$para["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTOITEMUSAGE'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$para["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,597 @@
|
||||
<?php
|
||||
|
||||
class JournalPenyesuaian extends MY_Controller {
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "Jurnal Penyesuaian";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
# QUERY #
|
||||
|
||||
public function getDaftarPeriode() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID,
|
||||
periodeName,
|
||||
DATE_FORMAT(periodeStartDate, '%d %M %Y') AS periodeStartDate,
|
||||
DATE_FORMAT(periodeEndDate, '%d %M %Y') AS periodeEndDate
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get daftar periode");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDaftarTipeJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$sql = "SELECT
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeIsActive = 'Y'";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get daftar tipe jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$all = [
|
||||
'JurnalTypeID' => 0,
|
||||
'JurnalTypeCode' => "X",
|
||||
'JurnalTypeName' => "SEMUA"
|
||||
];
|
||||
array_unshift($data, $all);
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDaftarJournalClosed() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$isFromBranch = " ";
|
||||
if ($user['M_BranchID'] != "0") {
|
||||
$isFromBranch .= " AND jurnalM_BranchCode = '{$user['M_BranchCode']}'";
|
||||
}
|
||||
|
||||
$keyword = "%";
|
||||
if ($param['search'] != '') {
|
||||
$keyword .= $param['search'] . "%";
|
||||
}
|
||||
|
||||
$row_limit = 5;
|
||||
$curr_page = (int)($param['currpage'] ?? 1);
|
||||
$row_offset = max(0, ($curr_page - 1) * $row_limit);
|
||||
|
||||
$sql_base = "SELECT
|
||||
jurnalID,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
S_RegionalName,
|
||||
M_BranchName,
|
||||
M_BranchCompanyName
|
||||
FROM jurnal
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeIsActive = 'Y'
|
||||
JOIN m_branch_company ON M_BranchCompanyID = jurnalM_BranchCompanyID
|
||||
JOIN s_regional ON S_RegionalID = JurnalS_RegionalID
|
||||
LEFT JOIN m_branch ON M_BranchCode = jurnalM_BranchCode
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsClosed = 'Y'
|
||||
AND (jurnalJurnalTypeID = ? OR 0 = ?)
|
||||
AND jurnalDate BETWEEN DATE(?) AND DATE(?)
|
||||
AND jurnalNo LIKE ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalDalamPenyesuaian = 'N'
|
||||
AND jurnalIsActive = 'Y'" . $isFromBranch;
|
||||
|
||||
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'], $keyword,
|
||||
$row_limit, $row_offset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] get listing jurnal closed");
|
||||
exit;
|
||||
}
|
||||
|
||||
// get total jurnal is closed
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) as x";
|
||||
$que_total = $this->db->query($sql_total, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'], $keyword,
|
||||
]);
|
||||
if (!$que_total) {
|
||||
$this->sys_error_db("[Error] get total all jurnal closed");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = [
|
||||
"records" => $que_data->result_array(),
|
||||
"total" => $que_total->row_array()['total']
|
||||
];
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetailJournalClosed() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID
|
||||
AND jurnalAddOnIsActive = 'Y'
|
||||
WHERE jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END, jurnalTxID ASC";
|
||||
$que = $this->db->query($sql, [$param['jurnalID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get detail data jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDaftarAccount() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$keyword = "%";
|
||||
if ($param['keyword'] != '') {
|
||||
$keyword = $param['keyword'] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDaftarJournalBalik() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$isFromBranch = " ";
|
||||
if ($user['M_BranchID'] != "0") {
|
||||
$isFromBranch .= " AND jurnalM_BranchCode = '{$user['M_BranchCode']}' ";
|
||||
}
|
||||
|
||||
$keyword = "%";
|
||||
if ($param['search'] != '') {
|
||||
$keyword .= $param['search'] . "%";
|
||||
}
|
||||
|
||||
$row_limit = 5;
|
||||
$curr_page = (int)($param['currpage'] ?? 1);
|
||||
$row_offset = max(0, ($curr_page - 1) * $row_limit);
|
||||
|
||||
$sql_base = "SELECT
|
||||
jurnalID,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
jurnalPenyesuaianStatus,
|
||||
S_RegionalName,
|
||||
M_BranchName,
|
||||
M_BranchCompanyName
|
||||
FROM jurnal
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeIsActive = 'Y'
|
||||
JOIN m_branch_company ON M_BranchCompanyID = jurnalM_BranchCompanyID
|
||||
JOIN s_regional ON S_RegionalID = JurnalS_RegionalID
|
||||
LEFT JOIN m_branch ON M_BranchCode = jurnalM_BranchCode
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND (jurnalJurnalTypeID = ? OR 0 = ?)
|
||||
AND jurnalDate BETWEEN DATE(?) AND DATE(?)
|
||||
AND jurnalNo LIKE ?
|
||||
AND jurnalIsPenyesuaian = 'Y'
|
||||
AND jurnalIsActive = 'Y'" . $isFromBranch;
|
||||
|
||||
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'], $keyword,
|
||||
$row_limit, $row_offset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] get listing jurnal closed");
|
||||
exit;
|
||||
}
|
||||
|
||||
// get total jurnal is closed
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) as x";
|
||||
$que_total = $this->db->query($sql_total, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'], $keyword,
|
||||
]);
|
||||
if (!$que_total) {
|
||||
$this->sys_error_db("[Error] get total all jurnal closed");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = [
|
||||
"records" => $que_data->result_array(),
|
||||
"total" => $que_total->row_array()['total']
|
||||
];
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetailJournalBalik() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID
|
||||
AND jurnalAddOnIsActive = 'Y'
|
||||
WHERE jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY jurnalTxID ASC";
|
||||
$que = $this->db->query($sql, [$param['jurnalID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get detail data jurnal penyesuaian");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# MUTATIONS #
|
||||
public function saveKoreksiJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
# Update old jurnal #
|
||||
$sql_oldjurnal = "UPDATE jurnal
|
||||
SET jurnalDalamPenyesuaian = 'Y'
|
||||
WHERE jurnalID = ?";
|
||||
$que_oldjurnal = $this->db->query($sql_oldjurnal, [$param['oldJurnalID']]);
|
||||
if (!$que_oldjurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status penyesuaian");
|
||||
exit;
|
||||
}
|
||||
|
||||
# Generate jurnal number #
|
||||
$sql_jurnalno = "SELECT `fn_numbering`('J') AS numbering";
|
||||
$que_jurnalno = $this->db->query($sql_jurnalno, []);
|
||||
if (!$que_jurnalno) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] generate jurnal number");
|
||||
exit;
|
||||
}
|
||||
$JurnalNo = $que_jurnalno->row_array()['numbering'];
|
||||
|
||||
# GET current periode id #
|
||||
$sql_periode = "SELECT periodeID FROM periode WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
AND DATE(NOW()) BETWEEN DATE(periodeStartDate) AND DATE(periodeEndDate)";
|
||||
$que_periode = $this->db->query($sql_periode, []);
|
||||
if (!$que_periode) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get periode id");
|
||||
exit;
|
||||
}
|
||||
if (!$que_periode->num_rows() === 0) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] waktu periode tidak ditemukan");
|
||||
exit;
|
||||
}
|
||||
$JurnalPeriodeID = $que_periode->row_array()['periodeID'];
|
||||
|
||||
# GET jurnal type #
|
||||
$JurnalTypeCode = $param['jurnalTypeCode'];
|
||||
if ($JurnalTypeCode != '' && substr($JurnalTypeCode, 0, 4) === 'AUTO') {
|
||||
$JurnalTypeCode = substr($JurnalTypeCode, 4);
|
||||
}
|
||||
|
||||
$sql_jurnaltype = "SELECT JurnalTypeID FROM jurnal_type WHERE JurnalTypeCode LIKE ?
|
||||
AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'";
|
||||
$que_jurnaltype = $this->db->query($sql_jurnaltype, ['%' . $JurnalTypeCode]);
|
||||
if (!$que_jurnaltype) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get jurnal type id/code");
|
||||
exit;
|
||||
}
|
||||
$JurnalTypeID = $que_jurnaltype->row_array()['JurnalTypeID'];
|
||||
|
||||
# INSERT jurnal header #
|
||||
$title = "Jurnal Penyesuaian dari Jurnal Nomor " . $param['jurnalNo'];
|
||||
$descp = "Penyesuaian Jurnal Nomor {$param['jurnalNo']} tanggal {$param['jurnalDate']}";
|
||||
|
||||
$sql_header_jurnal = "INSERT INTO jurnal (
|
||||
jurnalM_BranchCompanyID,
|
||||
JurnalS_RegionalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
jurnalJurnalTypeID,
|
||||
jurnalIsPenyesuaian,
|
||||
jurnalPenyesuaianStatus,
|
||||
jurnalM_UserID
|
||||
) VALUES (?,?,?,?,?,?,?,NOW(),?,'Y','draft', ?)";
|
||||
$que_header_jurnal = $this->db->query($sql_header_jurnal, [
|
||||
$user['M_BranchCompanyID'], $user['S_RegionalID'], $user['M_BranchCode'],
|
||||
$JurnalPeriodeID, $JurnalNo, $title, $descp, $JurnalTypeID, $user['M_UserID']
|
||||
]);
|
||||
if (!$que_header_jurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal header");
|
||||
exit;
|
||||
}
|
||||
$JurnalID = $this->db->insert_id();
|
||||
|
||||
foreach ($param['detailtrx'] as $key => $obj) {
|
||||
$sql_transac_jurnal = "INSERT INTO jurnal_tx (
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID
|
||||
) VALUES (?,?,?,?,?,?)";
|
||||
$que_transac_jurnal = $this->db->query($sql_transac_jurnal, [
|
||||
$JurnalID, $obj['coaID'], $obj['coaDescription'],
|
||||
$obj['debit'], $obj['kredit'], $user['M_UserID']
|
||||
]);
|
||||
if (!$que_transac_jurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal tx");
|
||||
exit;
|
||||
}
|
||||
$JurnalTxID = $this->db->insert_id();
|
||||
|
||||
$sql_addon_jurnal = "INSERT INTO jurnal_addon (
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnJurnalTxID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,?,?,NOW(),?)";
|
||||
$que_addon_jurnal = $this->db->query($sql_addon_jurnal, [
|
||||
$JurnalID, $JurnalTxID, $obj['infocode'], $obj['info'], $user['M_UserID']
|
||||
]);
|
||||
if (!$que_addon_jurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal addon");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] insert Jurnal Penyesuaian");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateStatusKoreksiJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error('Invalid Token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql_update = "UPDATE jurnal SET
|
||||
jurnalPenyesuaianStatus = ?,
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_update = $this->db->query($sql_update, [
|
||||
$param['status'], $param['jurnalID']
|
||||
]);
|
||||
if (!$que_update) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status {$param['status']} jurnal koreksi");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[success] jurnal koreksi {$param['status']}");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
AND M_ApproveLevelIsActive = 'Y'
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user['M_UserID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = array(
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => ''
|
||||
);
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
|
||||
class JournalVerifEdit extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "Verifikasi Edit Journal";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
# QUERY #
|
||||
public function getListPeriode() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID,
|
||||
periodeName,
|
||||
DATE_FORMAT(periodeStartDate, '%d %M %Y') AS periodeStartDate,
|
||||
DATE_FORMAT(periodeEndDate, '%d %M %Y') AS periodeEndDate
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get daftar periode");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getListTypeJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$sql = "SELECT
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeIsActive = 'Y'";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get daftar tipe jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$all = [
|
||||
'JurnalTypeID' => 0,
|
||||
'JurnalTypeCode' => "X",
|
||||
'JurnalTypeName' => "SEMUA"
|
||||
];
|
||||
array_unshift($data, $all);
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getListJournalEdit() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$isBranch = " ";
|
||||
if ($user['M_BranchID'] != '0') {
|
||||
$isBranch .= " AND jurnalM_BranchCode = '{$user['M_BranchCode']}'";
|
||||
}
|
||||
|
||||
$keyword = "%";
|
||||
if ($param['search'] != '') {
|
||||
$keyword = $param['search'] . "%";
|
||||
}
|
||||
|
||||
$row_limit = 10;
|
||||
$curr_page = (int)($param['page'] ?? 1);
|
||||
$row_ofset = max(0, ($curr_page - 1) * $row_limit);
|
||||
|
||||
$sql_base = "SELECT
|
||||
jurnalID,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalEditStatus,
|
||||
jurnalDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalRequestEditID,
|
||||
JurnalRequestEditStaffID,
|
||||
JurnalRequestEditStaffName,
|
||||
JurnalRequestEditStatusRequest,
|
||||
apr.M_UserUsername AS RequestApprovedBy,
|
||||
JurnalRequestEditStatusEdit,
|
||||
ape.M_UserUsername AS EditApprovedBy,
|
||||
S_RegionalName,
|
||||
M_BranchName,
|
||||
M_BranchCompanyName
|
||||
FROM jurnal
|
||||
JOIN jurnal_request_edit ON JurnalRequestEditJurnalID = jurnalID
|
||||
AND JurnalRequestEditIsActive = 'Y'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeIsActive = 'Y'
|
||||
JOIN m_branch_company ON M_BranchCompanyID = jurnalM_BranchCompanyID
|
||||
JOIN s_regional ON S_RegionalID = JurnalS_RegionalID
|
||||
LEFT JOIN m_branch ON M_BranchCode = jurnalM_BranchCode
|
||||
LEFT JOIN m_user apr ON apr.M_UserID = JurnalRequestEditApproveRequestBy
|
||||
LEFT JOIN m_user ape ON ape.M_UserID = JurnalRequestEditApproveEditBy
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND (jurnalJurnalTypeID = ? OR 0 = ?)
|
||||
AND jurnalDate BETWEEN DATE(?) AND DATE(?)
|
||||
AND jurnalNo LIKE ?
|
||||
AND jurnalIsActive = 'Y'
|
||||
" . $isBranch;
|
||||
|
||||
$sql_data = $sql_base . " LIMIT ? OFFSET ?";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'],
|
||||
$keyword, $row_limit, $row_ofset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] get daftar journal edit");
|
||||
exit;
|
||||
}
|
||||
|
||||
// get total all journal edit
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) as x";
|
||||
$que_total = $this->db->query($sql_total, [
|
||||
$param['periodeID'], $user['S_RegionalID'],
|
||||
$param['typeJournalID'], $param['typeJournalID'],
|
||||
$param['startdate'], $param['enddate'], $keyword
|
||||
]);
|
||||
if (!$que_total) {
|
||||
$this->sys_error_db("[Error] get total all journal edit");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = [
|
||||
"records" => $que_data->result_array(),
|
||||
"total" => $que_total->row_array()['total']
|
||||
];
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetailJournalEdit() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
## get latest edit change log data ##
|
||||
$sql_data = "SELECT
|
||||
JurnalEditLogID,
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID AS StaffUserID,
|
||||
IFNULL(NULLIF(M_UserFullName, ''), M_UserUsername) AS StaffName
|
||||
FROM acc_one_log.jurnal_edit_log
|
||||
JOIN m_user ON M_UserID = JurnalEditLogUserID
|
||||
WHERE JurnalEditLogIDJurnalID = ?
|
||||
AND JurnalEditLogIsActive = 'Y'
|
||||
ORDER BY JurnalEditLogID DESC
|
||||
LIMIT 1";
|
||||
$que_data = $this->db->query($sql_data, [$param['jurnalID']]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] get data change jurnal");
|
||||
exit;
|
||||
}
|
||||
$data = $que_data->result_array()[0];
|
||||
|
||||
$before = json_decode($data['JurnalEditLogIDJsonBefore'], true);
|
||||
$after = json_decode($data['JurnalEditLogIDJsonAfter'], true);
|
||||
|
||||
unset($data['JurnalEditLogIDJsonBefore']);
|
||||
unset($data['JurnalEditLogIDJsonAfter']);
|
||||
|
||||
$data['changeBefore'] = $before;
|
||||
$data['changeAfter'] = $after;
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
# MUTATION #
|
||||
public function requestEditJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
# insert into request jurnal edit #
|
||||
$sqlreq = "INSERT INTO jurnal_request_edit (
|
||||
JurnalRequestEditJurnalID,
|
||||
JurnalRequestEditStaffID,
|
||||
JurnalRequestEditStaffName,
|
||||
JurnalRequestEditUserID,
|
||||
JurnalRequestEditCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$quereq = $this->db->query($sqlreq, [
|
||||
$param['jurnalID'], $param['staffID'],
|
||||
$param['staffName'], $user['M_UserID']
|
||||
]);
|
||||
if (!$quereq) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert request edit into table jurnal request edit");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Request edit jurnal berhasil dibuat");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRequestEditJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
# update request jurnal edit status #
|
||||
$sqlreq = "UPDATE jurnal_request_edit SET
|
||||
JurnalRequestEditStatusRequest = ?,
|
||||
JurnalRequestEditApproveRequestBy = ?,
|
||||
JurnalRequestEditUpdated = NOW()
|
||||
WHERE JurnalRequestEditID = ?";
|
||||
$quereq = $this->db->query($sqlreq, [
|
||||
$param['status'], $user['M_UserID'],
|
||||
$param['JurnalRequestEditID']
|
||||
]);
|
||||
if (!$quereq) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update request edit status");
|
||||
exit;
|
||||
}
|
||||
|
||||
# update data header jurnal status edit #
|
||||
$sqlheader = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$queheader = $this->db->query($sqlheader, [$param['jurnalID']]);
|
||||
if (!$queheader) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update header jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status request");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveEditJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$old_jurnaltx = $param['oldjurnaltx'];
|
||||
$new_jurnaltx = $param['newjurnaltx'];
|
||||
|
||||
# log the data in accone log #
|
||||
$sql_addlog = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_addlog = $this->db->query($sql_addlog, [
|
||||
$param['jurnalID'], json_encode($old_jurnaltx),
|
||||
json_encode($new_jurnaltx), $user['M_UserID']
|
||||
]);
|
||||
if (!$que_addlog) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit;
|
||||
}
|
||||
$jurnalEditLogID = $this->db->insert_id();
|
||||
|
||||
# UPDATE table jurnal request edit #
|
||||
$sql_req = "UPDATE jurnal_request_edit SET
|
||||
JurnalRequestEditJurnalEditLogID = ?
|
||||
WHERE JurnalRequestEditID = ?";
|
||||
$que_req = $this->db->query($sql_req, [
|
||||
$jurnalEditLogID, $param['jurnalRequestEditID']
|
||||
]);
|
||||
if (!$que_req) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update table jurnal request edit");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] save edit jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifEditJurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
# UPDATE jurnal tx #
|
||||
$newtrx = $param['newtrx'];
|
||||
$sqltrx = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
foreach ($newtrx as $key => $obj) {
|
||||
$quetrx = $this->db->query($sqltrx, [
|
||||
$obj['coaID'], $obj['coaDescription'], $user['M_UserID'],
|
||||
$obj['jurnalTxID'], $obj['jurnalTxJurnalID']
|
||||
]);
|
||||
if (!$quetrx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update new jurnal tx");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
# UPDATE jurnal header edit status #
|
||||
$sql = "UPDATE jurnal
|
||||
SET jurnalEditStatus = 'N',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que = $this->db->query($sql, [$param['jurnalID']]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status edit");
|
||||
exit;
|
||||
}
|
||||
|
||||
# UPDATE jurnal status edit jurnal #
|
||||
$sqlreq = "UPDATE jurnal_request_edit SET
|
||||
JurnalRequestEditStatusEdit = ?,
|
||||
JurnalRequestEditApproveEditBy = ?,
|
||||
JurnalRequestEditUpdated = NOW()
|
||||
WHERE JurnalRequestEditID = ?";
|
||||
$quereq = $this->db->query($sqlreq, [
|
||||
$param['status'], $user['M_UserID'],
|
||||
$param['JurnalRequestEditID']
|
||||
]);
|
||||
if (!$quereq) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status edit jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] approve edit jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
class Journalar extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PENDAPATAN CASH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$periodeid = $prm["periodeid"];
|
||||
$xdate = $prm["xdate"];
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
DATE_FORMAT(jurnalDate, '%d %M %Y') as jurnalDatexx,
|
||||
jurnalType,
|
||||
jurnalTxID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
CONCAT(IFNULL(coaDescription, ''), ' | ', IFNULL(jurnalArM_CompanyName, '')) as descriptionAndCompanyName,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
periodeIsClosed,
|
||||
CASE
|
||||
WHEN coaAccountType = 'DB' THEN jurnalTxDebit
|
||||
WHEN coaAccountType = 'CR' THEN jurnalTxCredit
|
||||
END as value,
|
||||
jurnalArID,
|
||||
jurnalArRefNo,
|
||||
jurnalArM_CompanyCode,
|
||||
jurnalArM_CompanyName,
|
||||
0 as subtotal
|
||||
FROM jurnal
|
||||
JOIN jurnal_tx ON jurnalID = jurnalTxJurnalID
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
LEFT JOIN jurnal_ar ON jurnalTxID = jurnalArJurnalTxID
|
||||
AND jurnalArIsActive = 'Y'
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND jurnalperiodeID = ?
|
||||
AND jurnalType = 'AR'
|
||||
AND jurnalDate = ?";
|
||||
$qry = $this->db->query($sql, [$periodeid, $xdate]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalDebit = 0;
|
||||
$totalCredit = 0;
|
||||
$totalBalance = 0;
|
||||
|
||||
for ($i = 0; $i < count($rows); $i++) {
|
||||
// print_r($rows[$i]);
|
||||
// exit;
|
||||
$data = $rows[$i];
|
||||
if ($data['coaAccountType'] == 'DB') {
|
||||
$totalDebit = $totalDebit + floatval($data['value']);
|
||||
}
|
||||
if ($data['coaAccountType'] == 'CR') {
|
||||
$totalCredit = $totalCredit + floatval($data['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$totalBalance = $totalDebit - $totalCredit;
|
||||
$arrTotal = array('debit' => $totalDebit, 'credit' => $totalCredit, 'balance' => $totalBalance);
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
// print_r($value);
|
||||
// exit;
|
||||
$debittot = 0;
|
||||
$credittot = 0;
|
||||
$xsubtotal = 0;
|
||||
|
||||
if ($value['coaAccountType'] == 'DB') {
|
||||
$debittot = floatval($value['value']);
|
||||
}
|
||||
if ($value['coaAccountType'] == 'CR') {
|
||||
$credittot = floatval($value['value']);
|
||||
}
|
||||
$xsubtotal = $debittot + $credittot;
|
||||
$rows[$key]['subtotal'] = $xsubtotal;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'records' => $rows,
|
||||
'total' => $arrTotal
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
class Journalarpayment extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PAYMENT RECEIVE";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$periodeid = $prm["periodeid"];
|
||||
$xdate = $prm["xdate"];
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
DATE_FORMAT(jurnalDate, '%d %M %Y') as jurnalDatexx,
|
||||
jurnalType,
|
||||
jurnalTxID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
CONCAT(IFNULL(coaDescription, ''), ' | ', IFNULL(jurnalArM_CompanyName, '')) as descriptionAndCompanyName,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
periodeIsClosed,
|
||||
CASE
|
||||
WHEN coaAccountType = 'DB' THEN jurnalTxDebit
|
||||
WHEN coaAccountType = 'CR' THEN jurnalTxCredit
|
||||
END as value,
|
||||
jurnalArID,
|
||||
jurnalArRefNo,
|
||||
jurnalArM_CompanyCode,
|
||||
jurnalArM_CompanyName,
|
||||
0 as subtotal
|
||||
FROM jurnal
|
||||
JOIN jurnal_tx ON jurnalID = jurnalTxJurnalID
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
LEFT JOIN jurnal_ar ON jurnalTxID = jurnalArJurnalTxID
|
||||
AND jurnalArIsActive = 'Y'
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND jurnalperiodeID = ?
|
||||
AND jurnalType = 'ARPay'
|
||||
AND jurnalDate = ?";
|
||||
$qry = $this->db->query($sql, [$periodeid, $xdate]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalDebit = 0;
|
||||
$totalCredit = 0;
|
||||
$totalBalance = 0;
|
||||
|
||||
for ($i = 0; $i < count($rows); $i++) {
|
||||
// print_r($rows[$i]);
|
||||
// exit;
|
||||
$data = $rows[$i];
|
||||
if ($data['coaAccountType'] == 'DB') {
|
||||
$totalDebit = $totalDebit + floatval($data['value']);
|
||||
}
|
||||
if ($data['coaAccountType'] == 'CR') {
|
||||
$totalCredit = $totalCredit + floatval($data['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$totalBalance = $totalDebit - $totalCredit;
|
||||
$arrTotal = array('debit' => $totalDebit, 'credit' => $totalCredit, 'balance' => $totalBalance);
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
// print_r($value);
|
||||
// exit;
|
||||
$debittot = 0;
|
||||
$credittot = 0;
|
||||
$xsubtotal = 0;
|
||||
|
||||
if ($value['coaAccountType'] == 'DB') {
|
||||
$debittot = floatval($value['value']);
|
||||
}
|
||||
if ($value['coaAccountType'] == 'CR') {
|
||||
$credittot = floatval($value['value']);
|
||||
}
|
||||
$xsubtotal = $debittot + $credittot;
|
||||
$rows[$key]['subtotal'] = $xsubtotal;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'records' => $rows,
|
||||
'total' => $arrTotal
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
class Journalarpaymentv2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PAYMENT RECEIVE";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeID IN (11, 12,13)
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'ARDATE' OR jurnalAddOnCode = 'CMPNYNAME' OR jurnalAddOnCode = 'CMPNYNUM')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeID IN (11,12,13)
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeID IN (11,12,13)
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
class Journalarv2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PENDAPATAN CASH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTODAILYAR'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'CMPNYNAME' OR jurnalAddOnCode = 'CMPNYNUM')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTODAILYAR'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTODAILYAR'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
class Journalcash extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PENDAPATAN CASH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$periodeid = $prm["periodeid"];
|
||||
$xdate = $prm["xdate"];
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalTxID,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
periodeIsClosed,
|
||||
CASE
|
||||
WHEN coaAccountType = 'DB' THEN jurnalTxDebit
|
||||
WHEN coaAccountType = 'CR' THEN jurnalTxCredit
|
||||
END as value,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
JurnalTypeIsAuto
|
||||
FROM jurnal
|
||||
JOIN jurnal_tx ON jurnalID = jurnalTxJurnalID
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y'
|
||||
AND JurnalTypeIsAuto = 'Y' AND JurnalTypeCode = 'AUTODAILYSALES'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND jurnalperiodeID = ?
|
||||
AND jurnalDate = ?";
|
||||
$qry = $this->db->query($sql, [$periodeid, $xdate]);
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalDebit = 0;
|
||||
$totalCredit = 0;
|
||||
$totalBalance = 0;
|
||||
|
||||
for ($i = 0; $i < count($rows); $i++) {
|
||||
// print_r($rows[$i]);
|
||||
// exit;
|
||||
$data = $rows[$i];
|
||||
if ($data['coaAccountType'] == 'DB') {
|
||||
$totalDebit = $totalDebit + floatval($data['value']);
|
||||
}
|
||||
if ($data['coaAccountType'] == 'CR') {
|
||||
$totalCredit = $totalCredit + floatval($data['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$totalBalance = $totalDebit - $totalCredit;
|
||||
$arrTotal = array('debit' => $totalDebit, 'credit' => $totalCredit, 'balance' => $totalBalance);
|
||||
|
||||
$result = array(
|
||||
'records' => $rows,
|
||||
'total' => $arrTotal
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
class Journalcashv2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PENDAPATAN CASH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTODAILYSALES'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND jurnalAddOnCode = 'OMZNAME'
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTODAILYSALES'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTODAILYSALES'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,762 @@
|
||||
<?php
|
||||
|
||||
class Journalfixasset extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "FIX ASSET";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'FIXASSET'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'JFA')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'FIXASSET'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'FIXASSET'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
class Journalfixedasset extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PAYMENT VOUCHER API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$periodeid = $prm["periodeid"];
|
||||
$xdate = $prm["xdate"];
|
||||
|
||||
$branchid = $prm["branchid"];
|
||||
$regionalid = $prm["regionalid"];
|
||||
|
||||
$filter_regional = "";
|
||||
$filter_cabang = "";
|
||||
$join_regional = "";
|
||||
$join_cabang = "";
|
||||
|
||||
if (intval($branchid) === 0) {
|
||||
$filter_regional = " AND S_RegionalID = {$regionalid}";
|
||||
$join_regional = " LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
} else {
|
||||
$filter_cabang = " AND S_RegionalID = {$regionalid} AND M_BranchID = {$branchid}";
|
||||
$join_cabang = " JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
M_ItemCode CodeFixedAsset,
|
||||
M_ItemDesc NameFixedAsset,
|
||||
Fa_ItemAcquisitionPrice AcquisitionPrice,
|
||||
IFNULL(Fa_ClassDepreCorp,0) DepreRateFixedAsset,
|
||||
IFNULL(Fa_ClassDepreGov,0) DepreGovPercent,
|
||||
0 DebitFixedAsset,
|
||||
0 CreditFixedAsset,
|
||||
IFNULL(Fa_ClassDepreCorp,0)/12*Fa_ItemAcquisitionPrice AccumDepreFixedAsset,
|
||||
Fa_ItemAcquisitionPrice - IFNULL(Fa_ClassDepreCorp,0)/12*Fa_ItemAcquisitionPrice RemainingValueFixedAsset,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM fa_item
|
||||
JOIN m_item ON M_ItemID = Fa_ItemM_ItemID
|
||||
JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID
|
||||
WHERE Fa_ItemIsActive = 'Y'
|
||||
ORDER BY M_ItemCode ASC";
|
||||
|
||||
|
||||
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total);
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
$qry = $this->db->query($sql_select);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, array($value["jurnalID"]));
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row['JurnalErr_Msg'] = json_decode($row['JurnalErr_Msg'], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = 'Y';
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = 'N';
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'PVNO')
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID";
|
||||
$qry_detail = $this->db->query($sql_detail, array($value["jurnalID"]));
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'total' => $totalPage,
|
||||
'totalfilter' => $totalCount,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,764 @@
|
||||
<?php
|
||||
|
||||
class Journalgoodreceive extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "AUTO PENERIMAAN BARANG";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? $user["S_RegionalID"];
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOGOODRECEIVE'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
-- AND (jurnalAddOnCode = 'RONUMB')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
// "sql" => $sql,
|
||||
// "bcode" => $branchCode,
|
||||
// "user" => $user,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTOGOODRECEIVE'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTOGOODRECEIVE'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,768 @@
|
||||
<?php
|
||||
|
||||
class Journalpaymentinv extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "Payment Invoice";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
jurnalIsClosed,
|
||||
jurnalEditStatus,
|
||||
JurnalRequestEditID,
|
||||
JurnalRequestEditStaffName,
|
||||
JurnalRequestEditStatusRequest,
|
||||
JurnalRequestEditStatusEdit,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
LEFT JOIN jurnal_request_edit ON JurnalRequestEditJurnalID = jurnalID
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'
|
||||
AND JurnalTypeCode = 'PAYMENTINV'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'JFA')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
AND M_ApproveLevelIsActive = 'Y'
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'PAYMENTINV'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'PAYMENTINV'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,775 @@
|
||||
<?php
|
||||
|
||||
class Journalpv extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "PAYMENT VOUCHER API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? $user["S_RegionalID"];
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
jurnalIsClosed,
|
||||
jurnalEditStatus,
|
||||
JurnalRequestEditID,
|
||||
JurnalRequestEditStaffName,
|
||||
JurnalRequestEditStatusRequest,
|
||||
JurnalRequestEditStatusEdit,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
LEFT JOIN jurnal_request_edit ON JurnalRequestEditJurnalID = jurnalID
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOPV'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'PVNO')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
AND M_ApproveLevelIsActive = 'Y'
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaAccountType,
|
||||
coaCurrencyCode,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCashFlowCategory,
|
||||
coaSubDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTOPV'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTOPV'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,763 @@
|
||||
<?php
|
||||
|
||||
class Journalsuratjalan extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "Jurnal Surat Jalan";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOSENDGOODR'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'SENDGOODRDST')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_ApproveLevelIsActive = 'Y'
|
||||
AND M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM
|
||||
TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTOSENDGOODR'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTOSENDGOODR'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,694 @@
|
||||
<?php
|
||||
|
||||
class Journalterimabarang extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "API JURNAL PENERIMAAN BARANG";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/* DIPAKAI FE */
|
||||
public function getTipeJurnal()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
*
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("getTipeJurnal: ", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
foreach ($rst as $key => $value) {
|
||||
if ($value['JurnalTypeCode'] == 'GOODRECEIVE') {
|
||||
$default = $value;
|
||||
}
|
||||
}
|
||||
$this->sys_ok([
|
||||
"default" => $default,
|
||||
"records" => $rst
|
||||
]);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$sql = "SELECT
|
||||
CONCAT(periodeYear, ' - ', periodeName) as displayPeriode,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode,
|
||||
periode.*
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
AND CONCAT(periodeYear, ' - ', periodeName) LIKE ?
|
||||
LIMIT 70
|
||||
";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get periode", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSupplier()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = '%%';
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $search . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
CONCAT(SupplierCode, ' - ', SupplierName) as displaySupplier,
|
||||
supplier.*
|
||||
FROM supplier
|
||||
WHERE SupplierIsActive = 'Y'
|
||||
AND CONCAT(SupplierCode, ' - ', SupplierName) LIKE ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select supplier", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCoa()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$limit = 70; // dihapus jika perlu tampil semua
|
||||
|
||||
$sql = "SELECT
|
||||
*
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
-- AND coaIsInput = 'Y' -- TODO: uncomment setelah diinject
|
||||
AND coaAccountNo != ''
|
||||
AND (coaDescription LIKE ? OR coaSubDescription LIKE ? OR coaAccountNo LIKE ?)
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$search, $search, $search, $limit]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function createJurnal()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
// Get Parameter
|
||||
$userID = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$jurnalTypeID = $prm['jurnalType'] ?? 2; // Harusnya 2 : GOODRECEIVE
|
||||
$details = $prm['details'];
|
||||
|
||||
// TODO: Dihapus jika sudah ada M_BranchCode di parameter
|
||||
$sql = "SELECT M_BranchCode FROM m_branch WHERE M_BranchID = ?";
|
||||
$qry = $this->db->query($sql, [$prm['M_BranchID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Failed to get branch code", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->row();
|
||||
$branchCode = $rst->M_BranchCode;
|
||||
|
||||
$sql = "SELECT `fn_numbering`('J') as jurnalNo";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Failed to get jurnal number", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->row();
|
||||
$jurnalNo = $rst->jurnalNo;
|
||||
|
||||
// Start Transaction
|
||||
$this->db->trans_start();
|
||||
|
||||
$sqlHeader = "INSERT INTO jurnal
|
||||
(jurnalM_BranchCompanyID, JurnalS_RegionalID, jurnalM_BranchCode,
|
||||
jurnalperiodeID, jurnalNo, jurnalTitle,
|
||||
jurnalDescription, jurnalDate, jurnalJurnalTypeID,
|
||||
jurnalM_UserID, jurnalCreated)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())";
|
||||
|
||||
$this->db->query($sqlHeader, [
|
||||
$prm['M_BranchCompanyID'],
|
||||
$prm['S_RegionalID'],
|
||||
$branchCode,
|
||||
$prm['periodeID'],
|
||||
$jurnalNo,
|
||||
$prm['jurnalTitle'],
|
||||
$prm['jurnalDescription'],
|
||||
$prm['jurnalDate'],
|
||||
$jurnalTypeID,
|
||||
$userID
|
||||
]);
|
||||
|
||||
$jurnalID = $this->db->insert_id();
|
||||
|
||||
foreach ($details as $detail) {
|
||||
$this->createFormDetail($detail, $jurnalID); // Child Transaction
|
||||
}
|
||||
$this->db->trans_complete();
|
||||
|
||||
if ($this->db->trans_status() === FALSE) {
|
||||
$this->sys_error_db('Failed to create jurnal: ', $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$this->sys_ok("Berhasil simpan jurnal");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteJurnal()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$jurnalID = $prm['jurnalID'];
|
||||
$userID = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "SELECT jurnalIsPosted FROM jurnal WHERE jurnalID = ?";
|
||||
$isPosted = $this->db->query($sql, [$jurnalID])->row()->jurnalIsPosted ?? null;
|
||||
if (!$isPosted) {
|
||||
$this->sys_error_db("Failed to get jurnalIsPosted", $this->db);
|
||||
exit;
|
||||
}
|
||||
if ($isPosted == 'Y') {
|
||||
$this->sys_error("Jurnal sudah diposting, tidak bisa dihapus");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Start Transaction
|
||||
$this->db->trans_start();
|
||||
// 1. Update jurnal where jurnalID = ?
|
||||
$this->db->set('jurnalIsActive', 'N');
|
||||
$this->db->set('jurnalLastUpdated', 'NOW()', FALSE);
|
||||
$this->db->set('jurnalM_UserID', $userID);
|
||||
$this->db->where('jurnalID', $jurnalID);
|
||||
$this->db->update('jurnal');
|
||||
|
||||
// 2. Update jurnal_tx where jurnalTxJurnalID = ?
|
||||
$this->db->set('jurnalTxIsActive', 'N');
|
||||
$this->db->set('jurnalTxLastUpdated', 'NOW()', FALSE);
|
||||
$this->db->set('jurnalTxM_UserID', $userID);
|
||||
$this->db->where('jurnalTxJurnalID', $jurnalID);
|
||||
$this->db->update('jurnal_tx');
|
||||
|
||||
// 3. Update jurnal_addon where jurnalAddOnJurnalID = ?
|
||||
$this->db->set('jurnalAddOnIsActive', 'N');
|
||||
$this->db->set('jurnalAddOnLastUpdated', 'NOW()', FALSE);
|
||||
$this->db->set('jurnalAddOnLastUpdatedUserID', $userID);
|
||||
$this->db->where('jurnalAddOnJurnalID', $jurnalID);
|
||||
$this->db->update('jurnal_addon');
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
if ($this->db->trans_status() === FALSE) {
|
||||
$this->sys_error_db('Failed to delete jurnal: ', $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$this->sys_ok("Berhasil hapus jurnal");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Mungkin ini nanti bisa lebih efektif untuk addOns
|
||||
public function loadEditDialog()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
// Get jurnal, jurnal_tx, and jurnal_addon by jurnalID
|
||||
$sql = "SELECT jurnalID, jurnalperiodeID, jurnalNo, jurnalTitle, jurnalDescription,
|
||||
DATE_FORMAT(jurnalDate, '%Y-%m-%d') as jurnalDate, jurnalIsPosted,
|
||||
M_BranchCompanyName, S_RegionalName, M_BranchName,
|
||||
M_BranchCompanyID, S_RegionalID, M_BranchID,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight
|
||||
FROM jurnal
|
||||
JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y'
|
||||
WHERE jurnalID = ? AND jurnalIsActive = 'Y'";
|
||||
|
||||
$qryj = $this->db->query($sql, [$prm['jurnalID']]);
|
||||
|
||||
if (!$qryj) {
|
||||
$this->sys_error_db("Failed to get jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
$jurnal = $qryj->row_array();
|
||||
if ($jurnal == null) {
|
||||
$this->sys_error("JurnalID: " . $prm['jurnalID'] . " tidak ditemukan");
|
||||
exit;
|
||||
}
|
||||
$result['jurnalHead'] = $jurnal;
|
||||
|
||||
// Get Selected Periode
|
||||
$sql = "SELECT
|
||||
CONCAT(periodeYear, ' - ', periodeName) as displayPeriode,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode,
|
||||
periode.*
|
||||
FROM jurnal
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y' AND periodeIsClosed = 'N'
|
||||
WHERE jurnalID = ? AND jurnalIsActive = 'Y'";
|
||||
$periode = $this->db->query($sql, [$prm['jurnalID']])->row_array();
|
||||
if (!$periode) {
|
||||
$this->sys_error_db("Failed to get periode", $this->db);
|
||||
exit;
|
||||
}
|
||||
$result['periode'] = $periode;
|
||||
|
||||
// Get suppliercode and grni/invoice code result object
|
||||
$sql = "SELECT * FROM jurnal_addon WHERE jurnalAddOnJurnalID = ? AND jurnalAddOnIsActive = 'Y'";
|
||||
$qryaddon = $this->db->query($sql, [$prm['jurnalID']]);
|
||||
if (!$qryaddon) {
|
||||
$this->sys_error_db("Failed to get jurnal_addon", $this->db);
|
||||
exit;
|
||||
}
|
||||
$addon = $qryaddon->result_array();
|
||||
foreach ($addon as $key => $value) {
|
||||
$result['jurnalHead'][$value['jurnalAddOnCode']] = $value['jurnalAddOnValue'];
|
||||
if ($value['jurnalAddOnCode'] == 'SUPCD') {
|
||||
$supcd = $value['jurnalAddOnValue'];
|
||||
}
|
||||
}
|
||||
|
||||
// Get supplier
|
||||
$sql = "SELECT
|
||||
CONCAT(SupplierCode, ' - ', SupplierName) as displaySupplier,
|
||||
supplier.*
|
||||
FROM supplier WHERE SupplierCode = ? AND SupplierIsActive = 'Y'";
|
||||
$qrysupplier = $this->db->query($sql, [$supcd]);
|
||||
if (!$qrysupplier) {
|
||||
$this->sys_error_db("Failed to get supplier", $this->db);
|
||||
exit;
|
||||
}
|
||||
$supplier = $qrysupplier->row_array();
|
||||
$result['supplier'] = $supplier;
|
||||
|
||||
$txsql = "SELECT jurnalTxID, jurnalTxCoaID as coaID, jurnalTxDescription as coaDescription,
|
||||
jurnalTxDebit, jurnalTxCredit, coaAccountNo
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
WHERE jurnalTxJurnalID = ? AND jurnalTxIsActive = 'Y'";
|
||||
$qrytx = $this->db->query($txsql, [$prm['jurnalID']]);
|
||||
if (!$qrytx) {
|
||||
$this->sys_error_db("Failed to get jurnal tx", $this->db);
|
||||
exit;
|
||||
}
|
||||
$tx = $qrytx->result_array();
|
||||
$result['details'] = $tx;
|
||||
|
||||
foreach ($result['details'] as $key => $value) {
|
||||
if ($value['jurnalTxCredit'] > 0) {
|
||||
$addonsql = "SELECT jurnalAddOnID, jurnalAddOnCode, jurnalAddOnValue FROM jurnal_addon WHERE jurnalAddOnJurnalTxID = ? AND jurnalAddOnIsActive = 'Y'";
|
||||
$qryaddon = $this->db->query($addonsql, [$value['jurnalTxID']]);
|
||||
if (!$qryaddon) {
|
||||
$this->sys_error_db("Failed to get jurnal_addon", $this->db);
|
||||
exit;
|
||||
}
|
||||
$addon = $qryaddon->result_array();
|
||||
$result['details'][$key]['addOns'] = $addon;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateJurnal()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user["M_UserID"];
|
||||
$jurnalID = $prm['jurnalID'];
|
||||
$details = $prm['details'];
|
||||
|
||||
$sql = "SELECT jurnalIsPosted FROM jurnal WHERE jurnalID = ?";
|
||||
$isPosted = $this->db->query($sql, [$jurnalID])->row()->jurnalIsPosted ?? null;
|
||||
if (!$isPosted) {
|
||||
$this->sys_error_db("Failed to get jurnalIsPosted", $this->db);
|
||||
exit;
|
||||
}
|
||||
if ($isPosted == 'Y') {
|
||||
$this->sys_error("Jurnal sudah diposting, tidak bisa diubah");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Start Transaction
|
||||
$this->db->trans_start();
|
||||
|
||||
// 1. Update jurnal
|
||||
$sql = "UPDATE jurnal
|
||||
SET jurnalDate = ?, jurnalperiodeID = ?,
|
||||
jurnalTitle = ?, jurnalDescription = ?,
|
||||
jurnalLastUpdated = NOW(), jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, [$prm['jurnalDate'], $prm['periodeID'], $prm['jurnalTitle'], $prm['jurnalDescription'], $userID, $jurnalID]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. Soft delete semua existing jurnal_tx and jurnal_addon where jurnalID = ?
|
||||
$tx = "UPDATE jurnal_tx SET jurnalTxIsActive = 'N' WHERE jurnalTxJurnalID = ?";
|
||||
$qrytx = $this->db->query($tx, [$jurnalID]);
|
||||
if (!$qrytx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$addon = "UPDATE jurnal_addon SET jurnalAddOnIsActive = 'N' WHERE jurnalAddOnJurnalID = ?";
|
||||
$qryaddon = $this->db->query($addon, [$jurnalID]);
|
||||
if (!$qryaddon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. Insert new jurnal_tx and jurnal_addon records
|
||||
foreach ($details as $detail) {
|
||||
$this->createFormDetail($detail, $jurnalID);
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
if ($this->db->trans_status() === FALSE) {
|
||||
$this->sys_error_db('Failed to update jurnal: ', $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$this->sys_ok("Berhasil update jurnal");
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
//* --- bandingkan dulu baru hapus ---
|
||||
public function updateJurnalV2()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user["M_UserID"];
|
||||
$jurnalID = $prm['jurnalID'];
|
||||
$details = $prm['details'];
|
||||
|
||||
$sql = "SELECT jurnalIsPosted FROM jurnal WHERE jurnalID = ?";
|
||||
$isPosted = $this->db->query($sql, [$jurnalID])->row()->jurnalIsPosted ?? null;
|
||||
if (!$isPosted) {
|
||||
$this->sys_error_db("Failed to get jurnalIsPosted", $this->db);
|
||||
exit;
|
||||
}
|
||||
if ($isPosted == 'Y') {
|
||||
$this->sys_error("Jurnal sudah diposting, tidak bisa diubah");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Start Transaction
|
||||
$this->db->trans_start();
|
||||
|
||||
// 1. Update jurnal
|
||||
$sql = "UPDATE jurnal
|
||||
SET jurnalDate = ?, jurnalperiodeID = ?,
|
||||
jurnalTitle = ?, jurnalDescription = ?,
|
||||
jurnalLastUpdated = NOW(), jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, [$prm['jurnalDate'], $prm['periodeID'], $prm['jurnalTitle'], $prm['jurnalDescription'], $userID, $jurnalID]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. Ambil data existing jurnal_tx and jurnal_addon where jurnalID = ?
|
||||
$tx = "SELECT * FROM jurnal_tx WHERE jurnalTxJurnalID = ? AND jurnalTxIsActive = 'Y'";
|
||||
$oldTx = $this->db->query($tx, [$jurnalID])->result_array() ?? null;
|
||||
if (!$oldTx) {
|
||||
$this->sys_error_db("Failed to get jurnalTx", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. Bandingin data jurnalTx: coaAccountNo, jurnalTxDebit, jurnalTxCredit
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function diffJurnalTx()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$jurnalID = $prm['jurnalID'];
|
||||
$details = $prm['details'];
|
||||
|
||||
$tx = "SELECT * FROM jurnal_tx WHERE jurnalTxJurnalID = ? AND jurnalTxIsActive = 'Y'";
|
||||
$oldTx = $this->db->query($tx, [$jurnalID])->result_array() ?? null;
|
||||
if (!$oldTx) {
|
||||
$this->sys_error_db("Failed to get jurnalTx", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
var_dump($oldTx);
|
||||
|
||||
var_dump($details);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* --- HELPER FUNCTION --- *
|
||||
*/
|
||||
private function createFormDetail($prm, $jurnalID)
|
||||
{
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$coaID = $prm['coaID'];
|
||||
$jurnalTxDescription = $prm['coaDescription'];
|
||||
$jurnalTxDebit = $prm['jurnalTxDebit'];
|
||||
$jurnalTxCredit = $prm['jurnalTxCredit'];
|
||||
$addOns = $prm['addOns']; // array
|
||||
|
||||
// Validasi debit dan kredit
|
||||
if ($jurnalTxCredit == 0 && $jurnalTxDebit > 0) {
|
||||
$isDebit = true;
|
||||
$isCredit = false;
|
||||
} else if ($jurnalTxDebit == 0 && $jurnalTxCredit > 0) {
|
||||
$isDebit = false;
|
||||
$isCredit = true;
|
||||
} else {
|
||||
$isDebit = false;
|
||||
$isCredit = false;
|
||||
$this->sys_error("Debit atau Kredit harus diisi");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if ($isDebit && $isCredit) {
|
||||
$this->sys_error("Debit dan Kredit tidak boleh diisi bersamaan");
|
||||
exit;
|
||||
}
|
||||
// Jika kredit, maka masuk ke jurnal_tx dan jurnal_addon
|
||||
else if ($isCredit && !$isDebit) {
|
||||
$insertTx = "INSERT INTO jurnal_tx
|
||||
(jurnalTxJurnalID, jurnalTxCoaID, jurnalTxDescription, jurnalTxCredit,
|
||||
jurnalTxIsActive, jurnalTxCreated, jurnalTxLastUpdated, jurnalTxM_UserID)
|
||||
VALUES (?, ?, ?, ?, 'Y', NOW(), NOW(), ?)";
|
||||
|
||||
$insertAddOn = "INSERT INTO jurnal_addon
|
||||
(jurnalAddOnJurnalID, jurnalAddOnJurnalTxID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnIsActive, jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID, jurnalAddOnLastUpdated, jurnalAddOnLastUpdatedUserID)
|
||||
VALUES (?, ?, ?, ?, 'Y', NOW(), ?, NOW(), ?)";
|
||||
|
||||
// Ikut parents transaction agar rollbacknya bisa langsung semua
|
||||
$insertTxCr = $this->db->query($insertTx, [$jurnalID, $coaID, $jurnalTxDescription, $jurnalTxCredit, $userid]);
|
||||
if (!$insertTxCr) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed Insert JurnalTx Credit", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$getTxId = $this->db->insert_id();
|
||||
|
||||
// Insert jurnalAddOn 1 kredit bisa ada 2-3 addOn
|
||||
foreach ($addOns as $item) {
|
||||
|
||||
$addOnState = $this->db->query($insertAddOn, [$jurnalID, $getTxId, $item['jurnalAddOnCode'], $item['jurnalAddOnValue'], $userid, $userid]);
|
||||
|
||||
if (!$addOnState) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed Insert JurnalAddOn Credit", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jika debit maka hanya masuk ke jurnal_tx
|
||||
else if ($isDebit && !$isCredit) {
|
||||
$sql = "INSERT INTO jurnal_tx
|
||||
(jurnalTxJurnalID, jurnalTxCoaID, jurnalTxDescription, jurnalTxDebit,
|
||||
jurnalTxIsActive, jurnalTxCreated, jurnalTxLastUpdated, jurnalTxM_UserID)
|
||||
VALUES (?, ?, ?, ?, 'Y', NOW(), NOW(), ?)";
|
||||
$qry = $this->db->query($sql, [$jurnalID, $coaID, $jurnalTxDescription, $jurnalTxDebit, $userid]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed Insert JurnalTx Debit", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$this->sys_error("Debit atau Kredit harus diisi");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getListFormDetail()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$jurnalID = $this->sys_input['jurnalID'];
|
||||
|
||||
$sql = "SELECT * FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$jurnalID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select jurnal_tx", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
class Journaltukarfaktur extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "TUKAR FAKTUR";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeID DESC, periodeMonth DESC
|
||||
LIMIT 18";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit();
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit();
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
||||
$periodeid = $prm["periodeid"] ?? null;
|
||||
$xdate = $prm["xdate"] ?? null;
|
||||
$search = $prm["search"] ?? "";
|
||||
$search = "%" . trim($search) . "%";
|
||||
|
||||
$loginLevel = $this->sys_user["loginLevel"];
|
||||
$where_conditions = [
|
||||
"jurnalIsActive = 'Y'",
|
||||
"jurnalperiodeID = ?",
|
||||
"DATE(jurnalDate) = ?",
|
||||
"jurnalNo LIKE ?",
|
||||
];
|
||||
$params = [$periodeid, $xdate, $search];
|
||||
|
||||
// Filter login level
|
||||
if ($loginLevel == "branch") {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
} elseif ($loginLevel == "regional") {
|
||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||
$params[] = $regionalId;
|
||||
|
||||
if (!empty($branchCode)) {
|
||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||
$params[] = $branchCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Gabungkan WHERE SQL
|
||||
$where_sql = implode(" AND ", $where_conditions);
|
||||
|
||||
// SQL utama
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
'' as ErrStatus,
|
||||
'' as ErrMsg,
|
||||
'' as detailtx
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
|
||||
AND JurnalTypeCode = 'AUTOINVOICE'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
WHERE $where_sql
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC
|
||||
";
|
||||
|
||||
// Ambil total count
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$qry_total = $this->db->query($sql_total, $params);
|
||||
|
||||
$number_limit = 10;
|
||||
$current_page = (int) ($prm["current_page"] ?? 1);
|
||||
$number_offset = max(0, ($current_page - 1) * $number_limit);
|
||||
|
||||
// Hitung total halaman
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->row()->total ?? 0;
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Tambahkan LIMIT OFFSET
|
||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||
|
||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql_err = "SELECT JurnalErr_ID,
|
||||
JurnalErr_Msg
|
||||
FROM jurnal_errors
|
||||
WHERE JurnalErr_IsActive = 'Y'
|
||||
AND JurnalErr_JurnalID = ?";
|
||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||
if (!$qry_err) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows_err = $qry_err->result_array();
|
||||
|
||||
// Decode JSON di dalam kolom JurnalErr_Msg
|
||||
foreach ($rows_err as &$row) {
|
||||
$row["JurnalErr_Msg"] = json_decode($row["JurnalErr_Msg"], true);
|
||||
}
|
||||
if (count($rows_err) > 0) {
|
||||
$rows[$key]["ErrStatus"] = "Y";
|
||||
$rows[$key]["ErrMsg"] = $rows_err;
|
||||
} else {
|
||||
$rows[$key]["ErrStatus"] = "N";
|
||||
$rows[$key]["ErrMsg"] = [];
|
||||
}
|
||||
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') as jurnalAddOnCode,
|
||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') as jurnalAddOnValue,
|
||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||
FROM jurnal_tx
|
||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||
AND (jurnalAddOnCode = 'INVGR')
|
||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
GROUP BY jurnalTxID
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
jurnalTxID ASC";
|
||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rows_detail = $qry_detail->result_array();
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$key]["detailtx"] = $rows_detail;
|
||||
} else {
|
||||
$rows[$key]["detailtx"] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $totalPage,
|
||||
"totalfilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regionalId = $prm["regionalId"] ?? null;
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
AND S_RegionalID = ?
|
||||
ORDER BY S_RegionalName ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$regionalId]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$selected = null;
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
foreach ($rows as $r) {
|
||||
if ($r["S_RegionalID"] == $regionalId) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = isset($prm["regionalId"]) ? $prm["regionalId"] : null;
|
||||
$branchCode = isset($prm["branchCode"]) ? $prm["branchCode"] : null;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit();
|
||||
}
|
||||
|
||||
$rows = $exec->result_array();
|
||||
$selected = [
|
||||
"M_BranchCode" => "",
|
||||
"M_BranchName" => "",
|
||||
];
|
||||
|
||||
// Cari regional yang sesuai dengan regionalId
|
||||
if (!empty($branchCode)) {
|
||||
foreach ($rows as $r) {
|
||||
if ($r["M_BranchCode"] == $branchCode) {
|
||||
$selected = $r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"selected" => $selected,
|
||||
"sql" => $this->db->last_query(),
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT
|
||||
M_ApproveLevelID,
|
||||
M_ApproveLevelName,
|
||||
DivisionID,
|
||||
DivisionName,
|
||||
DivisionKodeSurat
|
||||
FROM m_user
|
||||
LEFT JOIN m_approve_level ON M_ApproveLevelID = M_UserM_ApproveLevelID
|
||||
AND M_ApproveLevelIsActive = 'Y'
|
||||
JOIN m_userdivision ON M_UserDivisionM_UserID = M_UserID
|
||||
AND M_UserDivisionIsActive = 'Y'
|
||||
JOIN division ON DivisionID = M_UserDivisionDivisionID
|
||||
AND DivisionIsActive = 'Y'
|
||||
WHERE M_UserID = ?";
|
||||
$que = $this->db->query($sql, [$user["M_UserID"]]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get user approve level");
|
||||
exit();
|
||||
}
|
||||
|
||||
$result = $que->row_array();
|
||||
if (!$result) {
|
||||
$result = [
|
||||
"M_ApproveLevelID" => 0,
|
||||
"M_ApproveLevelName" => "",
|
||||
];
|
||||
}
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getListingCOA()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($param["keyword"] != "") {
|
||||
$keyword = $param["keyword"] . "%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaDescription LIKE ?";
|
||||
$que = $this->db->query($sql, [$keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listint account");
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveEditJurnal()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
// get current jurnal data
|
||||
$sql_data = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxJurnalID = ?";
|
||||
$que_current = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_current) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get current jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$curr_jurnal = $que_current->result_array();
|
||||
|
||||
$sql_header = "UPDATE jurnal SET
|
||||
jurnalEditStatus = 'Y',
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$que_header = $this->db->query($sql_header, [$param["jurnalID"]]);
|
||||
if (!$que_header) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal edit");
|
||||
exit();
|
||||
}
|
||||
|
||||
$jurnaldetail = $param["jurnaldetail"];
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'";
|
||||
|
||||
foreach ($jurnaldetail as $key => $obj) {
|
||||
$que = $this->db->query($sql, [
|
||||
$obj["coaID"],
|
||||
$obj["coaDescription"],
|
||||
$user["M_UserID"],
|
||||
$obj["jurnalTxID"],
|
||||
$obj["jurnalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update data jurnal tx");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// get new jurnal data
|
||||
$que_latest = $this->db->query($sql_data, [$param["jurnalID"]]);
|
||||
if (!$que_latest) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get latest jurnal tx data");
|
||||
exit();
|
||||
}
|
||||
$new_jurnal = $que_latest->result_array();
|
||||
|
||||
$sql_log = "INSERT INTO acc_one_log.jurnal_edit_log (
|
||||
JurnalEditLogIDJurnalID,
|
||||
JurnalEditLogIDJsonBefore,
|
||||
JurnalEditLogIDJsonAfter,
|
||||
JurnalEditLogUserID,
|
||||
JurnalEditLogCreated
|
||||
) VALUES (?,?,?,?,NOW())";
|
||||
$que_log = $this->db->query($sql_log, [
|
||||
$param["jurnalID"],
|
||||
json_encode($curr_jurnal),
|
||||
json_encode($new_jurnal),
|
||||
$user["M_UserID"],
|
||||
]);
|
||||
if (!$que_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into acc one jurnal log");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update jurnal");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeJurnalToPosted()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sqlbranch = " ";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = " . $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsPosted = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'N'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$param["periodeID"],
|
||||
$param["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke posting");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status posting jurnal pada periode ini");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalJurnalNotPostedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
)
|
||||
SELECT
|
||||
JurnalTypeID,
|
||||
TS.status AS jurnalEditStatus,
|
||||
COALESCE(COUNT(J.jurnalEditStatus), 0) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalEditStatus
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsPosted = 'N'
|
||||
JOIN jurnal_type ON JurnalTypeID = jurnalJurnalTypeID
|
||||
AND JurnalTypeCode = 'AUTOINVOICE'
|
||||
GROUP BY TS.status
|
||||
ORDER BY TS.status";
|
||||
|
||||
$que = $this->db->query($sql, [
|
||||
$param["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not posted");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function closeJurnalPerPeriode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sqlbranch = "";
|
||||
if ($user["M_BranchID"] != "0") {
|
||||
$sqlbranch .= " AND jurnalM_BranchCode = '{$user["M_BranchCode"]}'";
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsClosed = 'Y',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalperiodeID = ?
|
||||
AND jurnalJurnalTypeID = ?
|
||||
AND JurnalS_RegionalID = ?
|
||||
AND jurnalIsPosted = 'Y'
|
||||
AND jurnalEditStatus = 'N'
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$sql .= $sqlbranch;
|
||||
$que = $this->db->query($sql, [
|
||||
$user["M_UserID"],
|
||||
$para["periodeID"],
|
||||
$para["jurnalTypeID"],
|
||||
$user["S_RegionalID"],
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status jurnal ke closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] update status closed jurnal pada periode ini");
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataJurnalNotClosedPerPeriod()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit();
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$branchcode = "X";
|
||||
if ($user["M_BranchCode"] != "") {
|
||||
$branchcode = $user["M_BranchCode"];
|
||||
}
|
||||
|
||||
$sql = "WITH TargetStatuses AS (
|
||||
SELECT 'N' AS status
|
||||
UNION ALL
|
||||
SELECT 'Y' AS status
|
||||
),
|
||||
TargetType AS (
|
||||
SELECT JurnalTypeID
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'AUTOINVOICE'
|
||||
)
|
||||
SELECT
|
||||
TT.JurnalTypeID,
|
||||
TS.status AS jurnalIsPosted,
|
||||
COUNT(J.jurnalID) AS total_jurnal
|
||||
FROM TargetStatuses TS
|
||||
CROSS JOIN TargetType TT
|
||||
LEFT JOIN jurnal J ON TS.status = J.jurnalIsPosted
|
||||
AND J.jurnalJurnalTypeID = TT.JurnalTypeID
|
||||
AND J.jurnalperiodeID = ?
|
||||
AND J.JurnalS_RegionalID = ?
|
||||
AND (J.jurnalM_BranchCode = ? OR ? = 'X')
|
||||
AND J.jurnalIsActive = 'Y'
|
||||
AND J.jurnalIsClosed = 'N'
|
||||
GROUP BY TT.JurnalTypeID, TS.status
|
||||
ORDER BY TS.status";
|
||||
$que = $this->db->query($sql, [
|
||||
$para["periodeID"],
|
||||
$user["S_RegionalID"],
|
||||
$branchcode,
|
||||
$branchcode,
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get total jurnal not closed");
|
||||
exit();
|
||||
}
|
||||
|
||||
$total = $que->result_array();
|
||||
$this->sys_ok($total);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
1236
application/controllers/mockup/masterdata/accounting/Jurnalbiaya.php
Normal file
1236
application/controllers/mockup/masterdata/accounting/Jurnalbiaya.php
Normal file
File diff suppressed because it is too large
Load Diff
1228
application/controllers/mockup/masterdata/accounting/Jurnalgaji.php
Normal file
1228
application/controllers/mockup/masterdata/accounting/Jurnalgaji.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
class Jurnalpengeluaranbarang extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "JURNAL PENGELUARAN BARANG";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getperiode() {
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND (periodeYear LIKE ? OR periodeName LIKE ?)";
|
||||
$query = $this->db->query($sql, [$search, $search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get periode", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function searchcoa() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm["search"] . '%';
|
||||
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE
|
||||
coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (CONCAT(coaAccountNo, ' - ' ,coaDescription) LIKE ?)
|
||||
LIMIT 70";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total" => sizeof($rows)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function simpanjurnal() {
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$user = $this->sys_user;
|
||||
$userid = $user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
// get jurnal number
|
||||
$sql_no = "SELECT `fn_numbering`('PBC') as no_jurnal";
|
||||
$qry_no = $this->db->query($sql_no, []);
|
||||
if (!$qry_no) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get no jurnal");
|
||||
exit;
|
||||
}
|
||||
$numbering = $qry_no->row_array()['no_jurnal'];
|
||||
$currMonth = date('m');
|
||||
$currYear = date('Y');
|
||||
|
||||
$no_jurnal = 'PBC/' . $currYear . '/' . $currMonth . '/' . strval($numbering);
|
||||
|
||||
$sql_jurnal = "INSERT INTO jurnal(
|
||||
jurnalM_BranchCompanyID,
|
||||
JurnalS_RegionalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
jurnalJurnalTypeID,
|
||||
jurnalCreated,
|
||||
jurnalM_UserID
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,NOW(),?)";
|
||||
$qry_jurnal = $this->db->query($sql_jurnal, [
|
||||
$user['M_BranchCompanyID'],
|
||||
$user['S_RegionalID'],
|
||||
$user['M_BranchCode'],
|
||||
$prm['periodeid'],
|
||||
$no_jurnal,
|
||||
$prm['title'],
|
||||
$prm['description'],
|
||||
$prm['date'],
|
||||
$prm['jurnaltypeid'],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_jurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal ", $this->db);
|
||||
exit;
|
||||
}
|
||||
$lastJurnalInserted = $this->db->insert_id();
|
||||
|
||||
$sql_addon = "INSERT INTO jurnal_addon(
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES ({$lastJurnalInserted}, 'OGB', '{$user['M_BranchCode']}', NOW(),{$userid});";
|
||||
$qry_addon = $this->db->query($sql_addon, []);
|
||||
if (!$qry_addon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert jurnal_addon ", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$detail = $prm["detail"];
|
||||
foreach ($detail as $key => $value) {
|
||||
$sql_tx = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID
|
||||
) VALUES (?,?,?,?,?,NOW(),?)";
|
||||
$qry_tx = $this->db->query($sql_tx, [
|
||||
$lastJurnalInserted,
|
||||
$value["coaid"],
|
||||
$value["coadesc"],
|
||||
$value["debet"],
|
||||
$value["kredit"],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_tx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert jurnal_tx ", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editjurnal() {
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$user = $this->sys_user;
|
||||
$userid = $user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
$jurnalid = $prm["jurnalid"];
|
||||
|
||||
$sql_jurnal = "UPDATE jurnal SET
|
||||
jurnalperiodeID = ?,
|
||||
jurnalTitle = ?,
|
||||
jurnalDescription = ?,
|
||||
jurnalDate = ?,
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?
|
||||
";
|
||||
$qry_jurnal = $this->db->query($sql_jurnal, [
|
||||
$prm["periodeid"],
|
||||
$prm["title"],
|
||||
$prm["description"],
|
||||
$prm["date"],
|
||||
$userid,
|
||||
$jurnalid
|
||||
]);
|
||||
if (!$qry_jurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_n = "UPDATE jurnal_tx SET jurnalTxIsActive = 'N' WHERE jurnalTxJurnalID = ?";
|
||||
$qry_n = $this->db->query($sql_n, [$jurnalid]);
|
||||
if (!$qry_n) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update non active jurnal tx");
|
||||
exit;
|
||||
}
|
||||
|
||||
$detail = $prm["detail"];
|
||||
foreach ($detail as $key => $value) {
|
||||
$sql_tx = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID
|
||||
) VALUES (?,?,?,?,?,NOW(),?)";
|
||||
$qry_tx = $this->db->query($sql_tx, [
|
||||
$jurnalid,
|
||||
$value["coaid"],
|
||||
$value["coadesc"],
|
||||
$value["debet"],
|
||||
$value["kredit"],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_tx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert jurnal_tx ", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getdetailjurnal() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$jurnalid = $prm['jurnalid'];
|
||||
|
||||
$sql_a = "SELECT jurnalID, jurnalperiodeID, jurnalNo, jurnalTitle, jurnalDescription,
|
||||
DATE_FORMAT(jurnalDate, '%Y-%m-%d') as jurnalDate, jurnalIsPosted,
|
||||
M_BranchCompanyName, S_RegionalName, M_BranchName,
|
||||
M_BranchCompanyID, S_RegionalID, M_BranchID,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight
|
||||
FROM jurnal
|
||||
JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y'
|
||||
WHERE jurnalID = ? AND jurnalIsActive = 'Y'";
|
||||
|
||||
$qry_a = $this->db->query($sql_a, [$jurnalid]);
|
||||
if (!$qry_a) {
|
||||
$this->sys_error_db("error get jurnal data");
|
||||
exit;
|
||||
}
|
||||
$rows = $qry_a->row_array();
|
||||
|
||||
$sql_b = "SELECT
|
||||
CONCAT(periodeYear, ' - ', periodeName) as displayPeriode,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode,
|
||||
periode.*
|
||||
FROM jurnal
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y' AND periodeIsClosed = 'N'
|
||||
WHERE jurnalID = ? AND jurnalIsActive = 'Y'";
|
||||
$qry_b = $this->db->query($sql_b, [$jurnalid]);
|
||||
if (!$qry_b) {
|
||||
$this->sys_error_db("error get data periode");
|
||||
exit;
|
||||
}
|
||||
$periode = $qry_b->row_array();
|
||||
|
||||
$sql_tx = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxCoaID as coaid,
|
||||
jurnalTxDescription as coadesc,
|
||||
jurnalTxDebit as debet,
|
||||
jurnalTxCredit as kredit,
|
||||
coaAccountNo as coano
|
||||
FROM jurnal
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalID AND jurnalTxIsActive = 'Y'
|
||||
JOIN coa ON coaID = jurnalTxCoaID AND coaIsActive = 'Y'
|
||||
WHERE jurnalID = ? AND jurnalIsActive = 'Y'";
|
||||
$qry_tx = $this->db->query($sql_tx, [$jurnalid]);
|
||||
if (!$qry_tx) {
|
||||
$this->sys_error_db("error get jurnal tx");
|
||||
exit;
|
||||
}
|
||||
$detailjurnal = $qry_tx->result_array();
|
||||
|
||||
$result = array(
|
||||
"jurnal" => $rows,
|
||||
"periode" => $periode,
|
||||
"jurnaldetail" => $detailjurnal
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
<?php
|
||||
|
||||
class Jurnalsendreg extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "COA API";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function searchPeriode()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$sql = "SELECT
|
||||
CONCAT(periodeYear, ' - ', periodeName) as display,
|
||||
periode.*
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
AND CONCAT(periodeYear, ' - ', periodeName) LIKE ?
|
||||
LIMIT 70
|
||||
";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
function getBranch()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$sql = "SELECT
|
||||
M_BranchID as branchID,
|
||||
M_BranchS_RegionalID as branchRegionalID,
|
||||
M_BranchCode as branchCode ,
|
||||
M_BranchName as branchName,
|
||||
M_BranchCompanyDetailM_BranchCompanyID branchCompanyID
|
||||
FROM m_branch
|
||||
JOIN m_branch_companydetail
|
||||
ON M_BranchCode = M_BranchCompanyDetailM_BranchCode
|
||||
WHERE M_BranchS_RegionalID = ?
|
||||
AND M_BranchCompanyDetailIsActive = 'Y'
|
||||
AND M_BranchCompanyDetailM_BranchCompanyID = ?
|
||||
AND M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($prm['regional'], $prm['company']));
|
||||
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get branch");
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
function getJurnalType()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$sql = "SELECT * FROM jurnal_type WHERE JurnalTypeIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
exit;
|
||||
}
|
||||
$default = array();
|
||||
$data = $qry->result_array();
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['JurnalTypeCode'] == 'SENDGOODR') {
|
||||
$default = $value;
|
||||
}
|
||||
}
|
||||
$this->sys_ok([
|
||||
"records" => $data,
|
||||
"default" => $default
|
||||
]);
|
||||
}
|
||||
function searchCoa()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE
|
||||
coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (CONCAT(coaAccountNo, ' - ' ,coaDescription) LIKE ?)
|
||||
LIMIT 70
|
||||
|
||||
";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
function saveJurnal()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$detail = $prm['detail'];
|
||||
$jurnalRegional = $prm['jurnalRegional'];
|
||||
$sallary = $prm['sallary'];
|
||||
$user = $this->sys_user;
|
||||
$userid = $user["M_UserID"];
|
||||
$kreditTotal = 0;
|
||||
$debetTotal = 0;
|
||||
foreach ($detail as $i => $value) {
|
||||
if ($value['type'] == 'D') {
|
||||
$debetTotal = $debetTotal + doubleval($value['debet']);
|
||||
} else if ($value['type'] == 'K') {
|
||||
$kreditTotal = $kreditTotal + doubleval($value['kredit']);
|
||||
}
|
||||
# code...
|
||||
}
|
||||
if ($debetTotal != $kreditTotal) {
|
||||
$this->sys_error("Jumlah debet dan kredit secara total tidak balance" . ", debet " . strval($debetTotal) . " ,Kredit " . strval($kreditTotal));
|
||||
exit;
|
||||
}
|
||||
//insert jurnal regional
|
||||
$sql = "SELECT `fn_numbering`('PBR') as number";
|
||||
$qry = $this->db->query($sql, array());
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error get number");
|
||||
exit;
|
||||
}
|
||||
$numberingCounter = $qry->row_array()['number'];
|
||||
$currentMonth = date('m'); // Mendapatkan bulan saat ini dalam format angka dua digit
|
||||
$currentYear = date('Y'); // Mendapatkan tahun saat ini
|
||||
|
||||
|
||||
$numbering = 'PBR/' . $currentYear . "/" . $currentMonth . "/" . strval($numberingCounter);
|
||||
|
||||
$sql = "INSERT INTO jurnal (
|
||||
jurnalM_BranchCompanyID,
|
||||
JurnalS_RegionalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
jurnalJurnalTypeID,
|
||||
jurnalM_UserID)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$user['M_BranchCompanyID'],
|
||||
$user['S_RegionalID'],
|
||||
'',
|
||||
$prm['periodeID'],
|
||||
$numbering,
|
||||
$prm['title'],
|
||||
$prm['description'],
|
||||
$prm['date'],
|
||||
$prm['jurnalTypeID'],
|
||||
$userid
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal");
|
||||
exit;
|
||||
}
|
||||
$insertedJurnalRegID = $this->db->insert_id();
|
||||
$sql = "INSERT INTO jurnal_addon(
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreatedUserID)
|
||||
VALUES({$insertedJurnalRegID},'SENDGOODRDST','{$prm['branchCode']}',{$userid});";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal gaji addon regional");
|
||||
exit;
|
||||
}
|
||||
foreach ($detail as $i => $value) {
|
||||
$sql = 'INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID)
|
||||
VALUES(?,?,?,?,?,?)';
|
||||
$qry = $this->db->query($sql, array(
|
||||
$insertedJurnalRegID,
|
||||
$value['coaID'],
|
||||
$value['coaName'],
|
||||
$value['debet'],
|
||||
$value['kredit'],
|
||||
$userid
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal tx regional");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success");
|
||||
}
|
||||
|
||||
|
||||
function getDetail()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sql = "SELECT
|
||||
jurnal.*,
|
||||
M_BranchID as branchID,
|
||||
M_BranchName as branchName,
|
||||
M_branchCode as branchCode
|
||||
FROM jurnal
|
||||
JOIN jurnal_addon
|
||||
ON jurnalID = jurnalAddOnJurnalID
|
||||
AND jurnalAddOnCode = 'SENDGOODRDST'
|
||||
JOIN m_branch
|
||||
ON jurnalAddOnValue = M_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$id
|
||||
));
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("error get jurnal");
|
||||
exit;
|
||||
}
|
||||
$jurnal = $qry->row_array();
|
||||
$isEdit = 'Y';
|
||||
if ($jurnal['jurnalIsPosted'] === 'Y') {
|
||||
$isEdit = 'N';
|
||||
}
|
||||
$destination = [
|
||||
"branchID" => $jurnal['branchID'],
|
||||
"branchName" => $jurnal['branchName'],
|
||||
"branchCode" => $jurnal['branchCode'],
|
||||
];
|
||||
$date = $jurnal['jurnalDate'];
|
||||
$title = $jurnal['jurnalTitle'];
|
||||
$description = $jurnal['jurnalDescription'];
|
||||
$jurnalDetail = [];
|
||||
|
||||
$sql = "SELECT
|
||||
CONCAT(periodeYear, ' - ', periodeName) as display,
|
||||
periode.*
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeID = ?
|
||||
LIMIT 70
|
||||
";
|
||||
$qry = $this->db->query($sql, [$jurnal['jurnalperiodeID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$jurnalPeriode = $qry->row_array();
|
||||
$sql = "SELECT
|
||||
jurnalTxID as id,
|
||||
coaDescription as description,
|
||||
jurnalTxDebit as debet,
|
||||
jurnalTxCredit as kredit,
|
||||
CASE
|
||||
WHEN jurnalTxDebit > 0 THEN 'D'
|
||||
WHEN jurnalTxCredit > 0 THEN 'K'
|
||||
else ''
|
||||
END as type,
|
||||
'Y' as dataType,
|
||||
coaID,
|
||||
coaDescription as coaName,
|
||||
coaAccountNo as coaNo,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM jurnal_tx
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND jurnalTxJurnalID = ?
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get jurnal tx");
|
||||
exit;
|
||||
}
|
||||
$jurnalDetail = $qry->result_array();
|
||||
$result = array(
|
||||
"date" => $date,
|
||||
"isEdit" => $isEdit,
|
||||
"jurnal" => $jurnal,
|
||||
"destination" => $destination,
|
||||
"periode" => $jurnalPeriode,
|
||||
"title" => $title,
|
||||
"description" => $description,
|
||||
"jurnalDetail" => $jurnalDetail,
|
||||
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
function editJurnal()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$detail = $prm['detail'];
|
||||
$id = $prm['id'];
|
||||
|
||||
$user = $this->sys_user;
|
||||
$userid = $user["M_UserID"];
|
||||
$kreditTotal = 0;
|
||||
$debetTotal = 0;
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM jurnal
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$id
|
||||
));
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error cek jurnal jurnal");
|
||||
exit;
|
||||
}
|
||||
$cekJurnal = $qry->row_array();
|
||||
if ($cekJurnal['jurnalIsPosted'] == 'Y') {
|
||||
$this->sys_error('Jurnal sudah di post tidak bisa di ubah');
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($detail as $i => $value) {
|
||||
if ($value['type'] == 'D') {
|
||||
$debetTotal = $debetTotal + doubleval($value['debet']);
|
||||
} else if ($value['type'] == 'K') {
|
||||
$kreditTotal = $kreditTotal + doubleval($value['kredit']);
|
||||
}
|
||||
# code...
|
||||
}
|
||||
if ($debetTotal != $kreditTotal) {
|
||||
$this->sys_error("Jumlah debet dan kredit secara total tidak balance" . ", debet " . strval($debetTotal) . " ,Kredit " . strval($kreditTotal));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalperiodeID = ?,
|
||||
jurnalTitle = ?,
|
||||
jurnalDescription = ?,
|
||||
jurnalDate = ?,
|
||||
jurnalM_UserID = ?,
|
||||
jurnalLastUpdated = NOW()
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$prm['periodeID'],
|
||||
$prm['title'],
|
||||
$prm['description'],
|
||||
$prm['date'],
|
||||
$userid,
|
||||
$id
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal_addon SET
|
||||
jurnalAddOnValue = ?,
|
||||
jurnalAddOnLastUpdatedUserID = ?,
|
||||
jurnalAddOnLastUpdated = NOW()
|
||||
WHERE jurnalAddOnJurnalID = ?
|
||||
AND jurnalAddOnCode = 'SENDGOODRDST'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$prm['branchCode'], $userid, $id]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal addon regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = " UPDATE jurnal_tx SET jurnalTxIsActive = 'N' WHERE jurnalTxJurnalID = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$id
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error jurnal tx regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($detail as $i => $value) {
|
||||
if ($value['dataType'] == 'N') {
|
||||
$sql = 'INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID)
|
||||
VALUES(?,?,?,?,?,?)';
|
||||
$qry = $this->db->query($sql, array(
|
||||
$id,
|
||||
$value['coaID'],
|
||||
$value['coaName'],
|
||||
$value['debet'],
|
||||
$value['kredit'],
|
||||
$userid
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal tx regional");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$sql = "UPDATE jurnal_tx SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDescription = ?,
|
||||
jurnalTxDebit = ?,
|
||||
jurnalTxCredit = ?,
|
||||
jurnalTxM_UserID = ?,
|
||||
jurnalTxIsActive = 'Y',
|
||||
jurnalTxLastUpdated = NOW()
|
||||
WHERE jurnalTxID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$value['coaID'],
|
||||
$value['coaName'],
|
||||
$value['debet'],
|
||||
$value['kredit'],
|
||||
$userid,
|
||||
$value['id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert jurnal tx regional");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success");
|
||||
}
|
||||
|
||||
function deleteJurnal()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$detail = $prm['detail'];
|
||||
$id = $prm['id'];
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM jurnal
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$id
|
||||
));
|
||||
if (!$qry) {
|
||||
// $this->db->trans_rollback();
|
||||
$this->sys_error_db("Error cek jurnal jurnal");
|
||||
exit;
|
||||
}
|
||||
$cekJurnal = $qry->row_array();
|
||||
if ($cekJurnal['jurnalIsPosted'] == 'Y') {
|
||||
$this->sys_error('Jurnal sudah di post tidak bisa di hapus');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$userid = $user["M_UserID"];
|
||||
$sql = "UPDATE jurnal
|
||||
SET jurnalIsActive = 'N',
|
||||
jurnalM_UserID = ?
|
||||
WHERE
|
||||
jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delet jurnal gaji");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE jurnal_tx
|
||||
SET jurnalTxIsActive = 'N',
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE
|
||||
jurnalTxJurnalID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delet jurnal gaji tx");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE jurnal_addon
|
||||
SET jurnalAddOnIsActive = 'N',
|
||||
jurnalAddOnDeletedUserID = ?
|
||||
WHERE
|
||||
jurnalAddOnJurnalID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delet jurnal gaji tx");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,928 @@
|
||||
<?php
|
||||
class Jurnalumum extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "JURNAL API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 20;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
|
||||
$branchid = $prm["branchid"];
|
||||
$regionalid = $prm["regionalid"];
|
||||
|
||||
$filter_regional = "";
|
||||
$filter_cabang = "";
|
||||
$join_regional = "";
|
||||
$join_cabang = "";
|
||||
if (intval($branchid) === 0) {
|
||||
$filter_regional = " AND S_RegionalID = {$regionalid}";
|
||||
$join_regional = " LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
} else {
|
||||
$filter_cabang = " AND S_RegionalID = {$regionalid} AND M_BranchID = {$branchid}";
|
||||
$join_cabang = " JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
}
|
||||
// print_r($branchid);
|
||||
// exit;
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID as id,
|
||||
jurnalM_BranchCompanyID as branchcompanyid,
|
||||
JurnalS_RegionalID as regionalid,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
'' as detail
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
$join_cabang
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'
|
||||
$join_regional
|
||||
LEFT JOIN jurnal_addon ON jurnalID = jurnalAddOnJurnalID AND jurnalAddOnIsActive = 'Y'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND DATE(jurnalDate) BETWEEN '{$startdate}' AND '{$enddate}'
|
||||
AND (jurnalNo LIKE '{$search}' OR jurnalTitle LIKE '{$search}')
|
||||
$filter_regional $filter_cabang
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID DESC";
|
||||
|
||||
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total);
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
if ($qry_total) {
|
||||
$totalCount = $qry_total->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
|
||||
$qry = $this->db->query($sql_select);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID as coaid,
|
||||
jurnalTxDescription as description,
|
||||
jurnalTxDebit as debit,
|
||||
jurnalTxCredit as credit,
|
||||
'' as account
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?";
|
||||
$qry_detail = $this->db->query($sql_detail, array($v["id"]));
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$detail_rows = $qry_detail->result_array();
|
||||
|
||||
// Tambahkan account dari COA untuk setiap baris detail
|
||||
foreach ($detail_rows as $dk => $dv) {
|
||||
$sql_coa = "SELECT
|
||||
coaID,
|
||||
coaAccountNo as account
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaID = ?";
|
||||
$qry_coa = $this->db->query($sql_coa, array($dv["coaid"]));
|
||||
if ($qry_coa->num_rows() > 0) {
|
||||
$coa_row = $qry_coa->row_array();
|
||||
$detail_rows[$dk]["account"] = $coa_row["account"];
|
||||
} else {
|
||||
$detail_rows[$dk]["account"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$k]["detail"] = $detail_rows;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_old()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 20;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
|
||||
$branchid = $prm["branchid"];
|
||||
$regionalid = $prm["regionalid"];
|
||||
|
||||
$filter_regional = "";
|
||||
$filter_cabang = "";
|
||||
$join_regional = "";
|
||||
$join_cabang = "";
|
||||
if (intval($branchid) === 0) {
|
||||
$filter_regional = " AND S_RegionalID = {$regionalid}";
|
||||
$join_regional = " LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
} else {
|
||||
$filter_cabang = " AND S_RegionalID = {$regionalid} AND M_BranchID = {$branchid}";
|
||||
$join_cabang = " JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y' ";
|
||||
}
|
||||
// print_r($branchid);
|
||||
// exit;
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
$join_cabang
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'
|
||||
$join_regional
|
||||
LEFT JOIN jurnal_addon ON jurnalID = jurnalAddOnJurnalID AND jurnalAddOnIsActive = 'Y'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND DATE(jurnalDate) BETWEEN ? AND ?
|
||||
AND (jurnalNo LIKE ? OR jurnalTitle LIKE ?)
|
||||
$filter_regional $filter_cabang
|
||||
-- GROUP BY jurnalID
|
||||
ORDER BY jurnalID ASC";
|
||||
$qry_filter = $this->db->query($sql_filter, array(
|
||||
$startdate,
|
||||
$enddate,
|
||||
$search,
|
||||
$search
|
||||
));
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
if ($qry_filter) {
|
||||
$totalCount = $qry_filter->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID as id,
|
||||
jurnalM_BranchCompanyID as branchcompanyid,
|
||||
JurnalS_RegionalID as regionalid,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalM_BranchCode,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalIsPosted,
|
||||
M_BranchCompanyName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchName,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
'' as detail
|
||||
FROM jurnal
|
||||
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
$join_cabang
|
||||
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
|
||||
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'
|
||||
$join_regional
|
||||
LEFT JOIN jurnal_addon ON jurnalID = jurnalAddOnJurnalID AND jurnalAddOnIsActive = 'Y'
|
||||
WHERE jurnalIsActive = 'Y'
|
||||
AND DATE(jurnalDate) BETWEEN ? AND ?
|
||||
AND (jurnalNo LIKE ? OR jurnalTitle LIKE ?)
|
||||
$filter_regional $filter_cabang
|
||||
GROUP BY jurnalID
|
||||
ORDER BY jurnalID ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$startdate,
|
||||
$enddate,
|
||||
$search,
|
||||
$search,
|
||||
$number_limit,
|
||||
$number_offset,
|
||||
));
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$sql_detail = "SELECT
|
||||
jurnalTxID,
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID as coaid,
|
||||
jurnalTxDescription as description,
|
||||
jurnalTxDebit as debit,
|
||||
jurnalTxCredit as credit,
|
||||
'' as account
|
||||
FROM jurnal_tx
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?";
|
||||
$qry_detail = $this->db->query($sql_detail, array($v["id"]));
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$detail_rows = $qry_detail->result_array();
|
||||
|
||||
// Tambahkan account dari COA untuk setiap baris detail
|
||||
foreach ($detail_rows as $dk => $dv) {
|
||||
$sql_coa = "SELECT
|
||||
coaID,
|
||||
coaAccountNo as account
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaID = ?";
|
||||
$qry_coa = $this->db->query($sql_coa, array($dv["coaid"]));
|
||||
if ($qry_coa->num_rows() > 0) {
|
||||
$coa_row = $qry_coa->row_array();
|
||||
$detail_rows[$dk]["account"] = $coa_row["account"];
|
||||
} else {
|
||||
$detail_rows[$dk]["account"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$k]["detail"] = $detail_rows;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getjurnaltype()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT JurnalTypeID,
|
||||
JurnalTypeCode,
|
||||
JurnalTypeName,
|
||||
JurnalTypeAccesRight,
|
||||
JurnalTypeIsActive
|
||||
FROM jurnal_type
|
||||
WHERE JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'N'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal type error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$defaultju = [];
|
||||
foreach ($rows as $value) {
|
||||
if ($value["JurnalTypeCode"] == "GENERAL") {
|
||||
$defaultju = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"defaultju" => $defaultju,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getperiode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND (periodeYear LIKE ? OR periodeName LIKE ?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$search,
|
||||
$search
|
||||
));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select periode error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchcoa()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$search_name = '%' . $search . '%';
|
||||
$search_account = "$search%";
|
||||
|
||||
$number_limit = 10;
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
CONCAT(coaAccountNo, ' - ', coaDescription) as accountNoDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (coaDescription LIKE '{$search_name}' OR coaAccountNo LIKE '{$search_account}')
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, array($number_limit));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total_filter" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getbranch()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$branchid = $prm["branchid"];
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchID = ?";
|
||||
$qry = $this->db->query($sql, array($branchid));
|
||||
if ($qry) {
|
||||
$row = $qry->row_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $row,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function savejurnalumum()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
$branchid = $prm["branchid"];
|
||||
$branchcompanyid = $prm["branchcompanyid"];
|
||||
$date = $prm["date"];
|
||||
$description = $prm["description"];
|
||||
$periodeid = $prm["periodeid"];
|
||||
$regionalid = $prm["regionalid"];
|
||||
$title = $prm["title"];
|
||||
$typeid = $prm["typeid"];
|
||||
$detailjurnal = $prm["detailjurnal"];
|
||||
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchID = ?";
|
||||
$qry_branch = $this->db->query($sql_branch, array($branchid));
|
||||
if ($qry_branch) {
|
||||
$branchcodex = $qry_branch->row()->M_BranchCode;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO jurnal(
|
||||
jurnalM_BranchCompanyID,
|
||||
JurnalS_RegionalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
jurnalJurnalTypeID,
|
||||
jurnalIsActive,
|
||||
jurnalCreated,
|
||||
jurnalM_UserID
|
||||
) VALUES(?,?,?,?,`fn_numbering`('J'),?,?,?,?,'Y',NOW(),?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$branchcompanyid,
|
||||
$regionalid,
|
||||
$branchcodex,
|
||||
$periodeid,
|
||||
$title,
|
||||
$description,
|
||||
$date,
|
||||
$typeid,
|
||||
$userid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
|
||||
foreach ($detailjurnal as $key => $value) {
|
||||
$sql_detail = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxIsActive,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID) VALUES(?,?,?,?,?,'Y',NOW(),?)";
|
||||
$qry_detail = $this->db->query($sql_detail, array(
|
||||
$last_id,
|
||||
$value["coaid"],
|
||||
$value["description"],
|
||||
$value["debit"],
|
||||
$value["credit"],
|
||||
$userid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editjurnalumum()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
$branchid = $prm["branchid"];
|
||||
$branchcompanyid = $prm["branchcompanyid"];
|
||||
$date = $prm["date"];
|
||||
$description = $prm["description"];
|
||||
$periodeid = $prm["periodeid"];
|
||||
$regionalid = $prm["regionalid"];
|
||||
$title = $prm["title"];
|
||||
$typeid = $prm["typeid"];
|
||||
$detailjurnal = $prm["detailjurnal"];
|
||||
$id = $prm["id"];
|
||||
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchID = ?";
|
||||
$qry_branch = $this->db->query($sql_branch, array($branchid));
|
||||
if ($qry_branch) {
|
||||
$branchcodex = $qry_branch->row()->M_BranchCode;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalM_BranchCompanyID = ?,
|
||||
JurnalS_RegionalID = ?,
|
||||
jurnalM_BranchCode = ?,
|
||||
jurnalperiodeID = ?,
|
||||
jurnalTitle = ?,
|
||||
jurnalDescription = ?,
|
||||
jurnalDate = ?,
|
||||
jurnalJurnalTypeID = ?,
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$branchcompanyid,
|
||||
$regionalid,
|
||||
$branchcodex,
|
||||
$periodeid,
|
||||
$title,
|
||||
$description,
|
||||
$date,
|
||||
$typeid,
|
||||
$userid,
|
||||
$id
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("edit jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil data lama dari database
|
||||
$sql_select_jurnaltx = "SELECT * FROM jurnal_tx WHERE jurnalTxJurnalID = ? AND jurnalTxIsActive = 'Y'";
|
||||
$qry_select_jurnattx = $this->db->query($sql_select_jurnaltx, array($id));
|
||||
|
||||
if ($qry_select_jurnattx) {
|
||||
$rows_jurnaltx = $qry_select_jurnattx->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows_jurnaltx);
|
||||
|
||||
// Konversi existingData menjadi array dengan key jurnalTxID
|
||||
$existingDataAssoc = [];
|
||||
foreach ($rows_jurnaltx as $row) {
|
||||
$existingDataAssoc[$row['jurnalTxID']] = $row;
|
||||
}
|
||||
|
||||
// print_r($existingDataAssoc);
|
||||
$toInsert = [];
|
||||
$toUpdate = [];
|
||||
$existingIDs = array_keys($existingDataAssoc);
|
||||
$newIDs = [];
|
||||
|
||||
foreach ($detailjurnal as $item) {
|
||||
$newIDs[] = $item['jurnalTxID'] ?? null;
|
||||
|
||||
// print_r($newIDs);
|
||||
// exit;
|
||||
if (!isset($existingDataAssoc[$item['jurnalTxID']])) {
|
||||
// Data baru
|
||||
$toInsert[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$toDelete = array_diff($existingIDs, $newIDs);
|
||||
|
||||
// print_r($toInsert);
|
||||
// print_r($toDelete);
|
||||
// exit;
|
||||
|
||||
// hapus data yang sudah ada
|
||||
foreach ($toDelete as $value) {
|
||||
$sql_del = "UPDATE jurnal_tx SET
|
||||
jurnalTxIsActive = 'N',
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?";
|
||||
$qry_del = $this->db->query($sql_del, array(
|
||||
$userid,
|
||||
$value
|
||||
));
|
||||
if (!$qry_del) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
// $lastqry = $this->db->last_query();
|
||||
// echo $lastqry;
|
||||
}
|
||||
|
||||
// tambah data baru
|
||||
foreach ($toInsert as $val) {
|
||||
$sql_detail = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxIsActive,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID) VALUES(?,?,?,?,?,'Y',NOW(),?)";
|
||||
$qry_detail = $this->db->query($sql_detail, array(
|
||||
$id,
|
||||
$val["coaid"],
|
||||
$val["description"],
|
||||
$val["debit"],
|
||||
$val["credit"],
|
||||
$userid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletejurnalumum()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$id = $prm["id"];
|
||||
$detailjurnal = $prm["detailjurnal"];
|
||||
|
||||
$sql = "UPDATE jurnal SET
|
||||
jurnalIsActive = 'N',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$userid,
|
||||
$id
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($detailjurnal as $key => $value) {
|
||||
$sql_detail = "UPDATE jurnal_tx SET
|
||||
jurnalTxIsActive = 'N',
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ? AND jurnalTxJurnalID = ?";
|
||||
$qry_detail = $this->db->query($sql_detail, array(
|
||||
$userid,
|
||||
$value["jurnalTxID"],
|
||||
$id
|
||||
));
|
||||
if (!$qry_detail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete jurnal tx error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$addonSql = "UPDATE jurnal_addon
|
||||
SET jurnalAddOnIsActive = 'N', jurnalAddOnLastUpdated = NOW(),
|
||||
jurnalAddOnLastUpdatedUserID = ?
|
||||
WHERE jurnalAddOnJurnalID = ?";
|
||||
$addonqry = $this->db->query($addonSql, [$userid, $id]);
|
||||
if (!$addonqry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to delete jurnal_addon", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
560
application/controllers/mockup/masterdata/accounting/Maprk.php
Normal file
560
application/controllers/mockup/masterdata/accounting/Maprk.php
Normal file
@@ -0,0 +1,560 @@
|
||||
<?php
|
||||
class Maprk extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "MAPPING BANK COA API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getRegionalFilter()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM (
|
||||
SELECT '0' AS S_RegionalID, 'Kantor Pusat' AS S_RegionalName
|
||||
UNION
|
||||
SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
) AS x
|
||||
ORDER BY S_RegionalName ASC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM (
|
||||
SELECT '0' AS S_RegionalID, 'Kantor Pusat' AS S_RegionalName
|
||||
UNION
|
||||
SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'
|
||||
) AS x
|
||||
WHERE S_RegionalName LIKE '{$search}'
|
||||
ORDER BY S_RegionalName ASC";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select regional", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = $prm["regionalId"];
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getBranchFilter()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$regionalId = $prm["regionalId"];
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, [$regionalId]);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$regionalId = $prm['regionalId'];
|
||||
$branchCode = $prm['branchCode'];
|
||||
|
||||
$filter_regional = "";
|
||||
$join_reg_pusat = "";
|
||||
$join_regional = "";
|
||||
|
||||
// jika regionalid 0 maka kantor pusat
|
||||
if ($regionalId === 0 || $regionalId === "0") {
|
||||
$filter_regional .= " AND Map_RkCabang_SRegionalID = {$regionalId}";
|
||||
$join_reg_pusat .= " LEFT JOIN s_regional ON Map_RkCabang_SRegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON Map_RkCabang_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'";
|
||||
}
|
||||
|
||||
// jika regionalid > 0 maka filter berdasarkan regional
|
||||
if (intval($regionalId) > 0) {
|
||||
$filter_regional .= " AND Map_RkCabang_SRegionalID = {$regionalId}";
|
||||
$join_regional .= " JOIN s_regional ON Map_RkCabang_SRegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON Map_RkCabang_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'";
|
||||
}
|
||||
|
||||
// untuk load listing pada saat buka master rk
|
||||
if ($regionalId === "") {
|
||||
$join_regional .= " LEFT JOIN s_regional ON Map_RkCabang_SRegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON Map_RkCabang_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'";
|
||||
}
|
||||
|
||||
$filter_branch = "";
|
||||
// filter branch
|
||||
if ($branchCode != "") {
|
||||
$filter_branch .= " AND Map_RkCabang_BranchCode = '{$branchCode}'";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Map_RkCabang_ID,
|
||||
Map_RkCabang_Rk_TypeID,
|
||||
Map_RkCabang_SRegionalID,
|
||||
Map_RkCabang_BranchCode,
|
||||
Map_RkCabang_CoaID,
|
||||
Map_RkCabang_CoaAccountNo,
|
||||
Map_RkCabang_CoaDescription,
|
||||
Rk_TypeID,
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM map_rk_cabang
|
||||
JOIN rk_type ON Map_RkCabang_Rk_TypeID = Rk_TypeID AND Rk_TypeIsActive = 'Y'
|
||||
$join_reg_pusat
|
||||
$join_regional
|
||||
WHERE Map_RkCabang_IsActive = 'Y'
|
||||
$filter_regional
|
||||
$filter_branch
|
||||
AND (Map_RkCabang_CoaAccountNo LIKE '{$search}' OR Map_RkCabang_CoaDescription LIKE '{$search}')
|
||||
ORDER BY Map_RkCabang_ID DESC
|
||||
";
|
||||
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total, []);
|
||||
|
||||
// print_r($this->db->last_query());
|
||||
// exit;
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$total_count = 0;
|
||||
$total_page = 0;
|
||||
if ($qry_total) {
|
||||
$total_count = $qry_total->result_array()[0]["total"];
|
||||
$total_page = ceil($total_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select count bank coa count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_bank = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
$qry_bank = $this->db->query($sql_bank, []);
|
||||
if ($qry_bank) {
|
||||
$rows = $qry_bank->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select bank coa count error", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
if (intval($value["Map_RkCabang_SRegionalID"]) === 0) {
|
||||
$rows[$key]["S_RegionalID"] = "0";
|
||||
$rows[$key]["S_RegionalName"] = "Kantor Pusat";
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $total_page,
|
||||
"total_filter" => $total_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getType()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Rk_TypeID,
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName
|
||||
FROM rk_type
|
||||
WHERE Rk_TypeIsActive = 'Y'
|
||||
AND (Rk_TypeName LIKE ?)";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$search
|
||||
));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select type error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchCoaEDC()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = $prm["search"];
|
||||
$search_name = '%' . $search . '%';
|
||||
$search_account = "$search%";
|
||||
|
||||
$number_limit = 10;
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
CONCAT(coaAccountNo, ' - ', coaDescription) as accountNoDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND (coaDescription LIKE '{$search_name}' OR coaAccountNo LIKE '{$search_account}')
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, array($number_limit));
|
||||
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total_filter" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveRkCabang()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$rkCabangTypeId = $prm["rkCabangTypeId"];
|
||||
$rkCabangRegionalId = $prm["rkCabangRegionalId"];
|
||||
$rkCabangBranchCode = $prm["rkCabangBranchCode"];
|
||||
$rkCabangCoaId = $prm["rkCabangCoaId"];
|
||||
$rkCabangCoaAccountNo = $prm["rkCabangCoaAccountNo"];
|
||||
$rkCabangCoaDescription = $prm["rkCabangCoaDescription"];
|
||||
|
||||
$sql = "INSERT INTO map_rk_cabang(
|
||||
Map_RkCabang_Rk_TypeID,
|
||||
Map_RkCabang_SRegionalID,
|
||||
Map_RkCabang_BranchCode,
|
||||
Map_RkCabang_CoaID,
|
||||
Map_RkCabang_CoaAccountNo,
|
||||
Map_RkCabang_CoaDescription,
|
||||
Map_RkCabang_IsActive,
|
||||
Map_RkCabang_CreatedAt) VALUES(?,?,?,?,?,?,'Y',NOW())";
|
||||
$exec = $this->db->query($sql, [
|
||||
$rkCabangTypeId,
|
||||
$rkCabangRegionalId,
|
||||
$rkCabangBranchCode,
|
||||
$rkCabangCoaId,
|
||||
$rkCabangCoaAccountNo,
|
||||
$rkCabangCoaDescription
|
||||
]);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("map rk cabang insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRkCabang()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$rkCabangTypeId = $prm["rkCabangTypeId"];
|
||||
$rkCabangRegionalId = $prm["rkCabangRegionalId"];
|
||||
$rkCabangBranchCode = $prm["rkCabangBranchCode"];
|
||||
$rkCabangCoaId = $prm["rkCabangCoaId"];
|
||||
$rkCabangCoaAccountNo = $prm["rkCabangCoaAccountNo"];
|
||||
$rkCabangCoaDescription = $prm["rkCabangCoaDescription"];
|
||||
$rkCabangId = $prm["rkCabangId"];
|
||||
|
||||
$sql = "UPDATE map_rk_cabang SET
|
||||
Map_RkCabang_Rk_TypeID = ?,
|
||||
Map_RkCabang_SRegionalID = ?,
|
||||
Map_RkCabang_BranchCode = ?,
|
||||
Map_RkCabang_CoaID = ?,
|
||||
Map_RkCabang_CoaAccountNo = ?,
|
||||
Map_RkCabang_CoaDescription = ?,
|
||||
Map_RkCabang_LastUpdatedAt= NOW()
|
||||
WHERE Map_RkCabang_ID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$rkCabangTypeId,
|
||||
$rkCabangRegionalId,
|
||||
$rkCabangBranchCode,
|
||||
$rkCabangCoaId,
|
||||
$rkCabangCoaAccountNo,
|
||||
$rkCabangCoaDescription,
|
||||
$rkCabangId
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update rk cabang error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRkCabang()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$rkCabangId = $prm["rkCabangId"];
|
||||
|
||||
$sql = "UPDATE map_rk_cabang SET
|
||||
Map_RkCabang_IsActive = 'N',
|
||||
Map_RkCabang_LastUpdatedAt = NOW()
|
||||
WHERE Map_RkCabang_ID = ?";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$rkCabangId
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete rk cabang error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
class Mdaccountsales extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Account Sales API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
// Validasi token
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$searchSubGroupName = "";
|
||||
$searchOmzet = "";
|
||||
|
||||
if (isset($payload['searchSubGroupName']) || isset($payload['searchOmzet'])) {
|
||||
$searchSubGroupName = trim($payload["searchSubGroupName"]);
|
||||
$searchOmzet = trim($payload["searchOmzet"]);
|
||||
if ($searchSubGroupName !== "") {
|
||||
$searchSubGroupName = "%" . $payload["searchSubGroupName"] . "%";
|
||||
} else {
|
||||
$searchSubGroupName = "%%";
|
||||
}
|
||||
|
||||
if ($searchOmzet !== "") {
|
||||
$searchOmzet = $payload["searchOmzet"];
|
||||
} else {
|
||||
$searchOmzet = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$queryFilter = "SELECT count(*) as total
|
||||
FROM map_AccSales
|
||||
WHERE map_AccSalesNat_SubGroupIsActive = 'Y'
|
||||
AND map_AccSalesNat_SubGroupName LIKE ?
|
||||
AND map_AccSalesM_OmzetTypeID LIKE ?";
|
||||
$exec = $this->db->query($queryFilter, [$searchSubGroupName, $searchOmzet]);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select account sales", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT
|
||||
map_AccSalesNat_SubGroupID,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
map_AccSalesNat_SubGroupCode,
|
||||
map_AccSalesNat_SubGroupName,
|
||||
map_AccSalesM_OmzetTypeID,
|
||||
map_AccSalesM_OmzetTypeName
|
||||
FROM map_AccSales
|
||||
LEFT JOIN coa ON map_AccSales.map_AccSalesNat_SubGroupCoaID=coa.coaID
|
||||
INNER JOIN m_omzettype ON map_AccSales.map_AccSalesM_OmzetTypeID=m_omzettype.M_OmzetTypeID
|
||||
WHERE map_AccSalesNat_SubGroupIsActive = 'Y'
|
||||
AND M_OmzetTypeIsActive = 'Y'
|
||||
AND map_AccSalesNat_SubGroupName LIKE ?
|
||||
AND map_AccSalesM_OmzetTypeID LIKE ?
|
||||
ORDER BY map_AccSalesNat_SubGroupID ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$exec = $this->db->query($query, [$searchSubGroupName, $searchOmzet, $numberLimit, $numberOffset]);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select account sales", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function subGroupName()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
map_AccSalesNat_SubGroupName
|
||||
FROM map_AccSales
|
||||
WHERE map_AccSalesNat_SubGroupIsActive = 'Y'
|
||||
ORDER BY map_AccSalesNat_SubGroupName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select sub group name", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function coa()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
ORDER BY coaAccountNo ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function omzet()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
M_OmzetTypeID,
|
||||
M_OmzetTypeName
|
||||
FROM m_omzettype
|
||||
WHERE M_OmzetTypeIsActive = 'Y'
|
||||
ORDER BY M_OmzetTypeID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select omzet", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addNewAccountSales()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$coaId = $payload["coaId"];
|
||||
$subGroupCode = $payload["subGroupCode"];
|
||||
$subGroupName = $payload["subGroupName"];
|
||||
$omzetId = $payload["omzetId"];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM map_AccSales WHERE map_AccSalesNat_SubGroupIsActive = 'Y' AND map_AccSalesNat_SubGroupCode = ? AND map_AccSalesNat_SubGroupName = ? AND map_AccSalesNat_SubGroupCoaID = ? AND map_AccSalesM_OmzetTypeID = ?";
|
||||
$exist = $this->db->query($query, [$subGroupCode, $subGroupName, $coaId, $omzetId]);
|
||||
if ($exist) {
|
||||
$row = $exist->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$queryOmzet = "SELECT M_OmzetTypeName FROM m_omzettype WHERE M_OmzetTypeID = ?";
|
||||
$exec = $this->db->query($queryOmzet, [$omzetId]);
|
||||
$omzetName = $exec->result_array()[0]["M_OmzetTypeName"];
|
||||
|
||||
$sql = "INSERT INTO map_AccSales(
|
||||
map_AccSalesNat_SubGroupCoaID,
|
||||
map_AccSalesNat_SubGroupCode,
|
||||
map_AccSalesNat_SubGroupName,
|
||||
map_AccSalesM_OmzetTypeID,
|
||||
map_AccSalesM_OmzetTypeName,
|
||||
map_AccSalesNat_SubGroupCreated,
|
||||
map_AccSalesNat_SubGroupLastUpdated,
|
||||
map_AccSalesNat_SubGroupUserID,
|
||||
map_AccSalesNat_SubGroupIsActive
|
||||
) VALUES (?, ?, ?, ?, ?, NOW(), NOW(), ?, 'Y')";
|
||||
$exec = $this->db->query($sql, [
|
||||
$coaId,
|
||||
$subGroupCode,
|
||||
$subGroupName,
|
||||
$omzetId,
|
||||
$omzetName,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("account sales insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('msg' => 'Data sudah ada'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editAccountSales()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$subGroupId = $payload["subGroupId"];
|
||||
$coaId = $payload["coaId"];
|
||||
$subGroupCode = $payload["subGroupCode"];
|
||||
$subGroupName = $payload["subGroupName"];
|
||||
$omzetId = $payload["omzetId"];
|
||||
|
||||
$queryOmzet = "SELECT M_OmzetTypeName FROM m_omzettype WHERE M_OmzetTypeID = ?";
|
||||
$exec = $this->db->query($queryOmzet, [$omzetId]);
|
||||
$omzetName = $exec->result_array()[0]["M_OmzetTypeName"];
|
||||
|
||||
$sql = "UPDATE map_AccSales SET
|
||||
map_AccSalesNat_SubGroupCoaID = ?,
|
||||
map_AccSalesNat_SubGroupCode = ?,
|
||||
map_AccSalesNat_SubGroupName = ?,
|
||||
map_AccSalesM_OmzetTypeID = ?,
|
||||
map_AccSalesM_OmzetTypeName = ?,
|
||||
map_AccSalesNat_SubGroupLastUpdated = NOW()
|
||||
WHERE map_AccSalesNat_SubGroupID = ?";
|
||||
$exec = $this->db->query($sql, [$coaId, $subGroupCode, $subGroupName, $omzetId, $omzetName, $subGroupId]);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("account sales update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => $subGroupId));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function softDelete()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$subGroupId = $payload["subGroupId"];
|
||||
|
||||
$sql = "UPDATE map_AccSales SET
|
||||
map_AccSalesNat_SubGroupLastUpdated = NOW(),
|
||||
map_AccSalesNat_SubGroupIsActive = 'N'
|
||||
WHERE map_AccSalesNat_SubGroupID = ?";
|
||||
$exec = $this->db->query($sql, [$subGroupId]);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("account sales delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
class Mdcategory extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "MD ITEM CATEGORY API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listcategory()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
itemCategoryID,
|
||||
itemCategoryName,
|
||||
itemCategoryRk_TypeID,
|
||||
itemCategoryIsActive,
|
||||
Rk_TypeID,
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName
|
||||
FROM item_category
|
||||
LEFT JOIN rk_type ON itemCategoryRk_TypeID = Rk_TypeID AND Rk_TypeIsActive = 'Y'
|
||||
WHERE itemCategoryIsActive = 'Y'
|
||||
AND (itemCategoryName LIKE ?)
|
||||
ORDER BY itemCategoryID DESC";
|
||||
$query = $this->db->query($sql, [$search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("type list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$sql_tot = "SELECT count(*) as total
|
||||
FROM item_category
|
||||
LEFT JOIN rk_type ON itemCategoryRk_TypeID = Rk_TypeID AND Rk_TypeIsActive = 'Y'
|
||||
WHERE itemCategoryIsActive = 'Y'
|
||||
AND (itemCategoryName LIKE ?)";
|
||||
|
||||
$query_tot = $this->db->query($sql_tot, [$search]);
|
||||
$total_list = 0;
|
||||
if ($query_tot) {
|
||||
$total_list = $query_tot->result_array()[0]['total'];
|
||||
} else {
|
||||
$this->sys_error_db("type count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$rows[$k]['rownumber'] = $k + 1;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total_list,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function gettype()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Rk_TypeID,
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName
|
||||
FROM rk_type
|
||||
WHERE Rk_TypeIsActive = 'Y'
|
||||
AND (Rk_TypeCode LIKE ? OR Rk_TypeName LIKE ?)
|
||||
ORDER BY Rk_TypeName ASC";
|
||||
$query = $this->db->query($sql, [$search, $search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("type list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => count($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCategory()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$categoryid = $prm['categoryid'];
|
||||
|
||||
$sql = "UPDATE item_category SET
|
||||
itemCategoryIsActive = 'N',
|
||||
itemCategoryM_UserID = ?,
|
||||
itemCategoryLastUpdated = NOW()
|
||||
WHERE itemCategoryID = ?";
|
||||
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
array($userid, $categoryid)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("delete category");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"data" => array('status' => 'OK')
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addCategory()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$categoryname = $prm["categoryname"];
|
||||
$typeid = $prm["typeid"];
|
||||
|
||||
$sql = "INSERT INTO `item_category` (
|
||||
itemCategoryName,
|
||||
itemCategoryRk_TypeID,
|
||||
itemCategoryIsActive,
|
||||
itemCategoryM_UserID,
|
||||
itemCategoryCreated
|
||||
) VALUES (?,?,'Y',?,NOW())";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$categoryname,
|
||||
$typeid,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("category insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editCategory()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$categoryname = $prm["categoryname"];
|
||||
$typeid = $prm["typeid"];
|
||||
$categoryid = $prm["categoryid"];
|
||||
|
||||
$sql = "UPDATE item_category SET
|
||||
itemCategoryName = ?,
|
||||
itemCategoryRk_TypeID = ?,
|
||||
itemCategoryM_UserID = ?,
|
||||
itemCategoryLastUpdated = NOW()
|
||||
WHERE itemCategoryID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$categoryname,
|
||||
$typeid,
|
||||
$userid,
|
||||
$categoryid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("category error edit", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("itemCategoryID" => $categoryid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
274
application/controllers/mockup/masterdata/accounting/Mdcoa.php
Normal file
274
application/controllers/mockup/masterdata/accounting/Mdcoa.php
Normal file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
class Mdcoa extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "COA API";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND (coaDescription LIKE ? OR coaSubDescription LIKE ? OR coaAccountNo LIKE ?)";
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $search, $search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("coa count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
coaLevel
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND (coaDescription LIKE ? OR coaSubDescription LIKE ? OR coaAccountNo LIKE ?)
|
||||
ORDER BY coaAccountNo ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addnewcoa()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$accountno = $prm["accountno"];
|
||||
$description = $prm["description"];
|
||||
$subdescription = $prm["subdescription"];
|
||||
$accounttype = $prm["accounttype"];
|
||||
$currencycode = $prm["currencycode"];
|
||||
$cashflowcategory = $prm["cashflowcategory"];
|
||||
$reportschedule = $prm["reportschedule"];
|
||||
$level = $prm["level"];
|
||||
$isinput = $prm["isinput"];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM coa WHERE coaIsActive = 'Y' AND coaAccountNo = ?";
|
||||
$exist_accountno = $this->db->query($query, [$accountno]);
|
||||
if ($exist_accountno) {
|
||||
$row = $exist_accountno->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$sql = "INSERT INTO coa(
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
coaCreated,
|
||||
coaIsActive,
|
||||
coaLevel
|
||||
) VALUES(?,?,?,?,?,?,?,?,NOW(),'Y',?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$accountno,
|
||||
$description,
|
||||
$subdescription,
|
||||
$accounttype,
|
||||
$isinput,
|
||||
$reportschedule,
|
||||
$currencycode,
|
||||
$cashflowcategory,
|
||||
$level
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("coa insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('field' => 'account no', 'msg' => 'Account No sudah digunakan'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editcoa()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$coaid = $prm["coaid"];
|
||||
$accountno = $prm["accountno"];
|
||||
$description = $prm["description"];
|
||||
$subdescription = $prm["subdescription"];
|
||||
$accounttype = $prm["accounttype"];
|
||||
$currencycode = $prm["currencycode"];
|
||||
$cashflowcategory = $prm["cashflowcategory"];
|
||||
$reportschedule = $prm["reportschedule"];
|
||||
$level = $prm["level"];
|
||||
$isinput = $prm["isinput"];
|
||||
|
||||
$sql = "UPDATE coa SET
|
||||
coaAccountNo = ?,
|
||||
coaDescription = ?,
|
||||
coaSubDescription = ?,
|
||||
coaAccountType = ?,
|
||||
coaIsInput = ?,
|
||||
coaReportSchedule = ?,
|
||||
coaCurrencyCode = ?,
|
||||
coaCashFlowCategory = ?,
|
||||
coaLastUpdated = NOW(),
|
||||
coaLevel = ?
|
||||
WHERE coaID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$accountno,
|
||||
$description,
|
||||
$subdescription,
|
||||
$accounttype,
|
||||
$isinput,
|
||||
$reportschedule,
|
||||
$currencycode,
|
||||
$cashflowcategory,
|
||||
$level,
|
||||
$coaid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("coa update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => $coaid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletecoa()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$coaid = $prm["coaid"];
|
||||
|
||||
$sql = "UPDATE coa SET
|
||||
coaLastUpdated = NOW(),
|
||||
coaIsActive = 'N'
|
||||
WHERE coaID = ?";
|
||||
$qry = $this->db->query($sql, [$coaid]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("coa delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
944
application/controllers/mockup/masterdata/accounting/Mditem.php
Normal file
944
application/controllers/mockup/masterdata/accounting/Mditem.php
Normal file
@@ -0,0 +1,944 @@
|
||||
<?php
|
||||
|
||||
class Mditem extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Mditem API";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$where = "M_ItemIsActive = 'Y'";
|
||||
|
||||
// Filter by category
|
||||
// if (isset($prm['category_id']) && $prm['category_id'] != '' && intval($prm['category_id']) > 0) {
|
||||
// $where .= " AND M_ItemItem_CategoryID = " . $prm['category_id'];
|
||||
// }
|
||||
|
||||
// Filter by group
|
||||
if (isset($prm['group_id']) && $prm['group_id'] != '' && intval($prm['group_id']) > 0) {
|
||||
$where .= " AND M_ItemNat_GroupID = " . $prm['group_id'];
|
||||
}
|
||||
|
||||
// Search by name
|
||||
if (isset($prm['search']) && trim($prm['search']) != '') {
|
||||
$search = trim($prm['search']);
|
||||
$where .= " AND M_ItemDesc LIKE '%" . $search . "%'";
|
||||
}
|
||||
|
||||
// Pagination
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if (isset($prm['current_page']) && $prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
M_ItemInventoryCode,
|
||||
M_ItemItem_CategoryID,
|
||||
M_ItemNat_GroupID,
|
||||
M_ItemNat_SubGroupID,
|
||||
M_ItemFa_ClassID,
|
||||
M_ItemItem_UnitID,
|
||||
itemCategoryID,
|
||||
itemCategoryName,
|
||||
Nat_GroupID,
|
||||
Nat_GroupName,
|
||||
Nat_SubGroupID,
|
||||
Nat_SubGroupName,
|
||||
Fa_ClassID,
|
||||
Fa_ClassName,
|
||||
Fa_ClassFlagType,
|
||||
Fa_InventarisGolID,
|
||||
Fa_InventarisGolName,
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
GROUP_CONCAT(ItemUnitName) as ItemUnitName,
|
||||
'' as satuan
|
||||
FROM m_item
|
||||
LEFT JOIN item_category ON M_ItemItem_CategoryID = itemCategoryID
|
||||
LEFT JOIN nat_group ON M_ItemNat_GroupID = Nat_GroupID
|
||||
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
||||
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
|
||||
LEFT JOIN fa_inventaris_gol ON M_ItemM_InventarisGolID = Fa_InventarisGolID
|
||||
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
|
||||
AND ItemUnitMapIsActive = 'Y'
|
||||
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
|
||||
AND ItemUnitIsActive = 'Y'
|
||||
WHERE $where
|
||||
GROUP BY M_ItemID
|
||||
ORDER BY M_ItemID DESC
|
||||
LIMIT $number_limit OFFSET $number_offset";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("item list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql = "SELECT ItemUnitMapID as id,
|
||||
ItemUnitMapM_ItemID,
|
||||
ItemUnitMapItemUnitID,
|
||||
ItemUnitMapIsPurchase,
|
||||
ItemUnitMapIsReport,
|
||||
ItemUnitMapIsBase,
|
||||
CASE
|
||||
WHEN ItemUnitMapIsPurchase = 'Y' THEN 'purchase'
|
||||
WHEN ItemUnitMapIsReport = 'Y' THEN 'report'
|
||||
WHEN ItemUnitMapIsBase = 'Y' THEN 'base'
|
||||
END as detail_tipe_itemunit,
|
||||
ItemUnitName as item_unit_name,
|
||||
ItemUnitID as item_unit_id,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
ItemUnitMapMin as item_unit_min
|
||||
from itemunitmap
|
||||
JOIN itemunit
|
||||
ON ItemUnitMapItemUnitID = ItemUnitID
|
||||
AND ItemUnitIsActive = 'Y'
|
||||
Where
|
||||
ItemUnitMapIsActive = 'Y'
|
||||
AND ItemUnitMapM_ItemID = ?";
|
||||
$qry = $this->db->query($sql, array($value['M_ItemID']));
|
||||
if ($qry) {
|
||||
$rows_satuan = $qry->result_array();
|
||||
$rows[$key]['satuan'] = $rows_satuan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get total count
|
||||
$sql_count = "SELECT COUNT(*) as total FROM (
|
||||
SELECT M_ItemID
|
||||
FROM m_item
|
||||
LEFT JOIN item_category ON M_ItemItem_CategoryID = itemCategoryID
|
||||
LEFT JOIN nat_group ON M_ItemNat_GroupID = Nat_GroupID
|
||||
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
||||
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
|
||||
LEFT JOIN fa_inventaris_gol ON M_ItemM_InventarisGolID = Fa_InventarisGolID
|
||||
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
|
||||
AND ItemUnitMapIsActive = 'Y'
|
||||
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
|
||||
AND ItemUnitIsActive = 'Y'
|
||||
WHERE $where
|
||||
GROUP BY M_ItemID
|
||||
) x";
|
||||
|
||||
$query_count = $this->db->query($sql_count);
|
||||
$total = 0;
|
||||
if ($query_count) {
|
||||
$total = $query_count->row()->total;
|
||||
$total_page = ceil($total / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("item count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"total_page" => $total_page,
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_category()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = $prm["search"];
|
||||
|
||||
$where = "itemCategoryIsActive = 'Y'";
|
||||
if (!empty($search)) {
|
||||
$where .= " AND itemCategoryName LIKE '%$search%'";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
itemCategoryID,
|
||||
itemCategoryName
|
||||
FROM item_category
|
||||
WHERE $where
|
||||
ORDER BY itemCategoryID ASC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("category list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_group_filter()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
// $search = $prm["search"];
|
||||
|
||||
// $where = "Nat_GroupIsActive = 'Y'";
|
||||
// if (!empty($search)) {
|
||||
// $where .= " AND Nat_GroupName LIKE '%$search%'";
|
||||
// }
|
||||
|
||||
$sql = "SELECT
|
||||
Nat_GroupID,
|
||||
Nat_GroupName
|
||||
FROM nat_group
|
||||
WHERE Nat_GroupIsActive = 'Y'
|
||||
ORDER BY Nat_GroupID DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("group list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
if ($rows) {
|
||||
array_push($rows, ["Nat_GroupID" => "0", "Nat_GroupName" => "All"]);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_group()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = $prm["search"];
|
||||
|
||||
$where = "Nat_GroupIsActive = 'Y'";
|
||||
if (!empty($search)) {
|
||||
$where .= " AND Nat_GroupName LIKE '%$search%'";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Nat_GroupID,
|
||||
Nat_GroupCode,
|
||||
Nat_GroupName
|
||||
FROM nat_group
|
||||
WHERE Nat_GroupIsActive = 'Y'
|
||||
ORDER BY Nat_GroupID ASC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("group list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_subgroup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
$groupId = $prm["group_id"];
|
||||
|
||||
$sql = "SELECT
|
||||
Nat_SubGroupID,
|
||||
Nat_SubGroupNat_GroupID,
|
||||
Nat_SubGroupCode,
|
||||
Nat_SubGroupName,
|
||||
Nat_SubGroupLangName,
|
||||
Nat_SubGroupIsResult,
|
||||
Nat_SubGroupReportTitle
|
||||
FROM nat_subgroup
|
||||
WHERE Nat_SubGroupIsActive = 'Y'
|
||||
AND Nat_SubGroupName LIKE '%$search%'
|
||||
AND Nat_SubGroupNat_GroupID = $groupId
|
||||
ORDER BY Nat_SubGroupID DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("subgroup list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_fa_class()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
$flag_type = isset($prm["flag_type"]) ? $prm["flag_type"] : "";
|
||||
|
||||
$sql = "SELECT
|
||||
Fa_ClassID,
|
||||
Fa_ClassName,
|
||||
Fa_ClassFlagType,
|
||||
Fa_ClassCoaID,
|
||||
Fa_ClassCoaAccountNo,
|
||||
Fa_ClassCoaDesc,
|
||||
Fa_ClassDepreCorp,
|
||||
Fa_ClassDepreGov,
|
||||
Fa_ClassAccumDepreCoaID,
|
||||
Fa_ClassAccumDepreCoaAccountNo,
|
||||
Fa_ClassAccumDepreCoaDesc,
|
||||
Fa_ClassAccumNote,
|
||||
Fa_ClassAccumCreated,
|
||||
Fa_ClassAccumLastUpdated,
|
||||
Fa_ClassIsActive,
|
||||
Fa_ClassM_UserID
|
||||
FROM fa_class
|
||||
WHERE Fa_ClassIsActive = 'Y'
|
||||
AND Fa_ClassFlagType = '{$flag_type}'
|
||||
AND Fa_ClassName LIKE '%$search%'
|
||||
ORDER BY Fa_ClassID DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("fa class list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_fa_inventaris_gol()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
|
||||
$sql = "SELECT
|
||||
Fa_InventarisGolID,
|
||||
Fa_InventarisGolName,
|
||||
Fa_InventarisGolCreated,
|
||||
Fa_InventarisGolLastUpdated,
|
||||
Fa_InventarisGolIsActive,
|
||||
Fa_InventarisGolUserID
|
||||
FROM fa_inventaris_gol
|
||||
WHERE Fa_InventarisGolIsActive = 'Y'
|
||||
|
||||
ORDER BY Fa_InventarisGolID DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("fa inventaris gol list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_unit()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
|
||||
$sql = "SELECT
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCreated,
|
||||
ItemUnitLastUpdated,
|
||||
ItemUnitIsActive,
|
||||
ItemUnitUserID
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName LIKE '%$search%'
|
||||
ORDER BY ItemUnitID DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("item unit list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save_item()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$item_group_id = $prm['itemgroupid'];
|
||||
$item_sub_group_id = $prm['itemsubgroupid'];
|
||||
$item_fa_class_id = $prm['itemfaclassid'];
|
||||
$item_fa_inventaris_id = $prm['itemfainventarisid'];
|
||||
$item_name = $prm['itemname'];
|
||||
$inventory_code = $prm['inventory_code'];
|
||||
$item_category_id = $prm['itemcategoryid'];
|
||||
|
||||
$item_name_search = "";
|
||||
$item_name = "";
|
||||
if (isset($prm['itemname'])) {
|
||||
$item_name_search = trim($prm["itemname"]);
|
||||
$item_name = trim($prm['itemname']);
|
||||
if ($item_name_search != "") {
|
||||
$item_name_search = $prm['itemname'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql_count = "SELECT COUNT(*) as exist
|
||||
FROM m_item
|
||||
WHERE M_ItemIsActive = 'Y'
|
||||
AND M_ItemDesc = ?";
|
||||
|
||||
$query_count = $this->db->query($sql_count, [
|
||||
$item_name_search
|
||||
]);
|
||||
|
||||
if (!$query_count) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("item search & count by name");
|
||||
exit;
|
||||
}
|
||||
|
||||
$get_count = $query_count->row_array();
|
||||
if ($get_count['exist'] == 0) {
|
||||
// Continue with insert logic
|
||||
$sqlfn = "SELECT fn_numbering('I') as item";
|
||||
$queryfn = $this->db->query($sqlfn);
|
||||
|
||||
if (!$queryfn) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("item call sp");
|
||||
exit;
|
||||
} else {
|
||||
$get_item_code = $queryfn->result_array()[0]["item"];
|
||||
}
|
||||
|
||||
$sql_insert = "INSERT INTO m_item (
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
M_ItemItem_CategoryID,
|
||||
M_ItemInventoryCode,
|
||||
M_ItemNat_GroupID,
|
||||
M_ItemNat_SubGroupID,
|
||||
M_ItemFa_ClassID,
|
||||
M_ItemM_InventarisGolID,
|
||||
M_ItemIsActive,
|
||||
M_ItemCreated,
|
||||
M_ItemLastUpdated,
|
||||
M_ItemM_UserID
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
'Y',
|
||||
NOW(),
|
||||
NOW(),
|
||||
?
|
||||
)";
|
||||
|
||||
$query_insert = $this->db->query($sql_insert, [
|
||||
$get_item_code,
|
||||
$item_name,
|
||||
$item_category_id,
|
||||
$inventory_code,
|
||||
$item_group_id,
|
||||
$item_sub_group_id,
|
||||
$item_fa_class_id,
|
||||
$item_fa_inventaris_id,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$query_insert) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to insert item");
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
|
||||
// Insert batch item unit map
|
||||
if (isset($prm['satuan']) && count($prm['satuan']) > 0) {
|
||||
foreach ($prm['satuan'] as $key => $value) {
|
||||
$ItemUnitMapItemUnitID = trim($value['item_unit_id']);
|
||||
$itemunitpurchase = 'N';
|
||||
$itemunitbase = 'N';
|
||||
$itemunitreport = 'N';
|
||||
$item_unit_min = trim($value['item_unit_min']);
|
||||
|
||||
if ($value['detail_tipe_itemunit'] == "purchase") {
|
||||
$itemunitpurchase = 'Y';
|
||||
} else if ($value['detail_tipe_itemunit'] == "base") {
|
||||
$itemunitbase = 'Y';
|
||||
} else if ($value['detail_tipe_itemunit'] == "report") {
|
||||
$itemunitreport = 'Y';
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO itemunitmap(
|
||||
ItemUnitMapM_ItemID,
|
||||
ItemUnitMapItemUnitID,
|
||||
ItemUnitMapIsPurchase,
|
||||
ItemUnitMapIsReport,
|
||||
ItemUnitMapIsBase,
|
||||
ItemUnitMapMin,
|
||||
ItemUnitMapIsActive,
|
||||
ItemUnitMapCreated,
|
||||
ItemUnitMapLastUpdated,
|
||||
ItemUnitMapUserID
|
||||
) VALUES (
|
||||
?,?,?,?,?,?,?,NOW(),NOW(),?
|
||||
)";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$last_id,
|
||||
$ItemUnitMapItemUnitID,
|
||||
$itemunitpurchase,
|
||||
$itemunitreport,
|
||||
$itemunitbase,
|
||||
$item_unit_min,
|
||||
'Y',
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to insert item unit map");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array(
|
||||
"M_ItemCode" => $get_item_code,
|
||||
"M_ItemDesc" => $item_name
|
||||
)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
array_push($errors, array(
|
||||
'field' => 'name',
|
||||
'msg' => 'Nama ' . $item_name . ' sudah ada'
|
||||
));
|
||||
|
||||
$result = array(
|
||||
"total" => -1,
|
||||
"errors" => $errors,
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update_item()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$item_group_id = $prm['itemgroupid'];
|
||||
$item_sub_group_id = $prm['itemsubgroupid'];
|
||||
$item_fa_class_id = $prm['itemfaclassid'];
|
||||
$item_fa_inventaris_id = $prm['itemfainventarisid'];
|
||||
$item_name = $prm['itemname'];
|
||||
$inventory_code = $prm['inventory_code'];
|
||||
$item_category_id = $prm['itemcategoryid'];
|
||||
$item_id = $prm['itemid'];
|
||||
|
||||
$item_name_search = "";
|
||||
$item_name = "";
|
||||
if (isset($prm['itemname'])) {
|
||||
$item_name_search = trim($prm["itemname"]);
|
||||
$item_name = trim($prm['itemname']);
|
||||
if ($item_name_search != "") {
|
||||
$item_name_search = $prm['itemname'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql_count = "SELECT COUNT(*) as exist
|
||||
FROM m_item
|
||||
WHERE M_ItemIsActive = 'Y'
|
||||
AND M_ItemDesc = ?";
|
||||
|
||||
$query_count = $this->db->query($sql_count, [
|
||||
$item_name_search
|
||||
]);
|
||||
|
||||
if (!$query_count) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("item search & count by name");
|
||||
exit;
|
||||
} else {
|
||||
|
||||
// $get_count = $query_count->row_array();
|
||||
// if ($get_count['exist'] == 0) {
|
||||
|
||||
$sql_update = "UPDATE m_item SET
|
||||
M_ItemDesc = ?,
|
||||
M_ItemItem_CategoryID = ?,
|
||||
M_ItemInventoryCode = ?,
|
||||
M_ItemNat_GroupID = ?,
|
||||
M_ItemNat_SubGroupID = ?,
|
||||
M_ItemFa_ClassID = ?,
|
||||
M_ItemM_InventarisGolID = ?,
|
||||
M_ItemIsActive = 'Y',
|
||||
M_ItemLastUpdated = NOW(),
|
||||
M_ItemM_UserID = ?
|
||||
WHERE M_ItemID = ?";
|
||||
|
||||
$query_update = $this->db->query($sql_update, [
|
||||
$item_name,
|
||||
$item_category_id,
|
||||
$inventory_code,
|
||||
$item_group_id,
|
||||
$item_sub_group_id,
|
||||
$item_fa_class_id,
|
||||
$item_fa_inventaris_id,
|
||||
$userid,
|
||||
$item_id
|
||||
]);
|
||||
|
||||
|
||||
if (!$query_update) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update item");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_update_itemunitmap = "UPDATE itemunitmap SET
|
||||
ItemUnitMapIsActive = 'N'
|
||||
WHERE ItemUnitMapM_ItemID = ?";
|
||||
$query_update_itemunitmap = $this->db->query($sql_update_itemunitmap, [
|
||||
$item_id
|
||||
]);
|
||||
|
||||
if (!$query_update_itemunitmap) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update item unit map");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Insert batch item unit map
|
||||
if (isset($prm['satuan']) && count($prm['satuan']) > 0) {
|
||||
foreach ($prm['satuan'] as $key => $value) {
|
||||
$ItemUnitMapItemUnitID = trim($value['item_unit_id']);
|
||||
$itemunitpurchase = 'N';
|
||||
$itemunitbase = 'N';
|
||||
$itemunitreport = 'N';
|
||||
$item_unit_min = trim($value['item_unit_min']);
|
||||
|
||||
if ($value['detail_tipe_itemunit'] == "purchase") {
|
||||
$itemunitpurchase = 'Y';
|
||||
} else if ($value['detail_tipe_itemunit'] == "base") {
|
||||
$itemunitbase = 'Y';
|
||||
} else if ($value['detail_tipe_itemunit'] == "report") {
|
||||
$itemunitreport = 'Y';
|
||||
}
|
||||
|
||||
if (intval($value['id']) > 0) {
|
||||
// update
|
||||
$sql = "UPDATE itemunitmap SET
|
||||
ItemUnitMapItemUnitID = ?,
|
||||
ItemUnitMapIsPurchase = ?,
|
||||
ItemUnitMapIsReport = ?,
|
||||
ItemUnitMapIsBase = ?,
|
||||
ItemUnitMapMin = ?,
|
||||
ItemUnitMapIsActive = 'Y',
|
||||
ItemUnitMapLastUpdated = NOW(),
|
||||
ItemUnitMapUserID = ?
|
||||
WHERE ItemUnitMapID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$ItemUnitMapItemUnitID,
|
||||
$itemunitpurchase,
|
||||
$itemunitreport,
|
||||
$itemunitbase,
|
||||
$item_unit_min,
|
||||
$userid,
|
||||
$value['id']
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to update item unit map");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// insert
|
||||
$sql = "INSERT INTO itemunitmap(
|
||||
ItemUnitMapM_ItemID,
|
||||
ItemUnitMapItemUnitID,
|
||||
ItemUnitMapIsPurchase,
|
||||
ItemUnitMapIsReport,
|
||||
ItemUnitMapIsBase,
|
||||
ItemUnitMapMin,
|
||||
ItemUnitMapIsActive,
|
||||
ItemUnitMapCreated,
|
||||
ItemUnitMapLastUpdated,
|
||||
ItemUnitMapUserID
|
||||
) VALUES (
|
||||
?,?,?,?,?,?,?,NOW(),NOW(),?
|
||||
)";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$prm['itemid'],
|
||||
$ItemUnitMapItemUnitID,
|
||||
$itemunitpurchase,
|
||||
$itemunitreport,
|
||||
$itemunitbase,
|
||||
$item_unit_min,
|
||||
'Y',
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Failed to insert item unit map");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array(
|
||||
"M_ItemDesc" => $item_name
|
||||
)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
// } else {
|
||||
// $errors = array();
|
||||
// array_push($errors, array(
|
||||
// 'field' => 'name',
|
||||
// 'msg' => 'Nama ' . $item_name . ' sudah ada'
|
||||
// ));
|
||||
|
||||
// $result = array(
|
||||
// "total" => -1,
|
||||
// "errors" => $errors,
|
||||
// "records" => 0
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// }
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete_item()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$item_id = $prm['itemid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql_delete = "UPDATE m_item SET
|
||||
M_ItemIsActive = 'N',
|
||||
M_ItemLastUpdated = NOW(),
|
||||
M_ItemM_UserID = ?
|
||||
WHERE M_ItemID = ?";
|
||||
|
||||
$query_delete = $this->db->query($sql_delete, [
|
||||
$userid,
|
||||
$item_id
|
||||
]);
|
||||
|
||||
if (!$query_delete) {
|
||||
$this->sys_error_db("Failed to delete item");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_delete_itemunitmap = "UPDATE itemunitmap SET
|
||||
ItemUnitMapIsActive = 'N',
|
||||
ItemUnitMapLastUpdated = NOW(),
|
||||
ItemUnitMapUserID = ?
|
||||
WHERE ItemUnitMapM_ItemID = ?";
|
||||
$query_delete_itemunitmap = $this->db->query($sql_delete_itemunitmap, [
|
||||
$userid,
|
||||
$item_id
|
||||
]);
|
||||
|
||||
if (!$query_delete_itemunitmap) {
|
||||
$this->sys_error_db("Failed to delete item unit map");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => array(
|
||||
"M_ItemID" => $item_id
|
||||
)
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
class Mdperiode extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "MD Periode API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listperiode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
periodeIsActive,
|
||||
periodeIsClosed
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'";
|
||||
$query = $this->db->query($sql);
|
||||
$rows = $query->result_array();
|
||||
|
||||
$sql_tot = "SELECT count(periodeID) as total
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'";
|
||||
|
||||
$query_tot = $this->db->query($sql_tot);
|
||||
$total_list = 0;
|
||||
if ($query_tot) {
|
||||
$total_list = $query_tot->result_array()[0]['total'];
|
||||
} else {
|
||||
$this->sys_error_db("periode count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total_list,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteperiode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$periodeID = $prm['id'];
|
||||
|
||||
$sql = "UPDATE periode SET
|
||||
periodeIsActive = 'N',
|
||||
periodeLastUpdated = now()
|
||||
WHERE periodeID = ?";
|
||||
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
array($periodeID)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("update periode active");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"data" => array('status' => 'OK')
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addperiode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$periodeyear = $prm["periodeYear"];
|
||||
$periodemonth = $prm["periodeMonth"];
|
||||
$periodename = $prm["periodeName"];
|
||||
$periodestart = $prm["periodeStartDate"];
|
||||
$periodeend = $prm["periodeEndDate"];
|
||||
|
||||
$sql = "INSERT INTO `periode` (
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate
|
||||
) VALUES (?,?,?,?,?)";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$periodeyear,
|
||||
$periodemonth,
|
||||
$periodename,
|
||||
$periodestart,
|
||||
$periodeend
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("periode insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editperiode()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$periodeid = $prm["periodeID"];
|
||||
$periodeyear = $prm["periodeYear"];
|
||||
$periodemonth = $prm["periodeMonth"];
|
||||
$periodename = $prm["periodeName"];
|
||||
$periodestart = $prm["periodeStartDate"];
|
||||
$periodeend = $prm["periodeEndDate"];
|
||||
|
||||
$sql = "UPDATE periode SET
|
||||
periodeYear = ?,
|
||||
periodeMonth = ?,
|
||||
periodeName = ?,
|
||||
periodeStartDate = ?,
|
||||
periodeEndDate = ?
|
||||
WHERE periodeID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$periodeyear,
|
||||
$periodemonth,
|
||||
$periodename,
|
||||
$periodestart,
|
||||
$periodeend,
|
||||
$periodeid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("periode error edit", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("periodeID" => $periodeid));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
205
application/controllers/mockup/masterdata/accounting/Mdtype.php
Normal file
205
application/controllers/mockup/masterdata/accounting/Mdtype.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
class Mdtype extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "MD RK TYPE API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listtype()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
Rk_TypeID,
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName,
|
||||
Rk_TypeIsActive,
|
||||
'' as rownumber
|
||||
FROM rk_type
|
||||
WHERE Rk_TypeIsActive = 'Y'
|
||||
AND (Rk_TypeCode LIKE ? OR Rk_TypeName LIKE ?)
|
||||
ORDER BY Rk_TypeID DESC";
|
||||
$query = $this->db->query($sql, [$search, $search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("type list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$sql_tot = "SELECT count(Rk_TypeID) as total
|
||||
FROM rk_type
|
||||
WHERE Rk_TypeIsActive = 'Y'
|
||||
AND (Rk_TypeCode LIKE ? OR Rk_TypeName LIKE ?)";
|
||||
|
||||
$query_tot = $this->db->query($sql_tot, [$search, $search]);
|
||||
$total_list = 0;
|
||||
if ($query_tot) {
|
||||
$total_list = $query_tot->result_array()[0]['total'];
|
||||
} else {
|
||||
$this->sys_error_db("type count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$rows[$k]['rownumber'] = $k + 1;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total_list,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteType()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$typeid = $prm['typeid'];
|
||||
|
||||
$sql = "UPDATE rk_type SET
|
||||
Rk_TypeIsActive = 'N',
|
||||
Rk_TypeM_UserID = ?,
|
||||
Rk_TypeLastUpdated = now()
|
||||
WHERE Rk_TypeID = ?";
|
||||
|
||||
$query = $this->db->query(
|
||||
$sql,
|
||||
array($userid, $typeid)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("update type");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"data" => array('status' => 'OK')
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addType()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$typecode = $prm["typecode"];
|
||||
$typename = $prm["typename"];
|
||||
|
||||
$sql = "INSERT INTO `rk_type` (
|
||||
Rk_TypeCode,
|
||||
Rk_TypeName,
|
||||
Rk_TypeIsActive,
|
||||
Rk_TypeM_UserID,
|
||||
Rk_TypeCreated
|
||||
) VALUES (?,?,'Y',?,NOW())";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$typecode,
|
||||
$typename,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("type insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function editType()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$typecode = $prm["typecode"];
|
||||
$typename = $prm["typename"];
|
||||
$typeid = $prm["typeid"];
|
||||
|
||||
$sql = "UPDATE rk_type SET
|
||||
Rk_TypeCode = ?,
|
||||
Rk_TypeName = ?,
|
||||
Rk_TypeM_UserID = ?,
|
||||
Rk_TypeLastUpdated = NOW()
|
||||
WHERE Rk_TypeID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$typecode,
|
||||
$typename,
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("type error edit", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("typeID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,537 @@
|
||||
<?php
|
||||
class Presentasecabang extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "Presentase Cabang";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listpresentasecabang()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$limit = 10;
|
||||
$pages = 0;
|
||||
|
||||
if ($prm['currpages'] > 0) {
|
||||
$pages = ($prm['currpages'] - 1) * $limit;
|
||||
}
|
||||
|
||||
$total = "SELECT COUNT(*) as total FROM branch_percent WHERE BranchPercentIsActive = 'Y'";
|
||||
$qtotal = $this->db->query($total);
|
||||
$rtotal = $qtotal->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
BranchPercentID,
|
||||
BranchPercentType,
|
||||
BranchPercentIsActive
|
||||
from branch_percent
|
||||
where BranchPercentIsActive = 'Y'
|
||||
limit ? offset ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$limit, $pages]);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing presentase cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => (int)$rtotal,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function inserttypepresentase()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "INSERT INTO `branch_percent` (
|
||||
BranchPercentType,
|
||||
BranchPercentCreated,
|
||||
BranchPercentCreatedUserID
|
||||
) VALUES (?, NOW(), ?)";
|
||||
|
||||
$query = $this->db->query($sql, [$typename, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("type presentase error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edittypepresentase()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_percent SET
|
||||
BranchPercentType = ?,
|
||||
BranchPercentLastUpdated = now(),
|
||||
BranchPercentLastUpdatedUserID = ?
|
||||
WHERE BranchPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$typename,
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update type presentase cabang", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletetypepresentase()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_percent SET
|
||||
BranchPercentIsActive = 'N',
|
||||
BranchPercentDeleted = now(),
|
||||
BranchPercentDeletedUserID = ?
|
||||
WHERE BranchPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete type presentase", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function detailpresentasecabang()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$branchPercentID = $prm['presentasecabangid'];
|
||||
$currPages = $prm['currpages'];
|
||||
|
||||
$total = "SELECT
|
||||
COUNT(DISTINCT S_RegionalID) as total
|
||||
FROM branch_percent_detail
|
||||
JOIN m_branch ON BranchPercentDetailM_BranchID = M_BranchID
|
||||
JOIN s_regional ON BranchPercentDetailS_RegionalID = S_RegionalID
|
||||
WHERE BranchPercentDetailBranchPercentID = ? AND BranchPercentDetailIsActive = 'Y'
|
||||
";
|
||||
|
||||
$que_to = $this->db->query($total, array($branchPercentID));
|
||||
if (!$que_to) {
|
||||
$this->sys_error_db("error get total data detail");
|
||||
exit;
|
||||
}
|
||||
$row_to = $que_to->result_array()[0]["total"];
|
||||
|
||||
$pages = 0;
|
||||
$limit = 10;
|
||||
|
||||
if ($currPages > 0) {
|
||||
$pages = ($currPages - 1) * $limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
GROUP_CONCAT(CONCAT(M_BranchName, ' (', BranchPercentDetailValue, '%)') ORDER BY M_BranchName SEPARATOR ', ') as DetailCabang,
|
||||
GROUP_CONCAT(BranchPercentDetailID SEPARATOR ',') AS ListBranchPercentDetailID
|
||||
from branch_percent_detail
|
||||
join m_branch on BranchPercentDetailM_BranchID = M_BranchID
|
||||
join s_regional on BranchPercentDetailS_RegionalID = S_RegionalID
|
||||
where BranchPercentDetailBranchPercentID = ? and BranchPercentDetailIsActive = 'Y'
|
||||
group by S_RegionalID
|
||||
LIMIT ? OFFSET ?;
|
||||
";
|
||||
$query = $this->db->query($sql, array($branchPercentID, $limit, $pages));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("get listing detail presentase cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => $row_to,
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlistregional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function getregionalbranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$user_company = $this->sys_user["M_BranchCompanyID"];
|
||||
|
||||
// $sql = "SELECT
|
||||
// M_BranchID,
|
||||
// M_BranchCode,
|
||||
// M_BranchName,
|
||||
// 0 as branchValue,
|
||||
// '' as accountNumber,
|
||||
// '' as searchCoa
|
||||
// from m_branch
|
||||
// where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?";
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
0 as branchValue,
|
||||
'' as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch_company
|
||||
join m_branch_companydetail on M_BranchCompanyDetailM_BranchCompanyID = M_BranchCompanyID
|
||||
and M_BranchCompanyDetailIsActive = 'Y'
|
||||
join m_branch on M_BranchCode = M_BranchCompanyDetailM_BranchCode and M_BranchIsActive = 'Y'
|
||||
where M_BranchCompanyIsActive = 'Y' and M_BranchS_RegionalID = ? and M_BranchCompanyID = ?
|
||||
";
|
||||
|
||||
$query = $this->db->query($sql, array($regionalid, $user_company));
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional branches");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function insertdetailprecab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$bpid = $item['branchpercentid'];
|
||||
$rgid = $item['regionalid'];
|
||||
$brid = $item['branchid'];
|
||||
$valu = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "INSERT INTO `branch_percent_detail` (
|
||||
BranchPercentDetailBranchPercentID,
|
||||
BranchPercentDetailS_RegionalID,
|
||||
BranchPercentDetailM_BranchID,
|
||||
BranchPercentDetailValue,
|
||||
BranchPercentDetailAccountNumber,
|
||||
BranchPercentDetailCreated,
|
||||
BranchPercentDetailCreatedUserID
|
||||
) VALUES (?, ?, ?, ?, ?, NOW(), ?)";
|
||||
$query = $this->db->query($sql, [$bpid, $rgid, $brid, $valu, $noacc, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function editdetailprecab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$detid = $item['precabdetailid'];
|
||||
$value = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "UPDATE branch_percent_detail SET
|
||||
BranchPercentDetailValue = ?,
|
||||
BranchPercentDetailAccountNumber = ?,
|
||||
BranchPercentDetailLastUpdated = now(),
|
||||
BranchPercentDetailLastUpdatedUserID = ?
|
||||
WHERE BranchPercentDetailID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [$value, $noacc, $userid, $detid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function getvaluedetailprecab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchpercentid = $prm['branchpercentid'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
BranchPercentDetailID,
|
||||
CAST(COALESCE(BranchPercentDetailValue, 0) AS DECIMAL(10, 2)) as branchValue,
|
||||
COALESCE(BranchPercentDetailAccountNumber, 0) as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch
|
||||
join branch_percent_detail on BranchPercentDetailM_BranchID = M_BranchID
|
||||
join branch_percent on BranchPercentID = BranchPercentDetailBranchPercentID
|
||||
where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?
|
||||
and BranchPercentID = ?";
|
||||
$query = $this->db->query($sql, [$regionalid, $branchpercentid]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get current value detail precab");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function deletedetailprecab()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = "(" . $prm["precabdetailid"] . ")";
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_percent_detail SET
|
||||
BranchPercentDetailIsActive = 'N',
|
||||
BranchPercentDetailDeleted = now(),
|
||||
BranchPercentDetailDeletedUserID = ?
|
||||
WHERE BranchPercentDetailID IN " . $input;
|
||||
$query = $this->db->query($sql, [$userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error delete precab detail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $input
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function searchcoa()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$keyword = "%" . $prm['keyword'] . "%";
|
||||
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y' AND coaIsInput = 'Y'
|
||||
AND (CONCAT(coaAccountNo, ' - ' ,coaDescription) LIKE ?)
|
||||
LIMIT 20";
|
||||
$query = $this->db->query($sql, [$keyword]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Error get listing coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,537 @@
|
||||
<?php
|
||||
class Presentasecost extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "Presentase Biaya Cabang";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listpresentasecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$limit = 10;
|
||||
$pages = 0;
|
||||
|
||||
if ($prm['currpages'] > 0) {
|
||||
$pages = ($prm['currpages'] - 1) * $limit;
|
||||
}
|
||||
|
||||
$total = "SELECT COUNT(*) as total FROM branch_cost_percent WHERE BranchCostPercentIsActive = 'Y'";
|
||||
$qtotal = $this->db->query($total);
|
||||
$rtotal = $qtotal->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
BranchCostPercentID,
|
||||
BranchCostPercentType,
|
||||
BranchCostPercentIsActive
|
||||
from branch_cost_percent
|
||||
where BranchCostPercentIsActive = 'Y'
|
||||
limit ? offset ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$limit, $pages]);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing presentase biaya cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => (int)$rtotal,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function inserttypepresentasecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "INSERT INTO `branch_cost_percent` (
|
||||
BranchCostPercentType,
|
||||
BranchCostPercentCreated,
|
||||
BranchCostPercentCreatedUserID
|
||||
) VALUES (?, NOW(), ?)";
|
||||
|
||||
$query = $this->db->query($sql, [$typename, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("type presentase error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edittypepresentasecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_cost_percent SET
|
||||
BranchCostPercentType = ?,
|
||||
BranchCostPercentLastUpdated = now(),
|
||||
BranchCostPercentLastUpdatedUserID = ?
|
||||
WHERE BranchCostPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$typename,
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update type presentase cabang", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchCostPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletetypepresentasecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_cost_percent SET
|
||||
BranchCostPercentIsActive = 'N',
|
||||
BranchCostPercentDeleted = now(),
|
||||
BranchCostPercentDeletedUserID = ?
|
||||
WHERE BranchCostPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete type presentase", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchCostPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function detailpresentasecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$branchCostPercentID = $prm['presentasecostid'];
|
||||
$currPages = $prm['currpages'];
|
||||
|
||||
$total = "SELECT
|
||||
COUNT(DISTINCT S_RegionalID) as total
|
||||
FROM branch_cost_percent_detail
|
||||
JOIN m_branch ON BranchCostPercentDetailM_BranchID = M_BranchID
|
||||
JOIN s_regional ON BranchCostPercentDetailS_RegionalID = S_RegionalID
|
||||
WHERE BranchCostPercentDetailBranchCostPercentID = ? AND BranchCostPercentDetailIsActive = 'Y'
|
||||
";
|
||||
|
||||
$que_to = $this->db->query($total, array($branchCostPercentID));
|
||||
if (!$que_to) {
|
||||
$this->sys_error_db("error get total data detail");
|
||||
exit;
|
||||
}
|
||||
$row_to = $que_to->result_array()[0]["total"];
|
||||
|
||||
$pages = 0;
|
||||
$limit = 10;
|
||||
|
||||
if ($currPages > 0) {
|
||||
$pages = ($currPages - 1) * $limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
GROUP_CONCAT(CONCAT(M_BranchName, ' (', BranchCostPercentDetailValue, '%)') ORDER BY M_BranchName SEPARATOR ', ') as DetailCabang,
|
||||
GROUP_CONCAT(BranchCostPercentDetailID SEPARATOR ',') AS ListBranchPercentDetailID
|
||||
from branch_cost_percent_detail
|
||||
join m_branch on BranchCostPercentDetailM_BranchID = M_BranchID
|
||||
join s_regional on BranchCostPercentDetailS_RegionalID = S_RegionalID
|
||||
where BranchCostPercentDetailBranchCostPercentID = ? and BranchCostPercentDetailIsActive = 'Y'
|
||||
group by S_RegionalID
|
||||
LIMIT ? OFFSET ?;
|
||||
";
|
||||
$query = $this->db->query($sql, array($branchCostPercentID, $limit, $pages));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("get listing detail presentase cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => $row_to,
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlistregional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function getregionalbranch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$user_company = $this->sys_user["M_BranchCompanyID"];
|
||||
|
||||
// $sql = "SELECT
|
||||
// M_BranchID,
|
||||
// M_BranchCode,
|
||||
// M_BranchName,
|
||||
// 0 as branchValue,
|
||||
// '' as accountNumber,
|
||||
// '' as searchCoa
|
||||
// from m_branch
|
||||
// where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?";
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
0 as branchValue,
|
||||
'' as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch_company
|
||||
join m_branch_companydetail on M_BranchCompanyDetailM_BranchCompanyID = M_BranchCompanyID
|
||||
and M_BranchCompanyDetailIsActive = 'Y'
|
||||
join m_branch on M_BranchCode = M_BranchCompanyDetailM_BranchCode and M_BranchIsActive = 'Y'
|
||||
where M_BranchCompanyIsActive = 'Y' and M_BranchS_RegionalID = ? and M_BranchCompanyID = ?
|
||||
";
|
||||
|
||||
$query = $this->db->query($sql, array($regionalid, $user_company));
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional branches");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function insertdetailprecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$bpid = $item['branchcostpercentid'];
|
||||
$rgid = $item['regionalid'];
|
||||
$brid = $item['branchid'];
|
||||
$valu = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "INSERT INTO `branch_cost_percent_detail` (
|
||||
BranchCostPercentDetailBranchCostPercentID,
|
||||
BranchCostPercentDetailS_RegionalID,
|
||||
BranchCostPercentDetailM_BranchID,
|
||||
BranchCostPercentDetailValue,
|
||||
BranchCostPercentDetailAccountNumber,
|
||||
BranchCostPercentDetailCreated,
|
||||
BranchCostPercentDetailCreatedUserID
|
||||
) VALUES (?, ?, ?, ?, ?, NOW(), ?)";
|
||||
$query = $this->db->query($sql, [$bpid, $rgid, $brid, $valu, $noacc, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function editdetailprecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$detid = $item['precabdetailid'];
|
||||
$value = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "UPDATE branch_cost_percent_detail SET
|
||||
BranchCostPercentDetailValue = ?,
|
||||
BranchCostPercentDetailAccountNumber = ?,
|
||||
BranchCostPercentDetailLastUpdated = now(),
|
||||
BranchCostPercentDetailLastUpdatedUserID = ?
|
||||
WHERE BranchCostPercentDetailID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [$value, $noacc, $userid, $detid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function getvaluedetailprecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchcostpercentid = $prm['branchcostpercentid'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
BranchCostPercentDetailID,
|
||||
CAST(COALESCE(BranchCostPercentDetailValue, 0) AS DECIMAL(10, 2)) as branchValue,
|
||||
COALESCE(BranchCostPercentDetailAccountNumber, 0) as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch
|
||||
join branch_cost_percent_detail on BranchCostPercentDetailM_BranchID = M_BranchID
|
||||
join branch_cost_percent on BranchCostPercentID = BranchCostPercentDetailBranchCostPercentID
|
||||
where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?
|
||||
and BranchCostPercentID = ?";
|
||||
$query = $this->db->query($sql, [$regionalid, $branchcostpercentid]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get current value detail precab");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function deletedetailprecost()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = "(" . $prm["precabdetailid"] . ")";
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_cost_percent_detail SET
|
||||
BranchCostPercentDetailIsActive = 'N',
|
||||
BranchCostPercentDetailDeleted = now(),
|
||||
BranchCostPercentDetailDeletedUserID = ?
|
||||
WHERE BranchCostPercentDetailID IN " . $input;
|
||||
$query = $this->db->query($sql, [$userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error delete precab detail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $input
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function searchcoa()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$keyword = "%" . $prm['keyword'] . "%";
|
||||
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y' AND coaIsInput = 'Y'
|
||||
AND (CONCAT(coaAccountNo, ' - ' ,coaDescription) LIKE ?)
|
||||
LIMIT 20";
|
||||
$query = $this->db->query($sql, [$keyword]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Error get listing coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,529 @@
|
||||
<?php
|
||||
class Presentasefacabang extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "Presentase Cabang";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function listpresentasecabang() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$limit = 10;
|
||||
$pages = 0;
|
||||
|
||||
if ($prm['currpages'] > 0) {
|
||||
$pages = ($prm['currpages'] - 1) * $limit;
|
||||
}
|
||||
|
||||
$total = "SELECT COUNT(*) as total FROM branch_fa_percent WHERE BranchFaPercentIsActive = 'Y'";
|
||||
$qtotal = $this->db->query($total);
|
||||
$rtotal = $qtotal->result_array()[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
BranchFaPercentID,
|
||||
BranchFaPercentType,
|
||||
BranchFaPercentIsActive
|
||||
from branch_fa_percent
|
||||
where BranchFaPercentIsActive = 'Y'
|
||||
limit ? offset ?
|
||||
";
|
||||
$query = $this->db->query($sql, [$limit, $pages]);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing presentase cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => (int)$rtotal,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function inserttypepresentase() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "INSERT INTO `branch_fa_percent` (
|
||||
BranchFaPercentType,
|
||||
BranchFaPercentCreated,
|
||||
BranchFaPercentCreatedUserID
|
||||
) VALUES (?, NOW(), ?)";
|
||||
|
||||
$query = $this->db->query($sql, [$typename, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("type presentase error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edittypepresentase() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$typename = $prm['typename'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_fa_percent SET
|
||||
BranchFaPercentType = ?,
|
||||
BranchFaPercentLastUpdated = now(),
|
||||
BranchFaPercentLastUpdatedUserID = ?
|
||||
WHERE BranchFaPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$typename,
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update type presentase cabang", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchFaPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletetypepresentase() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$typeid = $prm['typeid'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_fa_percent SET
|
||||
BranchFaPercentIsActive = 'N',
|
||||
BranchFaPercentDeleted = now(),
|
||||
BranchFaPercentDeletedUserID = ?
|
||||
WHERE BranchFaPercentID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [
|
||||
$userid,
|
||||
$typeid
|
||||
]);
|
||||
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete type presentase", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("BranchFaPercentID" => $typeid));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function detailpresentasecabang() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$branchPercentID = $prm['presentasecabangid'];
|
||||
$currPages = $prm['currpages'];
|
||||
|
||||
$total = "SELECT
|
||||
COUNT(DISTINCT S_RegionalID) as total
|
||||
FROM branch_fa_percent_detail
|
||||
JOIN m_branch ON BranchFaPercentDetailM_BranchID = M_BranchID
|
||||
JOIN s_regional ON BranchFaPercentDetailS_RegionalID = S_RegionalID
|
||||
WHERE BranchFaPercentDetailBranchFaPercentID = ? AND BranchFaPercentDetailIsActive = 'Y'
|
||||
";
|
||||
|
||||
$que_to = $this->db->query($total, array($branchPercentID));
|
||||
if (!$que_to) {
|
||||
$this->sys_error_db("error get total data detail");
|
||||
exit;
|
||||
}
|
||||
$row_to = $que_to->result_array()[0]["total"];
|
||||
|
||||
$pages = 0;
|
||||
$limit = 10;
|
||||
|
||||
if ($currPages > 0) {
|
||||
$pages = ($currPages - 1) * $limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
GROUP_CONCAT(CONCAT(M_BranchName, ' (', BranchFaPercentDetailValue, '%)') ORDER BY M_BranchName SEPARATOR ', ') as DetailCabang,
|
||||
GROUP_CONCAT(BranchFaPercentDetailID SEPARATOR ',') AS ListBranchFaPercentDetailID
|
||||
from branch_fa_percent_detail
|
||||
join m_branch on BranchFaPercentDetailM_BranchID = M_BranchID
|
||||
join s_regional on BranchFaPercentDetailS_RegionalID = S_RegionalID
|
||||
where BranchFaPercentDetailBranchFaPercentID = ? and BranchFaPercentDetailIsActive = 'Y'
|
||||
group by S_RegionalID
|
||||
LIMIT ? OFFSET ?;
|
||||
";
|
||||
$query = $this->db->query($sql, array($branchPercentID, $limit, $pages));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("get listing detail presentase cabang");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => $row_to,
|
||||
"records" => $rows
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlistregional() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
S_RegionalID,
|
||||
S_RegionalName
|
||||
FROM s_regional
|
||||
WHERE S_RegionalIsActive = 'Y'";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function getregionalbranch() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$user_company = $this->sys_user["M_BranchCompanyID"];
|
||||
|
||||
// $sql = "SELECT
|
||||
// M_BranchID,
|
||||
// M_BranchCode,
|
||||
// M_BranchName,
|
||||
// 0 as branchValue,
|
||||
// '' as accountNumber,
|
||||
// '' as searchCoa
|
||||
// from m_branch
|
||||
// where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?";
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
0 as branchValue,
|
||||
'' as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch_company
|
||||
join m_branch_companydetail on M_BranchCompanyDetailM_BranchCompanyID = M_BranchCompanyID
|
||||
and M_BranchCompanyDetailIsActive = 'Y'
|
||||
join m_branch on M_BranchCode = M_BranchCompanyDetailM_BranchCode and M_BranchIsActive = 'Y'
|
||||
where M_BranchCompanyIsActive = 'Y' and M_BranchS_RegionalID = ? and M_BranchCompanyID = ?
|
||||
";
|
||||
|
||||
$query = $this->db->query($sql, array($regionalid, $user_company));
|
||||
if (! $query) {
|
||||
$this->sys_error_db("get listing regional branches");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$mssg = $exc->getMessage();
|
||||
$this->sys_error($mssg);
|
||||
}
|
||||
}
|
||||
|
||||
function insertdetailprecab() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$bpid = $item['branchpercentid'];
|
||||
$rgid = $item['regionalid'];
|
||||
$brid = $item['branchid'];
|
||||
$valu = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "INSERT INTO `branch_fa_percent_detail` (
|
||||
BranchFaPercentDetailBranchFaPercentID,
|
||||
BranchFaPercentDetailS_RegionalID,
|
||||
BranchFaPercentDetailM_BranchID,
|
||||
BranchFaPercentDetailValue,
|
||||
BranchFaPercentDetailAccountNumber,
|
||||
BranchFaPercentDetailCreated,
|
||||
BranchFaPercentDetailCreatedUserID
|
||||
) VALUES (?, ?, ?, ?, ?, NOW(), ?)";
|
||||
$query = $this->db->query($sql, [$bpid, $rgid, $brid, $valu, $noacc, $userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function editdetailprecab() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = $prm["branchvalue"];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($input as $item) {
|
||||
$detid = $item['precabdetailid'];
|
||||
$value = $item['value'];
|
||||
$noacc = $item['noacc'];
|
||||
|
||||
$sql = "UPDATE branch_fa_percent_detail SET
|
||||
BranchFaPercentDetailValue = ?,
|
||||
BranchFaPercentDetailAccountNumber = ?,
|
||||
BranchFaPercentDetailLastUpdated = now(),
|
||||
BranchFaPercentDetailLastUpdatedUserID = ?
|
||||
WHERE BranchFaPercentDetailID = ?";
|
||||
|
||||
$query = $this->db->query($sql, [$value, $noacc, $userid, $detid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update precab detail");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => sizeof($input),
|
||||
"records" => 0
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function getvaluedetailprecab() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchpercentid = $prm['branchpercentid'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
BranchFaPercentDetailID,
|
||||
CAST(COALESCE(BranchFaPercentDetailValue, 0) AS DECIMAL(10, 2)) as branchValue,
|
||||
COALESCE(BranchFaPercentDetailAccountNumber, 0) as accountNumber,
|
||||
'' as searchCoa
|
||||
from m_branch
|
||||
join branch_fa_percent_detail on BranchFaPercentDetailM_BranchID = M_BranchID
|
||||
join branch_fa_percent on BranchFaPercentID = BranchFaPercentDetailBranchFaPercentID
|
||||
where M_BranchIsActive = 'Y' and M_BranchS_RegionalID = ?
|
||||
and BranchFaPercentID = ?";
|
||||
$query = $this->db->query($sql, [$regionalid, $branchpercentid]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get current value detail precab");
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function deletedetailprecab() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$input = "(" . $prm["precabdetailid"] . ")";
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE branch_fa_percent_detail SET
|
||||
BranchFaPercentDetailIsActive = 'N',
|
||||
BranchFaPercentDetailDeleted = now(),
|
||||
BranchFaPercentDetailDeletedUserID = ?
|
||||
WHERE BranchFaPercentDetailID IN " . $input;
|
||||
$query = $this->db->query($sql, [$userid]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error delete precab detail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $input
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function searchcoa() {
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$keyword = "%" . $prm['keyword'] . "%";
|
||||
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' - ' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y' AND coaIsInput = 'Y'
|
||||
AND (CONCAT(coaAccountNo, ' - ' ,coaDescription) LIKE ?)
|
||||
LIMIT 20";
|
||||
$query = $this->db->query($sql, [$keyword]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("Error get listing coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$msg = $ex->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
POST https://{{host}}/mockup/masterdata/accounting/presetjurnal/getPeriode
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0"
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/masterdata/accounting/presetjurnal/searchDetail
|
||||
Content-Type: "application/json"
|
||||
|
||||
{
|
||||
"page": 3,
|
||||
"jurnal": {"id":3},
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0"
|
||||
}
|
||||
@@ -0,0 +1,866 @@
|
||||
<?php
|
||||
|
||||
class Presetjurnal extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "COA API";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function getPeriode()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeName as name,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d-%m-%Y'), ' - ',DATE_FORMAT(periodeEndDate, '%d-%m-%Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
// $data = array(
|
||||
// array("id" => "1", "name" => "Periode Januari", "periode" => '01-01-2024 - 31-01-2024'),
|
||||
// array("id" => "2", "name" => "Periode Februari", "periode" => '01-02-2024 - 31-02-2024'),
|
||||
// array("id" => "3", "name" => "Periode Maret", "periode" => '01-03-2024 - 31-03-2024'),
|
||||
// );
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function getBranch()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
M_BranchID branchID,
|
||||
M_BranchCode branchCode,
|
||||
M_BranchName branchName
|
||||
FROM m_branch WHERE M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("get branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function addJurnal()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "SELECT fn_numbering('PJ') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("get numbering", $this->db);
|
||||
exit;
|
||||
}
|
||||
$numbering = $qry->result_array()[0]['number'];
|
||||
$sql = "INSERT INTO t_presetjurnal(
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalType,
|
||||
jurnalCreated,
|
||||
jurnalM_UserID)
|
||||
VALUES (?,?,?,?,?,NOW(),?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$prm['branch'],
|
||||
$prm['periode'],
|
||||
$numbering,
|
||||
$prm['name'],
|
||||
$prm['type'],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error insert preset jurnal header", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok($numbering);
|
||||
}
|
||||
function editJurnal()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE t_presetjurnal SET
|
||||
jurnalM_BranchCode = ?,
|
||||
jurnalperiodeID = ?,
|
||||
jurnalTitle = ?,
|
||||
jurnalType = ?,
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [
|
||||
$prm['branch'],
|
||||
$prm['periode'],
|
||||
$prm['name'],
|
||||
$prm['type'],
|
||||
$userid,
|
||||
$prm['id'],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update preset jurnal header", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function deleteJurnal()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE t_presetjurnal SET
|
||||
jurnalIsActive = 'N',
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userid,
|
||||
$prm['id'],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delete jurnal header", $this->db);
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE t_presetjurnaldetail SET
|
||||
jurnalTxIsActive = 'N',
|
||||
jurnalTxLastUpdated = NOW(),
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxJurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userid,
|
||||
$prm['id'],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delete jurnal header", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function searchHeader()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$page = $prm["page"];
|
||||
$periode = $prm["periode"];
|
||||
$ROW_PER_PAGE = 5;
|
||||
$start_offset = 0;
|
||||
// print_r($prm);
|
||||
|
||||
if (isset($prm["page"])) {
|
||||
if (
|
||||
is_numeric($prm["page"]) && $prm["page"] > 0
|
||||
) {
|
||||
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
COUNT(jurnalID) as total
|
||||
FROM t_presetjurnal
|
||||
JOIN periode
|
||||
ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON jurnalM_BranchCode = M_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE (jurnalNo LIKE ? OR jurnalTitle LIKE ?)
|
||||
AND jurnalperiodeID = ?
|
||||
AND jurnalIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [
|
||||
$search,
|
||||
$search,
|
||||
$periode
|
||||
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get total", $this->db);
|
||||
exit;
|
||||
}
|
||||
$total = $qry->result_array()[0]['total'];
|
||||
$sql = "SELECT
|
||||
jurnalID id,
|
||||
jurnalM_BranchCode as branch,
|
||||
jurnalperiodeID periode,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d/%m/%Y'), ' - ',DATE_FORMAT(periodeEndDate, '%d/%m/%Y')) as periodeDate,
|
||||
M_BranchName branchName,
|
||||
jurnalNo number,
|
||||
jurnalTitle name,
|
||||
jurnalType as type,
|
||||
CASE
|
||||
WHEN jurnalStatus = 0 THEN 'NEW'
|
||||
WHEN jurnalStatus <> 0 THEN 'POST'
|
||||
END as status
|
||||
FROM t_presetjurnal
|
||||
JOIN periode
|
||||
ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON jurnalM_BranchCode = M_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE (jurnalNo LIKE ? OR jurnalTitle LIKE ?)
|
||||
AND jurnalperiodeID = ?
|
||||
AND jurnalIsActive = 'Y'
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$search,
|
||||
$search,
|
||||
$periode,
|
||||
$ROW_PER_PAGE,
|
||||
$start_offset
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get total", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = array(
|
||||
"total" => ceil($total / $ROW_PER_PAGE),
|
||||
"records" => $qry->result_array()
|
||||
);
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function cek()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT COUNT(*) as total FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array()[0]['total'];
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function save()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$jurnal = $prm['jurnal'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "SELECT COUNT(*) as total FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$total = $qry->result_array()[0]['total'];
|
||||
if (intval($total) > 0) {
|
||||
$sql = "DELETE FROM t_presetjurnaldetail WHERE jurnalTxJurnalID = ?";
|
||||
$qry = $this->db->query($sql, [$jurnal['id']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$cekData = $data[$i];
|
||||
if (!array_key_exists('Number', $cekData)) {
|
||||
$this->sys_error("Kolom Number tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Keterangan', $cekData)) {
|
||||
$this->sys_error("Kolom Keterangan tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Debit', $cekData)) {
|
||||
$this->sys_error("Kolom Debit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Kredit', $cekData)) {
|
||||
$this->sys_error("Kolom Kredit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (floatval($cekData['Debit']) > 0 && floatval($cekData['Kredit']) > 0) {
|
||||
$this->sys_error("Jumlah debit dan credit keduanya lebih besar dari 0");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT coaID FROM coa
|
||||
WHERE coaAccountNo = ?
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$cekData['Number']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("cek coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->result_array();
|
||||
if (count($cek) == 0) {
|
||||
$this->sys_error_db("{$cekData['Number']} tidak ada di coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$data[$i]['coaID'] = $cek[0]['coaID'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$dataCoa = $data[$i];
|
||||
$debit = $dataCoa['Debit'];
|
||||
$credit = $dataCoa['Kredit'];
|
||||
$type = 'DB';
|
||||
if (floatval($dataCoa['Kredit']) > 0) {
|
||||
$type = 'CR';
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO t_presetjurnaldetail(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID)
|
||||
VALUES(?,?,?,?,?,NOW(),?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$jurnal['id'],
|
||||
$dataCoa['coaID'],
|
||||
$dataCoa['Keterangan'],
|
||||
$debit,
|
||||
$credit,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error insert beginning balance", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok("OK");
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
function addData()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$jurnal = $prm['jurnal'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "SELECT COUNT(*) as total FROM t_beginningbalance";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$total = $qry->result_array()[0]['total'];
|
||||
// if (intval($total) > 0) {
|
||||
// $sql = "DELETE FROM t_presetjurnaldetail";
|
||||
// $qry = $this->db->query($sql, []);
|
||||
// if (!$qry) {
|
||||
// $this->sys_error_db("Error truncate", $this->db);
|
||||
// $this->db->trans_rollback();
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$cekData = $data[$i];
|
||||
if (!array_key_exists('Number', $cekData)) {
|
||||
$this->sys_error("Pilih coa terlebih dahulu");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Keterangan', $cekData)) {
|
||||
$this->sys_error("Kolom Keterangan tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (trim($cekData['Keterangan']) == '') {
|
||||
$this->sys_error("Keterangan tidak boleh kosong");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Debit', $cekData)) {
|
||||
$this->sys_error("Kolom Debit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists('Kredit', $cekData)) {
|
||||
$this->sys_error("Kolom Kredit tidak ditemukan");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
if (floatval($cekData['Debit']) > 0 && floatval($cekData['Kredit']) > 0) {
|
||||
$this->sys_error("Jumlah debit dan credit keduanya lebih besar dari 0");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT coaID FROM coa
|
||||
WHERE coaAccountNo = ?
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$cekData['Number']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("cek coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->result_array();
|
||||
if (count($cek) == 0) {
|
||||
$this->sys_error_db("{$cekData['Number']} tidak ada di coa", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$data[$i]['coaID'] = $cek[0]['coaID'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$dataCoa = $data[$i];
|
||||
$debit = $dataCoa['Debit'];
|
||||
$credit = $dataCoa['Kredit'];
|
||||
$type = 'DB';
|
||||
if (floatval($dataCoa['Kredit']) > 0) {
|
||||
$type = 'CR';
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO t_presetjurnaldetail(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID)
|
||||
VALUES(?,?,?,?,?,NOW(),?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$jurnal['id'],
|
||||
$dataCoa['coaID'],
|
||||
$dataCoa['Keterangan'],
|
||||
$debit,
|
||||
$credit,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error insert beginning balance", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok("OK");
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$page = $prm["page"];
|
||||
$jurnal = $prm["jurnal"];
|
||||
$ROW_PER_PAGE = 20;
|
||||
$start_offset = 0;
|
||||
// print_r($prm);
|
||||
|
||||
if (isset($prm["page"])) {
|
||||
if (
|
||||
is_numeric($prm["page"]) && $prm["page"] > 0
|
||||
) {
|
||||
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
count(jurnalTxID) as total
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
WHERE (coaAccountNo LIKE ? OR junalTxDescription LIKE ?)
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$search,
|
||||
$search,
|
||||
$jurnal['id']
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get total", $this->db);
|
||||
exit;
|
||||
}
|
||||
$total = $qry->result_array()[0]['total'];
|
||||
$sql = "SELECT
|
||||
jurnalTxID id,
|
||||
coaAccountNo number,
|
||||
jurnalTxCoaID coaid,
|
||||
CONCAT(coaAccountNo, ' ' ,coaDescription) as searchCoa,
|
||||
coaDescription,
|
||||
junalTxDescription keterangan,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
CASE
|
||||
WHEN jurnalTxDebit <> 0 AND jurnalTxCredit = 0 THEN jurnalTxDebit
|
||||
WHEN jurnalTxCredit <> 0 AND jurnalTxDebit = 0 THEN jurnalTxCredit
|
||||
WHEN jurnalTxCredit = 0 AND jurnalTxDebit = 0 THEN jurnalTxDebit
|
||||
ELSE jurnalTxDebit
|
||||
END as value,
|
||||
CASE
|
||||
WHEN jurnalTxDebit <> 0 AND jurnalTxCredit = 0 THEN 'DB'
|
||||
WHEN jurnalTxCredit <> 0 AND jurnalTxDebit = 0 THEN 'CR'
|
||||
WHEN jurnalTxCredit = 0 AND jurnalTxDebit = 0 THEN 'DB'
|
||||
ELSE 'ERROR'
|
||||
END as type
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
WHERE (coaAccountNo LIKE ? OR junalTxDescription LIKE ?)
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $search, $jurnal['id'], $ROW_PER_PAGE, $start_offset]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("search detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$totalDebit = 0;
|
||||
$totalCredit = 0;
|
||||
$totalBalance = 0;
|
||||
$status = 'N';
|
||||
|
||||
$sql = "SELECT
|
||||
IFNULL(SUM(jurnalTxDebit), 0) as debit,
|
||||
IFNULL(SUM(jurnalTxCredit), 0) as credit
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$jurnal['id'],]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error sql count balance", $this->db);
|
||||
exit;
|
||||
}
|
||||
$totalSum = $qry->row_array();
|
||||
$totalDebit = $totalSum['debit'];
|
||||
$totalCredit = $totalSum['credit'];
|
||||
|
||||
// for ($i = 0; $i < count($data); $i++) {
|
||||
// $dataCek = $data[$i];
|
||||
// if ($dataCek['type'] == 'DB') {
|
||||
// $totalDebit = $totalDebit + floatval($dataCek['value']);
|
||||
// }
|
||||
// if ($dataCek['type'] == 'CR') {
|
||||
// $totalCredit = $totalCredit + floatval($dataCek['value']);
|
||||
// }
|
||||
// }
|
||||
$totalBalance = $totalDebit - $totalCredit;
|
||||
$periode = array();
|
||||
|
||||
|
||||
$rst = array(
|
||||
'data' => $data,
|
||||
"total" => ceil($total / $ROW_PER_PAGE),
|
||||
'summary' => array(
|
||||
'debit' => $totalDebit,
|
||||
'credit' => $totalCredit,
|
||||
'balance' => $totalBalance
|
||||
)
|
||||
);
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
function updateData()
|
||||
{
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$data = $prm['data'];
|
||||
$coa = $prm['coa'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$debit = 0;
|
||||
$credit = 0;
|
||||
$type = $data['type'];
|
||||
if ($type == 'DB') {
|
||||
$debit = $data['value'];
|
||||
$credit = 0;
|
||||
}
|
||||
if ($type == 'CR') {
|
||||
$credit = $data['value'];
|
||||
$debit = 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE t_presetjurnaldetail
|
||||
SET
|
||||
jurnalTxCoaID = ?,
|
||||
jurnalTxDebit = ?,
|
||||
jurnalTxCredit = ?,
|
||||
junalTxDescription = ?,
|
||||
jurnalTxM_UserID = ?
|
||||
WHERE jurnalTxID = ?";
|
||||
$qry = $this->db->query($sql, [$coa['coaID'], $debit, $credit, $data['keterangan'], $userid, $data['id']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update preset jurnal", $this->db);
|
||||
exit;
|
||||
}
|
||||
$retval = array(
|
||||
"debit" => $debit,
|
||||
"type" => $type,
|
||||
"credit" => $credit,
|
||||
"last_qry" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($retval);
|
||||
}
|
||||
function postData()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$sql = "SELECT
|
||||
COUNT(jurnalTxCoaID) as total
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error sql count balance", $this->db);
|
||||
exit;
|
||||
}
|
||||
$totalData = $qry->row_array()['total'];
|
||||
if (intval($totalData) == 0) {
|
||||
$this->sys_error_db("Belum memiliki jurnal detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
$sql = "SELECT
|
||||
IFNULL(SUM(jurnalTxDebit), 0) as debit,
|
||||
IFNULL(SUM(jurnalTxCredit), 0) as credit
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error sql count balance", $this->db);
|
||||
exit;
|
||||
}
|
||||
$totalSum = $qry->row_array();
|
||||
$totalDebit = $totalSum['debit'];
|
||||
$totalCredit = $totalSum['credit'];
|
||||
if ((floatval($totalDebit) - floatval($totalCredit)) != 0) {
|
||||
$this->sys_error_db(" GAGAL, Jurnal tidak balance !", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "INSERT INTO jurnal
|
||||
(jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDate,
|
||||
jurnalType,
|
||||
jurnalM_UserID)
|
||||
SELECT
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
fn_numbering('J'),
|
||||
jurnalTitle,
|
||||
NOW(),
|
||||
jurnalType,
|
||||
{$userid}
|
||||
FROM t_presetjurnal
|
||||
WHERE jurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Insert jurnal", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$insertedID = $this->db->insert_id();
|
||||
$sql = "UPDATE t_presetjurnal SET
|
||||
jurnalStatus = ?,
|
||||
jurnalLastUpdated = NOW(),
|
||||
jurnalM_UserID = ?
|
||||
WHERE jurnalID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [
|
||||
$insertedID,
|
||||
$userid,
|
||||
$id
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update preset jurnal header", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID)
|
||||
SELECT
|
||||
{$insertedID},
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
{$userid}
|
||||
FROM t_presetjurnaldetail
|
||||
JOIN coa
|
||||
ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
WHERE jurnalTxIsActive = 'Y'
|
||||
AND jurnalTxJurnalID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$id
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update preset jurnal detail", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function delete()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$sql = "DELETE FROM t_presetjurnaldetail WHERE jurnalTxID = ?";
|
||||
$qry = $this->db->query($sql, [$prm['id']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delete", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('OK');
|
||||
}
|
||||
function searchCoa()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$jurnal = $prm['jurnal'];
|
||||
$sql = "SELECT
|
||||
coaID,
|
||||
jurnalTxID ,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, ' ' ,coaDescription) as display
|
||||
FROM coa
|
||||
LEFT JOIN t_presetjurnaldetail
|
||||
ON coaID = jurnalTxCoaID
|
||||
AND jurnalTxJurnalID = ?
|
||||
WHERE
|
||||
coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'
|
||||
AND (coaAccountNo LIKE ? OR coaDescription LIKE ? OR CONCAT(coaAccountNo, ' ' ,coaDescription) LIKE ? )
|
||||
";
|
||||
// AND jurnalTxID IS NULL
|
||||
$qry = $this->db->query($sql, [$jurnal['id'], $search, $search, $search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
class Recrusivetemplate extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "COA API";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function searchCoa()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$sql = "SELECT
|
||||
coaID as id,
|
||||
coaAccountNo as number,
|
||||
coaDescription as keterangan,
|
||||
CONCAT(coaAccountNo, '-' ,coaDescription) as display
|
||||
FROM coa
|
||||
WHERE
|
||||
coaIsInput = 'Y'
|
||||
AND coaIsActive = 'Y'
|
||||
AND (CONCAT(coaAccountNo, '-' ,coaDescription) LIKE ?)
|
||||
";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error truncate", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
function insertTemplate()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$startDate = $prm['startDate'];
|
||||
$endDate = $prm['endDate'];
|
||||
$tenor = $prm['tenor'];
|
||||
$prePaid = $prm['prePaid'];
|
||||
$kredit = $prm['kredit'];
|
||||
$debet = $prm['debet'];
|
||||
$bulanan = $prm['bulanan'];
|
||||
$sql = "SELECT fn_numbering('RJT') as number
|
||||
";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get number", $this->db);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->row_array()['number'];
|
||||
$sql = "INSERT INTO t_recrusivejurnaltemplate(
|
||||
T_RecrusiveJurnalTemplateNumber,
|
||||
T_RecrusiveJurnalTemplateStartDate,
|
||||
T_RecrusiveJurnalTemplateEndDate,
|
||||
T_RecrusiveJurnalTemplateTenor,
|
||||
T_RecrusiveJurnalTemplatePrePaid,
|
||||
T_RecrusiveJurnalTemplateCreditCoaID,
|
||||
T_RecrusiveJurnalTemplateDebetCoaID,
|
||||
T_RecrusiveJurnalTemplateMonthly,
|
||||
T_RecrusiveJurnalTemplateCreatedUserID,
|
||||
T_RecrusiveJurnalTemplateCreated
|
||||
)
|
||||
VALUES(?,
|
||||
?,?,?,?,?,?,?,?,NOW()
|
||||
)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$number,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$tenor,
|
||||
$prePaid,
|
||||
$kredit,
|
||||
$debet,
|
||||
$bulanan,
|
||||
$userid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error Insert Recrusive Jurnal Template", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok("Success tambah data");
|
||||
}
|
||||
function updateTemplate()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$startDate = $prm['startDate'];
|
||||
$id = $prm['id'];
|
||||
$endDate = $prm['endDate'];
|
||||
$tenor = $prm['tenor'];
|
||||
$prePaid = $prm['prePaid'];
|
||||
$kredit = $prm['kredit'];
|
||||
$debet = $prm['debet'];
|
||||
$bulanan = $prm['bulanan'];
|
||||
|
||||
$sql = "UPDATE t_recrusivejurnaltemplate SET
|
||||
T_RecrusiveJurnalTemplateStartDate = ?,
|
||||
T_RecrusiveJurnalTemplateEndDate = ?,
|
||||
T_RecrusiveJurnalTemplateTenor = ?,
|
||||
T_RecrusiveJurnalTemplatePrePaid = ?,
|
||||
T_RecrusiveJurnalTemplateCreditCoaID = ?,
|
||||
T_RecrusiveJurnalTemplateDebetCoaID = ?,
|
||||
T_RecrusiveJurnalTemplateMonthly = ?,
|
||||
T_RecrusiveJurnalTemplateLastUpdatedUserID = '{$userid}',
|
||||
T_RecrusiveJurnalTemplateLastUpdated = NOW()
|
||||
WHERE T_RecrusiveJurnalTemplateID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$startDate,
|
||||
$endDate,
|
||||
$tenor,
|
||||
$prePaid,
|
||||
$kredit,
|
||||
$debet,
|
||||
$bulanan,
|
||||
$id
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error Update Recrusive Jurnal Template", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok("Success update data");
|
||||
}
|
||||
function deleteTemplate()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$id = $prm['id'];
|
||||
|
||||
$sql = "UPDATE t_recrusivejurnaltemplate SET
|
||||
T_RecrusiveJurnalTemplateIsActive = 'N',
|
||||
T_RecrusiveJurnalTemplateDeletedUserID = '{$userid}',
|
||||
T_RecrusiveJurnalTemplateDeleted = NOW()
|
||||
WHERE T_RecrusiveJurnalTemplateID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$id
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error delete Recrusive Jurnal Template", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok("Success delete data");
|
||||
}
|
||||
function search()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$page = $prm["page"];
|
||||
|
||||
$ROW_PER_PAGE = 5;
|
||||
$start_offset = 0;
|
||||
// print_r($prm);
|
||||
|
||||
if (isset($prm["page"])) {
|
||||
if (
|
||||
is_numeric($prm["page"]) && $prm["page"] > 0
|
||||
) {
|
||||
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT
|
||||
COUNT(T_RecrusiveJurnalTemplateID) as total
|
||||
FROM t_recrusivejurnaltemplate
|
||||
JOIN coa c
|
||||
ON T_RecrusiveJurnalTemplateCreditCoaID = c.coaID
|
||||
JOIN coa d
|
||||
ON T_RecrusiveJurnalTemplateDebetCoaID = d.coaID
|
||||
WHERE T_RecrusiveJurnalTemplateNumber LIKE ?
|
||||
AND T_RecrusiveJurnalTemplateIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, [
|
||||
$search,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error search", $this->db);
|
||||
exit;
|
||||
}
|
||||
$total = $qry->row_array()['total'];
|
||||
$sql = "SELECT
|
||||
T_RecrusiveJurnalTemplateID as id,
|
||||
c.coaID as creditCoaID,
|
||||
CONCAT(c.coaAccountNo, '-' ,c.coaDescription) as creditName,
|
||||
d.coaID as debitCoaID,
|
||||
CONCAT(d.coaAccountNo, '-' ,d.coaDescription) as debitName,
|
||||
T_RecrusiveJurnalTemplateNumber as number,
|
||||
T_RecrusiveJurnalTemplatePrePaid as prePaid,
|
||||
DATE_FORMAT(T_RecrusiveJurnalTemplateStartDate , '%d-%m-%Y') as startDate,
|
||||
T_RecrusiveJurnalTemplateStartDate as startDateVal,
|
||||
DATE_FORMAT(T_RecrusiveJurnalTemplateEndDate, '%d-%m-%Y') as endDate,
|
||||
T_RecrusiveJurnalTemplateEndDate as endDateVal,
|
||||
T_RecrusiveJurnalTemplateTenor as tenor,
|
||||
T_RecrusiveJurnalTemplateMonthly as bulanan
|
||||
FROM t_recrusivejurnaltemplate
|
||||
JOIN coa c
|
||||
ON T_RecrusiveJurnalTemplateCreditCoaID = c.coaID
|
||||
JOIN coa d
|
||||
ON T_RecrusiveJurnalTemplateDebetCoaID = d.coaID
|
||||
WHERE T_RecrusiveJurnalTemplateNumber LIKE ?
|
||||
AND T_RecrusiveJurnalTemplateIsActive = 'Y'
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$search,
|
||||
$ROW_PER_PAGE,
|
||||
$start_offset
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error search", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = array(
|
||||
"total" => ceil($total / $ROW_PER_PAGE),
|
||||
"records" => $qry->result_array()
|
||||
);
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
}
|
||||
333
application/controllers/mockup/masterdata/accounting/Reverse.php
Normal file
333
application/controllers/mockup/masterdata/accounting/Reverse.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
class Reverse extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "REVERSE JURNAL API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPeriode()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
periodeID AS id,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||
periodeName,
|
||||
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
|
||||
FROM periode
|
||||
WHERE periodeIsActive = 'Y'
|
||||
AND periodeIsClosed = 'N'
|
||||
ORDER BY periodeMonth DESC
|
||||
";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select period", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rst = $qry->result_array();
|
||||
$this->sys_ok($rst);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$periodeid = $prm["periodeid"];
|
||||
$journalno = $prm["journalno"];
|
||||
// $prm['current_page'] = isset($prm['current_page']) ? $prm['current_page'] : 1;
|
||||
|
||||
if (intval($periodeid) == 0) {
|
||||
$this->sys_error("Periode belum dipilih, silahkan dipilih dulu.");
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_where = "WHERE jurnalIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
if ($periodeid != "") {
|
||||
if ($sql_where != "") {
|
||||
$sql_where .= " AND ";
|
||||
}
|
||||
$sql_where .= " jurnalperiodeID = ?";
|
||||
$sql_param[] = $periodeid;
|
||||
}
|
||||
if ($journalno != "") {
|
||||
if ($sql_where != "") {
|
||||
$sql_where .= " AND ";
|
||||
}
|
||||
$sql_where .= " jurnalNo LIKE ? ";
|
||||
$sql_param[] = "%$journalno%";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
jurnalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
DATE_FORMAT(jurnalDate, '%d-%m-%Y') as jurnalDate,
|
||||
jurnalType,
|
||||
jurnalTxID,
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
coaID,
|
||||
coaAccountNo,
|
||||
coaDescription,
|
||||
coaSubDescription,
|
||||
coaAccountType,
|
||||
coaIsInput,
|
||||
coaReportSchedule,
|
||||
coaCurrencyCode,
|
||||
coaCashFlowCategory,
|
||||
periodeID,
|
||||
periodeYear,
|
||||
periodeMonth,
|
||||
periodeName,
|
||||
periodeStartDate,
|
||||
periodeEndDate,
|
||||
periodeIsClosed,
|
||||
CASE
|
||||
WHEN jurnalTxDebit <> 0 AND jurnalTxCredit = 0 THEN jurnalTxDebit
|
||||
WHEN jurnalTxCredit <> 0 AND jurnalTxDebit = 0 THEN jurnalTxCredit
|
||||
WHEN jurnalTxCredit = 0 AND jurnalTxDebit = 0 THEN jurnalTxDebit
|
||||
ELSE jurnalTxDebit
|
||||
END as value,
|
||||
CASE
|
||||
WHEN jurnalTxDebit <> 0 AND jurnalTxCredit = 0 THEN 'DB'
|
||||
WHEN jurnalTxCredit <> 0 AND jurnalTxDebit = 0 THEN 'CR'
|
||||
WHEN jurnalTxCredit = 0 AND jurnalTxDebit = 0 THEN 'DB'
|
||||
ELSE 'ERROR'
|
||||
END as type,
|
||||
jurnalArID,
|
||||
jurnalArJurnalTxID,
|
||||
jurnalArM_CompanyID,
|
||||
jurnalArRefNo,
|
||||
jurnalArM_CompanyCode,
|
||||
jurnalArM_CompanyName
|
||||
FROM jurnal
|
||||
JOIN jurnal_tx ON jurnalID = jurnalTxJurnalID
|
||||
AND jurnalTxIsActive = 'Y'
|
||||
LEFT JOIN jurnal_ar ON jurnalTxID = jurnalArJurnalTxID
|
||||
AND jurnalArIsActive = 'Y'
|
||||
JOIN coa ON jurnalTxCoaID = coaID
|
||||
AND coaIsActive = 'Y'
|
||||
JOIN periode ON jurnalperiodeID = periodeID
|
||||
AND periodeIsActive = 'Y'
|
||||
$sql_where";
|
||||
$qry = $this->db->query($sql, $sql_param);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select jurnal error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// $sql_count = "SELECT
|
||||
// jurnalID,
|
||||
// IFNULL(SUM(jurnalTxDebit),0) as debit,
|
||||
// IFNULL(SUM(jurnalTxCredit),0) as credit
|
||||
// FROM jurnal
|
||||
// JOIN jurnal_tx ON jurnalID = jurnalTxJurnalID
|
||||
// AND jurnalTxIsActive = 'Y'
|
||||
// LEFT JOIN jurnal_ar ON jurnalTxID = jurnalArJurnalTxID
|
||||
// AND jurnalArIsActive = 'Y'
|
||||
// JOIN coa ON jurnalTxCoaID = coaID
|
||||
// AND coaIsActive = 'Y'
|
||||
// JOIN periode ON jurnalperiodeID = periodeID
|
||||
// AND periodeIsActive = 'Y'
|
||||
// $sql_where";
|
||||
// $qry_count = $this->db->query($sql_count, $sql_param);
|
||||
// if ($qry_count) {
|
||||
// $sumtotal = $qry_count->row_array();
|
||||
// } else {
|
||||
// $this->sys_error_db("select sum jurnal error", $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// $totalDebit = $sumtotal['debit'];
|
||||
// $totalCredit = $sumtotal['credit'];
|
||||
// $totalBalance = 0;
|
||||
|
||||
|
||||
// $totalBalance = $totalDebit - $totalCredit;
|
||||
// $arrTotal = array('debit' => $totalDebit, 'credit' => $totalCredit, 'balance' => $totalBalance);
|
||||
|
||||
|
||||
// $jurnalNumbers = [];
|
||||
// $description = [];
|
||||
// if ($rows) {
|
||||
// $coaAccountNoCheck = "";
|
||||
|
||||
// foreach ($rows as $key => $value) {
|
||||
|
||||
// if ($journalno != "") {
|
||||
|
||||
// if (!in_array($value['jurnalNo'], $jurnalNumbers)) {
|
||||
// $jurnalNumbers[] = $value['jurnalNo'];
|
||||
// }
|
||||
|
||||
// if ($coaAccountNoCheck != $value['coaAccountNo']) {
|
||||
// $description[] = $value['junalTxDescription'];
|
||||
// $coaAccountNoCheck = $value['coaAccountNo'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// $selectjournal = array('jurnalnumber' => $jurnalNumbers, 'description' => $description);
|
||||
|
||||
$result = array("records" => $rows, "sql" => $this->db->last_query());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function numbering($jurnalno)
|
||||
{
|
||||
$numbers = 'R' . '-' . $jurnalno;
|
||||
return $numbers;
|
||||
}
|
||||
|
||||
function savereverse()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$prm = $this->sys_input;
|
||||
$reverse = $prm['reversejournal'];
|
||||
// print_r($reverse[0]);
|
||||
// exit;
|
||||
|
||||
$sqlj = "INSERT INTO jurnal(
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDate,
|
||||
jurnalType,
|
||||
jurnalM_UserID)
|
||||
SELECT
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
'{$reverse[0]['jurnalNo']}',
|
||||
'{$reverse[0]['jurnalTitle']}',
|
||||
NOW(),
|
||||
jurnalType,
|
||||
{$userid}
|
||||
FROM jurnal
|
||||
WHERE jurnalID = {$reverse[0]['jurnalID']}";
|
||||
$qryj = $this->db->query($sqlj);
|
||||
if (!$qryj) {
|
||||
$this->sys_error_db("Insert jurnal", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$insertedID = $this->db->insert_id();
|
||||
|
||||
foreach ($reverse as $k => $v) {
|
||||
// print_r($v[0]);
|
||||
// exit;
|
||||
|
||||
$sql_tx = "INSERT INTO jurnal_tx(
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
junalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxCreated,
|
||||
jurnalTxM_UserID) VALUES(?,?,?,?,?,NOW(),?)";
|
||||
$qry_tx = $this->db->query($sql_tx, [
|
||||
$insertedID,
|
||||
$v['jurnalTxCoaID'],
|
||||
$v['junalTxDescription'],
|
||||
$v['jurnalTxDebit'],
|
||||
$v['jurnalTxCredit'],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_tx) {
|
||||
$this->sys_error_db("Insert jurnal tx", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$insertedtxID = $this->db->insert_id();
|
||||
|
||||
if ($v['jurnalType'] == 'AR') {
|
||||
$sql_ar = "INSERT INTO jurnal_ar(
|
||||
jurnalArJurnalTxID,
|
||||
jurnalArM_CompanyID,
|
||||
jurnalArRefNo,
|
||||
jurnalArM_CompanyCode,
|
||||
jurnalArM_CompanyName,
|
||||
jurnalArCreated,
|
||||
jurnalArM_UserID
|
||||
) VALUES(?,?,?,?,?,NOW(),?)";
|
||||
$qry_ar = $this->db->query($sql_ar, [
|
||||
$insertedtxID,
|
||||
$v['jurnalArM_CompanyID'],
|
||||
$v['jurnalArRefNo'],
|
||||
$v['jurnalArM_CompanyCode'],
|
||||
$v['jurnalArM_CompanyName'],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_ar) {
|
||||
$this->sys_error_db("Insert jurnal ar", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
1003
application/controllers/mockup/masterdata/accounting/Supplier.php
Normal file
1003
application/controllers/mockup/masterdata/accounting/Supplier.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,737 @@
|
||||
<?php
|
||||
class Supplier extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "SUPPLIER API";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_count = "SELECT count(*) as total
|
||||
FROM supplier
|
||||
WHERE SupplierIsActive = 'Y'
|
||||
AND (SupplierCode LIKE ? OR SupplierName LIKE ?)";
|
||||
$qry_count = $this->db->query($sql_count, [$search, $search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_count) {
|
||||
$tot_count = $qry_count->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT SupplierID,
|
||||
SupplierCode,
|
||||
SupplierName,
|
||||
SupplierIsPpn,
|
||||
SupplierIsPph,
|
||||
SupplierPpnPct,
|
||||
SupplierPphPct
|
||||
FROM supplier
|
||||
WHERE SupplierIsActive = 'Y'
|
||||
AND (SupplierCode LIKE ? OR SupplierName LIKE ?)
|
||||
ORDER BY SupplierID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier list error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchdetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
// Get supplier ID from parameters
|
||||
if (!isset($prm['supplier_id'])) {
|
||||
$this->sys_error("Supplier ID is required");
|
||||
exit;
|
||||
}
|
||||
$supplier_id = $prm['supplier_id'];
|
||||
|
||||
// Handle search parameter
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
// Pagination setup
|
||||
$number_limit = 20;
|
||||
$number_offset = 0;
|
||||
if ($prm['current_page'] > 0) {
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
// Count total records
|
||||
$sql_count = "SELECT COUNT(*) as total
|
||||
FROM supplier_price sp
|
||||
JOIN m_item mi ON sp.SupplierPriceM_ItemID = mi.M_ItemID
|
||||
LEFT JOIN itemunit iu ON sp.SupplierPriceItemUnitID = iu.ItemUnitID
|
||||
WHERE sp.SupplierPriceIsActive = 'Y'
|
||||
AND sp.SupplierPriceSupplierID = ?
|
||||
AND (mi.M_ItemCode LIKE ? OR mi.M_ItemDesc LIKE ?)";
|
||||
|
||||
$qry_count = $this->db->query($sql_count, [$supplier_id, $search, $search]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_count) {
|
||||
$tot_count = $qry_count->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get detailed records
|
||||
$sql = "SELECT
|
||||
sp.SupplierPriceID,
|
||||
sp.SupplierPriceSupplierID,
|
||||
mi.M_ItemID,
|
||||
mi.M_ItemCode,
|
||||
mi.M_ItemDesc,
|
||||
iu.ItemUnitID,
|
||||
iu.ItemUnitCode,
|
||||
iu.ItemUnitName,
|
||||
sp.SupplierPricePrice,
|
||||
sp.SupplierPriceCreated,
|
||||
sp.SupplierPriceLastUpdated
|
||||
FROM supplier_price sp
|
||||
JOIN m_item mi ON sp.SupplierPriceM_ItemID = mi.M_ItemID
|
||||
LEFT JOIN itemunit iu ON sp.SupplierPriceItemUnitID = iu.ItemUnitID
|
||||
WHERE sp.SupplierPriceIsActive = 'Y'
|
||||
AND sp.SupplierPriceSupplierID = ?
|
||||
AND (mi.M_ItemCode LIKE ? OR mi.M_ItemDesc LIKE ?)
|
||||
ORDER BY sp.SupplierPriceID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$supplier_id, $search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price list error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['nameSupplier']) || trim($prm['nameSupplier']) == "") {
|
||||
$this->sys_error("Supplier name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$nameSupplier = "";
|
||||
if (isset($prm['nameSupplier'])) {
|
||||
$nameSupplier = trim($prm['nameSupplier']);
|
||||
}
|
||||
$isPpn = "";
|
||||
if (isset($prm['isPpn'])) {
|
||||
$isPpn = trim($prm['isPpn']);
|
||||
}
|
||||
$isPph = "";
|
||||
if (isset($prm['isPph'])) {
|
||||
$isPph = trim($prm['isPph']);
|
||||
}
|
||||
$PpnPercent = "";
|
||||
if (isset($prm['PpnPercent'])) {
|
||||
$PpnPercent = trim($prm['PpnPercent']);
|
||||
}
|
||||
$PphPercent = "";
|
||||
if (isset($prm['PphPercent'])) {
|
||||
$PphPercent = trim($prm['PphPercent']);
|
||||
}
|
||||
|
||||
$codeSql = "SELECT `fn_numbering`('S') as codeSp";
|
||||
$exec = $this->db->query($codeSql, []);
|
||||
$codeSupplier = "";
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("generate code error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$codeSupplier = $exec->result_array()[0]["codeSp"];
|
||||
}
|
||||
|
||||
// Check for existing supplier with same name
|
||||
$sql_check = "SELECT COUNT(*) as total FROM supplier
|
||||
WHERE SupplierName = ? AND SupplierIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$nameSupplier]);
|
||||
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Nama supplier sudah ada");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO supplier(
|
||||
SupplierCode,
|
||||
SupplierName,
|
||||
SupplierIsPpn,
|
||||
SupplierIsPph,
|
||||
SupplierPpnPct,
|
||||
SupplierPphPct,
|
||||
SupplierIsActive,
|
||||
SupplierCreatedUserID,
|
||||
SupplierCreated
|
||||
) VALUES(?,?,?,?,?,?,'Y',?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$codeSupplier,
|
||||
$nameSupplier,
|
||||
$isPpn,
|
||||
$isPph,
|
||||
$PpnPercent,
|
||||
$PphPercent,
|
||||
$userId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM supplier WHERE SupplierCode = '{$codeSupplier}' AND SupplierIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['nameSupplier']) || trim($prm['nameSupplier']) == "") {
|
||||
$this->sys_error("Supplier name is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$nameSupplier = "";
|
||||
if (isset($prm['nameSupplier'])) {
|
||||
$nameSupplier = trim($prm['nameSupplier']);
|
||||
}
|
||||
$isPpn = "";
|
||||
if (isset($prm['isPpn'])) {
|
||||
$isPpn = trim($prm['isPpn']);
|
||||
}
|
||||
$isPph = "";
|
||||
if (isset($prm['isPph'])) {
|
||||
$isPph = trim($prm['isPph']);
|
||||
}
|
||||
$PpnPercent = "";
|
||||
if (isset($prm['PpnPercent'])) {
|
||||
$PpnPercent = trim($prm['PpnPercent']);
|
||||
}
|
||||
$PphPercent = "";
|
||||
if (isset($prm['PphPercent'])) {
|
||||
$PphPercent = trim($prm['PphPercent']);
|
||||
}
|
||||
$supplier_id = "";
|
||||
if (isset($prm['supplier_id'])) {
|
||||
$supplier_id = trim($prm['supplier_id']);
|
||||
}
|
||||
|
||||
$sql = "UPDATE supplier SET
|
||||
SupplierName = ?,
|
||||
SupplierIsPpn = ?,
|
||||
SupplierIsPph = ?,
|
||||
SupplierPpnPct = ?,
|
||||
SupplierPphPct = ?,
|
||||
SupplierLastUpdatedUserID = ?,
|
||||
SupplierLastUpdated = NOW()
|
||||
WHERE SupplierID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$nameSupplier,
|
||||
$isPpn,
|
||||
$isPph,
|
||||
$PpnPercent,
|
||||
$PphPercent,
|
||||
$userId,
|
||||
$supplier_id
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM supplier WHERE SupplierID = {$supplier_id} AND SupplierIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deletesupplier()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$supplier_id = "";
|
||||
if (isset($prm['supplier_id'])) {
|
||||
$supplier_id = trim($prm['supplier_id']);
|
||||
}
|
||||
|
||||
$sql = "UPDATE supplier SET
|
||||
SupplierIsActive = 'N',
|
||||
SupplierDeletedUserID = ?,
|
||||
SupplierDeleted = NOW()
|
||||
WHERE SupplierID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userId,
|
||||
$supplier_id
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_price = "UPDATE supplier_price SET
|
||||
SupplierPriceIsActive = 'N',
|
||||
SupplierPriceUserID = ?,
|
||||
SupplierPriceLastUpdated = NOW()
|
||||
WHERE SupplierPriceSupplierID = ?";
|
||||
$qry_price = $this->db->query($sql_price, [
|
||||
$userId,
|
||||
$supplier_id
|
||||
]);
|
||||
|
||||
if (!$qry_price) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => array("xId" => $prm["supplier_id"])
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchItem()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($payload["search"])) {
|
||||
$search = trim($payload["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $payload["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$number_limit = 10;
|
||||
$sql = "SELECT
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
IF(M_ItemDesc = '', '-', M_ItemDesc) AS M_ItemDesc
|
||||
FROM m_item
|
||||
WHERE (M_ItemCode LIKE ? OR M_ItemDesc LIKE ?)
|
||||
ORDER BY M_ItemDesc ASC
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, array($search, $search, $number_limit));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select item error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total_filter" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUnit()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
$itemID = $prm["itemID"];
|
||||
|
||||
$sql = "SELECT
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCreated,
|
||||
ItemUnitLastUpdated,
|
||||
ItemUnitIsActive,
|
||||
ItemUnitUserID
|
||||
FROM itemunit
|
||||
JOIN itemunitmap ON ItemUnitMapItemUnitID = ItemUnitID
|
||||
AND ItemUnitMapM_ItemID = {$itemID}
|
||||
AND ItemUnitMapIsActive = 'Y'
|
||||
AND ItemUnitMapIsPurchase = 'Y'
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName LIKE '%$search%'
|
||||
ORDER BY ItemUnitName ASC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("item unit list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveprice()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['supplier_id']) || !isset($prm['item_id']) || !isset($prm['unit_id']) || !isset($prm['price'])) {
|
||||
$this->sys_error("All fields are required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$supplier_id = trim($prm['supplier_id']);
|
||||
$item_id = trim($prm['item_id']);
|
||||
$unit_id = trim($prm['unit_id']);
|
||||
$price = trim($prm['price']);
|
||||
|
||||
// Check for existing supplier price with same item and unit
|
||||
$sql_check = "SELECT COUNT(*) as total
|
||||
FROM supplier_price
|
||||
WHERE SupplierPriceSupplierID = ?
|
||||
AND SupplierPriceM_ItemID = ?
|
||||
AND SupplierPriceItemUnitID = ?
|
||||
AND SupplierPriceIsActive = 'Y'";
|
||||
$qry_check = $this->db->query($sql_check, [$supplier_id, $item_id, $unit_id]);
|
||||
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Price for this item and unit already exists");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO supplier_price(
|
||||
SupplierPriceSupplierID,
|
||||
SupplierPriceM_ItemID,
|
||||
SupplierPriceItemUnitID,
|
||||
SupplierPricePrice,
|
||||
SupplierPriceIsActive,
|
||||
SupplierPriceUserID,
|
||||
SupplierPriceCreated
|
||||
) VALUES(?,?,?,?,'Y',?,NOW())";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$supplier_id,
|
||||
$item_id,
|
||||
$unit_id,
|
||||
$price,
|
||||
$userId
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT sp.*, mi.M_ItemCode, mi.M_ItemDesc, iu.ItemUnitCode, iu.ItemUnitName
|
||||
FROM supplier_price sp
|
||||
JOIN m_item mi ON sp.SupplierPriceM_ItemID = mi.M_ItemID
|
||||
JOIN itemunit iu ON sp.SupplierPriceItemUnitID = iu.ItemUnitID
|
||||
WHERE sp.SupplierPriceID = LAST_INSERT_ID()";
|
||||
$records = $this->db->query($newInsert)->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateprice()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['supplier_price_id']) || !isset($prm['item_id']) || !isset($prm['unit_id']) || !isset($prm['price'])) {
|
||||
$this->sys_error("All fields are required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$supplier_id = trim($prm['supplier_id']);
|
||||
$supplier_price_id = trim($prm['supplier_price_id']);
|
||||
$item_id = trim($prm['item_id']);
|
||||
$unit_id = trim($prm['unit_id']);
|
||||
$price = trim($prm['price']);
|
||||
|
||||
// Check for existing supplier price with same item and unit
|
||||
$sql_check = "SELECT COUNT(*) as total
|
||||
FROM supplier_price
|
||||
WHERE SupplierPriceSupplierID = ?
|
||||
AND SupplierPriceM_ItemID = ?
|
||||
AND SupplierPriceItemUnitID = ?
|
||||
AND SupplierPriceIsActive = 'Y'
|
||||
AND SupplierPriceID != ?";
|
||||
$qry_check = $this->db->query($sql_check, [$supplier_id, $item_id, $unit_id, $supplier_price_id]);
|
||||
|
||||
if ($qry_check && $qry_check->result_array()[0]['total'] > 0) {
|
||||
$this->sys_error("Price for this item and unit already exists");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE supplier_price SET
|
||||
SupplierPriceM_ItemID = ?,
|
||||
SupplierPriceItemUnitID = ?,
|
||||
SupplierPricePrice = ?,
|
||||
SupplierPriceUserID = ?,
|
||||
SupplierPriceLastUpdated = NOW()
|
||||
WHERE SupplierPriceID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$item_id,
|
||||
$unit_id,
|
||||
$price,
|
||||
$userId,
|
||||
$supplier_price_id
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT sp.*, mi.M_ItemCode, mi.M_ItemDesc, iu.ItemUnitCode, iu.ItemUnitName
|
||||
FROM supplier_price sp
|
||||
JOIN m_item mi ON sp.SupplierPriceM_ItemID = mi.M_ItemID
|
||||
JOIN itemunit iu ON sp.SupplierPriceItemUnitID = iu.ItemUnitID
|
||||
WHERE sp.SupplierPriceID = {$supplier_price_id}";
|
||||
$records = $this->db->query($newInsert)->result_array();
|
||||
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"records" => $records
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteprice()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
// Validate required parameters
|
||||
if (!isset($prm['supplier_price_id'])) {
|
||||
$this->sys_error("All fields are required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$supplier_id = trim($prm['supplier_id']);
|
||||
$supplier_price_id = trim($prm['supplier_price_id']);
|
||||
$item_id = trim($prm['item_id']);
|
||||
$unit_id = trim($prm['unit_id']);
|
||||
$price = trim($prm['price']);
|
||||
|
||||
$sql = "UPDATE supplier_price SET
|
||||
SupplierPriceIsActive = 'N',
|
||||
SupplierPriceUserID = ?,
|
||||
SupplierPriceLastUpdated = NOW()
|
||||
WHERE SupplierPriceID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$userId,
|
||||
$supplier_price_id
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("supplier price delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok(array(
|
||||
"total" => 1,
|
||||
"qry" => $this->db->last_query()
|
||||
));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,526 @@
|
||||
<?php
|
||||
|
||||
class Unitconvert extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Api: Training Playground";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
} else
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
if (isset($prm["search"])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = "%" . $prm["search"] . "%";
|
||||
} else {
|
||||
$search = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$sortBy = $prm["sortBy"];
|
||||
$sortStatus = $prm["sortStatus"];
|
||||
if ($sortBy) {
|
||||
$q_sort = "ORDER BY " . $sortBy . " " . $sortStatus;
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 10;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT COUNT(*) as total
|
||||
FROM (
|
||||
SELECT DISTINCT
|
||||
UnitConvertID AS id
|
||||
FROM unitconvert
|
||||
JOIN itemunit AS fromitemunit ON UnitConvertFromItemUnitID = fromitemunit.ItemUnitID
|
||||
JOIN itemunit AS toitemunit ON UnitConvertToItemUnitID = toitemunit.ItemUnitID
|
||||
WHERE
|
||||
( fromitemunit.ItemUnitName LIKE ? OR toitemunit.ItemUnitName LIKE ? ) AND UnitConvertIsActive = 'Y'
|
||||
) x";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $search]);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("itemunitconvert count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT
|
||||
UnitConvertID AS id,
|
||||
fromitemunit.ItemUnitID AS FromItemUnitID,
|
||||
fromitemunit.ItemUnitName AS FromItemUnitName,
|
||||
toitemunit.ItemUnitID AS ToItemUnitID,
|
||||
toitemunit.ItemUnitName AS ToItemUnitName,
|
||||
UnitConvertAmount AS Amount
|
||||
FROM unitconvert
|
||||
JOIN itemunit AS fromitemunit ON UnitConvertFromItemUnitID = fromitemunit.ItemUnitID
|
||||
|
||||
JOIN itemunit AS toitemunit ON UnitConvertToItemUnitID = toitemunit.ItemUnitID
|
||||
WHERE
|
||||
( fromitemunit.ItemUnitName LIKE ? OR toitemunit.ItemUnitName LIKE ? ) AND UnitConvertIsActive = 'Y'
|
||||
$q_sort
|
||||
LIMIT ? offset ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($search, $search, $number_limit, $number_offset));
|
||||
//echo $this->db->last_query();
|
||||
// print_r($rows = $qry->result_array());
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
//echo $this->db->last_query();
|
||||
$this->sys_error_db("Itemunitconvert select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchitemx()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT ItemID as id_item,
|
||||
ItemName as name_item
|
||||
FROM item
|
||||
JOIN itemunitmap ON ItemID = itemUnitMapItemID
|
||||
WHERE ItemIsActive = 'Y'";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$rows = $query->result_array();
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"]
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// konversi awal
|
||||
function fromitemunit()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT ItemUnitID as id,
|
||||
ItemUnitName as name
|
||||
FROM itemunit
|
||||
WHERE
|
||||
ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName LIKE CONCAT('%',?,'%')";
|
||||
|
||||
$qry = $this->db->query($sql, array($prm['search']));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"]
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// konversi akhir
|
||||
function toitemunit()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$id = "";
|
||||
|
||||
$sql = "SELECT ItemUnitID as id,
|
||||
ItemUnitName as name
|
||||
FROM itemunit
|
||||
AND ItemUnitIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"]
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
// convert
|
||||
$id_item = 0;
|
||||
$id_fromitemunit = 0;
|
||||
$id_toitemunit = 0;
|
||||
$amount = 0;
|
||||
|
||||
if (isset($prm['id_fromitemunit'])) {
|
||||
$id_fromitemunit = trim($prm['id_fromitemunit']);
|
||||
}
|
||||
|
||||
if (isset($prm['id_toitemunit'])) {
|
||||
$id_toitemunit = trim($prm['id_toitemunit']);
|
||||
}
|
||||
|
||||
if (isset($prm['amount'])) {
|
||||
$amount = trim($prm['amount']);
|
||||
}
|
||||
|
||||
// sql insert
|
||||
$sql = "INSERT INTO unitconvert(
|
||||
UnitConvertFromItemUnitID,
|
||||
UnitConvertToItemUnitID,
|
||||
UnitConvertAmount,
|
||||
UnitConvertCreated,
|
||||
UnitConvertLAstUpdated,
|
||||
UnitConvertUserID)
|
||||
VALUES ( ?, ?, ?, NOW(), NOW(), ?)";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$id_fromitemunit,
|
||||
$id_toitemunit,
|
||||
$amount,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Itemunitconvert insert", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insert_id = $this->db->insert_id();
|
||||
|
||||
$sql_json_before = "SELECT *
|
||||
FROM unitconvert
|
||||
WHERE UnitConvertIsActive = 'Y'
|
||||
AND UnitConvertID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query($sql_json_before, [
|
||||
$insert_id
|
||||
]);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunitconvert select json", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_by_id = $qry_json_before->row();
|
||||
|
||||
$json_after_log = json_encode($data_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.unitconvert_log(
|
||||
UnitConvertLogStatus,
|
||||
UnitConvertLogUnitConvertID,
|
||||
UnitConvertLogJSONBefore,
|
||||
UnitConvertLogJSONAfter,
|
||||
UnitConvertLogUserID,
|
||||
UnitConvertLogCreated
|
||||
) VALUES('ADD',?,NULL,?,?,NOW())";
|
||||
|
||||
$qry_insert_log = $this->db->query($sql_insert_log, [
|
||||
$insert_id,
|
||||
$json_after_log,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert log error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function edit()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$id = $prm["id"];
|
||||
|
||||
$sql_data = "UPDATE unitconvert
|
||||
SET UnitConvertFromItemUnitID = ?,
|
||||
UnitConvertToItemUnitID = ?,
|
||||
UnitConvertAmount = ?,
|
||||
UnitConvertLAstUpdated = NOW(),
|
||||
UnitConvertUserID = ?
|
||||
WHERE UnitConvertID = ?";
|
||||
|
||||
$qry_data = $this->db->query($sql_data, [
|
||||
$prm["id_fromitemunit"],
|
||||
$prm["id_toitemunit"],
|
||||
$prm["amount"],
|
||||
$userid,
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$qry_data) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Itemunitconvert update", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json before
|
||||
$sql_json_before = "SELECT *
|
||||
FROM unitconvert
|
||||
WHERE UnitConvertIsActive = 'Y'
|
||||
AND UnitConvertID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query($sql_json_before, [
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunitconvert select json before, $this->db");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before = json_encode($data_before_by_id);
|
||||
|
||||
// json after
|
||||
$sql_json_after = "SELECT *
|
||||
FROM unitconvert
|
||||
WHERE UnitConvertIsActive = 'Y'
|
||||
AND UnitConvertID = ?";
|
||||
|
||||
$qry_json_after = $this->db->query($sql_json_after, [
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$qry_json_after) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunitconvert select json after, $this->db");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_after_by_id = $qry_json_after->row();
|
||||
|
||||
$json_after = json_encode($data_after_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.unitconvert_log(
|
||||
UnitConvertLogStatus,
|
||||
UnitConvertLogUnitConvertID,
|
||||
UnitConvertLogJSONBefore,
|
||||
UnitConvertLogJSONAfter,
|
||||
UnitConvertLogUserID,
|
||||
UnitConvertLogCreated
|
||||
) VALUES('EDIT',?,?,?,?,NOW())";
|
||||
|
||||
$qry_insert_log = $this->db->query($sql_insert_log, [
|
||||
$id,
|
||||
$json_before,
|
||||
$json_after,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update log error, $this->db");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$id = $prm["id"];
|
||||
|
||||
$sql_data = "UPDATE unitconvert
|
||||
SET UnitConvertIsActive = 'N',
|
||||
UnitConvertLAstUpdated = NOW(),
|
||||
UnitConvertUserID = ?
|
||||
WHERE UnitConvertID = ?";
|
||||
|
||||
$qry_data = $this->db->query($sql_data, [
|
||||
$userid,
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$qry_data) {
|
||||
$this->db->trans_commit();
|
||||
$this->sys_error_db("itemunitconvert delete", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json before
|
||||
$sql_json_before = "SELECT *
|
||||
FROM unitconvert
|
||||
WHERE UnitConvertID = ?";
|
||||
|
||||
$qry_json_before = $this->db->query($sql_json_before, [
|
||||
$id
|
||||
]);
|
||||
|
||||
if (!$qry_json_before) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("itemunitconvert select json, $this->db");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_before_by_id = $qry_json_before->row();
|
||||
|
||||
$json_before = json_encode($data_before_by_id);
|
||||
|
||||
$sql_insert_log = "INSERT INTO acc_one_log.unitconvert_log(
|
||||
UnitConvertLogStatus,
|
||||
UnitConvertLogUnitConvertID,
|
||||
UnitConvertLogJSONBefore,
|
||||
UnitConvertLogJSONAfter,
|
||||
UnitConvertLogUserID,
|
||||
UnitConvertLogCreated
|
||||
) VALUES('DELETE',?,NULL,?,?,NOW())";
|
||||
|
||||
$qry_insert_log = $this->db->query($sql_insert_log, [
|
||||
$id,
|
||||
$json_before,
|
||||
$userid
|
||||
]);
|
||||
|
||||
if (!$qry_insert_log) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete log error, $this->db");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array("xid" => 0)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
<?php
|
||||
|
||||
class Rochecklist extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "md ro checklist";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getItemCategory()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$sql = "SELECT
|
||||
itemCategoryID,
|
||||
itemCategoryName
|
||||
FROM item_category
|
||||
WHERE itemCategoryIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get item category", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($this->db->last_query());
|
||||
$data = $qry->result_array();
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
public function getItemGroup()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$sql = "SELECT
|
||||
Nat_GroupID,
|
||||
Nat_GroupName
|
||||
FROM nat_group
|
||||
WHERE Nat_GroupIsActive = 'Y';";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get item group", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($this->db->last_query());
|
||||
$group = $qry->result_array();
|
||||
$sql = "SELECT Nat_SubGroupID,
|
||||
Nat_SubGroupNat_GroupID,
|
||||
Nat_SubGroupName
|
||||
FROM nat_subgroup
|
||||
WHERE Nat_SubGroupIsActive = 'Y';";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get item sub group", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($this->db->last_query());
|
||||
$subgGroup = $qry->result_array();
|
||||
$this->sys_ok([
|
||||
'group' => $group,
|
||||
'subGroup' => $subgGroup
|
||||
]);
|
||||
}
|
||||
public function search()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
|
||||
$page = $prm["page"];
|
||||
$type = $prm["type"];
|
||||
|
||||
$ROW_PER_PAGE = 15;
|
||||
$start_offset = 0;
|
||||
// print_r($prm);
|
||||
|
||||
if (isset($prm["page"])) {
|
||||
if (
|
||||
is_numeric($prm["page"]) && $prm["page"] > 0
|
||||
) {
|
||||
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
||||
}
|
||||
}
|
||||
$sqlType = '';
|
||||
if ($type == 'G') {
|
||||
$sqlType = "AND RoChecklistType = 'G";
|
||||
}
|
||||
if ($type == 'C') {
|
||||
$sqlType = "AND RoChecklistType = 'C";
|
||||
}
|
||||
if ($type == 'P') {
|
||||
$sqlType = "AND RoChecklistType = 'P";
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) as total
|
||||
FROM ro_checklist
|
||||
WHERE RoChecklistIsActive = 'Y'
|
||||
AND RoChecklistName LIKE ?
|
||||
{$sqlType}";
|
||||
$qry = $this->db->query($sql, [$search]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get total", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($this->db->last_query());
|
||||
$total = $qry->row_array()['total'];
|
||||
$sql = "SELECT *
|
||||
FROM ro_checklist
|
||||
WHERE RoChecklistIsActive = 'Y'
|
||||
AND RoChecklistName LIKE ?
|
||||
{$sqlType}
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [$search, $ROW_PER_PAGE, $start_offset]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get total", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($this->db->last_query());
|
||||
$rst = array(
|
||||
"total" => ceil($total / $ROW_PER_PAGE),
|
||||
"records" => $qry->result_array()
|
||||
);
|
||||
$this->sys_ok($rst);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
// $this->db->trans_commit();
|
||||
// $this->db->trans_rollback();
|
||||
$this->db->trans_begin();
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
$page = $prm["page"];
|
||||
$type = $prm["type"];
|
||||
$detail = $prm["detail"];
|
||||
|
||||
if (!in_array($type, ['G', 'C', 'P'])) {
|
||||
$this->sys_error("Type tidak sesuai");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ro_checklist (
|
||||
RoChecklistName,
|
||||
RoChecklistType,
|
||||
RoChecklistTypeCreatedUserID
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?
|
||||
);";
|
||||
$qry = $this->db->query($sql, [$prm['name'], $type, $userId]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add ", $this->db);
|
||||
print_r($this->db->last_query());
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$checklistID = $this->db->insert_id();
|
||||
if ($type == 'C') {
|
||||
$sqlInsert = '';
|
||||
$arrCategory = [];
|
||||
foreach ($detail as $key => $value) {
|
||||
$sqlInsert = "{$sqlInsert} ({$checklistID}, {$value['itemCategoryID']}, {$userId})";
|
||||
if (($key + 1) != count($detail)) {
|
||||
$sqlInsert = "{$sqlInsert},";
|
||||
}
|
||||
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapItemCategoryID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$checklistID, $value['itemCategoryID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
if (!empty($cek) || in_array($value['itemCategoryID'], $arrCategory)) {
|
||||
$this->sys_error_db("{$value['itemCategoryName']} sudah pernah di pilih ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arrCategory[] = $value['itemCategoryID'];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ro_checklist_map (
|
||||
RoChecklistMapRoChecklistID,
|
||||
RoChecklistMapItemCategoryID,
|
||||
RoChecklistMapCreatedUserID
|
||||
) VALUES {$sqlInsert};";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($type == 'P') {
|
||||
$sqlInsert = '';
|
||||
$arrSubGroup = [];
|
||||
foreach ($detail as $key => $value) {
|
||||
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapNat_GroupID = ?
|
||||
AND RoChecklistMapNat_SubGroupID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$checklistID, $value['Nat_SubGroupNat_GroupID'], $value['Nat_SubGroupID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
// echo empty($cek);
|
||||
// echo $value['Nat_SubGroupID'];
|
||||
// echo "\n";
|
||||
// print_r($arrSubGroup);
|
||||
// echo "\n";
|
||||
// echo in_array($value['Nat_SubGroupID'], $arrSubGroup);
|
||||
if (!empty($cek) || in_array($value['Nat_SubGroupID'], $arrSubGroup)) {
|
||||
$this->sys_error_db("{$value['Nat_SubGroupName']} sudah pernah di pilih", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arrSubGroup[] = $value['Nat_SubGroupID'];
|
||||
$sqlInsert = "{$sqlInsert} ({$checklistID}, {$value['Nat_SubGroupNat_GroupID']}, {$value['Nat_SubGroupID']},{$userId})";
|
||||
if (($key + 1) != count($detail)) {
|
||||
$sqlInsert = "{$sqlInsert},";
|
||||
}
|
||||
}
|
||||
$sql = "INSERT INTO ro_checklist_map (
|
||||
RoChecklistMapRoChecklistID,
|
||||
RoChecklistMapNat_GroupID,
|
||||
RoChecklistMapNat_SubGroupID,
|
||||
RoChecklistMapCreatedUserID
|
||||
) VALUES {$sqlInsert};";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping product", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
|
||||
public function addItem()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$id = $prm["id"];
|
||||
$type = $prm["type"];
|
||||
$detail = $prm["detail"];
|
||||
if ($type == 'C') {
|
||||
$sqlInsert = '';
|
||||
$arrCategory = [];
|
||||
foreach ($detail as $key => $value) {
|
||||
$sqlInsert = "{$sqlInsert} ({$id}, {$value['itemCategoryID']}, {$userId})";
|
||||
if (($key + 1) != count($detail)) {
|
||||
$sqlInsert = "{$sqlInsert},";
|
||||
}
|
||||
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapItemCategoryID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$id, $value['itemCategoryID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
if (!empty($cek) || in_array($value['itemCategoryID'], $arrCategory)) {
|
||||
$this->sys_error_db("{$value['itemCategoryName']} sudah pernah di pilih ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arrCategory[] = $value['itemCategoryID'];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ro_checklist_map (
|
||||
RoChecklistMapRoChecklistID,
|
||||
RoChecklistMapItemCategoryID,
|
||||
RoChecklistMapCreatedUserID
|
||||
) VALUES {$sqlInsert};";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($type == 'P') {
|
||||
$sqlInsert = '';
|
||||
$arrSubGroup = [];
|
||||
foreach ($detail as $key => $value) {
|
||||
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapNat_GroupID = ?
|
||||
AND RoChecklistMapNat_SubGroupID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$id, $value['Nat_SubGroupNat_GroupID'], $value['Nat_SubGroupID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
if (!empty($cek) || in_array($value['Nat_SubGroupID'], $arrSubGroup)) {
|
||||
$this->sys_error_db("{$value['Nat_SubGroupName']} sudah pernah di pilih", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$arrSubGroup[] = $value['Nat_SubGroupID'];
|
||||
$sqlInsert = "{$sqlInsert} ({$id}, {$value['Nat_SubGroupNat_GroupID']}, {$value['Nat_SubGroupID']},{$userId})";
|
||||
if (($key + 1) != count($detail)) {
|
||||
$sqlInsert = "{$sqlInsert},";
|
||||
}
|
||||
}
|
||||
$sql = "INSERT INTO ro_checklist_map (
|
||||
RoChecklistMapRoChecklistID,
|
||||
RoChecklistMapNat_GroupID,
|
||||
RoChecklistMapNat_SubGroupID,
|
||||
RoChecklistMapCreatedUserID
|
||||
) VALUES {$sqlInsert};";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping product", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
|
||||
public function getDetail()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$id = $prm["id"];
|
||||
$sql = "SELECT *
|
||||
FROM ro_checklist
|
||||
WHERE RoChecklistIsActive = 'Y'
|
||||
AND RoChecklistID = ?
|
||||
LIMIT 1";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get checklist", $this->db);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->row_array();
|
||||
$retval = [];
|
||||
if ($data['RoChecklistType'] == 'C') {
|
||||
$sql = "SELECT
|
||||
RoChecklistMapID,
|
||||
RoChecklistMapRoChecklistID,
|
||||
RoChecklistMapItemCategoryID itemCategoryID,
|
||||
itemCategoryName
|
||||
FROM
|
||||
ro_checklist_map
|
||||
JOIN
|
||||
ro_checklist
|
||||
ON RoChecklistMapRoChecklistID = RoChecklistID
|
||||
JOIN item_category
|
||||
ON RoChecklistMapItemCategoryID = itemCategoryID
|
||||
WHERE
|
||||
RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get checklist detail category", $this->db);
|
||||
exit;
|
||||
}
|
||||
$retval = $qry->result_array();
|
||||
}
|
||||
if ($data['RoChecklistType'] == 'P') {
|
||||
$sql = "SELECT
|
||||
RoChecklistMapID,
|
||||
RoChecklistMapRoChecklistID,
|
||||
Nat_GroupID,
|
||||
Nat_GroupName,
|
||||
Nat_SubGroupID,
|
||||
Nat_SubGroupName
|
||||
FROM
|
||||
ro_checklist_map
|
||||
JOIN
|
||||
ro_checklist
|
||||
ON RoChecklistMapRoChecklistID = RoChecklistID
|
||||
JOIN nat_group
|
||||
ON RoChecklistMapNat_GroupID = Nat_GroupID
|
||||
JOIN nat_subgroup
|
||||
ON RoChecklistMapNat_SubGroupID= Nat_SubGroupID
|
||||
WHERE
|
||||
RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapIsActive = 'Y';";
|
||||
$qry = $this->db->query($sql, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error get checklist detail category", $this->db);
|
||||
exit;
|
||||
}
|
||||
$retval = $qry->result_array();
|
||||
}
|
||||
$this->sys_ok($retval);
|
||||
}
|
||||
public function updateMapping()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$id = $prm["id"];
|
||||
$type = $prm["type"];
|
||||
$detail = $prm["detail"];
|
||||
|
||||
if (!in_array($type, ['G', 'C', 'P'])) {
|
||||
$this->sys_error("Type tidak sesuai");
|
||||
exit;
|
||||
}
|
||||
if ($type == 'C') {
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapItemCategoryID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$id, $detail['itemCategoryID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
if (!empty($cek)) {
|
||||
$this->sys_error_db("{$detail['itemCategoryName']} sudah pernah di pilih ", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ro_checklist_map SET
|
||||
RoChecklistMapItemCategoryID = ?,
|
||||
RoChecklistMapLastUpdatedUserID = ?
|
||||
WHERE RoChecklistMapID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$detail['itemCategoryID'], $userId, $detail['RoChecklistMapID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($type == 'P') {
|
||||
$sqlCek = "SELECT * FROM ro_checklist_map
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapNat_GroupID = ?
|
||||
AND RoChecklistMapNat_SubGroupID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sqlCek, [$id, $detail['Nat_SubGroupNat_GroupID'], $detail['Nat_SubGroupID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek detail mapping category", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
// echo $this->db->last_query();
|
||||
// print_r($cek);
|
||||
// echo ($cek);
|
||||
// exit;
|
||||
if (!empty($cek)) {
|
||||
$this->sys_error_db("{$detail['Nat_SubGroupName']} sudah pernah di pilih", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ro_checklist_map SET
|
||||
RoChecklistMapNat_GroupID = ?,
|
||||
RoChecklistMapNat_SubGroupID = ?,
|
||||
RoChecklistMapLastUpdatedUserID = ?
|
||||
WHERE RoChecklistMapID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$detail['Nat_SubGroupNat_GroupID'], $detail['Nat_SubGroupID'], $userId, $detail['RoChecklistMapID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error add detail mapping product", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
public function updateName()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$id = $prm["id"];
|
||||
// $type = $prm["type"];
|
||||
$name = $prm["name"];
|
||||
|
||||
|
||||
$sqlCek = "UPDATE ro_checklist SET
|
||||
RoChecklistName = ?,
|
||||
RoChecklistTypeLastUpdatedUserID = ?
|
||||
WHERE RoChecklistID = ?";
|
||||
$qry = $this->db->query($sqlCek, [$name, $userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update name", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
public function updateType()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$id = $prm["id"];
|
||||
// $type = $prm["type"];
|
||||
$type = $prm["type"];
|
||||
if (!in_array($type, ['G', 'C', 'P'])) {
|
||||
$this->sys_error("Type tidak sesuai");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlCek = "SELECT * FROM ro_checklist WHERE RoChecklistID = ?";
|
||||
$qry = $this->db->query($sqlCek, [$id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$cek = $qry->row_array();
|
||||
if ($cek['RoChecklistType'] == $type) {
|
||||
$this->sys_error_db("tipe tidak berubah", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = "UPDATE ro_checklist SET
|
||||
RoChecklistType = ?,
|
||||
RoChecklistTypeLastUpdatedUserID = ?
|
||||
WHERE RoChecklistID = ?";
|
||||
$qry = $this->db->query($sql, [$type, $userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update name", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ro_checklist_map SET
|
||||
RoChecklistMapIsActive = 'N',
|
||||
RoChecklistMapDeletedUserID = ?,
|
||||
RoChecklistMapDeleted = NOW()
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'
|
||||
|
||||
";
|
||||
$qry = $this->db->query($sql, [$userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error detail detail mapping", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
public function delete()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$id = $prm["id"];
|
||||
// $type = $prm["type"];
|
||||
|
||||
|
||||
|
||||
$sqlCek = "UPDATE ro_checklist SET
|
||||
RoChecklistIsActive = 'N',
|
||||
RoChecklistTypeDeleted = NOW(),
|
||||
RoChecklistTypeDeletedUserID = ?
|
||||
WHERE RoChecklistID = ?";
|
||||
$qry = $this->db->query($sqlCek, [$userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error update name", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ro_checklist_map SET
|
||||
RoChecklistMapIsActive = 'N',
|
||||
RoChecklistMapDeletedUserID = ?,
|
||||
RoChecklistMapDeleted = NOW()
|
||||
WHERE RoChecklistMapRoChecklistID = ?
|
||||
AND RoChecklistMapIsActive = 'Y'
|
||||
|
||||
";
|
||||
$qry = $this->db->query($sql, [$userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error detail detail mapping", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
public function deleteItem()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$id = $prm["id"];
|
||||
$sql = "UPDATE ro_checklist_map SET
|
||||
RoChecklistMapIsActive = 'N',
|
||||
RoChecklistMapDeletedUserID = ?,
|
||||
RoChecklistMapDeleted = NOW()
|
||||
WHERE RoChecklistMapID = ?
|
||||
|
||||
";
|
||||
$qry = $this->db->query($sql, [$userId, $id]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error detail detail mapping", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok('Success');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM0NSIsIk1fVXNlclVzZXJuYW1lIjoiY29iYWJyYW5jaCIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9hY2Mtb25lLW1kLWNvYVwvIiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMCIsIk1fU3RhZmZOYW1lIjoiQURNSU4iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsIk1fVXNlckxvY2F0aW9uSUQiOiIyIiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiQiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiJQcmFtaXRhIE5nYWdlbCBKYXlhIiwiTV9CcmFuY2hJRCI6IjEzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxNDkuMTEzLjExOS4yNDYiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdFwvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lXC8xMzEuMC4wLjAgU2FmYXJpXC81MzcuMzYgRWRnXC8xMzEuMC4wLjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wMS0wOCAxODowOTozNSIsIk1fU2F0ZWxsaXRlSUQiOjB9.0D4KFzCL2VY3R_vM9b6o2wupRu-KjATCRVUL7S89wtc"
|
||||
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto
|
||||
# @host = https://accone-prod.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto
|
||||
|
||||
### LIST OF Endpoints
|
||||
### {{ host }}//insertSales/{branchCode}/{date}
|
||||
### {{ host }}//insertAr/{branchCode}/{date}
|
||||
### {{ host }}//insertArPayment/{branchCode}/{date}
|
||||
### {{ host }}//insertRkTagihan/{branchCode}/{date}
|
||||
### {{ host }}//insertRkPelunasan/{branchCode}/{date}
|
||||
|
||||
|
||||
###
|
||||
GET https://accone.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto/index
|
||||
|
||||
### AUTO JURNAL PENJUALAN
|
||||
GET {{host}}/insertSales/LE/2025-05-13?isregen=1&jurnalno=ACSL/202505/0311/LE
|
||||
|
||||
{
|
||||
"isDebug": true
|
||||
}
|
||||
|
||||
### REGEN AUTO JURNAL PENJUALAN
|
||||
GET {{host}}/insertSales/LD/2025-05-21?isregen=1&jurnalno=ACSL/202505/0234
|
||||
|
||||
{
|
||||
"isDebug": false
|
||||
}
|
||||
|
||||
### AUTO JURNAL AR
|
||||
GET {{host}}/insertAr/LE/2025-04-12
|
||||
|
||||
{
|
||||
"isDebug": false
|
||||
}
|
||||
|
||||
### AUTO JURNAL AR PAYMENT
|
||||
GET {{host}}/insertArPayment/LE/2025-04-12
|
||||
|
||||
{
|
||||
"isDebug": false
|
||||
}
|
||||
|
||||
### AUTO JURNAL RK TAGIHAN
|
||||
GET {{host}}/insertRkTagihan/LE/2025-04-12
|
||||
|
||||
{
|
||||
"isDebug": false
|
||||
}
|
||||
|
||||
### AUTO JURNAL RK PELUNASAN
|
||||
GET {{host}}/insertRkPelunasan/LB/2025-05-15/1/1527
|
||||
|
||||
{
|
||||
"isDebug": false
|
||||
}
|
||||
|
||||
### DELETE DUMMY DATA
|
||||
POST {{ host }}/deleteDummyData
|
||||
|
||||
{
|
||||
"jurnalID": "389",
|
||||
"token": {{ token }}
|
||||
}
|
||||
|
||||
### * Inject Map Bank per Cabang
|
||||
### @param = branchCode
|
||||
GET {{ host }}/injectMapBankCab/LE
|
||||
|
||||
### * Inject Map Bank per Regional
|
||||
### @param = regionalID
|
||||
GET {{ host }}/injectMapBank/6
|
||||
|
||||
|
||||
###
|
||||
## *UNTUK CEK API DI CABANG
|
||||
###
|
||||
###
|
||||
GET http://devone.aplikasi.web.id/one-api/keu/Acc_one/getBanks
|
||||
|
||||
###
|
||||
GET http://ngagel/one-api/keu/Acc_one/sales/2025-12-01/json
|
||||
|
||||
###
|
||||
GET http://jemur/one-api/keu/Acc_one/sales/2025-05-21/json
|
||||
|
||||
###
|
||||
GET http://ngagel/one-api/keu/Acc_one/getBanks
|
||||
|
||||
### sales
|
||||
GET http://192.168.250.241/one-api/keu/Acc_one/sales/2025-01-03/json/
|
||||
|
||||
### ar
|
||||
GET http://aditya/one-api/keu/Acc_one/ar/2025-05-13/json/
|
||||
|
||||
### ar payment
|
||||
GET http://192.168.250.181/one-api/keu/Acc_one/arPayment/2025-01-02/json/
|
||||
|
||||
### TAGIHAN
|
||||
GET http://192.168.250.181/one-api/keu/Acc_one/arPaymentRkTagihan/2025-01-10/json/
|
||||
|
||||
### PELUNASAN
|
||||
GET http://192.168.250.182/one-api/keu/Acc_one/arPaymentRkPelunasan/2025-01-10/
|
||||
|
||||
|
||||
### ----------------------------
|
||||
### KEBONJERUK
|
||||
GET http://192.168.250.182/one-api/keu/Acc_one/arPaymentRkPelunasan/2025-01-02/
|
||||
|
||||
###
|
||||
GET http://192.168.250.182/one-api/keu/acc_one/arPayment/2025-01-02/json/
|
||||
|
||||
|
||||
|
||||
|
||||
### REGENERATE
|
||||
GET https://accone.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto/insertSales/BA/2025-01-11/1/157
|
||||
|
||||
###
|
||||
GET https://accone.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto/insertAr/BA/2025-01-09/1/157
|
||||
|
||||
###
|
||||
GET https://accone.aplikasi.web.id/one-api/mockup/masterdata/accounting/Mediajurnalauto/insertArPayment/BA/2025-01-06/1/246
|
||||
|
||||
###
|
||||
GET {{ host }}/testExc
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user