Files
2026-04-15 15:24:12 +07:00

230 lines
7.0 KiB
PHP

<?php
class Perujukinternal extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( F_PaymentKasirDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( F_PaymentKasirNumber LIKE '%{$search}%') AND ";
$sql = " SELECT count(*) as total
FROM f_payment_kasir
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$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("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT F_PaymentKasirID ,
F_PaymentKasirNumber ,
date_format(F_PaymentKasirDate,'%d-%m-%Y %T') as F_PaymentKasirDate ,
F_PaymentKasirCreated ,
F_PaymentKasirLastUpdated ,M_StaffName,
if(F_PaymentKasirIsReceived = 'N','Belum Diterima' ,'Sudah diterima') as F_PaymentKasirIsReceived ,
F_PaymentKasirIsActive
FROM f_payment_kasir
JOIN m_user on F_PaymentKasirUserID = M_UserID
join m_staff on M_UserM_StaffID = M_StaffID
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )
ORDER BY F_PaymentKasirID asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_PaymentKasirID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function save()
{
//# ambil parameter input
$prm = $this->sys_input;
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
echo $this->db_onedev->last_query();
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment save rows", $this->db_onedev);
exit;
}
}
public function search_company()
{
$prm = $this->sys_input;
$search = '%'.$prm['search'].'%';
$max_rst = 12;
// QUERY TOTAL
$sql = "select count(DISTINCT M_CompanyID) total
from m_company
where M_CompanyIsActive = 'Y'
and M_CompanyName LIKE ?
order by M_CompanyName ASC";
$query = $this->db_onedev->query($sql, $search);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("price company count", $this->db_onedev);
exit;
}
$sql = "select M_CompanyID, M_CompanyName,
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouIsReleased', M_MouIsReleased, 'M_MouIsVerified', M_MouIsVerified) ), ']'), '[]') as mou
from m_company
left join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
-- AND M_MouIsReleased = 'Y'
and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now())
where M_CompanyIsActive = 'Y'
and M_CompanyName LIKE ?
group by m_companyid
order by M_CompanyName ASC
limit 0, {$max_rst}";
$query = $this->db_onedev->query($sql, $search);
if ($query)
{
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_onedev->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("price company rows", $this->db_onedev);
exit;
}
}
public function search_mou()
{
$prm = $this->sys_input;
$max_rst = 12;
$search = '%' . $prm["search"] . '%';
$company = $prm["company_id"];
// QUERY TOTAL
$sql = "select count(*) total
from m_mou
where M_MouIsActive = 'Y'
and M_MouM_CompanyID = ?
and M_MouName LIKE ?
order by M_MouName ASC";
$query = $this->db_onedev->query($sql, $company, $search);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("price mou count", $this->db_onedev);
exit;
}
$sql = "select M_MouID, M_MouName, M_MouStartDate, M_MouEndDate
from m_mou
where M_MouIsActive = 'Y'
and M_MouM_CompanyID = ?
and M_MouName LIKE ?
order by M_MouName ASC
limit 0, {$max_rst}";
$query = $this->db_onedev->query($sql, $company, $search);
if ($query)
{
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_onedev->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("price mou rows", $this->db_onedev);
exit;
}
}
public function savetutup()
{
//# ambil parameter input
$prm = $this->sys_input;
$ppaymentkasirid = $prm['pPaymentKasirID'];
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_received_cashier('{$ppaymentkasirid}','{$puserid}')";
//$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment savetutup rows", $this->db_onedev);
exit;
}
}
}