<?php

if (count(get_included_files()) == 0){

include 'connections/customPDO.php';

}

class ProccessClaimNo{



    private	$mysqllocal;

	private $inscompany;

	private $member_no;

	private $companyid;

	private $providerid;

	private $typeofvisit;

	private $providerid_id_for;

	private $userid;

	private $attending_officer;





function ProccessClaimNo($local)

{

	# code...

	$this->mysqllocal=$local;

}





function checkUserid($value,$at)

{

	# code...

	$this->userid=$this->mysqllocal->quote($value);

	



	$ins=$this->mysqllocal->selectData("SELECT * FROM users WHERE id=".$this->userid);

if ($ins==false) {

	# code...

	return false;

}else{



	$full=$ins[0]["surname"]." ".$ins[0]["firstnames"];

	if(strcasecmp(trim($at),$full)==0){

	return true;

}else{return false;}

}

}





function get_process_claim_no($inscompany, $member_no, $providerid, $typeofvisit,$userid,$attending_officer){

	

$REQUESTMODE='API';

$this->inscompany=$this->mysqllocal->quote($inscompany);

$this->member_no=$this->mysqllocal->quote($member_no);

$this->providerid=$this->mysqllocal->quote($providerid);

$this->providerid_id_for=$this->mysqllocal->quote($providerid);

$this->typeofvisit=$this->mysqllocal->quote($typeofvisit);

$this->userid=$this->mysqllocal->quote($userid);

$this->attending_officer=$this->mysqllocal->quote($attending_officer);







$query_rsodest_claim = $this->mysqllocal->selectData("select *, DATE_FORMAT(datetimeadded, '%e %b %Y %r') as dateprocessing from process_claim_no where ins_company=".$this->inscompany." and member_no=".$this->member_no." and provider_id=".$this->providerid." and status='In Use'");



	

if($query_rsodest_claim==false){

	

	$query_rsodest_provider_id =$this->mysqllocal->selectData( "select * from insurance_company where company_code=".$this->inscompany);

	$totalRows_rsodest_pin=1;	

				

if($totalRows_rsodest_pin>0){

	

	$characters = array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z", "1","2","3","4","5","6","7","8","9");

		$PASSSALT=$characters[rand(0,32)].$characters[rand(0,32)];

		

		$characters = array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z", "1","2","3","4","5","6","7","8","9");

		$VALIDSALT=$characters[rand(0,32)].$characters[rand(0,32)].$characters[rand(0,32)].$characters[rand(0,32)];

		

		

		if($provider_id_for){

		$query_rsodest="INSERT INTO `process_claim_no` ( `provider_id`, `ins_company`, `member_no`, `pass_salt`, `datetimeadded`, `date_added`, `request_mode`, `validation_salt`, `typeofvisit`, `attending_officer`, `provider_id_data_for`,`user_id`) VALUES (".$this->providerid.", ".$this->inscompany.", ".$this->member_no.", '$PASSSALT', NOW(), NOW(), '$REQUESTMODE', '$VALIDSALT', ".$this->typeofvisit.", ".$this->attending_officer.",".$this->providerid_id_for.", ".$this->userid.")";

		}else{

		$query_rsodest="INSERT INTO `process_claim_no` ( `provider_id`, `ins_company`, `member_no`, `pass_salt`, `datetimeadded`, `date_added`, `request_mode`, `validation_salt`, `typeofvisit`, `attending_officer`,`user_id`) VALUES ( ".$this->providerid.", ".$this->inscompany.", ".$this->member_no.",'$PASSSALT', NOW(), NOW(), '$REQUESTMODE', '$VALIDSALT', ".$this->typeofvisit.", ".$this->attending_officer.", ".$this->userid.")";	

		}

		

		//echo $query_rsodest;

		$rsodest = $this->mysqllocal->insertData($query_rsodest);

		$CLAIMID=$this->mysqllocal->lastInsertId ();

		$lenclaim=strlen($CLAIMID);

		$lenprovider=strlen($providerid);

		$claimidzero=str_repeat("0",(4-$lenclaim)).$CLAIMID;

		$provideridzero=str_repeat("0",(4-$lenprovider)).$providerid;

			

	

		$CLAIMNUMBER=$inscompany.$provideridzero.$claimidzero.$PASSSALT.date('y');

		

		

		

		

		$this->mysqllocal->insertData("update process_claim_no set process_claim_no='$CLAIMNUMBER' where id='$CLAIMID'");

		

	$query_rsodest_claim = $this->mysqllocal->selectData("select *, DATE_FORMAT(datetimeadded, '%e %b %Y %r') as dateprocessing  from process_claim_no where ins_company=".$this->inscompany." and member_no=".$this->member_no." and provider_id=".$this->providerid." and id=$CLAIMID");

	

	

	$row_rsodest_claim['total_row']=1;

	$row_rsodest_claim['STATUSCODE']='003';

	$row_rsodest_claim['STATUSMSG']='Authorization Permitted. Process Claim Number Generated.';

	$row_rsodest_claim['ins_company']=$inscompany;

	$row_rsodest_claim['member_no']=$member_no;

	$row_rsodest_claim['process_claim_no']=$CLAIMNUMBER;

	$row_rsodest_claim['typeofvisit']=$typeofvisit;

		

	

}else{

	

	$row_rsodest_claim['total_row']=0;

	$row_rsodest_claim['STATUSCODE']='002';

	$row_rsodest_claim['STATUSMSG']='Authorization Permitted but WRONG CLIENT PIN. PLEASE TRY AGIAN.';

	

	

}







}else{

	

	foreach ($query_rsodest_claim as $key) {

		# code...

		$CLAIMNUMBER=$key["process_claim_no"];

	}

	$row_rsodest_claim['total_row']=1;

	$row_rsodest_claim['STATUSCODE']='003';

	$row_rsodest_claim['STATUSMSG']='Authorization Permitted. Process Claim Number Generated.';

	$row_rsodest_claim['ins_company']=$inscompany;

	$row_rsodest_claim['member_no']=$member_no;

	$row_rsodest_claim['process_claim_no']=$CLAIMNUMBER;

	$row_rsodest_claim['typeofvisit']=$typeofvisit;

	

}



$answer=$row_rsodest_claim;



return $answer;	

}



}

?>