189 lines
7.4 KiB
PHP
Executable File
189 lines
7.4 KiB
PHP
Executable File
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
exit('No direct script access allowed');
|
|
|
|
class Bills_model extends CI_model {
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->load->database();
|
|
}
|
|
|
|
function name_list(){
|
|
$this->db->select("bill.*");
|
|
$this->db->select("CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS patient_name");
|
|
$this->db->from("bill");
|
|
$this->db->join("patient_details", "bill.patient_id = patient_details.id");
|
|
|
|
//echo $this->db->get_compiled_select(); die;
|
|
$query = $this->db->get()->result();
|
|
//echo $this->db->last_query();die;
|
|
//echo '<pre>'; print_r($query); echo '</pre>'; exit;
|
|
return $query;
|
|
}
|
|
|
|
|
|
function getNameBysearch($search,$orderColumn, $orderType) {
|
|
//die('hhh');
|
|
if($orderColumn==1)
|
|
$this->db->order_by('invoice_id', $orderType);
|
|
else if($orderColumn==2)
|
|
$this->db->order_by('patient_name', $orderType);
|
|
|
|
$this->db->like('id', $search);
|
|
$this->db->or_like('name', $search);
|
|
$this->db->or_like('invoice_id', $search);
|
|
$this->db->limit($limit, $start);
|
|
$this->db->select("bill.*");
|
|
$this->db->select("patient.name as patient_name");
|
|
$this->db->from("bill");
|
|
$this->db->join("patient", "bill.patient_id = patient.id");
|
|
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
function getNameByLimit($limit, $start, $orderColumn, $orderType) {
|
|
//die('hhh');
|
|
if($orderColumn==1)
|
|
$this->db->order_by('invoice_id', $orderType);
|
|
else if($orderColumn==2)
|
|
$this->db->order_by('patient_name', $orderType);
|
|
|
|
$this->db->select("bill.*");
|
|
$this->db->select("CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS patient_name");
|
|
$this->db->from("bill");
|
|
$this->db->join("patient_details", "bill.patient_id = patient_details.id");
|
|
|
|
$this->db->limit($limit, $start);
|
|
$query = $this->db->get()->result();
|
|
//echo '<pre>'; print_r($query); echo '</pre>'; exit;
|
|
return $query;
|
|
}
|
|
|
|
function getNameByLimitBySearch($limit, $start, $search,$orderColumn,$orderType) {
|
|
|
|
if($orderColumn==1)
|
|
$this->db->order_by('invoice_id', $orderType);
|
|
else if($orderColumn==2)
|
|
$this->db->order_by('patient_name', $orderType);
|
|
|
|
$this->db->select("bill.*");
|
|
$this->db->from("bill");
|
|
$this->db->select("patient.name as patient_name");
|
|
$this->db->join("patient", "bill.patient_id = patient.id");
|
|
$this->db->or_like('patient.name', $search);
|
|
$this->db->or_like('invoice_id', $search);
|
|
$this->db->limit($limit, $start);
|
|
//echo $this->db->get_compiled_select(); die;
|
|
$query = $this->db->get()->result();
|
|
return $query;
|
|
}
|
|
function bill_details($id){
|
|
//echo '<pre>'; print_r($id); echo '</pre>'; exit;
|
|
$this->db->select("bill.*");
|
|
$this->db->select("CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS patient_name");
|
|
$this->db->where('bill.id', $id);
|
|
$this->db->from("bill");
|
|
$this->db->join("patient_details", "bill.patient_id = patient_details.id");
|
|
|
|
$query = $this->db->get()->row();
|
|
//echo $this->db->last_query();die;
|
|
//echo '<pre>'; print_r($query); echo '</pre>'; exit;
|
|
return $query;
|
|
}
|
|
public function model_get_revenue($stat=false,$startDate=null,$endDate=null){
|
|
try{
|
|
if($stat && $startDate!=null && $endDate!=null){
|
|
$query=$this->db->query("
|
|
SELECT
|
|
mcs.name AS service,
|
|
SUM(b.rate) AS amount
|
|
FROM bill b
|
|
JOIN patient_details p ON b.patient_id=p.id
|
|
JOIN master_cg_skills mcs ON p.level_of_service=mcs.id
|
|
WHERE b.billing_end BETWEEN '$startDate' AND '$endDate'
|
|
GROUP BY p.level_of_service
|
|
UNION
|
|
SELECT
|
|
mcs.name AS service,
|
|
0 AS amount
|
|
FROM master_cg_skills mcs
|
|
WHERE mcs.id NOT IN (
|
|
SELECT p.level_of_service
|
|
FROM bill b
|
|
JOIN patient_details p ON b.patient_id=p.id
|
|
WHERE b.billing_end BETWEEN '$startDate' AND '$endDate'
|
|
)
|
|
");
|
|
$result=$query->result();
|
|
foreach($result as $rs){
|
|
$response[$rs->service]=$rs->amount;
|
|
}
|
|
}else{
|
|
$query=$this->db->query("
|
|
SELECT SUM(b.rate) AS amount
|
|
FROM bill b
|
|
JOIN patient_details p ON b.patient_id=p.id
|
|
WHERE 1=1
|
|
");
|
|
$result=$query->result();
|
|
// $response=intval($result[0]->amount);
|
|
$query2=$this->db->query(
|
|
"SELECT mcs.name,COALESCE(SUM(b.rate), 0) AS amount
|
|
FROM master_cg_skills mcs
|
|
LEFT JOIN patient_details p ON mcs.id = p.level_of_service
|
|
LEFT JOIN bill b ON p.id = b.patient_id
|
|
WHERE 1=1
|
|
GROUP BY mcs.id, mcs.name"
|
|
);
|
|
$result2=$query2->result();
|
|
$response=[
|
|
'total_revenues'=>intval($result[0]->amount),
|
|
'total_services_revenues'=>$result2
|
|
];
|
|
}
|
|
return $response;
|
|
}catch(Exception $e){
|
|
$getMsg="Bills_model - model_get_revenue: ".$e->getMessage();
|
|
echo $getMsg;
|
|
}
|
|
}
|
|
public function model_calc_revenue($periods){
|
|
try{
|
|
$netRevenuesData=$this->model_get_revenue();
|
|
foreach($periods as $period){
|
|
list($start,$end)=explode(" ~ ", $period);
|
|
$servicesRevenues[$period]=$this->model_get_revenue(true,$start,$end);
|
|
}
|
|
|
|
$services=['RN','LPN','HHA','PCA','NP'];
|
|
$individualArrays=array_fill_keys($services,[]);
|
|
foreach($servicesRevenues as $serviceRevenues) {
|
|
foreach($services as $service){
|
|
$individualArrays[$service][]=isset($serviceRevenues[$service])?$serviceRevenues[$service]:0;
|
|
}
|
|
}
|
|
|
|
$weekly_revenues=array_fill(0,count(current($individualArrays)),0);
|
|
foreach ($individualArrays as $role => $values) {
|
|
$weekly_revenues=array_map(function ($sum, $value) {
|
|
return $sum + $value;
|
|
},$weekly_revenues,$values);
|
|
}
|
|
|
|
$response=[
|
|
'total_revenues'=>$netRevenuesData['total_revenues'],
|
|
'total_services_revenues'=>$netRevenuesData['total_services_revenues'],
|
|
'weekly_revenues'=>$weekly_revenues,
|
|
'weekly_services'=>$individualArrays
|
|
];
|
|
return $response;
|
|
}catch(Exception $e){
|
|
$getMsg="Bills_model - model_calc_revenue: ".$e->getMessage();
|
|
echo $getMsg;
|
|
}
|
|
}
|
|
}
|
|
?>
|