/** * @param LosConnection $losConnection * @param \Twig_Environment $twig * @param ContainerInterface $container */ public function __construct(LosConnection $losConnection, \Twig_Environment $twig, ContainerInterface $container) { $this->losConnection = $losConnection; $serviceUrl = $losConnection->getServiceUrl(); if (!isset($serviceUrl)) { $serviceUrl = $this::BASE_SERVICE_URL; } $this->client = new Client($serviceUrl); $this->twig = $twig; $this->em = $container->get('doctrine')->getEntityManager(); $this->container = $container; $this->logger = $this->container->get('logger'); }
/** * 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; }
/** * */ protected function prepareLosSettings(LoanApplication $application) { $settings = unserialize($this->losConnection->getSettings()); $losSettings = array(); if (isset($settings)) { foreach ($settings as $key => $value) { array_push($losSettings, array("Key" => $key, "Value" => $value)); } } return $losSettings; }
/** * @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()); } }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function losSettingsAction(Request $request) { $siteRequest = $this->get('sudoux.cms.site'); $site = $siteRequest->getSite(); $em = $this->getDoctrine()->getEntityManager(); $settings = $site->getSettings(); $conn = $settings->getLos(); if (!isset($conn)) { $conn = new LosConnection(); } // deserialize and normalize settings blob $losSettings = $conn->getSettings(); if (isset($losSettings)) { $losSettingsArray = unserialize($losSettings); $losSettingsText = ""; foreach ($losSettingsArray as $key => $value) { $losSettingsText .= $key . ':' . $value . "\r\n"; } $conn->setSettings($losSettingsText); } $conn->setSite($site); $form = $this->createForm(new LosConnectionType(), $conn); if ($request->getMethod() == 'POST') { $form->bindRequest($request); if ($form->isValid()) { $session = $request->getSession(); // parse the settings $losSettingsText = $conn->getSettings(); if (isset($losSettingsText)) { $losSettings = array(); $settingsLines = explode("\r\n", $losSettingsText); foreach ($settingsLines as $setting) { // setup the key value pairs $settingsPair = explode(':', $setting); $key = trim($settingsPair[0]); array_shift($settingsPair); // remove the key if (count($settingsPair) > 1) { $value = implode(':', $settingsPair); } else { $value = $settingsPair[0]; } $losSettings[$key] = trim($value); } $conn->setSettings(serialize($losSettings)); } $em->persist($conn); $settings->setLos($conn); $em->persist($settings); // try to connect $loanUtil = $this->get('sudoux_mortgage.los_util'); $losLogin = $loanUtil->tryLogin($site); if ($losLogin['success']) { // update milestones $job = new Job('sudoux:mortgage:los', array('upsert_milestones', sprintf('--site_id=%s', $site->getId()), '--env=' . $this->get('kernel')->getEnvironment(), '--no-debug'), true); $em->persist($job); $session->getFlashBag()->add('success', 'Your LOS settings have been updated.'); } else { $session->getFlashBag()->add('error', 'Failed to connect to the LOS'); } $em->flush(); } } return $this->render('SudouxMortgageBundle:SettingsAdmin:losSettings.html.twig', array('form' => $form->createView(), 'losConnection' => $conn)); }