<?php 
//include('accesscheck2.php');
require_once('Connections/courier.php'); 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
mysql_select_db($database_courier, $courier);

function get_submitted_no_of_transactions($inscompany, $yr, $mth){
$query_rsodest = "select count(id) as number_of_transactions, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and ins_company='$inscompany'"; 

//echo  $query_rsodest ;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_transactions'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_check_submit($inscompany, $yr, $mth){
$query_rsodest = "select * from payment_table_detail where monthofclaim='$mth' and yrofclaim='$yr' and ins_company='$inscompany'"; 

//echo  $query_rsodest ;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$total_row_rsodest=mysql_num_rows($rsodest);
if($total_row_rsodest>0){
$answer="<span style='color: green'><strong>CLOSED</strong></span>";
}else{
$query_rsodest = "select * from payment_table where monthofclaim='$mth' and yrofclaim='$yr' and ins_company='$inscompany'"; 

//echo  $query_rsodest ;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$total_row_rsodest=mysql_num_rows($rsodest);

if($total_row_rsodest>0){
$answer="<span style='color: green'><strong>CLOSED</strong></span>";
}else{
$answer="";		
}

	

}
//$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_submitted($inscompany, $yr, $mth, $claimarea){
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and ins_company='$inscompany' and mode_of_payment='$claimarea'"; 

//echo $query_rsodest;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_claims'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_submitted_in_patient($inscompany, $yr, $mth, $claimarea){
	
if($claimarea=='insurance' || $claimarea=='company'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and ins_company='$inscompany' and mode_of_payment='$claimarea' and type_of_visit='In Patient'"; 
}

if($claimarea=='staff' || $claimarea=='cash'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and mode_of_payment='$claimarea' and type_of_visit='In Patient'"; 
}


//echo $query_rsodest;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_claims'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_submitted_out_patient($inscompany, $yr, $mth, $claimarea){
	
if($claimarea=='insurance' || $claimarea=='company'){		
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and ins_company='$inscompany' and mode_of_payment='$claimarea' and type_of_visit='Out Patient'"; 
}

//echo $claimarea;
if($claimarea=='cash' || $claimarea=='staff'){		
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status='submitted' and mode_of_payment='$claimarea' and (type_of_visit='Out Patient' or type_of_visit='Guest')"; 
}


//echo $query_rsodest;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_claims'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_not_submitted_in_patient($inscompany, $yr, $mth, $claimarea){

if($claimarea=='insurance' || $claimarea=='company'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status is NULL and ins_company='$inscompany' and mode_of_payment='$claimarea' and type_of_visit='In Patient'";
}

if($claimarea=='cash' || $claimarea=='staff'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status is NULL and mode_of_payment='$claimarea' and type_of_visit='In Patient'";
}

//echo $query_rsodest;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_claims'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_not_submitted_out_patient($inscompany, $yr, $mth, $claimarea){
	
	
if($claimarea=='insurance' || $claimarea=='company'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status is NULL and ins_company='$inscompany' and mode_of_payment='$claimarea' and type_of_visit='Out Patient'"; 
}

if($claimarea=='cash' || $claimarea=='staff'){	
$query_rsodest = "select DISTINCT MONTH (date_of_consultation) AS payment_month, YEAR (date_of_consultation) AS payment_year, count(distinct (process_claim_no)) as number_of_claims, sum(qty*unit_price) as sum_of_claims from claims_details where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and submitted_status is NULL and mode_of_payment='$claimarea' and (type_of_visit='Out Patient' or type_of_visit='Guest')"; 
}


//echo $query_rsodest;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());
$row_rsodest = mysql_fetch_assoc($rsodest);
$answer[0]=$row_rsodest['number_of_claims'];
$answer[1]=$row_rsodest['sum_of_claims'];
return $answer;	
}


function get_not_submitted_outpatient_close($inscompany, $yr, $mth){
$submitted_time=gmdate('Y-m-d h:i:s');	
$query_rsodest = "update claims_details set  submitted_status='submitted', submit_time='$submitted_time' where MONTH (date_of_consultation)='$mth' and YEAR (date_of_consultation)='$yr' and type_of_visit='Out-Patient' and ins_company='$inscompany'";

//echo   $query_rsodest;
//exit;    
$rsodest = mysql_query($query_rsodest) or die(mysql_error());

$answer='done';

return $answer;	
}

?>
