Пример #1
0
 public function addBankInterestAction()
 {
     $session = new Zend_Session_Namespace('landlords_insurance_quote');
     $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID);
     $customerReferenceNumber = $quoteManager->getLegacyCustomerReference();
     $policyNumber = $quoteManager->getLegacyID();
     $request = $this->getRequest();
     $postData = $request->getPost();
     $return = array();
     $return['success'] = false;
     $ajaxForm = new LandlordsInsuranceQuote_Form_Subforms_BankInterestDialog();
     if ($ajaxForm->isValid($postData)) {
         //Create a new bank interest object populated with the details provided
         //by the user.
         $bankInterest = new Model_Insurance_LegacyBankInterest();
         $bankInterest->setBankName($postData['bank_name']);
         $bankInterest->setAccountNumber($postData['account_number']);
         $bankAddress = new Model_Core_Address();
         $bankAddress->addressLine1 = $postData['address_line1'];
         $bankAddress->addressLine2 = $postData['address_line2'];
         $bankAddress->town = $postData['town'];
         $bankAddress->postCode = $postData['postcode'];
         $bankInterest->setBankAddress($bankAddress);
         $bankInterest->setRefno($customerReferenceNumber);
         $bankInterest->setPolicyNumber($policyNumber);
         //Attempt to insert the bank interest object into the dbase.
         $bankInterestManager = new Manager_Insurance_LegacyBankInterest();
         $bankInterestManager->insertInterest($bankInterest);
         //Retrieve all the bank interests for display on the dialog.
         $bankInterestArray = $bankInterestManager->getAllInterests($policyNumber, $customerReferenceNumber);
         $model = array();
         foreach ($bankInterestArray as $bankInterest) {
             $model[] = array('bankInterest' => $bankInterest);
         }
         //Update the dialog.
         $return['html'] = $this->view->partialLoop('partials/bank-interest-list.phtml', $model);
         $return['success'] = true;
     } else {
         foreach ($ajaxForm->getMessages() as $error) {
             $return['errors'] = $error;
         }
     }
     echo Zend_Json::encode($return);
 }
 /**
  * Returns each bank interest associated with the quote/policy or reference number passed in.
  * 
  * Only the policynumber of the refno needs to be provided. However, at least one of these
  * must be provided, otherwise this method will return null.
  * 
  * @param string $policyNumber
  * The quote/policy number.
  * 
  * @param string $refNo
  * The policy reference number.
  * 
  * @return mixed
  * Returns an array of Model_Insurance_LegacyBankInterest objects, or null if no bank interest
  * found.
  */
 public function getAllInterests($policyNumber = null, $refNo = null)
 {
     //Ignore rubbish.
     if (empty($policyNumber) && empty($refNo)) {
         Application_Core_Logger::log("Can't insert bank interest in table {$this->_name}", 'error');
         return null;
     }
     //Retrieve the bank interests.
     $select = $this->select();
     if (!empty($policyNumber)) {
         $select->where('policynumber = ?', $policyNumber);
     } else {
         $select->where('refno = ?', $refNo);
     }
     $rows = $this->fetchAll($select);
     //Insert the interests into BankInterest objects.
     $returnArray = array();
     if (count($rows) > 0) {
         foreach ($rows as $currentRow) {
             $bankInterest = new Model_Insurance_LegacyBankInterest();
             $bankInterest->setInterestId($currentRow->interestID);
             $bankInterest->setRefno($currentRow->refno);
             $bankInterest->setPolicyNumber($currentRow->policynumber);
             $bankInterest->setBankName($currentRow->bankname);
             $address = new Model_Core_Address();
             $address->addressLine1 = $currentRow->bankaddress1;
             $address->addressLine2 = $currentRow->bankaddress2;
             $address->town = $currentRow->bankaddress3;
             $address->county = $currentRow->bankaddress4;
             $address->postCode = $currentRow->bankpostcode;
             $bankInterest->setBankAddress($address);
             $bankInterest->setAccountNumber($currentRow->accountnumber);
             $returnArray[] = $bankInterest;
         }
     }
     //Return the bank interests consistent with this function's contract.
     if (empty($returnArray)) {
         $returnVal = null;
     } else {
         $returnVal = $returnArray;
     }
     return $returnVal;
 }