Source

Apmgr / application / modules / unit / controllers / LeasewizardController.php

<?php
/**
 * Created on Mar 4, 2010 by rnelson
 * @name apmgr
 * @package application.modules.unit.controllers
 * <p>
 * The controller for the lease wizard
 * </p>
 */
 
 class Unit_LeasewizardController extends ZFController_Controller {		 	    
	
    /*
     *  Add user to unit
     */
    public function addusertolistAction() {
       $this->_helper->layout()->disableLayout();
       $this->_helper->viewRenderer->setNoRender(true);

    	$model = new Unit_Model_Tenet();  	
    	    	
    	$userId = $this->getRequest()->getParam('userId');
	
	$leaseWizardModel = new Unit_Model_LeaseWizard();
	$leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	$leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );	
	
	$userModel = new User_Model_User();	
	$tenet = $userModel->findById( $userId );	
	
	$leaseWizardItem->setTenet( $tenet );
	$leaseWizardItem->save();
	
	echo Zend_Json::encode( $leaseWizardItem->getTenet(true) );		
    }  // end addtounit function

    public function removeuserfromlistAction() {
       $this->_helper->layout()->disableLayout();
       $this->_helper->viewRenderer->setNoRender(true);

    	$model = new Unit_Model_Tenet();  	
    	    	
    	$userId = $this->getRequest()->getParam('userId');
	
	$leaseWizardModel = new Unit_Model_LeaseWizard();
	$leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	$leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );			
	
	$leaseWizardItem->removeTenet( $userId );
	$leaseWizardItem->save();
	
	echo Zend_Json::encode( $leaseWizardItem->getTenet(true) );			 
    }  // end addtounit function


        public function confirmationAction()  {
	    $form = new Unit_Form_Confirmation();
	    $form->setForm( array('next'=>'finish') );
	    $this->view->form = $form;
	    $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	      
	    //  display stuff to screen
	    
	    // move in date
	    // model rent schedule
	    // rent discounts
	    // tenets
	    // comments, account link, etc	      
	     
	    $leaseWizardModel = new Unit_Model_LeaseWizard();
	    $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	    $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );
	    
	     
	    $this->view->item = $leaseWizardItem;
	    
	    $item = new Unit_Model_ModelRentScheduleItem();	
	    $scheduleItem = $item->findById( $leaseWizardItem->getModelRentScheduleItemId() );
	    //var_dump($scheduleItem);
	    $this->view->scheduleItem = $scheduleItem;
	      
            if( $this->getRequest()->isPost()	        
	        and $this->_getParam('next') ) {		          
	      
	        //$leaseWizard = new Unit_Model_LeaseWizard();
		$leaseWizardItem->createLease();
		
	      /*	    
	        //$this->_helper->redirector('selecttenets', 'leasewizard', 'unit');
	        $this->_helper->redirector('index', 'leasewizard', 'unit');
	      */
	      
	    }
	    else if( $this->_getParam('previous') )
	        $this->_helper->redirector('selectaccountlink', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
 	}	  
	
	
	/**
	 *  User can enter discounts	   
	 **/
	public function enterdiscountsAction() {           	    	    	   	      
				
	      // load saved wizard variables	               	       	                 	      	     	      
	      $leaseWizardModel = new Unit_Model_LeaseWizard();
	      $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	      $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );	    	
		
	      // fetch model rent schedule item	
	      $model = new Unit_Model_ModelRentScheduleItem();		
	      $scheduleItem = $model->findById( $leaseWizardItem->getModelRentScheduleItemId() );
	      $this->view->scheduleItem = $scheduleItem;		
								
	      $form = new Unit_Form_EnterDiscounts();	
	      $form->setForm( $scheduleItem );
	      
	      $loadDiscount = $leaseWizardItem->getDiscount();
	      if($loadDiscount)
	          $form->populate( $loadDiscount );
	      $this->view->form = $form;		
		
	      if( $this->getRequest()->isPost()
		   and $form->isValid($this->getRequest()->getParams())
		   and $this->_getParam('next') ) {		    
		
	           $formValues = $form->getValues();
		   $discount = array_filter($formValues);		   
		   
		   if( $discount ) {		      
		       $leaseWizardItem->setDiscount( $discount );		       
		       $leaseWizardItem->save();
		   }    				    		    		    
		   $this->_helper->redirector('searchaddtenet', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
		}
		else if( $this->_getParam('previous') )
		    $this->_helper->redirector('selectrentschedule', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
 	}	
	
	/**
	 *  Enter Move In Date = effectiveDate
	 */	 
	public function entermoveindateAction() {
	      
	      $leaseWizardModel = new Unit_Model_LeaseWizard();
	      $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	      $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );	      			      
			      
	      $form = new Unit_Form_EnterMoveInDate();
	      $form->populate( $leaseWizardItem->toArray() );
	      $this->view->form = $form;				
					
	      if( $this->getRequest()->isPost()
	          and $form->isValid($this->getRequest()->getParams()) ) {		    
		  
		  $date = $form->getValue('effectiveDate');		    
		  
		  $leaseWizardItem->setEffectiveDate( $date );
		  $leaseWizardItem->setUnitId( '13' );  // TODO - temp until real unit selection is created	
		  $leaseWizardItem->save();
		      	    
		  $this->_helper->redirector('selectrentschedule', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
	      }        	    	    	    
 	}	
	
	/**
	 *  Stolen from the unit/controllers/TenetController.php file
	 */
	public function searchaddtenetAction() {
	      $form    = new User_Form_AddSearchTenet();			
	
	      $model = new User_Model_User();
	
	      $first = $this->getRequest()->getParam('firstName');
	      $last = $this->getRequest()->getParam('lastName');	
		
	      $sort=$this->_getParam('sort');
 	      $by=$this->_getParam('by'); 	     	     	    
		
	      $user=null;
		
	      if(isset($first) || isset($last)){
		     $search=array();
		       
		     if(isset($first))
			    $search['firstName'] = $first;
			  
		     if(isset($last))
			    $search['lastName'] = $last;  		     
			
		     $user = $model->findByKey( array('search'=>$search, 
							 'like'=>true,
							 'columnToSort'=>$by, 
							 'sortDirection'=>$sort 
							));			
		     $form->populate( $search );
	      }
												   	
	      if( $user ){
	           $this->view->records = $user;
		
		     $page=$this->_getParam('page',1);
		     $paginator = Zend_Paginator::factory($this->view->records);
		     //TODO Should this be a setting ?.
		     $paginator->setItemCountPerPage(1);
		     $paginator->setCurrentPageNumber($page);

		     Zend_Paginator::setDefaultScrollingStyle('Sliding');
		     Zend_View_Helper_PaginationControl::setDefaultViewPartial('t3.phtml');

		     $this->view->paginator=$paginator;	
	      }
	      
	      $leaseWizardModel = new Unit_Model_LeaseWizard();
	      $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	      $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );	   
	      $this->view->tenets = $leaseWizardItem->getTenet();
	      
	      $nextForm    = new Unit_Form_Confirmation();	      
	      
	      
	      if( $this->getRequest()->getParam('previous') ){
		     
	          $this->_helper->redirector('enterdiscounts', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
	      }	  
	      
	      if( $this->getRequest()->getParam('next') ){		     
		     // TODO error message here if no tenets selected
		     if($leaseWizardItem->getTenet())
		       $this->_helper->redirector('selectaccountlink', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
	      }
	      
	      
	      $this->view->nextForm = $nextForm;    
	      $this->view->form = $form;        
    } 
	
	/**
	 *  Account Link for the created bills
	 **/
	
	public function selectaccountlinkAction() {  	          	    
	    $leaseWizardModel = new Unit_Model_LeaseWizard();
	    $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	    $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );		    
	    
	    $form = new Unit_Form_SelectAccountLink();
	    $form->setForm( 'Rent' );
	    $form->populate( $leaseWizardItem->toArray() );
	    $this->view->form = $form;	        	    
	    		
	    if( $this->getRequest()->isPost()
		and $form->isValid($this->getRequest()->getParams())
		and $this->_getParam('next')  ){	     
		
		$values = $form->getValues();
		    		     		
		$linkId = $form->getValue('accountLinkId');
		$referenceNumber = $form->getValue('referenceNumber');
		$comment = $form->getValue('comment'); 
		    		    
		// unset on confirmation page
		//$cache = Zend_Registry::get('cache');
		    
		//$leaseWizard->setWizardVariable( array('accountLinkId'=>$linkId));
		//$leaseWizard->setWizardVariable( array('referenceNumber'=>$referenceNumber));
		//$leaseWizard->setWizardVariable( array('comment'=>$comment));
		
		$leaseWizardItem->setAccountLinkId( $linkId );
		$leaseWizardItem->setReferenceNumber( $referenceNumber );
		$leaseWizardItem->setComment( $comment );
		$leaseWizardItem->save();
		
		$this->_helper->redirector('confirmation', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
	    }
	    else if( $this->_getParam('previous') )
	        $this->_helper->redirector('searchaddtenet', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));	        
 	}			
	
	/**
	 *  Selects the rent amount to use
	 *  
	 **/
	public function selectrentscheduleAction() {  
	       	      
	      $leaseWizardModel = new Unit_Model_LeaseWizard();
	      $leaseWizardId = $this->getRequest()->getParam( 'leaseWizardId');
	      $leaseWizardItem = $leaseWizardModel->findById( $leaseWizardId );	      			      
			      
	      $form = new Unit_Form_SelectRentSchedule();
	      $form->setForm( $leaseWizardItem );
	      $form->populate( $leaseWizardItem->toArray() );
	      $this->view->form = $form;	    	    
	      		  	
	      if( $this->getRequest()->isPost()
	          and $form->isValid($this->getRequest()->getParams())
		  and $this->_getParam('next')  ){		    		     
		   
		  $item = $form->getValue('modelRentScheduleItemId');
		  $modelRentScheduleId = $form->getValue('modelRentScheduleId'); 
		    		    
		  $leaseWizardItem->setModelRentScheduleItemId( $item );
		  $leaseWizardItem->setModelRentScheduleId( $modelRentScheduleId );
		  $leaseWizardItem->save();
		    		    
		  $this->_helper->redirector('enterdiscounts', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));
	      }
	      else if( $this->_getParam('previous') )
	          $this->_helper->redirector('entermoveindate', 'leasewizard', 'unit', array('leaseWizardId'=>$leaseWizardId));	    	    
 	}	
 }
?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.