public static function updateSettings($data) { static::$nameToValue = []; $settings = SettingQuery::create()->find(); PropelDB::transaction(function () use($settings, $data) { foreach ($settings as $setting) { if (isset($data[$setting->getName()])) { $setting->setValue($data[$setting->getName()]); $setting->save(); } } }); }
public function review(Borrower $borrower, User $user, $data) { $review = ReviewQuery::create()->filterByBorrower($borrower)->findOne(); if (!$review) { $review = new Review(); $review->setBorrower($borrower)->setCreatedBy($user->getId()); } else { $review->setModifiedBy($user->getId()); } $review->setIsAddressLocatable($data['isAddressLocatable'])->setIsAddressLocatableNote($data['isAddressLocatableNote']); PropelDB::transaction(function () use($review, $borrower) { $review->save(); $borrower->setActivationStatus($review->isCompleted() ? Borrower::ACTIVATION_REVIEWED : Borrower::ACTIVATION_INCOMPLETE); $borrower->save(); }); return $review; }
public function updatePersonalInformation(Borrower $borrower, $data) { $updatedContacts = []; PropelDB::transaction(function ($con) use($borrower, $data, $updatedContacts) { $profile = $borrower->getProfile(); $profile->setAddress($data['address']); $profile->setAddressInstructions($data['addressInstructions']); $profile->setCity($data['city']); $profile->setNationalIdNumber($data['nationalIdNumber']); $profile->setPhoneNumber($data['phoneNumber']); $profile->setAlternatePhoneNumber($data['alternatePhoneNumber']); $profile->save($con); $communityLeader = $borrower->getCommunityLeader(); if ($communityLeader->getPhoneNumber() != $data['communityLeader']['phoneNumber']) { $updatedContacts[] = $communityLeader; } $communityLeader->setFirstName($data['communityLeader']['firstName'])->setLastName($data['communityLeader']['lastName'])->setPhoneNumber($data['communityLeader']['phoneNumber'])->setDescription($data['communityLeader']['description']); $communityLeader->save($con); foreach ($borrower->getFamilyMembers() as $i => $familyMember) { if ($familyMember->getPhoneNumber() != $data['familyMember'][$i + 1]['phoneNumber']) { $updatedContacts[] = $familyMember; } $familyMember->setFirstName($data['familyMember'][$i + 1]['firstName'])->setLastName($data['familyMember'][$i + 1]['lastName'])->setPhoneNumber($data['familyMember'][$i + 1]['phoneNumber'])->setDescription($data['familyMember'][$i + 1]['description']); $familyMember->save($con); } foreach ($borrower->getNeighbors() as $i => $neighbor) { if ($neighbor->getPhoneNumber() != $data['neighbor'][$i + 1]['phoneNumber']) { $updatedContacts[] = $neighbor; } $neighbor->setFirstName($data['neighbor'][$i + 1]['firstName'])->setLastName($data['neighbor'][$i + 1]['lastName'])->setPhoneNumber($data['neighbor'][$i + 1]['phoneNumber'])->setDescription($data['neighbor'][$i + 1]['description']); $neighbor->save($con); } }); foreach ($updatedContacts as $contact) { $this->borrowerSmsService->sendBorrowerJoinedContactConfirmationSms($contact); } }
public function disburseLoan(Loan $loan, \DateTime $disbursedDate, Money $nativeAmount) { $isDisbursed = TransactionQuery::create()->filterByLoan($loan)->filterDisbursement()->count(); if ($isDisbursed) { // TODO return; } PropelDB::transaction(function ($con) use($loan, $disbursedDate, $nativeAmount) { $this->transactionService->addDisbursementTransaction($con, $nativeAmount, $loan); $loans = LoanQuery::create()->filterByBorrower($loan->getBorrower())->count(); if ($loans == 1) { $this->transactionService->addFeeTransaction($con, $nativeAmount, $loan); } //TODO service fee rate $loan->setStatus(Loan::ACTIVE)->setNativeDisbursedAmount($nativeAmount)->setDisbursedDate($disbursedDate)->calculateExtraDays($disbursedDate)->setServiceFeeRate(2.5); $loan->save($con); $this->changeLoanStage($con, $loan, Loan::FUNDED, Loan::ACTIVE); $installments = $this->generateLoanInstallments($loan); foreach ($installments as $installment) { $installment->save($con); } }); //TODO Add repayment schedule //TODO Send email / sift sience event }
public function completeGiftCardTransaction(GiftCardTransaction $giftCardTransaction) { PropelDB::transaction(function ($con) use($giftCardTransaction) { $giftCardTransaction->setStatus(1); $giftCardTransaction->save($con); foreach ($giftCardTransaction->getGiftCards() as $giftCard) { $giftCard->setStatus(1); $giftCard->save($con); $this->transactionService->purchaseGiftCardTransaction($con, $giftCard); } }); foreach ($giftCardTransaction->getGiftCards() as $giftCard) { $this->lenderMailer->sendGiftCardMailToSender($giftCard); if ($giftCard->getOrderType() == 'email') { $this->lenderMailer->sendGiftCardMailToRecipient($giftCard); } } }
public function deactivateLender(Lender $lender) { if (!$lender->isActive()) { return false; } $currentBalance = TransactionQuery::create()->filterByUser($lender->getUser())->getTotalAmount(); if ($currentBalance->isPositive()) { PropelDB::transaction(function ($con) use($lender, $currentBalance) { $this->transactionService->addConvertToDonationTransaction($con, $lender, $currentBalance); $lender->setAdminDonate(true)->setActive(false); $lender->save($con); }); } return true; }
public function updateTranslations($filename, $languageCode, $data) { $translationLabels = TranslationLabelQuery::create()->filterByFilename($filename)->filterByLanguageCode($languageCode)->find(); PropelDB::transaction(function ($con) use($translationLabels, $data) { foreach ($translationLabels as $translationLabel) { if (!isset($data[$translationLabel->getKey()])) { continue; } $value = $data[$translationLabel->getKey()]; if ($value) { $translationLabel->setTranslated(true); } $translationLabel->setValue($value)->setUpdated(false); $translationLabel->save($con); } }); }