Commits

Anonymous committed 5b7d95b

save to billLease table and add some columns to lease table

Comments (0)

Files changed (8)

application/modules/financial/models/AccountTransaction.php

     // 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(){	
-	//$alModel = new Financial_Model_AccountLink();
-	
-	//foreach( $links as $id=>$billObj ){    
-	//    $accountLink = $alModel->findById( $billObj->getAccountLinkId() );	    
-	    
-	    // fetch account ids
-	 //   $debit = $accountLink->getDebitAccountId();
-	 //   $credit = $accountLink->getCreditAccountId();
-	 
+    public function saveAccountTransaction(){		 
 	    $debit = $this->accountLink->getDebitAccountId();
-	    $credit = $this->accountLink->getCreditAccountId();
-	    
-	   // var_dump( $this->getAccountLink() ); die;
-	   // var_dump( $debit );
-	   // var_dump( $credit ); 
-	    
-	    /*
-	    if( $values )
-		$this->setAmount( $values[$billObj->getId()] );
-	    else 	
-		$this->setAmount( $billObj->getOriginalAmountDue() );	    
-	    
-	    if( !$values['datePosted'] )
-		$this->setDatePosted( date('Y-m-d') );
-	    else	
-	        $this->setDatePosted( $values['datePosted'] );
-	    */
+	    $credit = $this->accountLink->getCreditAccountId();	    
+	  
 	    if( !$this->getDatePosted() )
 	        $this->setDatePosted( date('Y-m-d') );    
 	    

application/modules/financial/models/BillCreation.php

     /**
      * Currently used for creating individual bills
      */
-    public function createBill(){
-	//$db = Zend_Registry::get('db'); // used for all in transaction
-	//$this->db->beginTransaction();	
+    public function createBill(){		
 	
-	/*  bill
-	    bill unit
+	/*  bill	    
 	    transaction
 	    billTransaction
 	    accountTransaction
+	    billLease
 	*/	
 	
 	try{
-	    //var_dump( $formValues );  die;
-	    // set all to use the same db adapter so the transaction can be rolled back if smtg fails
-	  //  $formValues['dbAdapter'] = $db;
-	  //  $this->setDbAdapter( $db );
+	    //  1.  Bill
+	    $billId = $this->saveBill();    
+	   
 	    
-	    // save bill to bill and billUnit tables
-	    // needs accountLinkId, originalAmountDue, dueDate, referenceNumber
-	    //$bill = $this->saveBill( $formValues );
-	    $billId = $this->saveBill();
-	    
-	    /*
-	    // 2. Set transaction	    
-	    $transaction = new Financial_Model_Transaction( array( 'dbAdapter'=> $db) );
-	    if( isset($formValues['comment']) )
-		$transaction->setComment( $formValues['comment'] );
-	    $transaction->setAction( 'create bill' );
-	    $formValues['transactionId'] = $transaction->save();    	    	    
-	    */
-	    
+	    // 2.  Transaction
 	    if( !isset( $this->billTransactionId ) )
-	        $this->billTransactionId = $this->transactionModel->save();   		    
-	    
-            /*		
-	    // insert into billTransaction
-	    $formValues['billId'] = $bill->getId();
-	    $billTrans = new Financial_Model_BillTransaction( $formValues );
-	    $billTrans->save(); 		     
-	    */	
-	    	
+	        $this->billTransactionId = $this->transactionModel->save();   		    	    
+           
+	    // 3.  Bill Transaction	
 	    $this->billTransactionModel->setBillId( $billId );     
 	    $this->billTransactionModel->setTransactionId( $this->billTransactionId );
-            $this->billTransactionModel->save();
-		
-	    /*		     
-	    // insert into accountTransaction table
-	    $acctTrans = new Financial_Model_AccountTransaction( $formValues );
+            $this->billTransactionModel->save();		
 	    
-	    if( isset($formValues['datePosted']) )
-		$transaction->setComment( $formValues['comment'] );
-		
-	    $acctTrans->saveAccountTransaction( $formValues, array($bill) );	    	
-	    */
+	    // 3.  Account Transaction
 	    $billObj = $this->billModel->findById( $billId );
 	    
 	    $alModel = new Financial_Model_AccountLink();
 	    $this->accountTransactionModel->setTransactionId($this->billTransactionId);
 	    $this->accountTransactionModel->saveAccountTransaction();
 	    
-	    //TODO!!! save into billLease table!!
-	    
-	    //$this->db->commit();	    
+	    return $billId;    	    
 	}
 	catch ( Exception $e) {
 	    // rollback here kills the entire transaction.

application/modules/financial/models/BillLease.php

+<?php
+/**
+ * Created on Mar 27, 2010 by rnelson
+ * @name apmgr
+ * @package application.modules.financial.models
+ * <p>
+ * Stores the billLease
+ * * </p>
+ */
+	
+	
+class Financial_Model_BillLease extends ZFModel_ParentModel {    
+
+    /**
+    *@var billId
+    */        
+    protected $billId;
+    
+    /**
+    *@var leaseId
+    */        
+    protected $leaseId;
+
+    /**
+    *@var leaseScheduleId
+    */        
+    protected $leaseScheduleId; 
+      
+    /**
+    * Constructor of this object
+    */
+    public function __construct(array $options = null) {	
+        parent::__construct( $options );                       
+        $this->setDbTable('Financial_Model_DbTable_BillLease'); 
+    }    
+         
+   /**
+    * billId
+    */ 
+    public function setBillId( $var ) {
+        $this->billId = $var;
+    }
+    
+    public function getBillId() {
+        return $this->billId;
+    }
+    
+    /**
+    * leaseId
+    */ 
+    public function setLeaseId( $var ) {
+        $this->leaseId = $var;
+    }
+    
+    public function getLeaseId() {
+        return $this->leaseId;
+    }
+    
+     /**
+      * leaseScheduleItemId
+      */ 
+    public function setLeaseScheduleId( $var ) {
+        $this->leaseScheduleId = $var;
+    }
+    
+    public function getLeaseScheduleId() {
+        return $this->leaseScheduleId;
+    }  
+}
+?>

application/modules/financial/models/BillUnit.php

-<?php
-/**
- * Created on Feb 8, 2010 by rnelson
- * @name apmgr
- * @package application.modules.financial.models
- * <p>
- * Stores the billType
- * * </p>
- */
-	
-	
-class Financial_Model_BillUnit extends ZFModel_ParentModel {    
-
-    /**
-    *@var billId
-    */        
-    protected $billId;
-
-    /**
-    *@var unitId
-    */        
-    protected $unitId; 
-      
-    /**
-    * Constructor of this object
-    */
-    public function __construct(array $options = null) {	
-        parent::__construct( $options );                       
-        $this->setDbTable('Financial_Model_DbTable_BillUnit'); 
-    }    
-         
-   /**
-    * billId
-    */ 
-    public function setBillId( $var ) {
-        $this->billId = $var;
-    }
-    
-    public function getBillId() {
-        return $this->billId;
-    }
-    
-     /**
-      * unitId
-      */ 
-    public function setUnitId( $var ) {
-        $this->unitId = $var;
-    }
-    
-    public function getUnitId() {
-        return $this->unitId;
-    }  
-}
-?>

application/modules/financial/models/DbTable/BillLease.php

+<?php
+/**
+ * Created on Mar 27, 2010 by rnelson
+ * @name apmgr
+ * @package application.modules.financial.models.DTable
+ * <p>
+ * Contains the table for billLease
+ * </p>
+ */
+class Financial_Model_DbTable_BillLease extends Zend_Db_Table_Abstract {
+    protected $_name = 'billLease';        
+}
+?>

application/modules/financial/models/DbTable/BillUnit.php

-<?php
-/**
- * Created on Feb 8, 2010 by rnelson
- * @name apmgr
- * @package application.modules.financial.models.DTable
- * <p>
- * Contains the table for billUnit
- * </p>
- */
-class Financial_Model_DbTable_BillUnit extends Zend_Db_Table_Abstract {
-    protected $_name = 'billUnit';        
-}
-?>

application/modules/unit/models/Lease.php

     /**
     *@var effectiveDate
     */        
-    protected $effectiveDate;  
+    protected $effectiveDate;
+    
+    /**
+    *@var lastDay
+    */        
+    protected $lastDay; 
    
    /**
     *@var unitId
     }    
          
    /**
-    * effectiveDate
+    * startDate
       */ 
     public function setEffectiveDate( $var ) {
         $this->effectiveDate = $var;
         return $this->effectiveDate;
     }
     
+     /**
+    * lastDay
+      */ 
+    public function setLastDay( $var ) {
+        $this->lastDay = $var;
+    }
+    
+    public function getLastDay() {
+        return $this->lastDay;
+    }
+    
     /**
     * unitId
       */ 

application/modules/unit/models/LeaseWizard.php

 	$latestSchedule = $rentSchedule->getLatestSchedule( $unit->getUnitModelId() );
 	
 	return $latestSchedule;
-    }   
-    
-    /**
-     *  These variables are saved at the end of the wizard to their respective tables and then deleted from the cache
-     **/
-    /*
-    function setWizardVariable( $variables=array() ){
-	$cache = Zend_Registry::get('cache');	
-	
-	foreach( $variables as $key=>$item ){
-	    $cache->save( $item, $key );
-	}
-    }
-    
-    function getWizardVariable( $key ){
-	$cache = Zend_Registry::get('cache');	
-	return $cache->load( $key );
-    }
-    */    
+    }     
     
     /**
      * Format vars for the lease model save function
 	*/	
 	
 	try {
-	    $db->beginTransaction();
-	    //var_dump( $formValues );  die;
+	    $db->beginTransaction();	    
 	    // set all to use the same db adapter so the transaction can be rolled back if smtg fails
 	    
 	    $formValues['dbAdapter'] = $db;
 	    
 	    // TODO:  make little functions for this, maybe	    
+	    // grab the numMonths on the rentschedule
+	    $rsi = new Unit_Model_ModelRentScheduleItem($formValues);	    
+	    $rentScheduleItem = $rsi->findById( $this->getModelRentScheduleItemId() );    
 	    
+	    
+	    
+	    // Set End Date
+	    $months = $rentScheduleItem->getNumMonths();
+	    $endDate = new Zend_Date($this->getEffectiveDate(),'YYYY-MM-dd' );
+	    $endDate->add( $months, Zend_Date::MONTH);
+	    //var_dump( $endDate->toString('YYYY-MM-dd') );
+	    $endDate->sub( 1, Zend_Date::DAY);
+	    //var_dump( $endDate->toString('YYYY-MM-dd') );
+	    //die;
+	
 	    // Set and save to lease table
 	    $lease = new Unit_Model_Lease( $formValues );
 	    $lease->setEffectiveDate( $this->getEffectiveDate() );
 	    $lease->setUnitId( $this->getUnitId() );
-	    $lease->setModelRentScheduleId( $this->getModelRentScheduleId()  );	    
+	    $lease->setModelRentScheduleId( $this->getModelRentScheduleId()  );
+	    $lease->setLastDay( $endDate->toString('YYYY-MM-dd') );
+		
+	    $billCreation = new Financial_Model_BillCreation( array( 'db'=>$db ) );	
+	    $billModel = $billCreation->getBillModel();	
+	    // TODO:  Make sure this shit is localized - damn you zend_date		
+	    
+	    
 	    $leaseId = $lease->save();
 	    
+	    // ties bill to lease schedule item
+	    $billLeaseModel = new Financial_Model_BillLease( array( 'db'=>$db ) );	    
+	    $billLeaseModel->setLeaseId( $leaseId );
+	    
 	    // Set and save discounts to leaseDiscount table
 	    $leaseSchedule = new Unit_Model_LeaseSchedule( $formValues );
-	    $leaseSchedule->setLeaseId( $leaseId );
+	    $leaseSchedule->setLeaseId( $leaseId );    	    
 	    
-	    // grab the numMonths on the rentschedule
-	    $rsi = new Unit_Model_ModelRentScheduleItem($formValues);	    
-	    $rentScheduleItem = $rsi->findById( $this->getModelRentScheduleItemId() );
-	    //var_dump($this); die;
-	    
+	    // set discounts
 	    $discount = $this->getDiscount();
-	    
-	    for ( $i=1;  $i <= $rentScheduleItem->getNumMonths(); $i++ ) {
-		$disc = ( isset( $discount[$i] ) )? $discount[$i] : 0;
-		
-	        $leaseSchedule->setMonth( $i );
-		$leaseSchedule->setDiscount( $disc );
-		$leaseSchedule->save();
-	    }
-	    
-	    // save tenets
-	    
+	   	    
+	    // save tenets	    
 	    $tenetModel = new Unit_Model_Tenet($formValues);
 	    $tenetModel->setLeaseId( $leaseId );
 	   
 		$tenetModel->save();
 	    }    	    	    	    	           	      
 	     
-	    $rent = $rentScheduleItem->getRentAmount();
+	    $rent = $rentScheduleItem->getRentAmount();    	        
 	    
-	    $billCreation = new Financial_Model_BillCreation( array( 'db'=>$db ) );	    
-	    
-	    $billModel = $billCreation->getBillModel();
 	    // set common bill info
 	    $billModel->setAccountLinkId( $this->getAccountLinkId() );
 	    
 	    $transactionModel->setAction('lease creation');
 	    $transactionModel->setComment( $this->getComment());	    
 	    
+	    // set account transaction info
 	    $accountTransactionModel = $billCreation->getAccountTransactionModel();
 	    $accountTransactionModel->setReferenceNumber( $this->getReferenceNumber() );
-	    $accountTransactionModel->setAccountLink( $this->getAccountLink() );
-	    	    	    	        
+	    $accountTransactionModel->setAccountLink( $this->getAccountLink() );	    
+	    	    	    	    	        
 	    for ( $i=1;  $i <= $rentScheduleItem->getNumMonths(); $i++ ) {
 		// amount from rent model - discount = original amount due
 		$disc = ( isset( $discount[$i] ) )? $discount[$i] : 0;
 		
 		// TODO:  Make sure this shit is localized - damn you zend_date		
 		$billModel->setDueDate( $date->toString('YYYY-MM-dd') );
-		$accountTransactionModel->setDatePosted( $date->toString('YYYY-MM-dd') );
+		$accountTransactionModel->setDatePosted( $date->toString('YYYY-MM-dd') );		
 		
-	        $billCreation->createBill();
+		// save lease schedule item
+		$leaseSchedule->setMonth( $i );
+		$leaseSchedule->setDiscount( $disc );
+		$leaseScheduleItemId = $leaseSchedule->save();	
+		
+		// create bill
+	        $billId = $billCreation->createBill();
 		
 		// TODO add to billLease table
+		$billLeaseModel->setBillId( $billId );
+		$billLeaseModel->setLeaseScheduleId( $leaseScheduleItemId );		
+		$billLeaseModel->save();
 	    } 
 	    $db->commit();
 	}