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);
 }
Exemple #2
0
 public function savePayment($recordData)
 {
     $obj = new Billing_Model_Payment();
     $obj->setFromArray($recordData);
     try {
         $objId = $obj->getId();
         $obj = Billing_Controller_Payment::getInstance()->get($objId);
         $obj->setFromArray($recordData);
         $obj = Billing_Controller_Payment::getInstance()->update($obj);
     } catch (Exception $e) {
         $obj = Billing_Controller_Payment::getInstance()->create($obj);
     }
     return $obj->toArray();
 }
 public function runDebitDtaExport($jobId, $dueDate)
 {
     set_time_limit(0);
     error_reporting(E_ALL);
     $job = Billing_Api_BatchJobManager::getInstance()->loadBatchJob($jobId);
     Billing_Api_BatchJobManager::getInstance()->startBatchJob();
     try {
         //$dueDate = '2014-02-17';
         $dueDate = new Zend_Date($dueDate);
         // init wsf lib
         \worg\wsf\util\xml\XmlSerializer::setIgnoreEmptyTags(true);
         \worg\wsf\util\objects\Binding::getForXmlFile(CSopen::instance()->getLibPath() . 'wsflib/worg/wsf/sepa/binding/', 'debit-binding.xml');
         $sepa = $this->createNewSepa($creditor);
         $db = Tinebase_Core::getDb();
         $tm = Tinebase_TransactionManager::getInstance();
         $tId = $tm->startTransaction($db);
         $data = $job->getData();
         $filters = $data['filters'];
         $pagination = new Tinebase_Model_Pagination();
         $contexts = array('EVENTMANAGER' => 'Veranst.', 'MEMBERSHIP' => 'Beitrag', 'DONATOR' => 'Spende', 'ERP' => 'allg.');
         // get all open items (for debit)
         // grouped by debitors
         $filters[] = array('field' => 'job_id', 'operator' => 'equals', 'value' => $job->getId());
         $filter = new Billing_Model_BatchJobDtaFilter($filters, 'AND');
         // count membership matching filters
         $batchJobDtaIds = $this->search($filter, new Tinebase_Model_Pagination(array('sort' => 'n_family', 'dir' => 'ASC')), false, true);
         $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/';
         $hash = md5(microtime());
         $protocolBatchJobDtaIds = array();
         $sumOfPayment = 0;
         $countTransactions = 0;
         foreach ($batchJobDtaIds as $batchJobDtaId) {
             $batchJobDta = $this->get($batchJobDtaId);
             // keep out item which are diffed
             if ($batchJobDta->__get('bank_valid') != 'YES' || abs((double) $batchJobDta->__get('total_sum')) == 0) {
                 continue;
             }
             //$bankAccount = Billing_Api_BankAccount::getFromBatchJobDta($batchJobDta);
             $bankAccount = $batchJobDta->getBankAccount();
             if (is_null($bankAccount)) {
                 continue;
             }
             $batchJobDtaItems = Billing_Controller_BatchJobDtaItem::getInstance()->getByBatchJobDtaId($batchJobDtaId);
             $usage = array();
             $contactNr = $batchJobDta->getForeignId('contact_id');
             $usage[] = 'Adr.Nr ' . $contactNr;
             $payment = Billing_Model_Payment::createDebitFromDta($batchJobDtaId, $batchJobDta->getForeignId('debitor_id'), new Zend_Date($batchJobDta->__get('created_datetime')), $batchJobDta->__get('total_sum'), 'DEBIT', 'ERP');
             $this->extractUsageFromDtaItems($batchJobDtaItems, $usage, $contexts, $aReceiptIds);
             $paymentAmount = $batchJobDta->getTotalSum();
             $sumOfPayment += $paymentAmount;
             if (is_array($usage)) {
                 $usage = join(' ', $usage);
             }
             $endToEndId = $contactNr . '-' . join('-', $aReceiptIds);
             $this->addSepaTransaction($sepa, $batchJobDta, $bankAccount, $creditor, $dueDate, $paymentAmount, $endToEndId, $usage);
             if ($this->countTransactions % 1000 == 0) {
                 $filename = $tempFilePath . "SEPA-DD-" . $job->__get('job_nr') . "-" . ($this->getFileCount() + 1) . ".xml";
                 $this->finishSepaTransactionBlock($sepa, $filename);
                 $sepa = $this->createNewSepa($creditor);
             }
             $protocolBatchJobDtaIds[] = $batchJobDtaId;
             $batchJobDta->__set('action_state', 'EXPORTED');
             $batchJobDta->__set('process_datetime', Zend_Date::now());
             $batchJobDta->__set('processed_by_user', Tinebase_Core::get(Tinebase_Core::USER)->getId());
             $this->update($batchJobDta);
         }
         if ($this->hasOpenSepaContainer()) {
             $filename = $tempFilePath . "SEPA-DD-" . $job->__get('job_nr') . "-" . ($this->getFileCount() + 1) . ".xml";
             $this->finishSepaTransactionBlock($sepa, $filename);
         }
         if ($this->getFileCount() > 1) {
             $zip = new ZipArchive();
             $zipFilename = $tempFilePath . "SEPA-DD-" . $job->__get('job_nr') . ".zip";
             if ($zip->open($zipFilename, ZIPARCHIVE::CREATE) !== TRUE) {
                 throw new SPExcpetion("cannot open <{$filename}> for zip");
             }
             $lCount = 0;
             foreach ($this->sepaFiles as $file) {
                 $zip->addFile($file, 'SEPA-DD-' . $job->__get('job_nr') . '-' . ++$lCount . ".xml");
             }
             $zip->close();
             $jobFileName = $zipFilename;
             $downloadExt = '.zip';
         } else {
             $downloadExt = '.xml';
             $jobFileName = $this->sepaFiles[0];
         }
         Billing_Api_BatchJobManager::getInstance()->jobAddData('DTA', $jobFileName);
         Billing_Api_BatchJobManager::getInstance()->jobAddData('DTADownloadFilename', 'SEPA-DD-' . $job->__get('job_nr') . $downloadExt);
         //$tm->rollback($tId);
         $tm->commitTransaction($tId);
         //Billing_Api_BatchJobManager::getInstance()->finish();
         $this->printDtaExportPrepare($jobId, false, null, true, $protocolBatchJobDtaIds);
         return array('state' => 'success', 'result' => null);
         //        $outputFileName = $tempFilePath . md5(serialize($job).'preparePDF'.microtime()).'.pdf';
     } 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()));
     }
 }