194 lines
6.7 KiB
PHP
194 lines
6.7 KiB
PHP
<?php
|
|
|
|
class Homescreenv2 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 list_total(){
|
|
try {
|
|
//# cek token valid
|
|
/* if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
*/
|
|
$prm = $this->sys_input;
|
|
$companyid = $prm['companyid'];
|
|
|
|
$total = 'Rp.';
|
|
$kredit = 'Rp.';
|
|
$debit = 'Rp.';
|
|
|
|
$kredit_rows_confirm = 0 ;
|
|
$sql_kredit_confirm = "SELECT SUM(T_TransactionAmount) as total_kredit_confirm
|
|
FROM t_transaction WHERE T_TransactionType = 'KREDIT'
|
|
AND T_TransactionIsActive = 'Y'
|
|
AND T_TransactionIsConfirm = 'Y'
|
|
AND T_TransactionM_CompanyID = $companyid";
|
|
$query_kredit_confirm = $this->db_onedev->query($sql_kredit_confirm);
|
|
// echo $this->db_onedev->last_query();
|
|
if ($query_kredit_confirm) {
|
|
$kredit_rows_confirm = $query_kredit_confirm->row()->total_kredit_confirm;
|
|
} else {
|
|
$this->sys_error_db("Kredit select");
|
|
exit;
|
|
}
|
|
|
|
$debit_rows_confirm = 0 ;
|
|
$sql_debit_confirm = "SELECT SUM(T_TransactionAmount) as total_debit_confirm
|
|
FROM t_transaction WHERE T_TransactionType = 'DEBIT'
|
|
AND T_TransactionIsActive = 'Y'
|
|
AND T_TransactionIsConfirm = 'Y'
|
|
AND T_TransactionM_CompanyID = $companyid";
|
|
$query_debit_confirm = $this->db_onedev->query($sql_debit_confirm);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query_debit_confirm) {
|
|
$debit_rows_confirm = $query_debit_confirm->row()->total_debit_confirm;
|
|
} else {
|
|
$this->sys_error_db("Debit select");
|
|
exit;
|
|
}
|
|
|
|
|
|
$kredit_rows = 0 ;
|
|
$total_rows_confirm = $kredit_rows_confirm - $debit_rows_confirm;
|
|
|
|
$sql_kredit = "SELECT $total_rows_confirm + SUM(T_TransactionAmount) as total_kredit
|
|
FROM t_transaction WHERE T_TransactionType = 'KREDIT'
|
|
AND T_TransactionIsActive = 'Y'
|
|
AND T_TransactionIsConfirm = 'N'
|
|
AND T_TransactionM_CompanyID = $companyid";
|
|
$query_kredit = $this->db_onedev->query($sql_kredit);
|
|
// echo $this->db_onedev->last_query();
|
|
if ($query_kredit) {
|
|
$kredit_rows = $query_kredit->row()->total_kredit;
|
|
} else {
|
|
$this->sys_error_db("Kredit select");
|
|
exit;
|
|
}
|
|
|
|
$debit_rows = 0 ;
|
|
$sql_debit = "SELECT SUM(T_TransactionAmount) as total_debit
|
|
FROM t_transaction WHERE T_TransactionType = 'DEBIT'
|
|
AND T_TransactionIsActive = 'Y'
|
|
AND T_TransactionIsConfirm = 'N'
|
|
AND T_TransactionM_CompanyID = $companyid";
|
|
$query_debit = $this->db_onedev->query($sql_debit);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query_debit) {
|
|
$debit_rows = $query_debit->row()->total_debit;
|
|
} else {
|
|
$this->sys_error_db("Debit select");
|
|
exit;
|
|
}
|
|
|
|
|
|
$total_rows = $kredit_rows - $debit_rows;
|
|
$total = 'Rp ' .number_format($total_rows,2,',','.');
|
|
$kredit = 'Rp '.number_format($kredit_rows,2,',','.');
|
|
$debit = 'Rp '.number_format($debit_rows,2,',','.');
|
|
|
|
$result = array("total_all"=>$total,"kredit"=>$kredit,"debit"=>$debit,"sisa_confirm"=>$total_rows_confirm);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function list_transaction(){
|
|
try {
|
|
//# cek token valid
|
|
/* if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
*/
|
|
$prm = $this->sys_input;
|
|
$companyid = $prm['companyid'];
|
|
$sql = "SELECT T_TransactionID as id,
|
|
DATE_FORMAT(T_TransactionDate,'%d-%m-%Y') as tanggaltransaksi,
|
|
T_TransactionType as tipe,
|
|
IFNULL(M_CategoryID,0) as kategoriid,
|
|
IFNULL(M_CategoryName,'Saldo') as kategoriname,
|
|
T_TransactionNote as note,
|
|
CONCAT(REPLACE(CONCAT('Rp ',format(T_TransactionAmount,0)),',','.'),',00') as amount,
|
|
T_TransactionSender as sender,
|
|
T_TransactionImg as imgurl,
|
|
T_TransactionIsConfirm as isconfirm,
|
|
IFNULL(DATE_FORMAT(T_TransactionConfirmDate,'%d-%m-%Y'),'-') as tanggalconfirm,
|
|
a.M_UserUsername as usertransaksi,
|
|
IFNULL(b.M_UserUsername,'') as userconfirm,
|
|
IFNULL(DATE_FORMAT(T_TransactionCreated,'%d-%m-%Y %H:%i:%s'),'-') as tanggalcreated
|
|
|
|
FROM t_transaction
|
|
LEFT JOIN m_user a ON a.M_UserID = T_TransactionUserID
|
|
LEFT JOIN m_user b ON b.M_UserID = T_TransactionConfirmUserID
|
|
LEFT JOIN m_category ON M_CategoryID = T_TransactionM_CategoryID
|
|
WHERE T_TransactionIsActive = 'Y'
|
|
AND T_TransactionM_CompanyID = $companyid
|
|
ORDER BY T_TransactionID DESC LIMIT 5";
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("Transaksi select");
|
|
exit;
|
|
}
|
|
$this->sys_ok($rows);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function list_chart(){
|
|
try {
|
|
//# cek token valid
|
|
/* if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
*/
|
|
$prm = $this->sys_input;
|
|
$companyid = $prm['companyid'];
|
|
$sql = "SELECT xmonth,
|
|
xyear,
|
|
SUM(T_TransactionAmount) as total,
|
|
CONCAT(REPLACE(CONCAT('Rp ',format(SUM(T_TransactionAmount),0)),',','.'),',00') as totaltext
|
|
FROM ( SELECT T_TransactionAmount,
|
|
month(T_TransactionDate) as xmonth,
|
|
year(T_TransactionDate) as xyear
|
|
FROM t_transaction
|
|
WHERE T_TransactionIsActive = 'Y'
|
|
AND T_TransactionM_CompanyID = $companyid
|
|
AND T_TransactionType = 'DEBIT'
|
|
AND T_TransactionDate >= CURDATE() - INTERVAL 3 MONTH) a
|
|
GROUP BY xmonth
|
|
ORDER BY xyear ASC, xmonth ASC";
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("Transaksi select");
|
|
exit;
|
|
}
|
|
$this->sys_ok($rows);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
} |