/** * Creates or Updates a loan to the LOS * @param LoanApplication $application * @throws \Exception */ public function upsertLoanToLos(LoanApplication $application) { try { $loId = null; $loanOfficer = $application->getLoanOfficer(); if (isset($loanOfficer)) { $loId = $loanOfficer->getLosId(); } $params = array('vendor' => $this->losConnection->getUsername(), 'cust' => $this->losConnection->getLicenseKey(), 'LO' => $loId, 'FNM' => $this->loanToFannieMae($application)); $request = $this->client->post($this::BASE_SERVICE_URL . '/process1003.ashx', array('Content-Type' => 'text/plain'), $params); $factory = new PhpStreamRequestFactory(); $stream = $factory->fromRequest($request); $data = ''; // Read until the stream is closed while (!$stream->feof()) { // Read a line from the stream $data .= $stream->readLine(); } if (!is_numeric($data)) { $params = array('vendor' => $this->losConnection->getUsername(), 'cust' => $this->losConnection->getLicenseKey(), 'LO' => '', 'FNM' => $this->loanToFannieMae($application)); $request = $this->client->post($this::BASE_SERVICE_URL . '/process1003.ashx', array('Content-Type' => 'text/plain'), $params); $stream = $factory->fromRequest($request); $data = ''; // Read until the stream is closed while (!$stream->feof()) { // Read a line from the stream $data .= $stream->readLine(); } } if (is_numeric($data)) { $application->setLosId($data); $modifiedDate = new \DateTime(); $modifiedDate->getTimestamp(); $application->setLosModified($modifiedDate); $application->setLosLoanNumber($data); $application->setStatus(1); // lookup lo if (isset($loId)) { $losLoanOfficer = $this->em->getRepository('SudouxMortgageBundle:LoanOfficer')->findOneBySiteAndLosId($application->getSite(), $loId); $application->setLoanOfficer($losLoanOfficer); } else { $application->setLoanOfficer(null); } $this->em->persist($application); $this->em->flush(); } else { $e = new \Exception("Error adding loan - ID: " . $application->getId() . " Exception: " . $data); $this->logger->crit($e->getMessage()); throw $e; } } catch (\Exception $e) { $this->logger->crit($e->getMessage()); throw $e; } return $data; }
/** * * @param LoanApplication $application */ public function addProspects(LoanApplication $application) { $response = null; try { $borrowers = array($application->getBorrower()); foreach ($application->getCoBorrower() as $coBorrower) { array_push($borrowers, $coBorrower); } // prepare borrowers $prospects = array(); foreach ($borrowers as $borrower) { $married = false; if ($borrower->getMaritalStatus() == 0) { $married = true; } $prospect = array('id' => $borrower->getId(), 'firstName' => $borrower->getFirstName(), 'lastName' => $borrower->getLastName(), 'email' => $borrower->getEmail(), 'primaryPhone' => $borrower->getPhoneHome(), 'suffix' => $borrower->getSuffix(), 'middleInitial' => $borrower->getMiddleInitial(), 'ssn' => $borrower->getSsn(), 'married' => $married, 'birthDate' => $borrower->getBirthDate()->format($this::SERVICE_DATE_FORMAT), 'homeAddress' => array('street1' => $borrower->getLocation()->getLocation()->getAddress1(), 'street2' => $borrower->getLocation()->getLocation()->getAddress2(), 'city' => $borrower->getLocation()->getLocation()->getCity(), 'state' => $borrower->getLocation()->getLocation()->getState()->getName(), 'stateAbbreviation' => $borrower->getLocation()->getLocation()->getState()->getAbbreviation(), 'zipcode' => $borrower->getLocation()->getLocation()->getZipcode())); array_push($prospects, $prospect); } $paramLoanOfficer = null; $loanOfficer = $application->getLoanOfficer(); if (isset($loanOfficer)) { $loanOfficerLosId = $loanOfficer->getLosId(); if (isset($loanOfficerLosId)) { $paramLoanOfficer['username'] = $loanOfficerLosId; } } $params = array('user' => $this->user, 'prospects' => $prospects, 'loanOfficer' => $paramLoanOfficer); $response = $this->request('createProspect', $params); // update the los ids if ($response['result']['success']) { foreach ($response['result']['prospects'] as $p) { $borrower = $this->em->getRepository('SudouxMortgageBundle:Borrower')->find($p['id']); $borrower->setLosId($p['losID']); $this->em->persist($borrower); } $this->em->flush(); } } catch (\Exception $e) { $this->logger->crit($e->getMessage()); } return $response; }
/** * @param \Sudoux\MortgageBundle\Entity\LoanApplication $application * @return string * @throws \Exception * @author Eric Haynes */ public function upsertLoanToLos(LoanApplication $application) { try { $loId = null; $loanOfficer = $application->getLoanOfficer(); if (isset($loanOfficer)) { $loId = $loanOfficer->getLosId(); } $loanUtil = $this->container->get('sudoux_mortgage.loanformat_util'); $loanUtil->setType('destiny'); $destinyApp = $loanUtil->convertFromLoanApp($application); $request = $this->client->post(null, array('content-type' => 'application/xml'), array()); $request->setBody($destinyApp); $response = $request->send(); $statusCode = $response->getStatusCode(); $reason = $response->getReasonPhrase(); if ($statusCode == 200) { $this->resetApplication($application); $application->setLosId($application->getId()); $modifiedDate = new \DateTime(); $modifiedDate->getTimestamp(); $application->setLosModified($modifiedDate); $application->setLosLoanNumber($application->getId()); $application->setStatus(1); if (isset($loId)) { $losLoanOfficer = $this->em->getRepository('SudouxMortgageBundle:LoanOfficer')->findOneBySiteAndLosId($application->getSite(), $loId); $application->setLoanOfficer($losLoanOfficer); } else { $application->setLoanOfficer(null); } $this->em->persist($application); $this->em->flush(); } else { $e = new \Exception("Error adding loan - ID: " . $application->getId() . " Exception: " . $reason); $this->logger->crit($e->getMessage()); throw $e; } } catch (\Exception $e) { $this->logger->crit($e->getMessage()); throw $e; } return $response; }