add more BE file from server
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user