Ejemplo n.º 1
0
 public static function import($fileName)
 {
     $result = array('failcount' => 0, 'totalcount' => 0, 'duplicatecount' => 0, 'status' => 'success');
     try {
         $reader = new Reader();
         $statements = $reader->getStatements(file_get_contents($fileName));
         foreach ($statements as $statement) {
             foreach ($statement->getTransactions() as $transaction) {
                 //echo $transaction->getAmount() . "\n";
                 $amount = (double) $transaction->getAmount();
                 $description = $transaction->getDescription();
                 $accountNumber = $statement->getAccount()->getNumber();
                 //echo $accountNumber;
                 $num = null;
                 $debitorNr = null;
                 $memberNr = null;
                 $receiptNr = null;
                 $context = 'ERP';
                 $cdesc = strtolower($description);
                 $opNr = null;
                 $openItemId = null;
                 $debitorId = null;
                 $opId = null;
                 $type = null;
                 $state = 'RED';
                 $opAmount = 0;
                 $overpay = 0;
                 if ($amount < 0) {
                     $type = 'DEBIT';
                 } else {
                     $type = 'CREDIT';
                 }
                 if (strpos($cdesc, 'mitg') || strpos($cdesc, 'tgli') || strpos($cdesc, 'beitr')) {
                     $context = 'MEMBERSHIP';
                 } elseif (strpos($cdesc, 'spend')) {
                     $context = 'DONATOR';
                 }
                 $isReturnDebit = false;
                 if (strpos($cdesc, 'rueckbelast')) {
                     $isReturnDebit = true;
                 }
                 $numDesc = $transaction->getDescriptionConcat(1, 7);
                 $numDescCheck = strtolower($numDesc);
                 $pos = strpos($numDescCheck, 'mitg');
                 if (!$pos) {
                     $pos = strpos($numDescCheck, 'tgli');
                 }
                 if (!pos) {
                     $pos = strpos($numDescCheck, 'beitr');
                 }
                 if (!pos) {
                     $pos = strpos($numDescCheck, 'rech');
                 }
                 if ($numDesc && $pos) {
                     if (preg_match('/([0-9]{5,7})/', substr($numDesc, $pos), $match)) {
                         $num = $match[1];
                     }
                 }
                 if ($num && !$isReturnDebit) {
                     if (strpos($cdesc, 'rech')) {
                         try {
                             $receiptNr = $num;
                             $receiptId = Billing_Controller_Receipt::getInstance()->getIdByProperty('invoice_nr', $num);
                             $receipt = Billing_Controller_Receipt::getInstance()->get($receiptId);
                             $context = $receipt->getForeignId('erp_context_id');
                             $order = $receipt->getForeignRecordBreakNull('order_id', Billing_Controller_Order::getInstance());
                             $debitor = $order->getForeignRecordBreakNull('debitor_id', Billing_Controller_Debitor::getInstance());
                             if ($debitor) {
                                 $debitorId = $debitor->getId();
                                 $state = 'ORANGE';
                                 $openItems = Billing_Controller_OpenItem::getInstance()->getByDebitor($debitorId);
                                 foreach ($openItems as $op) {
                                     if ($op->__get('state') != 'DONE') {
                                         $openItem = $op;
                                         break;
                                     }
                                 }
                                 //$openItem = $openItems->getFirstRecord();
                                 $openItemId = $openItem->getId();
                                 $opAmount = $openItem->__get('open_sum');
                             }
                             if (abs($amount) > abs($opAmount)) {
                                 $overpay = abs($amount) - abs($opAmount);
                             }
                             if ($overpay == 0) {
                                 $state = 'GREEN';
                             }
                             /*if((float)abs($openItem->__get('total_brutto')) == (float)abs($amount)){
                             			$state = 'GREEN';
                             		}*/
                         } catch (Exception $e) {
                         }
                     } elseif (strpos($cdesc, 'mitg')) {
                         $memberNr = $num;
                         try {
                             $member = Membership_Controller_SoMember::getInstance()->getSoMemberByMemberNr($memberNr);
                             $contactId = $member->getForeignId('contact_id');
                             $debitorId = Billing_Controller_Debitor::getInstance()->getIdByContactId($contactId);
                             $state = 'ORANGE';
                             $openItems = Billing_Controller_OpenItem::getInstance()->getByDebitor($debitorId);
                             foreach ($openItems as $op) {
                                 if ($op->__get('state') != 'DONE') {
                                     $openItem = $op;
                                     break;
                                 }
                             }
                             //$openItem = $openItems->getFirstRecord();
                             if ($openItem) {
                                 $openItemId = $openItem->getId();
                                 $opAmount = $openItem->__get('open_sum');
                                 if (abs($amount) > abs($opAmount)) {
                                     $overpay = abs($amount) - abs($opAmount);
                                 }
                                 if ($overpay == 0) {
                                     $state = 'GREEN';
                                 }
                             }
                             /*if((float)abs($openItem->__get('total_brutto')) == (float)abs($amount)){
                             			$state = 'GREEN';
                             		}*/
                         } catch (Exception $e) {
                         }
                     } else {
                         try {
                             $contactId = (int) trim($num);
                             $debitorId = Billing_Controller_Debitor::getInstance()->getIdByContactId($contactId);
                             $state = 'ORANGE';
                             $openItems = Billing_Controller_OpenItem::getInstance()->getByDebitor($debitorId);
                             foreach ($openItems as $op) {
                                 if ($op->__get('state') != 'DONE') {
                                     $openItem = $op;
                                     break;
                                 }
                             }
                             // changed behviour: was only correct in first period :-/
                             //$openItem = $openItems->getFirstRecord();
                             if ($openItem) {
                                 $openItemId = $openItem->getId();
                                 $opAmount = $openItem->__get('open_sum');
                             }
                             if (abs($amount) > abs($opAmount)) {
                                 $overpay = abs($amount) - abs($opAmount);
                             }
                             if ($overpay == 0) {
                                 $state = 'GREEN';
                             }
                             //if((float)abs($openItem->__get('total_brutto')) == (float)abs($amount)){
                             //	$state = 'GREEN';
                             //}
                         } catch (Exception $e) {
                         }
                     }
                 }
                 if ($isReturnDebit) {
                     $returnDebitFee = (double) Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::DEBIT_RETURN_FEE);
                     if ($num) {
                         $contactId = (int) trim($num);
                         $debitorId = null;
                         try {
                             $debitorId = Billing_Controller_Debitor::getInstance()->getIdByContactId($contactId);
                             $state = 'ORANGE';
                         } catch (Exception $e) {
                             $state = 'RED';
                         }
                         try {
                             $toReturnPayment = Billing_Controller_Payment::getInstance()->getDebitToReturn($debitorId, $amount, $returnDebitFee, 'DEBIT');
                             $returnPaymentId = $toReturnPayment->getId();
                             if ($returnPaymentId && $debitorId && $toReturnPayment->__get('is_cancelled') == false) {
                                 $state = 'GREEN';
                             }
                             if ($toReturnPayment->__get('is_cancelled') == true) {
                                 $returnPaymentId = null;
                             }
                         } catch (Exception $e) {
                             $returnPaymentId = null;
                         }
                     }
                 }
                 $id = md5($cdesc);
                 try {
                     $payment = Billing_Controller_MT940Payment::getInstance()->get($id);
                 } catch (Exception $e) {
                     $payment = Billing_Controller_MT940Payment::getInstance()->getEmptyMT940Payment();
                     $bankAccount = Billing_Controller_AccountSystem::getInstance()->getDefaultBankAccount();
                     $fordAccount = Billing_Controller_AccountSystem::getInstance()->getByNumber('14000');
                     if (!$isReturnDebit) {
                         if ($type == 'DEBIT') {
                             $payment->__set('account_system_id', $bankAccount->getId());
                             $payment->__set('account_system_id_haben', $fordAccount->getId());
                         } else {
                             $payment->__set('account_system_id', $fordAccount->getId());
                             $payment->__set('account_system_id_haben', $bankAccount->getId());
                         }
                     } else {
                         $debitSettleAccount = Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::FIBU_KTO_DEBITOR);
                         $payment->__set('account_system_id', $debitSettleAccount);
                         $payment->__set('account_system_id_haben', $bankAccount->getId());
                         $payment->__set('is_return_debit', true);
                         $payment->__set('print_inquiry', true);
                         $payment->__set('set_accounts_banktransfer', true);
                         $payment->__set('return_inquiry_fee', $returnDebitFee);
                         $payment->__set('return_debit_base_payment_id', $returnPaymentId);
                     }
                     $payment->__set('id', $id);
                     $payment->__set('erp_context_id', $context);
                     if ($opNr) {
                         $payment->__set('op_nr', $opNr);
                     }
                     if ($openItemId) {
                         $payment->__set('op_id', $openItemId);
                         $payment->__set('due_date', new Zend_Date($openItem->__get('due_date')));
                         $payment->__set('op_amount', $openItem->__get('total_brutto'));
                     }
                     if ($debitorId) {
                         $payment->__set('debitor_id', $debitorId);
                     }
                     $payment->__set('type', $type);
                     $payment->__set('payment_date', new Zend_Date($transaction->getBookDate()->format('Y-m-d H:i:s')));
                     $payment->__set('payment_amount', abs($amount));
                     $payment->__set('state', $state);
                     $payment->__set('usage_payment', $description);
                     $payment->__set('usage', $numDesc);
                     $payment->__set('overpay_amount', $overpay);
                     Billing_Controller_MT940Payment::getInstance()->create($payment);
                 }
             }
             /*echo $statement->getOpeningBalance()->getAmount() . "\n";
               
                  foreach ($statement->getTransactions() as $transaction) {
                      echo $transaction->getAmount() . "\n";
                  }
               
                  echo $statement->getClosingBalance()->getAmount() . "\n";*/
         }
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . 'TD-Import - Es trat ein Fehler auf. Nicht ausgeführt.' . print_r($e->__toString(), true));
         $result['status'] = 'error';
         $result['errorInfo'] = $e->getMessage();
         $result['errorTrace'] = $e->getTrace();
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function getPayableOpenItems($memberNr, $contactNr, $amount)
 {
     // start transaction
     $db = Tinebase_Core::getDb();
     $tm = Tinebase_TransactionManager::getInstance();
     $tId = $tm->startTransaction($db);
     try {
         if ($memberNr) {
             $member = Membership_Controller_SoMember::getInstance()->getSoMemberByMemberNr($memberNr);
             $contactNr = $member->getForeignId('contact_id');
         }
         $debitor = Billing_Controller_Debitor::getInstance()->getByContactOrCreate($contactNr);
         $debitorId = $debitor->getId();
         $filters[] = array('field' => 'debitor_id', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $debitorId)));
         $filters[] = array('field' => 'state', 'operator' => 'equals', 'value' => 'OPEN');
         $filters[] = array('field' => 'type', 'operator' => 'equals', 'value' => 'DEBIT');
         $filter = new Billing_Model_OpenItemFilter($filters, 'AND');
         $openItems = $this->search($filter, new Tinebase_Model_Pagination(array('sort' => 'receipt_date', 'dir' => 'ASC')));
         $payableAmount = 0;
         if ($amount > 0) {
             $payableAmount = $amount;
         }
         $resultArray = array();
         foreach ($openItems as $openItem) {
             $value = (double) $openItem->__get('open_sum');
             $aOpenItem = $openItem->toArray();
             $aOpenItem['proprosal_payment_amount'] = 0;
             $aOpenItem['payment_amount'] = $value;
             if ($value <= $payableAmount) {
                 $aOpenItem['proprosal_payment_amount'] = $value;
             }
             $resultArray[] = $aOpenItem;
             $payableAmount -= $value;
         }
         $tm->commitTransaction($tId);
         return array('success' => true, 'debitor' => $debitor->toArray(true), 'result' => $resultArray);
     } catch (Exception $e) {
         $tm->rollback($tId);
         return array('success' => false, 'debitor' => null, 'result' => null, 'errorInfo' => $e->getTrace(), 'errorMessage' => $e->getMessage());
     }
 }
Ejemplo n.º 3
0
 public function prepareDebitDtaExport(Billing_Model_BatchJob $job)
 {
     error_reporting(E_ALL);
     set_time_limit(0);
     try {
         $dueDate = new Zend_Date();
         $db = Tinebase_Core::getDb();
         $tm = Tinebase_TransactionManager::getInstance();
         $tId = $tm->startTransaction($db);
         $job = Billing_Api_BatchJobManager::getInstance()->loadBatchJob($job->getId());
         //			Billing_Api_BatchJobManager::getInstance()->startBatchJob();
         $data = $job->getData();
         $filters = $data['filters'];
         $aContexts = $data['contexts'];
         if (!is_array($aContexts)) {
             $aContexts = Zend_Json::decode($aContexts);
         }
         $pagination = new Tinebase_Model_Pagination();
         //require_once 'Payment/DTA.php';
         if (!is_array($filters)) {
             $filters = Zend_Json::decode($filters);
         }
         // get all open items (for debit)
         // grouped by debitors
         /*$filters[] = array(
         		'field' => 'banking_exp_date',
         		'operator' => 'isnull',
         		'value' => ''
         		);*/
         $filters[] = array('field' => 'state', 'operator' => 'not', 'value' => 'DONE');
         $filters[] = array('field' => 'type', 'operator' => 'equals', 'value' => 'DEBIT');
         $filters[] = array('field' => 'is_cancelled', 'operator' => 'equals', 'value' => 0);
         $filters[] = array('field' => 'is_cancellation', 'operator' => 'equals', 'value' => 0);
         //$contextFilters = array('ERP');
         $contextFilters = array();
         foreach ($aContexts as $context => $flag) {
             if ($flag) {
                 $contextFilters[] = $context;
             }
         }
         $filters[] = array('field' => 'erp_context_id', 'operator' => 'in', 'value' => $contextFilters);
         $rawFilters = $filters;
         $paymentTypeCount = count($paymentTypeKeys);
         $filter = new Billing_Model_OpenItemFilter($filters, 'AND');
         // due date: means date of execution of debit -> necessary for determination of sepa mandates
         // Telefonat: Rudat, hhartl 14.05.2014
         // "wenn im Filter angegeben, dann verwenden, ansonsten Tagesdatum"
         if ($filter->isFilterSet("due_date")) {
             $dueDate = new Zend_Date($filter->getFilter("due_date")->getValue());
         }
         // count membership matching filters
         $openItemIds = Billing_Controller_OpenItem::getInstance()->search($filter, new Tinebase_Model_Pagination(array('sort' => 'id', 'dir' => 'ASC')), false, true);
         //ob_start();
         $debitorOpenItemIds = array();
         $limit = 0;
         //echo "global count: ".count($openItemIds);
         foreach ($openItemIds as $openItemId) {
             /*if($limit++ > 250){
             			break;
             		}*/
             $openItem = Billing_Controller_OpenItem::getInstance()->get($openItemId);
             $debitorId = $openItem->getForeignId('debitor_id');
             if (!array_key_exists($debitorId, $debitorOpenItemIds)) {
                 $debitorOpenItemIds[$debitorId] = array();
             }
             $debitorOpenItemIds[$debitorId][] = $openItemId;
         }
         $addFilters = array();
         $addFilters[] = array('field' => 'membership_type', 'operator' => 'notin', 'value' => array('MEMBER_EX', 'MEMBER_GESCHENK', 'SCHENKER'));
         foreach ($debitorOpenItemIds as $debitorId => $debitorOpenItems) {
             $debitor = null;
             $contact = null;
             $contactId = null;
             $isError = false;
             try {
                 $debitor = Billing_Controller_Debitor::getInstance()->get($debitorId);
                 $contactId = $debitor->getForeignId('contact_id');
                 $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance());
                 $valid = 'UNKNOWN';
                 $activeMembershipIds = Membership_Controller_SoMember::getInstance()->getActiveMembershipsByContactId($contact->getId(), $dueDate, $addFilters);
                 $mandate = null;
                 $count = count($activeMembershipIds);
                 if (count($activeMembershipIds) == 1) {
                     $membership = Membership_Controller_SoMember::getInstance()->getSoMember($activeMembershipIds[0]);
                     if ($membership->allowsSepaDirectDebit($dueDate)) {
                         //echo "has::";
                         $hasMandate = true;
                         $mandate = $membership->getForeignRecordBreakNull('sepa_mandate_id', Billing_Controller_SepaMandate::getInstance());
                         $valid = 'YES';
                     }
                     $bankAccount = $membership->getForeignRecordBreakNull('bank_account_id', Billing_Controller_BankAccount::getInstance());
                 } elseif (count($activeMembershipIds) == 0) {
                     $regularDonations = Donator_Controller_RegularDonation::getInstance()->getByContactId($contact->getId());
                     foreach ($regularDonations as $regDon) {
                         if ($regDon->allowsSepaDirectDebit()) {
                             $mandate = $regDon->getForeignRecordBreakNull('sepa_mandate_id', Billing_Controller_SepaMandate::getInstance());
                             $valid = 'YES';
                             //echo "has::";
                             break;
                         }
                     }
                 }
                 $bankAccountName = '';
                 $bankName = '';
                 //echo "adr $contactId - count: $count\r\n";
                 if (is_null($mandate)) {
                     $bankAccount = null;
                     $valid = 'NO';
                     $sepaMandateId = null;
                     $bankAccountId = null;
                     $receipt = $openItem->getForeignRecordBreakNull('receipt_id', Billing_Controller_Receipt::getInstance());
                     $text = 'Kein gültiges Sepa-Mandat';
                     if ($receipt->getForeignId('payment_method_id') != 'DEBIT') {
                         continue;
                     }
                 } else {
                     $text = 'Sepa-Lastschrift';
                     $bankAccountId = $mandate->getForeignIdBreakNull('bank_account_id');
                     $sepaMandateId = $mandate->getId();
                 }
                 $errorInfo = '';
                 // REMARK[HH, 2013-08-23]: now set saldation contexts chosen by checkbox in start dialog:
                 // fixes quickhack hardcoded array('MEMBERSHIP','DONATOR')
                 //
                 $aSaldation = Billing_Controller_DebitorAccount::getInstance()->getSummationByDebitorId($debitorId, $contextFilters);
                 $saldation = $aSaldation['sum'];
                 $actionState = 'OPEN';
             } catch (Exception $e) {
                 $isError = true;
                 $valid = "NO";
                 $text = "Fehler - Debitor {$debitorId} kann nicht verarbeitet werden.";
                 $em = "";
                 if (is_null($debitor)) {
                     $em .= "Debitor konnte nicht geladen werden " . $debitorId . " ";
                 }
                 if (is_null($contact) || is_null($contactId)) {
                     $em .= "Kontakt konnte nicht geladen werden. Debitor.Nr.:" . $debitorId;
                 }
                 $errorInfo = "Fehler: " . $em . " <br/>\r\n Original-Meldung: " . $e->__toString();
                 $bankAccountId = null;
                 $mandate = null;
                 $actionState = 'ERROR';
                 $bankAccountName = "";
                 $bankName = "";
                 $sepaMandateId = null;
                 $contactId = $debitorId;
             }
             $batchJobDta = new Billing_Model_BatchJobDta(null, true);
             $batchJobDta->setFromArray(array('job_id' => $job->getId(), 'contact_id' => $contactId, 'debitor_id' => $debitorId, 'bank_account_id' => $bankAccountId, 'bank_account_usage_id' => 1, 'sepa_mandate_id' => $sepaMandateId, 'bank_valid' => $valid, 'bank_account_number' => 0, 'bank_code' => 0, 'bank_account_name' => $bankAccountName, 'bank_name' => $bankName, 'total_sum' => 0, 'total_saldation' => $saldation, 'diff_saldation' => 0, 'count_pos' => 0, 'skip' => !is_null($mandate), 'action_text' => $text, 'action_data' => null, 'action_type' => 'DRYRUN', 'action_state' => $actionState, 'error_info' => $errorInfo, 'created_datetime' => Zend_Date::now(), 'valid_datetime' => Zend_Date::now(), 'to_process_datetime' => Zend_Date::now(), 'process_datetime' => Zend_Date::now(), 'usage' => ''));
             $batchJobDta = $this->create($batchJobDta);
             if (!$isError) {
                 $batchJobDtaId = $batchJobDta->getId();
                 $posCount = count($debitorOpenItems);
                 $totalSum = 0;
                 $usages = array();
                 foreach ($debitorOpenItems as $openItemId) {
                     $openItem = Billing_Controller_OpenItem::getInstance()->get($openItemId);
                     $sum = (double) $openItem->__get('open_sum');
                     $batchJobDtaItem = new Billing_Model_BatchJobDtaItem(null, true);
                     $batchJobDtaItem->setFromArray(array('batch_dta_id' => $batchJobDtaId, 'open_item_id' => $openItem->getId(), 'erp_context_id' => $openItem->__get('erp_context_id'), 'total_sum' => $sum, 'skip' => false, 'usage' => $openItem->__get('usage')));
                     $usages[] = $openItem->__get('usage');
                     $totalSum += $sum;
                     Billing_Controller_BatchJobDtaItem::getInstance()->create($batchJobDtaItem);
                 }
                 $usage = implode(' ', $usages);
                 $batchJobDta->__set('usage', $usage);
                 $batchJobDta->__set('total_sum', $totalSum);
                 $batchJobDta->__set('diff_saldation', $totalSum + $saldation);
                 if ($totalSum + $saldation != 0) {
                     $batchJobDta->__set('action_text', $batchJobDta->__get('action_text') . ' Differenz überprüfen');
                 }
                 $batchJobDta->__set('count_pos', $posCount);
                 $this->update($batchJobDta);
             }
         }
         //$log = ob_get_clean();
         //Billing_Api_BatchJobManager::getInstance()->finishError($log);
         Billing_Api_BatchJobManager::getInstance()->finish();
         $tm->commitTransaction($tId);
         return array('state' => 'success', 'result' => null);
     } catch (Exception $e) {
         echo $e->__toString();
         $tm->rollback($tId);
         Billing_Api_BatchJobManager::getInstance()->finishError($e->__toString());
         return array('state' => 'failure', 'result' => null, 'errorInfo' => array('message' => $e->getMessage(), 'trace' => $e->getTrace()));
     }
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
     }
 }