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 printMonitionExportPrepare($jobId, $filteredList, $filteredListData, $monitionProtocol = false, array $batchJobMonitionIds = null) { set_time_limit(0); ignore_user_abort(true); error_reporting(E_ALL); try { $job = Billing_Api_BatchJobManager::getInstance()->loadBatchJob($jobId); Billing_Api_BatchJobManager::getInstance()->startBatchJob(); $db = Tinebase_Core::getDb(); $tm = Tinebase_TransactionManager::getInstance(); $tId = $tm->startTransaction($db); $data = $job->getData(); $pagination = new Tinebase_Model_Pagination(); //require_once 'Payment/Monition.php'; $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/'; if ($monitionProtocol) { $outputFileName = $tempFilePath . 'Protokoll-Mahnung-' . $job->getId() . '.pdf'; } else { // get all open items (for debit) // grouped by debitors $filters[] = array('field' => 'job_id', 'operator' => 'equals', 'value' => $job->getId()); $sort = array('sort' => 'n_family', 'dir' => 'ASC'); if ($filteredList) { if (!is_array($filteredListData)) { $filteredListData = Zend_Json::decode($filteredListData); } $additionalFilters = $filteredListData['filter']; if (count($additionalFilters) > 0) { $filters = array_merge($filters, $additionalFilters); } $sort = array('sort' => $filteredListData['sort']['field'], 'dir' => $filteredListData['sort']['direction']); } $filter = new Billing_Model_BatchJobMonitionFilter($filters, 'AND'); // count membership matching filters $batchJobMonitionIds = $this->search($filter, new Tinebase_Model_Pagination($sort), false, true); $outputFileName = $tempFilePath . 'Vorbereitungsliste-' . $job->getId() . '.pdf'; } $contexts = array('MEMBERSHIP' => 'Beitrag', 'DONATOR' => 'Spende', 'ERP' => 'allg.'); $data = array(); $total = 0; $count = 0; //count($batchJobMonitionIds); $subSums = array(); foreach ($batchJobMonitionIds as $batchJobDataId) { $batchJobData = $this->get($batchJobDataId); // keep out item which are diffed if (!$filteredList && $batchJobData->__get('monition_lock') == 1) { continue; } $count++; $batchJobDataItems = Billing_Controller_BatchJobMonitionItem::getInstance()->getByBatchJobMonitionId($batchJobData->getId()); $contact = $batchJobData->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance()); $strOP = ''; foreach ($batchJobDataItems as $item) { // Kontext / Fällig am / Beleg / Betrag $openItem = $item->getForeignRecord('open_item_id', Billing_Controller_OpenItem::getInstance()); /*if($openItem->__get('state') != 'OPEN'){ // tried to include open item which was already done!!! // break the job $this->cleanupJob($jobId); // break job! throw new Billing_Exception_OpenItem('Open item '.$openItem->__get('op_nr').' is already finished.'); }*/ $receipt = $openItem->getForeignRecord('receipt_id', Billing_Controller_Receipt::getInstance()); $contactNr = $batchJobData->getForeignId('contact_id'); $receiptNr = $receipt->__get('invoice_nr'); if ($receipt->getAdditionalItem('MNR')) { $contactNr = $receipt->getAdditionalItem('MNR'); } $dueDate = $openItem->__get('due_date'); $erpContext = $contexts[$receipt->__get('erp_context_id')]; $sum = $openItem->__get('open_sum'); $context = $receipt->__get('erp_context_id'); $strOP .= $receiptNr . "<text:tab/><text:tab/>" . $contactNr . "<text:tab/><text:tab/>" . $erpContext . "<text:tab/><text:tab/>" . \org\sopen\app\util\format\Date::format($dueDate) . "<text:tab/><text:tab/>" . $openItem->__get('due_days') . "<text:tab/><text:tab/>" . $openItem->getNextMonitionStage() . "<text:tab/><text:tab/>" . number_format($sum, 2, ',', '.') . "<text:line-break/>"; if (!array_key_exists($context, $subSums)) { $subSums[$context] = array('context' => $erpContext, 'method' => '', 'count' => 0, 'sum' => 0); } $subSums[$context]['sum'] += $sum; $subSums[$context]['count']++; } $usage = array(); $contactNr = $batchJobData->getForeignId('contact_id'); $usage[] = 'Adr.Nr ' . $contactNr; //$this->extractUsageFromMonitionItems( $batchJobDataItems, &$usage, $contexts); $strUsage = implode('<text:line-break/>', $usage); /* ##MNR## ##LASTNAME## ##FORENAME## ##OPENITEMS## ##AMOUNT## */ $data[] = array('MNR' => $contact->getId(), 'FORENAME' => $contact->__get('n_given'), 'LASTNAME' => $contact->__get('n_family'), 'FORENAME_PARTNER' => $contact->__get('partner_forename'), 'LASTNAME_PARTNER' => $contact->__get('partner_lastname'), 'COMPANY' => $contact->__get('org_name') . ($contact->__get('company2') ? ' ' . $contact->__get('company2') : ''), 'USAGE' => $strUsage, 'OPENITEMS' => $strOP, 'OPEN' => number_format($batchJobData->__get('open_sum'), 2, ',', '.'), 'SALDO' => number_format($batchJobData->__get('total_saldation'), 2, ',', '.'), 'TOTAL' => number_format($batchJobData->__get('total_sum'), 2, ',', '.')); $total += $batchJobData->__get('total_sum'); } $dynTable = array(); foreach ($subSums as $context => $subItem) { $dynTable[] = array('headers' => array(), 'rows' => array(array('text' => $subItem['context'], 'dcount' => $subItem['count'], 'dsum' => number_format($subItem['sum'], 2, ',', '.')))); } $fullData = array(array('REPEATABLE_DYN_TABLE' => $dynTable, 'POS_TABLE' => $data, 'total' => number_format($total, 2, ',', '.'), 'count' => $count)); $outputFileName = $tempFilePath . md5(serialize($job) . 'preparePDF' . microtime()) . '.pdf'; $templateId = Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::TEMPLATE_MONITION_PREPARE); Billing_Controller_PrintJobRecordData::getInstance()->export($fullData, $templateId, 'Vorbereitungsliste-' . $job->getId() . '.pdf', true, $outputFileName); if (!$monitionProtocol) { if (!$filteredList) { Billing_Api_BatchJobManager::getInstance()->jobAddData('preparePDF', $outputFileName); Billing_Api_BatchJobManager::getInstance()->jobAddData('preparePDFDownloadFilename', 'Vorbereitungsliste-' . $job->getId() . '.pdf'); } else { Billing_Api_BatchJobManager::getInstance()->jobAddData('filteredPreparePDF', $outputFileName); Billing_Api_BatchJobManager::getInstance()->jobAddData('filteredPreparePDFDownloadFilename', 'Gefilterte-Vorbereitungsliste-' . $job->getId() . '.pdf'); } } else { Billing_Api_BatchJobManager::getInstance()->jobAddData('protocolPDF', $outputFileName); Billing_Api_BatchJobManager::getInstance()->jobAddData('protocolPDFDownloadFilename', 'Protokoll-Monition-' . $job->getId() . '.pdf'); } $tm->commitTransaction($tId); Billing_Api_BatchJobManager::getInstance()->finish(); 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())); } }
public function exportArticleSellList($data, $exportType) { $export = Billing_Custom_ArticleExportData::create($data); if ($export->hasNoGrouping() || $exportType == 'CSV') { $export->setRecordSet(Billing_Controller_ArticleSold::getInstance()->search($export->getFilter(), $export->getPagination())); } elseif ($export->hasGroupingCustomer()) { // get all customers // -> maybe a huge set // check restrictions of filter regarding customer (customer_group) /* $debitorFilter = new Billing_Model_DebitorFilter(array(),'AND'); $debFilter = null; $articleFilter = $export->getFilter(); if($articleFilter->isFilterSet('debitor_id')){ $debFilter = $articleFilter->getFilter('debitor_id'); if($debFilter->isFilterSet('id')){ $debitorFilter->addFilter($debFilter->get('id')); } if($debFilter->isFilterSet('debitor_group_id')){ $debitorFilter->addFilter($debFilter->get('debitor_group_id')); } }*/ $debitorIds = Billing_Controller_ArticleSold::getInstance()->getDebitorIds($export->getFilter()); foreach ($debitorIds as $debitorId) { $debitor = Billing_Controller_Debitor::getInstance()->get($debitorId); $export->addCustomerRecordSet(Billing_Controller_ArticleSold::getInstance()->search($export->getCustomerFilter($debitor), $export->getPagination()), $debitorId); } } switch ($exportType) { case 'PDF': $outputFileName = 'Artikel-Verkaufsliste-' . strftime('%d-%m-%Y %H-%M-%S') . '.pdf'; $templateId = Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::TEMPLATE_ARTICLE_SOLD); if ($export->hasGroupingCustomer()) { $data = array(); $aResult = $export->customerRecordsToArray(true); foreach ($aResult as $debitorId => $result) { $debitor = Billing_Controller_Debitor::getInstance()->get($debitorId); $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance()); $data[$contact->__get('n_fileas')] = array('POS_TABLE' => $result['data'], 'customer_nr' => $debitor->__get('debitor_nr'), 'customer_name' => $contact->__get('n_fileas'), 'begin_date' => \org\sopen\app\util\format\Date::format(new Zend_Date($export->getStartDate())), 'end_date' => $export->getEndDate() ? \org\sopen\app\util\format\Date::format(new Zend_Date($export->getEndDate())) : 'heute', 'sum_total_netto' => number_format($result['total_netto'], 2, ',', '.'), 'sum_total_brutto' => number_format($result['total_brutto'], 2, ',', '.')); } ksort($data); } else { $data = array(array('POS_TABLE' => $export->toArray(true), 'begin_date' => \org\sopen\app\util\format\Date::format(new Zend_Date($export->getStartDate())), 'end_date' => $export->getEndDate() ? \org\sopen\app\util\format\Date::format(new Zend_Date($export->getEndDate())) : 'heute', 'sum_total_netto' => number_format($export->getSumTotalNetto(), 2, ',', '.'), 'sum_total_brutto' => number_format($export->getSumTotalBrutto(), 2, ',', '.'))); } Billing_Controller_PrintJobRecordData::getInstance()->export($data, $templateId, $outputFileName); break; case 'CSV': $this->exportAsCsv($export, 'Artikel-Verkaufsliste-' . strftime('%d-%m-%Y %H-%M-%S') . '.csv'); break; } }