public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $site = $this->site;
     $application = $this->application;
     $builder->add('sale_price', 'money', array('label' => 'Sale Price', 'currency' => 'USD', 'required' => true, 'precision' => 2, 'grouping' => true, 'attr' => array('class' => 'span2')))->add('loan_amount', 'money', array('label' => 'Loan Amount', 'currency' => 'USD', 'required' => true, 'precision' => 2, 'grouping' => true, 'attr' => array('class' => 'span2')))->add('loan_term', 'number', array('label' => 'Term (Years)', 'required' => true, 'attr' => array('class' => 'span1', 'maxlength' => 2)))->add('loan_type', 'choice', array('label' => 'Which type of loan are you applying for?', 'multiple' => false, 'choices' => $application->loanTypes, 'expanded' => true, 'multiple' => false))->add('status', 'choice', array('label' => 'Loan Status', 'choices' => $application->loanStatuses))->add('num_units', 'number', array('label' => 'Number of Units', 'required' => true, 'attr' => array('class' => 'span1')))->add('property_type', 'choice', array('choices' => $application->propertyTypes, 'empty_value' => 'Please select one'))->add('property_year_built', 'text', array('label' => 'Year Built', 'required' => false, 'attr' => array('class' => 'span2', 'maxlength' => 4)))->add('residency_type', 'choice', array('choices' => $application->residencyTypes, 'empty_value' => 'Please select one'))->add('title_company1', 'text', array('label' => 'Name #1', 'required' => false))->add('title_company2', 'text', array('label' => 'Name #2', 'required' => false))->add('has_realtor', 'choice', array('label' => 'Are you currently working with a Realtor?', 'choices' => array(0 => 'No', 1 => 'Yes'), 'multiple' => false, 'expanded' => true))->add('property_location', new PropertyLocationType($site), array('validation_groups' => array('step2')))->add('realtor_name', 'text', array('attr' => array('class' => 'realtor-info-field')))->add('realtor_company', 'text', array('attr' => array('class' => 'realtor-info-field')))->add('realtor_phone', 'text', array('attr' => array('class' => 'realtor-info-field phonenumber')))->add('borrower', new BorrowerType())->add('co_borrower', 'collection', array('type' => new BorrowerType(), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false))->add('asset_account', 'collection', array('type' => new AssetAccountType($this->application->getId()), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false))->add('asset_real_estate', 'collection', array('type' => new AssetRealEstateType($this->application->getId()), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false))->add('income_other', 'collection', array('type' => new IncomeOtherType($this->application->getId()), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false))->add('income_monthly', 'collection', array('type' => new IncomeMonthlyType($this->application->getId()), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false))->add('agreement_one', 'checkbox', array('required' => true))->add('agreement_two', 'checkbox', array('required' => true))->add('agreement_three', 'checkbox', array('required' => true))->add('expense_housing', new ExpenseHousingType())->add('comments', 'textarea', array('attr' => array('class' => 'span3'), 'required' => false))->add('loan_officer', 'entity', array('label' => 'Are you working with a loan officer?', 'class' => 'SudouxMortgageBundle:LoanOfficer', 'property' => 'fullname', 'multiple' => false, 'empty_value' => 'Select a loan officer', 'required' => false, 'query_builder' => function (EntityRepository $er) use($site) {
         return $er->findAllBySiteType($site);
     }))->add('refinance_year_aquired', 'number', array('label' => 'Year Acquired', 'required' => true, 'attr' => array('class' => 'span1', 'maxlength' => 4)))->add('refinance_original_cost', 'money', array('label' => 'Original Cost', 'currency' => 'USD', 'required' => true, 'precision' => 2, 'grouping' => true, 'attr' => array('class' => 'span2')))->add('refinance_existing_liens', 'money', array('label' => 'Existing Liens', 'currency' => 'USD', 'required' => true, 'precision' => 2, 'grouping' => true, 'attr' => array('class' => 'span2')))->add('refinance_current_rate', 'text', array('label' => 'Current Rate', 'required' => true, 'attr' => array('class' => 'span1')))->add('refinance_current_loan_type', 'text', array('label' => 'Current Loan Type', 'required' => true, 'attr' => array('class' => 'span3')))->add('refinance_current_lender', 'text', array('label' => 'Current Lender', 'required' => true, 'attr' => array('class' => 'span3')))->add('refinance_purpose', 'choice', array('label' => 'Purpose of Refinance', 'choices' => $application->refinancePurposes, 'required' => true, 'empty_value' => 'Please select one'))->add('referral_source', 'entity', array('class' => 'Sudoux\\Cms\\FormBundle\\Entity\\ReferralSource', 'property' => 'name', 'required' => false, 'multiple' => true, 'expanded' => true, 'label' => 'Where did you hear about us?', 'attr' => array('class' => 'checkbox-group'), 'query_builder' => function (EntityRepository $er) use($site) {
         return $er->findAllActiveBySiteQuery($site);
     }))->add('no_property_location', 'checkbox', array('label' => 'I do not have a property yet', 'attr' => array('class' => ''), 'required' => false));
     $titleManner = $this->application->getTitleManner();
     if (isset($titleManner)) {
         $builder->add('title_manner', 'text', array('label' => 'Manner', 'required' => false));
     } else {
         $builder->add('title_manner', 'choice', array('label' => 'Manner', 'required' => false, 'choices' => $application->titleManners, 'empty_value' => 'Please select one', 'required' => false));
     }
     /*$group = $application->getMilestoneGroup();
             if(isset($group)) {
     			$builder->add('milestone', 'entity', array(
     				'label' => 'Loan Status',
     				'class' => 'SudouxMortgageBundle:LoanMilestone',
     				'property' => 'name',
     				'multiple' => false,
     				'empty_value' => 'Select a status',
     				'required' => false,
     				'query_builder' => function(EntityRepository $er) use ($group) {
     					return $er->findByMilestoneGroupQuery($group->getId());
     				}
     			));
     		}*/
 }
 protected function formatMismo231(LoanApplication $application)
 {
     $borrower = $application->getBorrower();
     $maritalStatusBorrower = $borrower->getMaritalStatus();
     $coBorrowers = $application->getCoBorrower();
     $type = $application->getLoanType();
     $propertyType = $application->getPropertyType();
     $resType = $application->getResidencyType();
     switch ($propertyType) {
         case '1':
             $application->setPropertyType("twotofourunitproperty");
             break;
         case '2':
             $application->setPropertyType("condominium");
             break;
         case '3':
             $application->setPropertyType("twotofourunitproperty");
             break;
         case '4':
             $application->setPropertyType("twotofourunitproperty");
             break;
         case '5':
             $application->setPropertyType("condominium");
             break;
         case '7':
             $application->setPropertyType("condominium");
             break;
         default:
             $application->setPropertyType("singlefamilyresidence");
     }
     if ($type == 0) {
         $application->setLoanType("Purchase");
     } else {
         if ($application->getRefinancePurpose() == 3) {
             $application->setLoanType("Refinance");
         } else {
             $application->setLoanType("Refinance");
         }
     }
     $appTitleManner = $application->getTitleManner();
     switch ($appTitleManner) {
         case 'Community property':
             $application->setTitleManner("Community Property");
             break;
         case 'Joint Tenants':
             $application->setTitleManner("Joint Tenancy");
             break;
         case 'Single Man':
             $application->setTitleManner("Single");
             break;
         case 'Single Woman':
             $application->setTitleManner("Single");
             break;
         case 'Married Man':
             $application->setTitleManner("A Married Man As His Separate Estate");
             break;
         case 'Married Woman':
             $application->setTitleManner("A Married Woman As Her Separate Estate");
             break;
         case 'Tenants in common':
             $application->setTitleManner("Tenancy in Common");
             break;
         case 'To be decided in escrow':
             $application->setTitleManner("");
             break;
         case 'Unmarried man':
             $application->setTitleManner("An Unmarried Person");
             break;
         case 'Unmarried woman':
             $application->setTitleManner("An Unmarried Person");
             break;
         case 'Other':
             $application->setTitleManner("");
             break;
         default:
             $application->setTitleManner("");
     }
     $refiPurpose = $application->getRefinancePurpose();
     switch ($refiPurpose) {
         case '0':
             $application->setRefinancePurpose("cashoutdebtconsolidation");
             break;
         case '1':
             $application->setRefinancePurpose("cashouthomeimprovement");
             break;
         case '2':
             $application->setRefinancePurpose("cashoutother");
             break;
         case '3':
             $application->setRefinancePurpose("nocashoutother");
             break;
         case '4':
             $application->setRefinancePurpose("cashoutlimited");
             break;
         default:
             $application->setRefinancePurpose("cashoutdebtconsolidation");
     }
     switch ($resType) {
         case '0':
             $application->setResidencyType("PrimaryResidence");
             break;
         case '1':
             $application->setResidencyType("SecondHome");
             break;
         case '2':
             $application->setResidencyType("Investor");
             break;
         default:
             $application->setResidencyType("PrimaryResidence");
     }
     if ($borrower->getDeclarationUsCitizen()) {
         $borrower->setDeclarationUsCitizen("USCitizen");
     } elseif ($borrower->getDeclarationResidentAlien()) {
         $borrower->setDeclarationUsCitizen("PermanentResidentAlien");
     } else {
         $borrower->setDeclarationUsCitizen("Unknown");
     }
     if ($borrower->getDeclarationOwnershipWithinThreeYears()) {
         switch ($borrower->getDeclarationOwnershipWithinThreeYearsPropertyTitle()) {
             case '0':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("Sole");
                 break;
             case '1':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("JointWithSpouse");
                 break;
             case '2':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("JointWithOtherThanSpouse");
                 break;
             default:
         }
         switch ($borrower->getDeclarationOwnershipWithinThreeYearsPropertyType()) {
             case '0':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyType("PrimaryResidence");
                 break;
             case '1':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyType("SecondaryResidence");
                 break;
             case '2':
                 $borrower->setDeclarationOwnershipWithinThreeYearsPropertyType("Investment");
                 break;
             default:
         }
     }
     if (!$borrower->getGovtMonitoringOptOut()) {
         switch ($borrower->getEthnicity()) {
             case '0':
                 $borrower->setEthnicity('HispanicOrLatino');
                 break;
             case '1':
                 $borrower->setEthnicity('NotHispanicOrLatino');
                 break;
             case '2':
                 $borrower->setEthnicity('NotApplicable');
                 break;
             default:
         }
         switch ($borrower->getRace()) {
             case '0':
                 $borrower->setRace('AmericanIndianOrAlaskanNative');
                 break;
             case '1':
                 $borrower->setRace('AsianOrPacificIslander');
                 break;
             case '2':
                 $borrower->setRace('BlackNotOfHispanicOrigin');
                 break;
             case '3':
                 $borrower->setRace('AsianOrPacificIslander');
                 break;
             case '4':
                 $borrower->setRace('WhiteNotOfHispanicOrigin');
                 break;
             default:
                 $borrower->setRace('Other');
         }
         if ($borrower->getIsMale()) {
             $borrower->setIsMale("Male");
         } else {
             $borrower->setIsMale("Female");
         }
     }
     $borrowerAssetsA = $borrower->getAssetAccount();
     foreach ($borrowerAssetsA as $a) {
         $aType = $a->getType();
         switch ($aType) {
             case '0':
                 $a->setType('CheckingAccount');
                 break;
             case '1':
                 $a->setType('SavingsAccount');
                 break;
             case '2':
                 $a->setType('MoneyMarketFund');
                 break;
             case '3':
                 $a->setType('CertificateOfDepositTimeDeposit');
                 break;
             case '4':
                 $a->setType('MutualFund');
                 break;
             case '5':
                 $a->setType('RetirementFund');
                 break;
             default:
                 $a->setType('OtherLiquidAssets');
         }
     }
     switch ($maritalStatusBorrower) {
         case '0':
             $borrower->setMaritalStatus('Married');
             break;
         case '1':
             $borrower->setMaritalStatus('Unmarried');
             break;
         case '2':
             $borrower->setMaritalStatus('Separated');
             break;
         default:
     }
     if ($borrower->getDependents()) {
         $BorrowerDependentsAges = explode(",", $application->getBorrower()->getDependentsAges());
         $application->getBorrower()->setDependentsAges($BorrowerDependentsAges);
     }
     $borrowerEmployment = $borrower->getEmployment()->getValues();
     foreach ($borrowerEmployment as $job) {
         $borEmpPhone = null;
         if ($job->getEndDate()->add(new \DateInterval('P1D')) >= $application->getCreated() && $application->getBorrower()->getEmployed()) {
             $job->setCurrent("Y");
         } else {
             $job->setCurrent("N");
         }
         switch ($job->getSelfEmployed()) {
             case '0':
                 $job->setSelfEmployed("N");
                 break;
             case '1':
                 $job->setSelfEmployed("Y");
                 break;
             default:
         }
         $borEmpPhone = $job->getEmployerPhone();
         if (isset($borEmpPhone)) {
             $borEmpPhone = preg_replace("/[^0-9]/", "", $borEmpPhone);
             $job->setEmployerPhone($borEmpPhone);
         }
     }
     ////////////////////////////////////////////////////////////////////////////
     //
     // Co Borrowers
     //
     ////////////////////////////////////////////////////////////////////
     foreach ($coBorrowers as $coBorrower) {
         $maritalStatusCoBorrower = $coBorrower->getMaritalStatus();
         $coBorrowerDependentsAges = NULL;
         if ($coBorrower->getDeclarationUsCitizen()) {
             $coBorrower->setDeclarationUsCitizen("USCitizen");
         } elseif ($coBorrower->getDeclarationResidentAlien()) {
             $coBorrower->setDeclarationUsCitizen("PermanentResidentAlien");
         } else {
             $coBorrower->setDeclarationUsCitizen("Unknown");
         }
         if ($coBorrower->getDeclarationOwnershipWithinThreeYears()) {
             switch ($coBorrower->getDeclarationOwnershipWithinThreeYearsPropertyTitle()) {
                 case '0':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("Sole");
                     break;
                 case '1':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("JointWithSpouse");
                     break;
                 case '2':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyTitle("JointWithOtherThanSpouse");
                     break;
                 default:
             }
             switch ($coBorrower->getDeclarationOwnershipWithinThreeYearsPropertyType()) {
                 case '0':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyType("PrimaryResidence");
                     break;
                 case '1':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyType("SecondaryResidence");
                     break;
                 case '2':
                     $coBorrower->setDeclarationOwnershipWithinThreeYearsPropertyType("Investment");
                     break;
                 default:
             }
         }
         if (!$coBorrower->getGovtMonitoringOptOut()) {
             switch ($coBorrower->getEthnicity()) {
                 case '0':
                     $coBorrower->setEthnicity('HispanicOrLatino');
                     break;
                 case '1':
                     $coBorrower->setEthnicity('NotHispanicOrLatino');
                     break;
                 case '2':
                     $coBorrower->setEthnicity('NotApplicable');
                     break;
                 default:
             }
             switch ($coBorrower->getRace()) {
                 case '0':
                     $coBorrower->setRace('AmericanIndianOrAlaskanNative');
                     break;
                 case '1':
                     $coBorrower->setRace('AsianOrPacificIslander');
                     break;
                 case '2':
                     $coBorrower->setRace('BlackNotOfHispanicOrigin');
                     break;
                 case '3':
                     $coBorrower->setRace('AsianOrPacificIslander');
                     break;
                 case '4':
                     $coBorrower->setRace('WhiteNotOfHispanicOrigin');
                     break;
                 default:
                     $coBorrower->setRace('Other');
             }
             if ($coBorrower->getIsMale()) {
                 $coBorrower->setIsMale("Male");
             } else {
                 $coBorrower->setIsMale("Female");
             }
         }
         switch ($maritalStatusCoBorrower) {
             case '0':
                 $coBorrower->setMaritalStatus('Married');
                 break;
             case '1':
                 $coBorrower->setMaritalStatus('Unmarried');
                 break;
             case '2':
                 $coBorrower->setMaritalStatus('Separated');
                 break;
             default:
         }
         if ($coBorrower->getDependents()) {
             $coBorrowerDependentsAges = explode(",", $coBorrower->getDependentsAges());
             $coBorrower->setDependentsAges($coBorrowerDependentsAges);
         }
         $coBorrowerEmployment = $coBorrower->getEmployment()->getValues();
         foreach ($coBorrowerEmployment as $job) {
             $coBorEmpPhone = null;
             if ($job->getEndDate()->add(new \DateInterval('P1D')) >= $application->getCreated() && $application->getBorrower()->getEmployed()) {
                 $job->setCurrent("Y");
             } else {
                 $job->setCurrent("N");
             }
             switch ($job->getSelfEmployed()) {
                 case '0':
                     $job->setSelfEmployed("N");
                     break;
                 case '1':
                     $job->setSelfEmployed("Y");
                     break;
                 default:
             }
             $coBorEmpPhone = $job->getEmployerPhone();
             if (isset($coBorEmpPhone)) {
                 $borEmpPhone = preg_replace("/[^0-9]/", "", $coBorEmpPhone);
                 $job->setEmployerPhone($borEmpPhone);
             }
         }
         $coBborrowerAssetsA = $coBorrower->getAssetAccount();
         foreach ($coBborrowerAssetsA as $a) {
             $aType = $a->getType();
             switch ($aType) {
                 case '0':
                     $a->setType('CheckingAccount');
                     break;
                 case '1':
                     $a->setType('SavingsAccount');
                     break;
                 case '2':
                     $a->setType('MoneyMarketFund');
                     break;
                 case '3':
                     $a->setType('CertificateOfDepositTimeDeposit');
                     break;
                 case '4':
                     $a->setType('MutualFund');
                     break;
                 case '5':
                     $a->setType('RetirementFund');
                     break;
                 default:
                     $a->setType('OtherLiquidAssets');
             }
         }
     }
     return $application;
 }