Example #1
0
 public function __construct(Borrower $borrower)
 {
     $this->borrower = $borrower;
     $this->currency = $this->borrower->getCountry()->getCurrency();
     $this->exchangeRate = ExchangeRateQuery::create()->findCurrent($this->currency);
     $this->loanCalculator = new LoanCalculator($borrower, $this->exchangeRate);
 }
Example #2
0
 public function updateExchangeRateForCountry($data)
 {
     $country = CountryQuery::create()->filterBySlug($data['countrySlug'])->findOne();
     $currencyCode = $country->getCurrency()->getCode();
     $lastRate = ExchangeRateQuery::create()->filterByCurrencyCode($currencyCode)->filterByEndDate(null)->findone();
     if ($lastRate) {
         $lastRate->setEndDate(new \DateTime());
         $lastRate->save();
     }
     $newRate = new ExchangeRate();
     $newRate->setStartDate(new \DateTime())->setCurrencyCode($currencyCode)->setRate($data['newRate']);
     $newRate->save();
     return $newRate;
 }
Example #3
0
 public function applyForLoan(Borrower $borrower, $data)
 {
     $exchangeRate = ExchangeRateQuery::create()->findCurrent($borrower->getCountry()->getCurrency());
     $data['currencyCode'] = $borrower->getCountry()->getCurrencyCode();
     $loanCategory = CategoryQuery::create()->findOneById($data['categoryId']);
     $data['nativeAmount'] = $data['amount'];
     // TODO
     $data['amount'] = Converter::toUSD(Money::create($data['nativeAmount'], $data['currencyCode']), $exchangeRate)->getAmount();
     $loan = Loan::createFromData($data);
     $loan->setCategory($loanCategory)->setBorrower($borrower)->setStatus(Loan::OPEN);
     PropelDB::transaction(function ($con) use($loan) {
         $loan->save($con);
         $this->changeLoanStage($con, $loan, null, Loan::OPEN);
     });
     $this->borrowerMailer->sendLoanConfirmation($borrower, $loan);
     // TODO send mail to lenders
     $this->addToLoanIndex($loan);
 }