Exemplo n.º 1
0
 /**
  * Saves the form data to the datastore.
  * 
  * @return void
  */
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     // Create a new Enquiry, or load the existing one.
     $referenceManager = new Manager_Referencing_Reference();
     if (empty($session->referenceId)) {
         $reference = $referenceManager->createReference();
         $session->referenceId = $reference->internalId;
     } else {
         $reference = $referenceManager->getReference($session->referenceId);
     }
     // Set the customer map
     if (empty($reference->customer)) {
         $reference->customer = new Model_Referencing_CustomerMap();
     }
     $reference->customer->customerType = Model_Referencing_CustomerTypes::LANDLORD;
     $reference->customer->customerId = $session->customerId;
     // Format the property details
     $postcodeManager = new Manager_Core_Postcode();
     $propertyAddress = $postcodeManager->getPropertyByID($data['subform_propertyaddress']['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $addressLine2 = $propertyAddress['address4'];
     $town = $propertyAddress['address5'];
     $postCode = $data['subform_propertyaddress']['ins_property_postcode'];
     // Store the property details into the PropertyLease.
     if (empty($reference->propertyLease)) {
         $propertyLeaseManager = new Manager_Referencing_PropertyLease();
         $reference->propertyLease = $propertyLeaseManager->insertPlaceholder($session->referenceId);
     }
     if (empty($reference->propertyLease->address)) {
         $addressManager = new Manager_Core_Address();
         $reference->propertyLease->address = $addressManager->createAddress();
     }
     $reference->propertyLease->address->addressLine1 = $addressLine1;
     $reference->propertyLease->address->addressLine2 = $addressLine2;
     $reference->propertyLease->address->town = $town;
     $reference->propertyLease->address->postCode = $postCode;
     // Store the rental price index details, if provided.
     $this->_savePropertyAspects();
     // Set the remainder of the property lease details.
     $reference->propertyLease->rentPerMonth = new Zend_Currency(array('value' => $data['subform_propertymisc']['total_rent'], 'precision' => 0));
     $reference->propertyLease->tenancyStartDate = new Zend_Date($data['subform_propertymisc']['tenancy_start_date'], Zend_Date::DATES);
     $reference->propertyLease->tenancyTerm = $data['subform_propertymisc']['tenancy_term'];
     $reference->propertyLease->noOfTenants = $data['subform_propertymisc']['no_of_tenants'];
     $referenceManager->updateReference($reference);
 }