Exemple #1
0
 protected function createBid(ConnectionInterface $con, Loan $loan, Lender $lender, $data)
 {
     $bidAmount = Money::create($data['amount'], 'USD');
     $oldBids = BidQuery::create()->getOrderedBids($loan)->find();
     $bid = new Bid();
     $bid->setLoan($loan)->setLender($lender)->setBorrower($loan->getBorrower())->setBidAmount($bidAmount)->setInterestRate($data['interestRate'])->setActive(true)->setBidDate(new \DateTime());
     $bidSuccess = $bid->save($con);
     if (!$bidSuccess) {
         throw new \Exception();
     }
     $newBids = BidQuery::create()->getOrderedBids($loan)->find();
     $oldAcceptedBids = $this->getAcceptedBids($oldBids, $loan->getAmount());
     $newAcceptedBids = $this->getAcceptedBids($newBids, $loan->getAmount());
     $changedBids = $this->getChangedBids($oldAcceptedBids, $newAcceptedBids);
     foreach ($changedBids as $bidId => $changedBid) {
         if ($changedBid['type'] == 'out_bid') {
             $this->transactionService->addOutBidTransaction($con, $changedBid['changedAmount'], $loan, $changedBid['bid']->getLender());
         } elseif ($changedBid['type'] == 'update_bid') {
             $this->transactionService->addUpdateBidTransaction($con, $changedBid['changedAmount'], $loan, $changedBid['bid']->getLender());
         } elseif ($changedBid['type'] == 'place_bid') {
             $this->transactionService->addPlaceBidTransaction($con, $changedBid['acceptedAmount'], $loan, $changedBid['bid']->getLender());
         }
     }
     return $bid;
 }