<?php
function calculate_total($postdata,$rostering_timesheet,$xcrud){
$billingid = $postdata->get('bill_id');
	$unitprice = $postdata->get('unit_price');
	$costprice = $postdata->get('cost_price');
   $qty = $postdata->get('qty');
	$total= $unitprice * $qty;
	
	$totalcost = $costprice * $qty;
	
	  $postdata->set('total', $total);
	 $postdata->set('total_cost', $totalcost);

	$db42 = Xcrud_db::get_instance();
	    $query2 = "SELECT 
		             gl_type,
		              sales_gl ,
					  cogs_gl
					  
		          FROM billing 				    
				   WHERE bill_id = '" . $billingid. "'";
        
        $db42->query($query2);
        $out42 = $db42->result();
        foreach($out42 as $output42){
			
			$gltype =$output42['gl_type'];
			
			$salesgl = $output42['sales_gl'];
			$cogsgl = $output42['cogs_gl'];
            
        } 

 if ($gltype == 'single'){
	 
	 //copy glcodes in each line items
	 
	 $postdata->set('sales_gl', $salesgl);
	 $postdata->set('cogs_gl', $cogsgl);
	 
	 
	 
 }
	
	
	
}
function total_hours($postdata,$timesheet,$xcrud){

	$timesheetid = $postdata->get('timesheet_id');
	
	$db42 = Xcrud_db::get_instance();
	    $query2 = "SELECT 
		             guardforceclient.patrollocation
		               
					  
		          FROM timesheetsuva INNER JOIN guardforceclient on
				  timesheetsuva.patrol_location = guardforceclient.clientid
				    
				   WHERE timesuvaid = '" . $timesheetid. "'";
        
        $db42->query($query2);
        $out42 = $db42->result();
        foreach($out42 as $output42){
			
			$patrol =$output42['patrollocation'];
			
			
            
        } 


	
	
	  $postdata->set('patrol_location', $patrol);
	
	//now get total hours in this location
	
  $db41 = Xcrud_db::get_instance();
	    $query = "SELECT 
		             sum(total_hrs) as totalhours
		               
					  
		          FROM timesheetsuvadetails
				    
				   WHERE timesuvaid = '" . $timesheetid. "'";
        
        $db41->query($query);
        $out41 = $db41->result();
        foreach($out41 as $output41){
			
			$totalhours=$output41['totalhours'];
			
			
            
        } 


	
	
	  $postdata->set('total_hours', $totalhours);
	
	//create entries in a poolguard table that will be used to roster guards from and keep a record of which one used and use one is not.
	
	
	
	
}