Source

Apmgr / application / modules / financial / models / AccountTransaction.php

Full commit
<?php
/**
 * Created on Feb 6, 2010 by rnelson
 * @name apmgr
 * @package application.modules.financial.models
 * <p>
 * Stores the accountTransaction
 * * </p>
 */
	
	
class Financial_Model_AccountTransaction extends ZFModel_ParentModel {    

    /**
    *@var datePosted
    */        
    protected $datePosted; 
    
    /**
    *@var accountId
    */        
    protected $accountId; 
   
    /**
    *@var transactionId
    */        
    protected $transactionId;
    
    /**
    *@var referenceNumber
    */        
    protected $referenceNumber;
    
    /**
    *@var side
    */        
    protected $side;
    
    /**
    *@var amount
    */        
    protected $amount; 
      
    protected $accountLink; // not in db - used for saving  (obj)
      
    /**
    * Constructor of this object
    */
    public function __construct(array $options = null) {	
        parent::__construct( $options );                       
        $this->setDbTable('Financial_Model_DbTable_AccountTransaction'); 
    }    
         
   /**
    *  datePosted
      */ 
    public function setDatePosted( $var ) {
        $this->datePosted = $var;
    }
    
    public function getDatePosted() {
        return $this->datePosted;
    }
    
     /**
    *  accountId
      */ 
    public function setAccountId( $var ) {
        $this->accountId = $var;
    }
    
    public function getAccountId() {
        return $this->accountId;
    }
    
      /**
    *  transactionId
      */ 
    public function setTransactionId( $var ) {
        $this->transactionId = $var;
    }
    
    public function getTransactionId() {
        return $this->transactionId;
    }
    
    /**
    *  referenceNumber
      */ 
    public function setReferenceNumber( $var ) {
        $this->referenceNumber = $var;
    }
    
    public function getReferenceNumber() {
        return $this->referenceNumber;
    }
    
    /**
    *  side
      */ 
    public function setSide( $var ) {
        $this->side = $var;
    }
    
    public function getSide() {
        return $this->side;
    }
    
    /**
    *  amount
      */ 
    public function setAmount( $var ) {
        $this->amount = $var;
    }
    
    public function getAmount() {
        return $this->amount;
    }
    
   /**
    *  accountLink
    */ 
    public function setAccountLink( $var ) {
        $this->accountLink = $var;
    }
    
    public function getAccountLink() {
        return $this->accountLink;
    }
    
    
    // TODO:  This will need to be optimized in the future to pull the accountLink account ids instead of the inefficient, lame thing here
    // This function must set two records - a debit and credit for balance
    // $values holds the amount due, links  holds the bill object records that hold the accountLinkId, which then has the accountId
    //public function saveAccountTransaction( $values=array(), $links ){
    public function saveAccountTransaction(){		 
	    $debit = $this->accountLink->getDebitAccountId();
	    $credit = $this->accountLink->getCreditAccountId();	    
	  
	    if( !$this->getDatePosted() )
	        $this->setDatePosted( date('Y-m-d') );    
	    
	    // save debit record
	    $this->setAccountId( $debit );
	    $this->setSide('debit');
	    $this->save();
	    
	    // save credit record
	    $this->setAccountId( $credit );
	    $this->setSide('credit');
	    $this->save();	    
	}	
    //}    
}
?>