';
}
public function Invoice_counter()
{
$sql="select * from invoice_med_master";
$query = $this->db->query($sql);
$data['invoiceMaster']= $query->result();
$sql="select * from inv_med_item";
$query = $this->db->query($sql);
$data['inv_items']= $query->result();
$sql="select sum(amount) as Gtotal from inv_med_item";
$query = $this->db->query($sql);
$data['invoiceGtotal']= $query->result();
$sql="select * from doctor_master where active=1";
$query = $this->db->query($sql);
$data['doclist']= $query->result();
if($data['invoiceMaster'][0]->case_id > 0)
{
$sql="select * from organization_case_master where id=".$data['invoiceMaster'][0]->case_id;
$query = $this->db->query($sql);
$data['OCaseMaster']= $query->result();
}
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$this->load->view('Medical/Medical_Invoice_V',$data);
}
public function Invoice_Med_Draft()
{
$this->load->view('Medical/Draft_Med_Invoice');
}
public function Invoice_Med_Return()
{
$this->load->view('Medical/Draft_Med_Return_Invoice');
}
public function Invoice_med_show($inv_id)
{
$sql="select *,if(ipd_credit>0,'Credit to IPD','CASH') as credit_status,
if(case_credit>0,'Credit to Org','CASH') as credit_org_status from invoice_med_master
where id=$inv_id";
$query = $this->db->query($sql);
$data['invoiceMaster']= $query->result();
$patient_id=$data['invoiceMaster'][0]->patient_id;
$inv_phone_number=$data['invoiceMaster'][0]->inv_phone_number;
if($patient_id==0)
{
}
$sql="select *,ifnull(DATEDIFF(expiry,CURDATE()),-1000) AS no_day from inv_med_item where inv_med_id=".$inv_id;
$query = $this->db->query($sql);
$data['inv_items']= $query->result();
$sql="select sum(amount) as Gtotal,sum(tamount) as tamt,sum(CGST) as TCGST,sum(SGST) as TSGST,sum(disc_amount) as t_dis_amt from inv_med_item where inv_med_id=".$inv_id;
$query = $this->db->query($sql);
$data['invoiceGtotal']= $query->result();
$sql="select * from doctor_master where active=1";
$query = $this->db->query($sql);
$data['doclist']= $query->result();
$sql="select *,
GET_AGE_1(dob,age,age_in_month,estimate_dob) AS age from patient_master where id='".$data['invoiceMaster'][0]->patient_id."' ";
$query = $this->db->query($sql);
$data['person_info']= $query->result();
$data['org_Name']="";
$ipd_id=$data['invoiceMaster'][0]->ipd_id;
if($ipd_id>0)
{
$sql="select * from ipd_master where id=".$ipd_id;
$query = $this->db->query($sql);
$ipd_master= $query->result();
$sql="select * from v_ipd_list m join patient_master p on m.p_id=p.id
where m.id=".$ipd_id;
$query = $this->db->query($sql);
$data['ipd_list']= $query->result();
$data['ipd_master']=$ipd_master;
if(count($ipd_master)>0)
{
$p_ipd_id=$ipd_master[0]->id;
$p_ipd_code=$ipd_master[0]->ipd_code;
if($ipd_master[0]->case_id>0)
{
$sql="select * from organization_case_master where id=".$ipd_master[0]->case_id;
$query = $this->db->query($sql);
$org_master= $query->result();
if(count($org_master)>0)
{
$data['org_Name']=$org_master[0]->insurance_company_name;
}
}
}
}
if($data['invoiceMaster'][0]->case_id > 0)
{
$sql="select * from organization_case_master where id=".$data['invoiceMaster'][0]->case_id;
$query = $this->db->query($sql);
$data['OCaseMaster']= $query->result();
}
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$data['sale_return']=$data['invoiceMaster'][0]->sale_return;
$data['content']=$this->load->view('Medical/Med_Item_List',$data,true);
if($data['invoiceMaster'][0]->sale_return==0)
{
$this->load->view('Medical/Medical_Invoice_V',$data);
}else{
$this->load->view('Medical/Medical_Invoice_Return_V',$data);
}
}
//New Invoice Edit
public function Invoice_med_datasheet($inv_id)
{
$sql="select *,if(ipd_credit>0,'Credit to IPD','CASH') as credit_status,
if(case_credit>0,'Credit to Org','CASH') as credit_org_status from invoice_med_master
where id=$inv_id";
$query = $this->db->query($sql);
$data['invoiceMaster']= $query->result();
$sql="select *,ifnull(DATEDIFF(expiry,CURDATE()),-1000) AS no_day from inv_med_item where inv_med_id=".$inv_id;
$query = $this->db->query($sql);
$data['inv_items']= $query->result();
$sql="select sum(amount) as Gtotal,sum(tamount) as tamt,sum(CGST) as TCGST,sum(SGST) as TSGST,sum(disc_amount) as t_dis_amt from inv_med_item where inv_med_id=".$inv_id;
$query = $this->db->query($sql);
$data['invoiceGtotal']= $query->result();
$sql="select * from doctor_master where active=1";
$query = $this->db->query($sql);
$data['doclist']= $query->result();
$sql="select *,
GET_AGE_1(dob,age,age_in_month,estimate_dob) AS age from patient_master where id='".$data['invoiceMaster'][0]->patient_id."' ";
$query = $this->db->query($sql);
$data['person_info']= $query->result();
$data['org_Name']="";
$ipd_id=$data['invoiceMaster'][0]->ipd_id;
if($ipd_id>0)
{
$sql="select * from ipd_master where id=".$ipd_id;
$query = $this->db->query($sql);
$ipd_master= $query->result();
$sql="select * from v_ipd_list m join patient_master p on m.p_id=p.id
where m.id=".$ipd_id;
$query = $this->db->query($sql);
$data['ipd_list']= $query->result();
$data['ipd_master']=$ipd_master;
if(count($ipd_master)>0)
{
$p_ipd_id=$ipd_master[0]->id;
$p_ipd_code=$ipd_master[0]->ipd_code;
if($ipd_master[0]->case_id>0)
{
$sql="select * from organization_case_master where id=".$ipd_master[0]->case_id;
$query = $this->db->query($sql);
$org_master= $query->result();
if(count($org_master)>0)
{
$data['org_Name']=$org_master[0]->insurance_company_name;
}
}
}
}
if($data['invoiceMaster'][0]->case_id > 0)
{
$sql="select * from organization_case_master where id=".$data['invoiceMaster'][0]->case_id;
$query = $this->db->query($sql);
$data['OCaseMaster']= $query->result();
}
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$data['sale_return']=$data['invoiceMaster'][0]->sale_return;
$data['content']=$this->load->view('Medical/Med_Item_List',$data,true);
if($data['invoiceMaster'][0]->sale_return==0)
{
$this->load->view('Medical/Medical_Invoice_V',$data);
}else{
$this->load->view('Medical/Medical_Invoice_Return_V',$data);
}
}
// Update Medical Invoice Master
public function update_uhid()
{
$this->load->model('Medical_M');
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$inv_id=$this->input->post('med_invoice_id');
$pid=$this->input->post('pid');
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$invoice_master= $query->result();
$sql="select * from patient_master_exten where id='".$pid."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
if(count($person_info)>0)
{
$patient_id=$person_info[0]->id;
$patient_code_u=$person_info[0]->p_code;
$custmer_Name=$person_info[0]->p_fname;
$data = array(
'customer_type'=>1,
'patient_id' => $patient_id,
'patient_code' => $patient_code_u,
'inv_name' => $custmer_Name,
'ipd_credit'=>0,
'case_credit'=>0,
'case_credit'=>0,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$this->Medical_M->update_invoice_group($inv_id);
$this->Medical_M->update_invoice_final($inv_id);
$status= 1;
$remark="Done";
}else{
$status=0;
$remark="Not Done";
}
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_ipd()
{
$this->load->model('Medical_M');
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$inv_id=$this->input->post('med_invoice_id');
$ipd_id=$this->input->post('ipd_id');
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$invoice_master= $query->result();
$sql="select * from ipd_master where id=".$ipd_id;
$query = $this->db->query($sql);
$ipd_master= $query->result();
$pid=$ipd_master[0]->p_id;
$sql="select * from patient_master_exten where id='".$pid."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
if(count($person_info)>0)
{
$patient_id=$person_info[0]->id;
$patient_code_u=$person_info[0]->p_code;
$custmer_Name=$person_info[0]->p_fname;
$ipd_id=$ipd_master[0]->id;
$ipd_code=$ipd_master[0]->ipd_code;
$data = array(
'customer_type'=>1,
'patient_id' => $patient_id,
'patient_code' => $patient_code_u,
'inv_name' => $custmer_Name,
'ipd_credit'=>0,
'case_credit'=>0,
'ipd_id'=> $ipd_id,
'ipd_code'=>$ipd_code,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$this->Medical_M->update_invoice_group($inv_id);
$this->Medical_M->update_invoice_final($inv_id);
$status= 1;
$remark="Done";
}else{
$status=0;
$remark="Not Done";
}
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_org()
{
$this->load->model('Medical_M');
$user = $this->ion_auth->user()->row();
$data['user_id'] = $user->id;
$inv_id=$this->input->post('med_invoice_id');
$org_id=$this->input->post('org_id');
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$invoice_master= $query->result();
$sql="select * from organization_case_master where case_type=0 and id=".$org_id;
$query = $this->db->query($sql);
$org_master= $query->result();
$pid=$org_master[0]->p_id;
$sql="select * from patient_master_exten where id='".$pid."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
if(count($person_info)>0)
{
$patient_id=$person_info[0]->id;
$patient_code_u=$person_info[0]->p_code;
$custmer_Name=$person_info[0]->p_fname;
$org_id=$org_master[0]->id;
$org_code=$org_master[0]->case_id_code;
$data = array(
'customer_type'=>1,
'patient_id' => $patient_id,
'patient_code' => $patient_code_u,
'inv_name' => $custmer_Name,
'ipd_credit'=>0,
'case_credit'=>1,
'ipd_id'=> 0,
'ipd_code'=>'',
'case_id'=>$org_id,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$this->Medical_M->update_invoice_group($inv_id);
$this->Medical_M->update_invoice_final($inv_id);
$status= 1;
$remark="Done";
}else{
$status=0;
$remark="Not Done";
}
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_invdate()
{
$this->load->model('Medical_M');
$inv_id=$this->input->post('med_invoice_id');
$inv_date=$this->input->post('inv_date');
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$invoice_master= $query->result();
$inv_date=str_to_MysqlDate($inv_date);
$data = array(
'inv_date' => $inv_date,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$status= 1;
$remark="Done";
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_name_phone()
{
$this->load->model('Medical_M');
$inv_id=$this->input->post('med_invoice_id');
$pid=$this->input->post('pid');
$customer_type=$this->input->post('customer_type');
$P_Name=$this->input->post('P_Name');
$P_Phone=$this->input->post('P_Phone');
$doc_id=$this->input->post('doc_id');
$doc_name=$this->input->post('doc_name');
$refername=$doc_name;
$sql="select * from doctor_master where id='".$doc_id."' ";
$query = $this->db->query($sql);
$doc_info= $query->result();
if(count($doc_info)>0)
{
$refername=$doc_info[0]->p_fname;
}
$data = array(
'customer_type'=>$customer_type,
'patient_id' => '0',
'patient_code' => '',
'inv_name' => $P_Name,
'inv_phone_number' => $P_Phone,
'ipd_credit'=>0,
'case_credit'=>0,
'ipd_id'=> 0,
'ipd_code'=>'',
'case_id'=>'0',
'doc_id' => $doc_id,
'doc_name' => $refername,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$status= 1;
$remark="Done";
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_doctor()
{
$this->load->model('Medical_M');
$inv_id=$this->input->post('med_invoice_id');
$doc_id=$this->input->post('doc_id');
$doc_name=$this->input->post('doc_name');
$refername=$doc_name;
$sql="select * from doctor_master where id='".$doc_id."' ";
$query = $this->db->query($sql);
$doc_info= $query->result();
if(count($doc_info)>0)
{
$refername=$doc_info[0]->p_fname;
}
$data = array(
'doc_id' => $doc_id,
'doc_name' => $refername,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$status= 1;
$remark="Done";
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
public function update_cr_status_ipd()
{
$this->load->model('Medical_M');
$inv_id=$this->input->post('med_invoice_id');
$credit_ipd=$this->input->post('credit_ipd');
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$invoice_master= $query->result();
$ipd_id=$invoice_master[0]->ipd_id;
$data = array(
'ipd_credit' => $credit_ipd,
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$status= 1;
$remark="Done";
$this->Medical_M->update_invoice_group_gst($ipd_id,'1');
$this->Medical_M->update_invoice_group_gst($ipd_id,'2');
$this->Medical_M->update_invoice_group_gst($ipd_id,'3');
$rvar=array(
'status' =>$status,
'remark'=>$remark
);
$encode_data = json_encode($rvar);
echo $encode_data;
}
// End Update Medical Invoice Master
public function search_customer($sale=0)
{
$data['sale']=$sale;
$this->load->view('Medical/Search_Patient',$data);
}
public function Invoice_counter_new($pno,$ipd_id,$case_id)
{
$select_doc=0;
$p_fname='';
$p_pcode='';
$p_pid=$pno;
$p_ipd_id=$ipd_id;
$p_ipd_code='';
$customer_type=0;
$select_doc=0;
$data['org_Name']="";
$data['content']="";
if($pno>0)
{
$sql="select *,if(gender=1,'Male','Female') as xgender,
GET_AGE_1(dob,age,age_in_month,estimate_dob) AS age from patient_master where id='".$pno."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
$sql="select doc_id from opd_master where p_id='".$pno."' order by opd_id desc limit 1";
$query = $this->db->query($sql);
$data['opd_master']= $query->result();
$p_fname=$person_info[0]->p_fname;
$p_pcode=$person_info[0]->p_code;
if(count($data['opd_master'])>0)
{
$select_doc=$data['opd_master'][0]->doc_id;
}else{
$select_doc=0;
}
$customer_type=1;
}
if($ipd_id>0)
{
$sql="select * from ipd_master where id=".$ipd_id;
$query = $this->db->query($sql);
$data['ipd_master']= $query->result();
$sql="select * from v_ipd_list m join patient_master p on m.p_id=p.id
where m.id=".$ipd_id;
$query = $this->db->query($sql);
$data['ipd_list']= $query->result();
$p_ipd_code=$data['ipd_master'][0]->ipd_code;
if($data['ipd_master'][0]->case_id>0)
{
$sql="select * from organization_case_master where id=".$data['ipd_master'][0]->case_id;
$query = $this->db->query($sql);
$org_master= $query->result();
if(count($org_master)>0)
{
$data['org_Name']=$org_master[0]->insurance_company_name;
}
}
}
$this->load->model('Medical_M');
$data['invoice_med_master'] = array(
'patient_id' => $p_pid,
'ipd_id' => $p_ipd_id,
'ipd_code' => $p_ipd_code,
'case_id' => $case_id,
'inv_date' => str_to_MysqlDate(date('d/m/Y')),
'inv_name' => $p_fname,
'patient_code' => $p_pcode,
'doc_id' => $select_doc,
'sale_return'=>0,
'case_credit'=>0,
'customer_type'=>$customer_type,
);
if($case_id>0)
{
$data['invoice_med_master']['case_credit']=1;
}
$inser_id=$this->Medical_M->add_invoice( $data['invoice_med_master']);
if($inser_id)
{
$sql="select *,if(ipd_credit>0,'Credit to IPD','CASH') as credit_status from invoice_med_master where id=".$inser_id;
$query = $this->db->query($sql);
$data['invoiceMaster']= $query->result();
$sql="select *,ifnull(DATEDIFF(expiry,CURDATE()),-1000) AS no_day from inv_med_item where inv_med_id=".$inser_id;
$query = $this->db->query($sql);
$data['inv_items']= $query->result();
$sql="select sum(amount) as Gtotal,sum(tamount) as tamt,sum(CGST) as TCGST,sum(SGST) as TSGST,sum(disc_amount) as t_dis_amt from inv_med_item where inv_med_id=".$inser_id;
$query = $this->db->query($sql);
$data['invoiceGtotal']= $query->result();
$sql="select * from doctor_master where active=1";
$query = $this->db->query($sql);
$data['doclist']= $query->result();
$sql="select * from organization_case_master where id=".$case_id;
$query = $this->db->query($sql);
$data['OCaseMaster']= $query->result();
$data['sale_return']=$data['invoiceMaster'][0]->sale_return;
$data['content']=$this->load->view('Medical/Med_Item_List',$data,true);
$this->load->view('Medical/Medical_Invoice_V',$data);
}
}
public function Invoice_Return_new($pno)
{
$select_doc=0;
$p_fname='';
$p_pcode='';
$p_pid=$pno;
$inv_phone_number='';
$data['content']='';
if($pno>0)
{
$sql="select *,if(gender=1,'Male','Female') as xgender,
GET_AGE_1(dob,age,age_in_month,estimate_dob) AS age from patient_master where id='".$pno."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
$p_fname=$person_info[0]->p_fname;
$p_pcode=$person_info[0]->p_code;
$inv_phone_number=$person_info[0]->mphone1;
$select_doc=0;
}
$this->load->model('Medical_M');
$data['invoice_med_master'] = array(
'patient_id' => $p_pid,
'inv_date' => str_to_MysqlDate(date('d/m/Y')),
'inv_name' => $p_fname,
'patient_code' => $p_pcode,
'doc_id' => $select_doc,
'inv_phone_number'=>$inv_phone_number,
'sale_return'=>1
);
$inser_id=$this->Medical_M->add_invoice( $data['invoice_med_master']);
if($inser_id)
{
$sql="select *,if(ipd_credit>0,'Credit to IPD','CASH') as credit_status from invoice_med_master where id=".$inser_id;
$query = $this->db->query($sql);
$data['invoiceMaster']= $query->result();
$sql="select *,ifnull(DATEDIFF(expiry,CURDATE()),-1000) AS no_day from inv_med_item where inv_med_id=".$inser_id;
$query = $this->db->query($sql);
$data['inv_items']= $query->result();
$sql="select sum(amount) as Gtotal,sum(tamount) as tamt,sum(CGST) as TCGST,sum(SGST) as TSGST,sum(disc_amount) as t_dis_amt from inv_med_item where inv_med_id=".$inser_id;
$query = $this->db->query($sql);
$data['invoiceGtotal']= $query->result();
$data['sale_return']=$data['invoiceMaster'][0]->sale_return;
$data['content']=$this->load->view('Medical/Med_Item_List',$data,true);
$this->load->view('Medical/Medical_Invoice_Return_V',$data);
}
}
public function item_stock_list($item_code)
{
$sql="SELECT p.item_name,t.batch_no,t.expiry_date as expiry_date_str,t.expiry_date,
(t.total_unit-t.total_sale_unit) AS c_qty,
t.id,t.mrp,t.selling_unit_rate,p.id AS item_code
FROM med_product_master p
JOIN purchase_invoice_item t ON p.id=t.item_code
where (t.total_unit-t.total_sale_unit)>0
and (expiry_date>date_add(sysdate(),interval 1 month) or p.exp_date_applicable=0)
and p.id =$item_code";
$query = $this->db->query($sql);
$data['Item_list']=$query->result_array() ;
$this->load->view('Medical/sale_item_list_for_add',$data);
}
public function get_drug(){
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$sql="SELECT p.item_name,t.batch_no,t.expiry_date as expiry_date_str,t.expiry_date,
(t.total_unit-t.total_sale_unit-total_lost_unit) AS c_qty,
t.id,t.mrp,t.selling_unit_rate,p.id AS item_code,p.packing
FROM med_product_master p
JOIN purchase_invoice_item t ON p.id=t.item_code and (t.total_unit-t.total_sale_unit-t.total_lost_unit)>0
and (expiry_date>date_add(sysdate(),interval 1 day) or p.exp_date_applicable=0)
and remove_item=0
where (p.item_name like '".$q."%' ";
if(strlen($q)>5)
{
$sql=$sql. " or p.item_name SOUNDS LIKE '".$q."'";
}
$sql=$sql.") order by id desc limit 100";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$new_row['label']=htmlentities(stripslashes($row['item_name'])).' |B:'.htmlentities(stripslashes($row['batch_no'])). ' |Pak:'.htmlentities(stripslashes($row['packing'])).' |Rs.'.htmlentities(stripslashes($row['mrp'])).' |Qty:'.htmlentities(stripslashes($row['c_qty']));
$new_row['value']=htmlentities(stripslashes($row['item_name']));
$new_row['l_item_code']=htmlentities(stripslashes($row['item_code']));
$new_row['l_ss_no']=htmlentities(stripslashes($row['id']));
$new_row['l_Batch']=htmlentities(stripslashes($row['batch_no']));
$new_row['l_Expiry']=htmlentities(stripslashes($row['expiry_date_str']));
$new_row['l_mrp']=htmlentities(stripslashes($row['mrp']));
$new_row['l_unit_rate']=htmlentities(stripslashes($row['selling_unit_rate']));
$new_row['l_c_qty']=htmlentities(stripslashes($row['c_qty']));
$new_row['l_packing']=htmlentities(stripslashes($row['packing']));
$new_row['sql']=$sql;
$row_set[] = $new_row; //build an array
}
echo json_encode($row_set); //format the array into json data
}else{
$new_row['sql']=$sql;
$row_set[] = $new_row;
echo json_encode($row_set);
}
}
}
public function get_drug_master(){
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$sql="select * from purchase_invoice_item p
where p.id in (select max(id) from purchase_invoice_item t
where t.Item_name like '".$q."%' group by t.Item_name )
order by p.Item_name ";
$sql="SELECT m.* ,p.id as ss_no,m.packing as p_packing,p.mrp,p.purchase_price,p.discount,
p.batch_no,date_format(expiry_date,'%m') as str_expiry_month ,
date_format(expiry_date,'%y') as str_expiry_year ,
m.batch_applicable,m.exp_date_applicable,
if(p.id is null,m.CGST_per,p.CGST_per) as p_CGST_per,
if(p.id is null,m.SGST_per,p.SGST_per) as p_SGST_per,
if(p.id is null,m.rack_no,p.rack_no) as p_rack_no,
if(p.id is null,m.shelf_no,p.shelf_no) as p_shelf_no,
if(p.id is null,m.cold_storage,p.cold_storage) as p_cold_storage
FROM med_product_master m
LEFT JOIN (SELECT * from purchase_invoice_item
WHERE id in (select max(id) from purchase_invoice_item
WHERE Item_name LIKE '".$q."%'
group BY item_code ) ) as p ON m.id=p.item_code
WHERE m.Item_name LIKE '".$q."%'
order BY m.item_name ";
$sql=$sql." limit 20";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$new_row['label']=htmlentities(stripslashes($row['item_name'])).' | '.htmlentities(stripslashes($row['p_packing'])).' | '.htmlentities(stripslashes($row['mrp']));
$new_row['value']=htmlentities(stripslashes($row['item_name']));
$new_row['l_item_code']=htmlentities(stripslashes($row['id']));
$new_row['l_mrp']=htmlentities(stripslashes($row['mrp']));
$new_row['l_packing']=htmlentities(stripslashes($row['packing']));
$new_row['l_CGST_per']=htmlentities(stripslashes($row['p_CGST_per']));
$new_row['l_SGST_per']=htmlentities(stripslashes($row['p_SGST_per']));
$new_row['l_HSNCODE']=htmlentities(stripslashes($row['HSNCODE']));
$new_row['l_batch_no']=htmlentities(stripslashes($row['batch_no']));
$new_row['l_purchase_price']=htmlentities(stripslashes($row['purchase_price']));
$new_row['l_package']=htmlentities(stripslashes($row['p_packing']));
$new_row['l_disc_price']=htmlentities(stripslashes($row['discount']));
$new_row['l_rack_no']=htmlentities(stripslashes($row['p_rack_no']));
$new_row['l_shelf_no']=htmlentities(stripslashes($row['p_shelf_no']));
$new_row['l_cold_storage']=htmlentities(stripslashes($row['p_cold_storage']));
$new_row['batch_applicable']=htmlentities(stripslashes($row['batch_applicable']));
$new_row['exp_date_applicable']=htmlentities(stripslashes($row['exp_date_applicable']));
$new_row['datepicker_doe_month']=htmlentities(stripslashes($row['str_expiry_month']));
$new_row['datepicker_doe_year']=htmlentities(stripslashes($row['str_expiry_year']));
$row_set[] = $new_row; //build an array
}
echo json_encode($row_set); //format the array into json data
}else{
$row_set[] = array();
echo json_encode($row_set);
}
}
}
public function get_formulation_desc(){
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$sql="select * from drugs_formulation where formulation_desc like '".$q."%'";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$new_row['label']=htmlentities(stripslashes($row['formulation_desc']));
$new_row['value']=htmlentities(stripslashes($row['formulation_desc']));
$row_set[] = $new_row; //build an array
}
echo json_encode($row_set); //format the array into json data
}
}
}
public function go_final()
{
$this->load->model('Medical_M');
$inv_id=$this->input->post('inv_id');
$doc_id=$this->input->post('doc_id');
$doc_name=$this->input->post('doc_name');
$remark_ipd=$this->input->post('input_remark_ipd');
$patient_code=$this->input->post('patient_code');
$custmer_Name=$this->input->post('custmer_Name');
$ipd_credit=$this->input->post('ipd_credit');
$org_credit=$this->input->post('org_credit');
$inv_date=$this->input->post('inv_date');
$sql="select * from patient_master where p_code='".$patient_code."' ";
$query = $this->db->query($sql);
$person_info= $query->result();
$sql="select * from doctor_master where id='".$doc_id."' ";
$query = $this->db->query($sql);
$doc_info= $query->result();
$sql="select * from invoice_med_master where id=".$inv_id;
$query = $this->db->query($sql);
$data['invoice_master']= $query->result();
if($this->ion_auth->in_group('InvoiceDateChanged') || $this->ion_auth->in_group('admin'))
{
$inv_date=str_to_MysqlDate($inv_date);
}else{
$inv_date=$data['invoice_master'][0]->inv_date;
}
if(count($person_info)>0)
{
$patient_id=$person_info[0]->id;
$patient_code_u=$patient_code;
$custmer_Name=$person_info[0]->p_fname;
}else{
$patient_id=0;
$patient_code_u='';
}
$refername=$doc_name;
if(count($doc_info)>0)
{
$refername=$doc_info[0]->p_fname;
}
$data = array(
'patient_id' => $patient_id,
'patient_code' => $patient_code_u,
'doc_id' => $doc_id,
'doc_name' => $refername,
'inv_name' => $custmer_Name,
'remark_ipd'=>$remark_ipd,
'ipd_credit'=>$ipd_credit,
'case_credit'=>$org_credit,
'inv_date' => $inv_date
);
$inser_id=$this->Medical_M->update_in_upv_item($data,$inv_id);
$this->Medical_M->update_invoice_group($inv_id);
$this->Medical_M->update_invoice_final($inv_id);
}
public function getDrugTable()
{
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'item_id',
1 => 'itemname',
2 => 'formulation',
3=> 'genericname',
5=> 'company_name_idx',
4=> 'mrp'
);
// getting total number records without any search
$sql_f_all = "select * ";
$sql_count="Select count(*) as no_rec ";
$sql_from=" from drug_temp ";
$total_sql=$sql_count.$sql_from;
$query = $this->db->query($total_sql);
$data['total_rec']= $query->result();
$totalData=$data['total_rec'][0]->no_rec;
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql_where=" WHERE 1 = 1";
$sql_where_flag=0;
// getting records as per search parameters
if( !empty($requestData['columns'][0]['search']['value']) ){ //item_id
$sql_where.=" AND item_id LIKE '".$requestData['columns'][0]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][1]['search']['value']) ){ //itemname
$sql_where.=" AND itemname LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][2]['search']['value']) ){ //dosage
$sql_where.=" AND formulation LIKE '%".$requestData['columns'][2]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][3]['search']['value']) ){ //formulation
$sql_where.=" AND genericname LIKE '%".$requestData['columns'][3]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][4]['search']['value']) ){ //therapeutic
$sql_where.=" AND company_name_idx LIKE '%".$requestData['columns'][4]['search']['value']."%' ";
$sql_where_flag=1;
}
$total_filer_sql=$sql_count.$sql_from.$sql_where;
$query = $this->db->query($total_filer_sql);
$data['total_rec_filter']= $query->result();// when there is a search parameter then we have to modify total number filtered rows as per search result.
$totalFiltered=$data['total_rec_filter'][0]->no_rec;
$sql_order=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length
$Result_sql=$sql_f_all.$sql_from.$sql_where.$sql_order;
$query = $this->db->query($Result_sql);
$rdata= $query->result_array();
$output = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => array(),
"sql" => $Result_sql
);
foreach($rdata as $aRow)
{
$row = array();
foreach($columns as $col)
{
$row[] = $aRow[$col];
}
$output['data'][] = $row;
}
echo json_encode($output); // send data as json format
}
public function getInvoiceTable()
{
//Single Store Remove Store ID feild
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 => 'inv_med_code',
1 => 'inv_name',
2 => 'Code',
3=> 'inv_date_str',
4=> 'net_amount',
5=> 'payment_received',
6=> 'payment_balance',
7=> 'id',
8=> 'ipd_status',
9=> 'org_status',
10=> 'ipd_credit_type',
11=> 'org_credit_type'
);
// getting total number records without any search
$sql_f_all = "select m.inv_med_code,m.inv_name,
Concat(if(m.patient_code<>'',Concat(m.patient_code,' '),''),
if(m.ipd_code<>'',Concat('',m.ipd_code,' '),''),
if(m.case_id>0,Concat(o.case_id_code,' '),'')) as Code ,
m.inv_date,Date_Format(m.inv_date,'%d-%m-%Y') as inv_date_str,
m.doc_name,m.net_amount,m.payment_received,m.payment_balance,m.id,i.ipd_status,
o.status as org_status,
m.ipd_credit as ipd_credit_type,m.case_credit as org_credit_type ";
$sql_count="Select count(*) as no_rec ";
$sql_from=" from (invoice_med_master m left join ipd_master i on m.ipd_id=i.id )
left join organization_case_master o on m.case_id=o.id ";
$total_sql=$sql_count.$sql_from;
$query = $this->db->query($total_sql);
$data['total_rec']= $query->result();
$totalData=$data['total_rec'][0]->no_rec;
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
if($this->ion_auth->in_group('MedicalStoreAdmin'))
{
$sql_where=" WHERE sale_return=0 ";
}else{
$sql_where=" WHERE sale_return=0 and inv_date >= date_add(sysdate(),interval -50 day) ";
}
$sql_where_flag=0;
// getting records as per search parameters
if( !empty($requestData['columns'][0]['search']['value']) ){ //inv_med_code
$sql_where.=" AND inv_med_code LIKE '%".$requestData['columns'][0]['search']['value']."' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][1]['search']['value']) ){ //inv_name
$stext=$requestData['columns'][1]['search']['value'];
if(is_numeric($stext) && strlen($stext)>3)
{
$sql_where.=" AND inv_phone_number LIKE '".$stext."%' ";
}else{
$sql_where.=" AND inv_name LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
}
$sql_where_flag=1;
}
if( !empty($requestData['columns'][2]['search']['value']) ){ //patient_code
$sql_where.=" AND (patient_code LIKE '%".$requestData['columns'][2]['search']['value']."' OR
m.ipd_code LIKE '%".$requestData['columns'][2]['search']['value']."' OR
o.case_id_code LIKE '%".$requestData['columns'][2]['search']['value']."' )";
$sql_where_flag=1;
}
$total_filer_sql=$sql_count.$sql_from.$sql_where;
$query = $this->db->query($total_filer_sql);
$data['total_rec_filter']= $query->result();// when there is a search parameter then we have to modify total number filtered rows as per search result.
$totalFiltered=$data['total_rec_filter'][0]->no_rec;
$sql_order=" ORDER BY id desc,". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length
$Result_sql=$sql_f_all.$sql_from.$sql_where.$sql_order;
$query = $this->db->query($Result_sql);
$rdata= $query->result_array();
$output = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => array(),
"sql" => $Result_sql
);
foreach($rdata as $aRow)
{
$row = array();
foreach($columns as $col)
{
$row[] = $aRow[$col];
}
$output['data'][] = $row;
}
echo json_encode($output); // send data as json format
}
public function getReturnInvoiceTable()
{
//Single Store Remove Store ID feild
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 => 'inv_med_code',
1 => 'inv_name',
2 => 'Code',
3=> 'inv_date_str',
4=> 'net_amount',
5=> 'payment_received',
6=> 'payment_balance',
7=> 'id',
8=> 'ipd_status',
9=> 'org_status',
10=> 'ipd_credit_type',
11=> 'org_credit_type'
);
// getting total number records without any search
$sql_f_all = "select m.inv_med_code,m.inv_name,
Concat(if(m.patient_code<>'',Concat(m.patient_code,' '),''),
if(m.ipd_code<>'',Concat('',m.ipd_code,' '),''),
if(m.case_id>0,Concat(o.case_id_code,' '),'')) as Code ,
m.inv_date,Date_Format(m.inv_date,'%d-%m-%Y') as inv_date_str,
m.doc_name,m.net_amount,m.payment_received,m.payment_balance,m.id,i.ipd_status,
o.status as org_status,
m.ipd_credit as ipd_credit_type,m.case_credit as org_credit_type ";
$sql_count="Select count(*) as no_rec ";
$sql_from=" from (invoice_med_master m left join ipd_master i on m.ipd_id=i.id )
left join organization_case_master o on m.case_id=o.id ";
$total_sql=$sql_count.$sql_from;
$query = $this->db->query($total_sql);
$data['total_rec']= $query->result();
$totalData=$data['total_rec'][0]->no_rec;
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
if($this->ion_auth->in_group('MedicalStoreAdmin'))
{
$sql_where=" WHERE sale_return=1 ";
}else{
$sql_where=" WHERE sale_return=1 and inv_date >= date_add(sysdate(),interval -50 day) ";
}
$sql_where_flag=0;
// getting records as per search parameters
if( !empty($requestData['columns'][0]['search']['value']) ){ //inv_med_code
$sql_where.=" AND inv_med_code LIKE '%".$requestData['columns'][0]['search']['value']."' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][1]['search']['value']) ){ //inv_name
$stext=$requestData['columns'][1]['search']['value'];
if(is_numeric($stext) && strlen($stext)>3)
{
$sql_where.=" AND inv_phone_number LIKE '".$stext."%' ";
}else{
$sql_where.=" AND inv_name LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
}
$sql_where_flag=1;
}
if( !empty($requestData['columns'][2]['search']['value']) ){ //patient_code
$sql_where.=" AND (patient_code LIKE '%".$requestData['columns'][2]['search']['value']."' OR
m.ipd_code LIKE '%".$requestData['columns'][2]['search']['value']."' OR
o.case_id_code LIKE '%".$requestData['columns'][2]['search']['value']."' )";
$sql_where_flag=1;
}
$total_filer_sql=$sql_count.$sql_from.$sql_where;
$query = $this->db->query($total_filer_sql);
$data['total_rec_filter']= $query->result();// when there is a search parameter then we have to modify total number filtered rows as per search result.
$totalFiltered=$data['total_rec_filter'][0]->no_rec;
$sql_order=" ORDER BY id desc,". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length
$Result_sql=$sql_f_all.$sql_from.$sql_where.$sql_order;
$query = $this->db->query($Result_sql);
$rdata= $query->result_array();
$output = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => array(),
"sql" => $Result_sql
);
foreach($rdata as $aRow)
{
$row = array();
foreach($columns as $col)
{
$row[] = $aRow[$col];
}
$output['data'][] = $row;
}
echo json_encode($output); // send data as json format
}
public function getStockDrugTable()
{
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'ss_no',
1 =>'item_code',
2 => 'item_name',
3 => 'formulation',
4 => 'rack_no',
5 => 'shelf_no',
6 => 'batch_no',
7 => 'total_unit',
8 => 'expiry_date',
9 => 'mrp',
10 => 'update_stock_qty'
);
// getting total number records without any search
$sql_f_all = "select * ";
$sql_count="Select count(*) as no_rec ";
$sql_from=" from stock_addition ";
$total_sql=$sql_count.$sql_from;
$query = $this->db->query($total_sql);
$data['total_rec']= $query->result();
$totalData=$data['total_rec'][0]->no_rec;
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql_where=" WHERE 1 = 1 ";
$sql_where_flag=0;
// getting records as per search parameters
if( !empty($requestData['columns'][0]['search']['value']) ){ //item_id
$sql_where.=" AND item_code LIKE '".$requestData['columns'][0]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][1]['search']['value']) ){ //itemname
$sql_where.=" AND item_name LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][2]['search']['value']) ){ //dosage
$sql_where.=" AND formulation LIKE '%".$requestData['columns'][2]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][3]['search']['value']) ){ //dosage
$sql_where.=" AND rack_no LIKE '%".$requestData['columns'][3]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][4]['search']['value']) ){ //dosage
$sql_where.=" AND shelf_no LIKE '%".$requestData['columns'][4]['search']['value']."%' ";
$sql_where_flag=1;
}
if( !empty($requestData['columns'][5]['search']['value']) ){ //dosage
$sql_where.=" AND batch_no LIKE '%".$requestData['columns'][5]['search']['value']."%' ";
$sql_where_flag=1;
}
$total_filer_sql=$sql_count.$sql_from.$sql_where;
$query = $this->db->query($total_filer_sql);
$data['total_rec_filter']= $query->result();// when there is a search parameter then we have to modify total number filtered rows as per search result.
$totalFiltered=$data['total_rec_filter'][0]->no_rec;
$sql_order=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length
$Result_sql=$sql_f_all.$sql_from.$sql_where.$sql_order;
$query = $this->db->query($Result_sql);
$rdata= $query->result_array();
$output = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => array(),
"sql" => $Result_sql
);
foreach($rdata as $aRow)
{
$row = array();
foreach($columns as $col)
{
$row[] = $aRow[$col];
}
$output['data'][] = $row;
}
echo json_encode($output); // send data as json format
}
public function confirm_payment()
{
if (!$this->input->is_ajax_request()) { exit('no valid req.'); }
$this->load->model('Medical_M');
$invoice_id=$this->input->post('med_invoice_id');
$input_amount_paid=$this->input->post('input_amount_paid');
$sql="select * from invoice_med_master where id='".$invoice_id."'";
$query = $this->db->query($sql);
$inv_master= $query->result();
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$user_name = $user->first_name.''. $user->last_name;
$showcontent1='