Esempio n. 1
0
 public function getBankAccountForDebitor($debitor, $paymentMethod = null)
 {
     if (!$debitor instanceof Billing_Model_Debitor) {
         $debitor = $this->get($debitor);
     }
     $bankAccount = Billing_Api_BankAccount::createEmpty();
     $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance());
     $memberships = Membership_Controller_SoMember::getInstance()->getByContactId($contact->getId());
     foreach ($memberships as $membership) {
         $bankAccount = Billing_Api_BankAccount::getFromSoMember($membership);
         //	if($bankAccount->isValidForPaymentMethod($paymentMethod)){
         if ($bankAccount->isValid()) {
             break;
         }
     }
     //if(!$bankAccount->isValidForPaymentMethod($paymentMethod)){
     if (!$bankAccount->isValid()) {
         try {
             $fundMaster = Donator_Controller_FundMaster::getInstance()->getByContactId($contact->getId());
             $bankAccount = Billing_Api_BankAccount::getFromFundMaster($fundMaster);
         } catch (Exception $e) {
         }
     }
     if (!$bankAccount->isValid()) {
         $bankAccount = Billing_Api_BankAccount::getFromContact($contact);
     }
     //if(!$bankAccount->isValidForPaymentMethod($paymentMethod)){
     /*if(!$bankAccount->isValid()){
       	throw new Billing_Exception_BankAccountInvalidForPaymentMethod('No valid bankaccount for debitor '.$debitor->getId(). ' and payment method '.$paymentMethod. ' log: '.$log);
       }*/
     return $bankAccount;
 }
Esempio n. 2
0
 private static function doSepa($contact)
 {
     try {
         $memberships = Membership_Controller_SoMember::getInstance()->getByContactId($contact->getId());
         foreach ($memberships as $membership) {
             $memKind = $membership->__get('membership_type');
             if ($memKind == 'MEMBER_EX' || $memKind == 'INTERESTED') {
                 continue;
             }
             if ($memKind == 'MEMBER_GESCHENK') {
                 $parentMembership = $membership->getForeignRecord('parent_member_id', Membership_Controller_SoMember::getInstance());
                 $bankAccount = Billing_Api_BankAccount::getFromSoMember($parentMembership);
             } else {
                 $bankAccount = Billing_Api_BankAccount::getFromSoMember($membership);
             }
             $objBankAccount = $bankAccount->convertSepa();
             if (!is_null($objBankAccount)) {
                 $usage = $objBankAccount->addUsageMembership($membership);
                 $membership->__set('bank_account_id', $objBankAccount->getId());
                 $membership->__set('bank_account_usage_id', $usage->getId());
                 Membership_Controller_SoMember::getInstance()->update($membership);
                 $paymentMethod = $bankAccount->getPaymentMethod();
                 if ($paymentMethod == 'DEBIT' || $paymentMethod == 'DEBIT_GM') {
                     Billing_Controller_SepaMandate::getInstance()->generateSepaMandateForBankAccountUsage($usage);
                 }
             }
         }
         $fundMasters = Donator_Controller_FundMaster::getInstance()->getAllByContactIdBreakNull($contact->getId());
         if (!is_null($fundMasters)) {
             foreach ($fundMasters as $fundMaster) {
                 if ($fundMaster instanceof Donator_Model_FundMaster) {
                     //regular donations
                     $regularDonations = Donator_Controller_RegularDonation::getInstance()->getByFundMasterId($fundMaster->getId());
                     foreach ($regularDonations as $regDon) {
                         if (!$regDon->__get('terminated') && !$regDon->__get('on_hold')) {
                             $bankAccount = Billing_Api_BankAccount::getFromRegularDonation($regDon);
                             $objBankAccount = $bankAccount->convertSepa();
                             if (!is_null($objBankAccount)) {
                                 $usage = $objBankAccount->addUsageRegularDonation($regDon);
                                 $regDon->__set('bank_account_id', $objBankAccount->getId());
                                 $regDon->__set('bank_account_usage_id', $usage->getId());
                                 Donator_Controller_RegularDonation::getInstance()->update($regDon);
                                 $paymentMethod = $bankAccount->getPaymentMethod();
                                 if ($paymentMethod == 'DEBIT' || $paymentMethod == 'DEBIT_GM') {
                                     Billing_Controller_SepaMandate::getInstance()->generateSepaMandateForBankAccountUsage($usage);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //$bankAccount = Billing_Api_BankAccount::getFromFundMaster($fundMaster);
         //$bankAccountCollection->attach($bankAccount);
         $bankAccount = Billing_Api_BankAccount::getFromContact($contact);
         $objBankAccount = $bankAccount->convertSepa();
         if (!is_null($objBankAccount)) {
             $objBankAccount->addUsageAll();
         }
     } catch (Exception $e) {
         \org\sopen\dev\DebugLogger::log('error ' . self::$errorCounter++ . ' contactId: ' . $contact->getId() . $e->getMessage());
         return;
     }
 }