Example #1
0
 public function generateSepaMandateForBankAccountUsage(Billing_Model_BankAccountUsage $usage)
 {
     // read full featured record from backend
     $usage = Billing_Controller_BankAccountUsage::getInstance()->get($usage->getId());
     $sepaMandate = $usage->getForeignRecordBreakNull('sepa_mandate_id', $this);
     if (!$sepaMandate || is_object($sepaMandate && $sepaMandate->__get('is_deleted'))) {
         $bank = $usage->getForeignRecord('bank_id', Billing_Controller_Bank::getInstance());
         $bankAccount = $usage->getForeignRecord('bank_account_id', Billing_Controller_BankAccount::getInstance());
         $sepaMandateIdent = $bankAccount->getForeignId('contact_id');
         $sepaMandate = $this->getByMandateIDBreakNull($sepaMandateIdent);
         //var_dump($sepaMandate);
         if (is_null($sepaMandate)) {
             //echo "create new...";
             $sepaMandate = new Billing_Model_SepaMandate();
             $sepaMandate->__set('contact_id', $bankAccount->getForeignId('contact_id'));
             $sepaMandate->__set('bank_account_id', $bankAccount->getId());
             $sepaCreditors = Billing_Controller_SepaCreditor::getInstance()->getAll();
             $sepaCreditor = $sepaCreditors->getFirstRecord();
             $sepaMandate->__set('sepa_creditor_id', $sepaCreditor->getId());
             $sepaMandate->__set('mandate_ident', $sepaMandateIdent);
             $sepaMandate->__set('is_single', false);
             $sepaMandate = $this->create($sepaMandate);
         } else {
             //echo "double...";
             if ($sepaMandate->getForeignId('bank_account_id') != $bankAccount->getId()) {
                 //echo "create...";
                 $sepaMandateIdent .= '-BA' . $bankAccount->getId();
                 $sepaMandate = new Billing_Model_SepaMandate();
                 $sepaMandate->__set('contact_id', $bankAccount->getForeignId('contact_id'));
                 $sepaMandate->__set('bank_account_id', $bankAccount->getId());
                 $sepaCreditors = Billing_Controller_SepaCreditor::getInstance()->getAll();
                 $sepaCreditor = $sepaCreditors->getFirstRecord();
                 $sepaMandate->__set('sepa_creditor_id', $sepaCreditor->getId());
                 $sepaMandate->__set('mandate_ident', $sepaMandateIdent);
                 $sepaMandate->__set('is_single', false);
                 $sepaMandate = $this->create($sepaMandate);
             }
         }
     }
     $usage->__set('sepa_mandate_id', $sepaMandate->getId());
     //echo "set usage sepa mandate:". $sepaMandate->getId();
     Billing_Controller_BankAccountUsage::getInstance()->update($usage);
 }
 public function setSepaMandate(Billing_Model_SepaMandate $mand)
 {
     $this->__set('sepa_mandate_id', $mand->getId());
 }