<?php
function addreceipt($postdata,$xcrud){

			$p = $postdata->get('payment_method');
	$bank= $postdata->get('electronic_bank_details');
	$bankdate = $postdata->get('electronic_bank_date');
	$clientaccount = $postdata->get('account_number');
	$ref = $postdata->get('reference');
	$amount = $postdata->get('ovamount');
	

	
   
$db41 = Xcrud_db::get_instance();
	    $query = "SELECT 
		            typeno
					  
		          FROM systypes
				    
				   WHERE typeid = '12'";
        
        $db41->query($query);
        $out41 = $db41->result();
        foreach($out41 as $output41){
			
			$current=$output41['typeno'];
			
        } 

	$newreceiptno = $current + 1;
	
	$date = date('Y-m-d H:i:s');
$postdata->set('transno', $newreceiptno);
	$postdata->set('inputdate', $date);
	$postdata->set('entered_date', $date);
	
	//now systypes
	
	
	$db43 = Xcrud_db::get_instance();
	    $query = "UPDATE systypes
		               
					  
		         set  typeno = '" . $newreceiptno . "'
				 
				 WHERE typeid = '12'";
        
        $db43->query($query);
	
	
	
       	if (($p =="EFPOS") || ($p == "Direct Deposit") || ($p == "Credit Card")) {
		
		
		$postdata->set('receipt_banked', '1');
		
		
		
			
			
			
	$db431= Xcrud_db::get_instance();
	    $query11 = "INSERT INTO banktrans (type,
								transno,
								client_account_number,
								bankact,
								ref,
								exrate,
								
								transdate,
								banktranstype,
								amount,
								currcode
								
								)
		VALUES (
			12,
			'" . $newreceiptno. "',
			'" . $clientaccount. "',
			'" . $bank. "',
			'" . $ref. "',
			'1',
			
			'" .$bankdate . "',
			'" .$p. "',
			'" . -$amount . "',
			'FJD'
		)";
        
        $db431->query($query11);
			
			
			
			
			
			
			
			
		
		
		
		
	}
	
	
	
}
function updatereceipt($postdata,$xcrud){
	
		$p = $postdata->get('payment_method');
	
		$bank= $postdata->get('electronic_bank_details');
	$bankdate = $postdata->get('electronic_bank_date');
	$clientaccount = $postdata->get('account_number');
	$ref = $postdata->get('reference');
	$amount = $postdata->get('ovamount');
	$newreceiptno = $postdata->get('transno');
	
	if (($p =="EFPOS") || ($p == "Direct Deposit") || ($p == "Credit Card")) {
		
		
		$postdata->set('receipt_banked', '1');
		
		
		
			
			
			
	$db431= Xcrud_db::get_instance();
	    $query11 = "INSERT INTO banktrans (type,
								transno,
								client_account_number,
								bankact,
								ref,
								exrate,
								
								transdate,
								banktranstype,
								amount,
								currcode
								
								)
		VALUES (
			12,
			'" . $newreceiptno. "',
			'" . $clientaccount. "',
			'" . $bank. "',
			'" . $ref. "',
			'1',
			
			'" .$bankdate . "',
			'" .$p. "',
			'" . -$amount . "',
			'FJD'
		)";
        
        $db431->query($query11);
			
			
			
			
			
			
			
			
		
		
	}
	
}
