Files
BE_IBL/application/controllers/mockup/masterdata/Bank.php
2026-04-15 15:24:12 +07:00

956 lines
29 KiB
PHP

<?php
class Bank extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupaccountbyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$bank = $prm['bank'];
$account = $prm['account'];;
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID AND Nat_BankIsActive = 'Y'
WHERE
Nat_BankName LIKE CONCAT('%','{$bank}','%') AND
(M_BankAccountName LIKE CONCAT('%','{$account}','%') OR M_BankAccountNo LIKE CONCAT('%','{$account}','%') OR Nat_BankName LIKE CONCAT('%','{$account}','%')) AND
M_BankAccountIsActive = 'Y' GROUP BY M_BankAccountID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_bank_account count", $this->db_onedev);
exit;
}
$sql = "select M_BankAccountID as id,
M_BankAccountName as name,
M_BankAccountNo as code,
CONCAT(Nat_BankName, ' [ ',M_BankAccountNo,' | ',IFNULL(M_BankAccountName,''),' ]') as account,
Nat_BankID,
Nat_BankName,
IF(M_BankAccountIsDefault = 'N','Tidak','Ya') as isdefault,
m_bank_account.*
from m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID AND Nat_BankIsActive = 'Y'
WHERE
Nat_BankName LIKE CONCAT('%','{$bank}','%') AND
(M_BankAccountName LIKE CONCAT('%','{$account}','%') OR M_BankAccountNo LIKE CONCAT('%','{$account}','%') OR Nat_BankName LIKE CONCAT('%','{$account}','%')) AND
M_BankAccountIsActive = 'Y'
GROUP BY M_BankAccountID
ORDER BY Nat_BankName ASC, M_BankAccountName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_bank_account select");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookupbankbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$bank = $prm['bank'];
$account = $prm['account'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from nat_bank
LEFT JOIN m_bank_account ON Nat_BankID = M_BankAccountNat_BankID AND M_BankAccountIsActive = 'Y'
where
Nat_BankName LIKE CONCAT('%','{$bank}','%') AND
(IFNULL(M_BankAccountName,'') LIKE CONCAT('%','{$account}','%') OR IFNULL(M_BankAccountNo,'') LIKE CONCAT('%','{$account}','%') OR Nat_BankName LIKE CONCAT('%','{$account}','%')) AND
Nat_BankIsActive = 'Y'
GROUP BY Nat_BankID) a";
$sql_param = array($search);
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("nat_bank count", $this->db_onedev);
exit;
}
$sql = "select Nat_BankID as id,
Nat_BankName as name,
Nat_BankName as namex,
IF(Nat_BankIsCard = 'N','Tidak','Ya') as iscard,
IF(Nat_BankIsEDC = 'N','Tidak','Ya') as isedc,
nat_bank.*
from nat_bank
LEFT JOIN m_bank_account ON Nat_BankID = M_BankAccountNat_BankID AND M_BankAccountIsActive = 'Y'
where
Nat_BankName LIKE CONCAT('%','{$bank}','%') AND
(IFNULL(M_BankAccountName,'') LIKE CONCAT('%','{$account}','%') OR IFNULL(M_BankAccountNo,'') LIKE CONCAT('%','{$account}','%') OR Nat_BankName LIKE CONCAT('%','{$account}','%')) AND
Nat_BankIsActive = 'Y'
GROUP BY Nat_BankID
ORDER BY Nat_BankName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_bank select");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewbank()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$code = $prm['code'];
$name = $prm['name'];
$iscard = $prm['iscard'];
$isedc = $prm['isedc'];
$query = "SELECT COUNT(*) as exist FROM nat_bank WHERE Nat_BankIsActive = 'Y' AND Nat_BankCode = '{$prm['code']}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "insert into nat_bank(
Nat_BankCode,
Nat_BankName,
Nat_BankIsCard,
Nat_BankIsEDC,
Nat_BankCreated,
Nat_BankLastUpdated
)
values( ?,?,?,?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$code,
$name,
$iscard,
$isedc
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_bank insert");
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Kode sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => array('status'=>'ERROR'));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editbank()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$name = $prm['name'];
$iscard = $prm['iscard'];
$isedc = $prm['isedc'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update nat_bank SET
Nat_BankCode = ?,
Nat_BankName = ?,
Nat_BankIsCard = ?,
Nat_BankIsEDC = ?,
Nat_BankLastUpdated = now()
where
Nat_BankID = ?
";
$querycompany = $this->db_onedev->query($sqlcompany,
array(
$code,
$name,
$iscard,
$isedc,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("nat_bank update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewaccount()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$bankid = $prm['bankid'];
$nomor = $prm['nomor'];
$name = $prm['name'];
$isdefault = $prm['isdefault'];
$userid = $this->sys_user["M_UserID"];
if($bankid == 0 ){
$errors = array();
if($bankid == 0){
array_push($errors,array('field'=>'bank','msg'=>'Bank dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
$sql = "insert into m_bank_account(
M_BankAccountNat_BankID,
M_BankAccountNo,
M_BankAccountName,
M_BankAccountIsDefault,
M_BankAccountUserID,
M_BankAccountLastUpdated,
M_BankAccountCreated)
values(?,?,?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$bankid,
$nomor,
$name,
$isdefault,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_bank_account insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
if ($isdefault == "Y" ) {
$sql = "update m_bank_account set M_BankAccountIsDefault= 'N'
where M_BankAccountID <> ? ";
$this->db_onedev->query($sql,array($last_id));
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE m_bank_account SET M_BankAccountNat_BankID = '{$bankid}',
M_BankAccountNo = '{$nomor}',
M_BankAccountName = '{$name}',
M_BankAccountUserID = '{$userid}',
M_BankAccountIsDefault = '{$isdefault}'
WHERE M_BankAccountID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
if ($isdefault == "Y" ) {
$sql = "update m_bank_account set M_BankAccountIsDefault= 'N'
where M_BankAccountID <> '{$prm['xid']}' ";
$this->db_onedev->query($sql);
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletebank()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update nat_bank SET
Nat_BankIsActive = 'N',
Nat_BankLastUpdated = now()
WHERE
Nat_BankID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_bank delete");
exit;
}
$sql = "update m_bank_account SET
M_BankAccountIsActive = 'N',
M_BankAccountLastUpdated = now()
WHERE
M_BankAccountNat_BankID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_bank_account delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteaccount()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update m_bank_account SET
M_BankAccountIsActive = 'N',
M_BankAccountLastUpdated = now()
WHERE
M_BankAccountID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_bank_account delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchbank(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_bank count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_BankID, Nat_BankName
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("nat_bank rows",$this->db_onedev);
exit;
}
}
function searchbankbyname(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_bank count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_BankID, Nat_BankName
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("nat_bank rows",$this->db_onedev);
exit;
}
}
function searchcity(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictM_CityID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictM_CityID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y' AND M_MouIsReleased = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_onedev);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y' AND M_MouIsReleased = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_onedev);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_onedev);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_onedev);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}