Ejemplo n.º 1
0
 public function repaymentAmountForLenders()
 {
     // TODO use disbursed amount in lenderInterest
     $totalLendersAmount = $this->loan->getNativeDisbursedAmount()->add($this->lenderInterest());
     $ratio = $this->loan->getNativeDisbursedAmount()->divide($totalLendersAmount);
     $repaymentAmountForLenders = $this->repaymentAmount->subtract($this->installmentServiceFee());
     return $repaymentAmountForLenders->multiply($ratio);
 }
Ejemplo n.º 2
0
 protected function getAcceptedBids($bids, Money $loanAmount)
 {
     $zero = Money::create(0, 'USD');
     $totalBidAmount = $zero;
     $acceptedBids = [];
     foreach ($bids as $bid) {
         $bidAmount = $bid->getBidAmount();
         $missingAmount = $loanAmount->subtract($totalBidAmount)->max($zero)->round(3);
         $totalBidAmount = $totalBidAmount->add($bidAmount);
         $acceptedAmount = $missingAmount->min($bidAmount);
         $acceptedBids[$bid->getId()] = compact('bid', 'acceptedAmount');
     }
     // Sort by bid date
     // TODO: why?
     uasort($acceptedBids, function ($b1, $b2) {
         return $b1['bid']->getBidDate() <= $b2['bid']->getBidDate();
     });
     return $acceptedBids;
 }
Ejemplo n.º 3
0
 public function calculateInstallmentCount(Money $nativeInstallmentAmount)
 {
     $maxYearlyInterest = $this->getNativeAmount()->multiply($this->getInterestRate() / 100);
     if ($this->isWeeklyInstallment()) {
         $maxInstallmentInterest = $maxYearlyInterest->divide(52);
     } else {
         $maxInstallmentInterest = $maxYearlyInterest->divide(12);
     }
     $maxNativeInstallmentAmount = $nativeInstallmentAmount->subtract($maxInstallmentInterest);
     $installmentCount = ceil($this->getNativeAmount()->getAmount() / $maxNativeInstallmentAmount->getAmount());
     return $this->setInstallmentCount($installmentCount);
 }