<?php
function checksplit($postdata,$split,$purchaseorders){
	

	$orderno =$postdata->get('orderno');
		$glcode =$postdata->get('glcode');
			$jobno =$postdata->get('jobno');
	
// $postdata->set('remarks', $glcode);
 
 
	if ($glcode =='' AND $jobno ==''){	
	$split->set_exception('glcode','Please select either glcode or jobno','error'); 
		
	}
		if ($glcode !=='' AND $jobno !==''){	
	$split->set_exception('glcode','Please select one. Either glcode OR jobno. Cant Select both!','error'); 
		
	}
}
function checksplit_total($postdata,$split,$purchaseorders){
	
	$amount =$postdata->get('amount');
	$on =$postdata->get('orderno');
	
	
	//get total vep
	 $db0 = Xcrud_db::get_instance();
	 $query0 = "SELECT total_vep
					  
		          FROM  purchorders
				  where orderno = '".$on."'
				  				  
				   ";
        
        $db0->query($query0);
        $outm0 = $db0->result();
        foreach($outm0 as $outputm0){
		
			$totalvep = $outputm0['total_vep'];
			
        } 
	 $db1 = Xcrud_db::get_instance();
		 $query1 = "SELECT SUM(amount) as total
					  
		          FROM  purchorder_split
				  where orderno = '".$on."'
				  				  
				   ";
        
        $db1->query($query1);
        $outm1 = $db1->result();
        foreach($outm1 as $outputm1){
		
			$total = $outputm1['total'];
			
        } 
	
	$total = $total + $amount;
	
	$totalvip = $totalvep * 1.15;
	if ($total > $totalvip){
		
		$split->set_exception('amount','Amount Exceeded the total amount PO was raised','error'); 
		
	}
	
}
	
	
		