public function printDocs()
 {
     // print payments which are debit returns and have flag print inquiry
     $resultData = array();
     $filters = array(array('field' => 'is_return_debit', 'operator' => 'equals', 'value' => '1'), array('field' => 'print_inquiry', 'operator' => 'equals', 'value' => '1'), array('field' => 'inquiry_print_date', 'operator' => 'isnull', 'value' => ''));
     $objFilter = new Billing_Model_PaymentFilter($filters, 'AND');
     $paymentIds = Billing_Controller_Payment::getInstance()->search($objFilter, null, null, true);
     foreach ($paymentIds as $paymentId) {
         $payment = Billing_Controller_Payment::getInstance()->get($paymentId);
         // get base payment
         $basePayment = $payment->getForeignRecordBreakNull('return_debit_base_payment_id', Billing_Controller_Payment::getInstance());
         if ($basePayment) {
             $batchJobDta = $basePayment->getForeignRecordBreakNull('batch_job_dta_id', Billing_Controller_BatchJobDta::getInstance());
             if ($batchJobDta) {
                 $bankAccount = Billing_Api_BankAccount::getFromBatchJobDta($batchJobDta);
                 $debitor = $payment->getForeignRecord('debitor_id', Billing_Controller_Debitor::getInstance());
                 $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance());
                 $data = array();
                 $dummyTextBlocks = null;
                 $data = array_merge($data, Addressbook_Custom_Template::getContactData(array('contact' => $contact, 'user' => Tinebase_Core::get(Tinebase_Core::USER), 'userContact' => Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::get(Tinebase_Core::USER)->getId())), $dummyTextBlocks));
                 $data = array_merge($data, array('bank_name' => $bankAccount->getBank(), 'account_name' => $bankAccount->getName(), 'account_nr' => $bankAccount->getNumber(), 'bank_code' => $bankAccount->getBankCode()));
                 $resultData[$contact->__get('n_fileas')] = $data;
                 $payment->__set('inquiry_print_date', new Zend_Date());
                 Billing_Controller_Payment::getInstance()->update($payment);
             }
         }
     }
     $outputFileName = 'Ruecklastschrift-Nachforschung-' . strftime('%d-%m-%Y %H-%M-%S') . '.pdf';
     $templateId = Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::TEMPLATE_DEBIT_RETURN_INQUIRY);
     ksort($resultData);
     Billing_Controller_PrintJobRecordData::getInstance()->export($resultData, $templateId, $outputFileName);
 }
 public function getBankAccount()
 {
     $basePayment = null;
     if ($this->payment->hasReturnDebitBasePayment()) {
         $basePayment = $this->payment->getReturnDebitBasePayment();
     }
     if (!$basePayment) {
         throw new Exception('No base payment found, therefore no bank account detectable');
     }
     $batchJobDta = $basePayment->getBatchJobDta();
     if (!$batchJobDta) {
         throw new Exception('No dta job referenced, therefore no bank account detectable');
     }
     return Billing_Api_BankAccount::getFromBatchJobDta($batchJobDta);
 }
Exemplo n.º 3
0
 public function _inspectUpdate($_record, $oldRecord)
 {
     // if iban has changed
     if ($oldRecord->__get('iban') != $_record->__get('iban')) {
         if (Billing_Api_BankAccount::improveIBAN($_record->__get('iban'))) {
             $bankAccount = $_record->getForeignRecord('bank_account_id', Billing_Controller_BankAccount::getInstance());
             $bankAccount->__set('iban', $_record->__get('iban'));
             Billing_Controller_BankAccount::getInstance()->update($bankAccount);
         }
     }
     if ($oldRecord->__get('account_name') != $_record->__get('account_name')) {
         $bankAccount = $_record->getForeignRecord('bank_account_id', Billing_Controller_BankAccount::getInstance());
         $bankAccount->__set('name', $_record->__get('account_name'));
         Billing_Controller_BankAccount::getInstance()->update($bankAccount);
     }
     if ($oldRecord->__get('mandate_state') != 'CONFIRMED' && $_record->__get('mandate_state') == 'CONFIRMED') {
         $_record->__set('is_valid', true);
     }
     if ($_record->__get('mandate_state') != 'CONFIRMED') {
         $_record->__set('is_valid', false);
     }
 }
Exemplo n.º 4
0
 public function calculateIBAN($bankCode, $bankAccountNumber)
 {
     try {
         $iban = Billing_Api_BankAccount::calculateIBAN('DE', $bankCode, $bankAccountNumber);
         if ($iban) {
             return array('state' => 'success', 'data' => array('IBAN' => $iban));
         } else {
             return array('state' => 'failure', 'data' => null);
         }
     } catch (Exception $e) {
         return array('state' => 'failure', 'errorcode' => $e->getCode(), 'data' => array(), 'count' => 0);
     }
 }
Exemplo n.º 5
0
 public function equals(Billing_Api_BankAccount $bankAccount)
 {
     if (trim($bankAccount->getNumber()) !== trim($this->getNumber())) {
         return false;
     }
     if (trim($bankAccount->getBankCode()) !== trim($this->getBankCode())) {
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 public function updateBankAccountFromIbanAndAccountName($bankAccountId, $iban, $bankAccountName)
 {
     $bankAccount = $this->get($bankAccountId);
     $update = false;
     if ($iban) {
         if (!Billing_Api_BankAccount::improveIBAN($iban)) {
             throw new Exception('Invalid iban');
         }
         $bankAccount->__set('iban', $iban);
         $update = true;
     }
     if ($bankAccountName) {
         $bankAccount->__set('name', $bankAccountName);
         $update = true;
     }
     if ($update) {
         $bankAccount = $this->update($bankAccount);
     }
     return $bankAccount;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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;
     }
 }