示例#1
0
 public function getBankAccountCollectionForDebitor($debitor, $paymentMethod = null)
 {
     if (!$debitor instanceof Billing_Model_Debitor) {
         $debitor = $this->get($debitor);
     }
     $bankAccountCollection = new Billing_Api_BankAccountCollection();
     //$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);
         $bankAccountCollection->attach($bankAccount);
     }
     try {
         $fundMaster = Donator_Controller_FundMaster::getInstance()->getByContactId($contact->getId());
         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);
                     $bankAccountCollection->attach($bankAccount);
                 }
             }
         }
     } catch (Exception $e) {
         // silent failure ok
     }
     //$bankAccount = Billing_Api_BankAccount::getFromFundMaster($fundMaster);
     //$bankAccountCollection->attach($bankAccount);
     $bankAccount = Billing_Api_BankAccount::getFromContact($contact);
     $bankAccountCollection->attach($bankAccount);
     return $bankAccountCollection;
 }
示例#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;
     }
 }