/** * 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 * @param $milestoneId * @param $milestoneGroupId * @return mixed */ public function setLoanMilestone(LoanApplication $application, $milestoneId, $milestoneGroupId) { try { $integrationSite = $this->losConnection->getSite(); //print_r('Site ID: '. $integrationSite->getId() . ' | Milestone ID: '. $milestoneId . ' | Milestone Group ID: ' . $milestoneGroupId); $newMilestone = $this->em->getRepository('SudouxMortgageBundle:LoanMilestone')->findOneMilestoneByLosId($integrationSite, $milestoneId, $milestoneGroupId); //print_r('Milestone Name: ' . $newMilestone->getName()); if (isset($newMilestone)) { // check for a change and send to the $currentMilestone = $application->getMilestone(); if (isset($currentMilestone)) { $sendNotifications = $application->getSite()->getSettings()->getInheritedSendMilestonesNotifications(); $user = $application->getUser(); if ($currentMilestone->getId() != $newMilestone->getId() && $sendNotifications && isset($user)) { if ($user->hasRole('ROLE_MEMBER')) { $email = new Email(); $email->setSubject("Your loan status has been updated"); $email->setMessage(sprintf("Your loan status for %s has been updated to %s.", $application->getPropertyLocation()->getAddress1(), $newMilestone->getName())); $email->setRecipient($user->getEmail()); $email->setSite($application->getSite()); $application->addEmail($email); $emailUtil = $this->container->get('sudoux.cms.message.email_util'); $emailUtil->logAndSend($email); } } } $application->setMilestone($newMilestone); $application->setMilestoneGroup($newMilestone->getMilestoneGroup()); } else { $e = new \Exception("Milestone not found for loan " . $application->getId()); $this->logger->crit($e->getMessage()); } } catch (\Exception $e) { $this->logger->crit($e->getMessage()); } }