/** * adds default filter on search * @see Tinebase_Controller_Record_Abstract::_addDefaultFilter() */ protected function _addDefaultFilter(Tinebase_Model_Filter_FilterGroup $_filter = NULL) { if ($this->_rightsLessSearch || Tinebase_Core::getUser()->hasRight('Sipgate', 'admin')) { return; } if (!Tinebase_Core::getUser()->hasRight('Sipgate', Sipgate_Acl_Rights::MANAGE_ACCOUNTS)) { throw new Tinebase_Exception_AccessDenied('You don\'t have insufficient permissions to manage accounts!'); } $fg = new Sipgate_Model_AccountFilter(array(), 'OR'); if (Tinebase_Core::getUser()->hasRight('Sipgate', Sipgate_Acl_Rights::MANAGE_PRIVATE_ACCOUNTS)) { $fg1 = new Sipgate_Model_AccountFilter(array(), 'AND'); $fg1->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'type', 'operator' => 'equals', 'value' => 'private'))); $fg1->addFilter(new Tinebase_Model_Filter_Id(array('field' => 'created_by', 'operator' => 'equals', 'value' => Tinebase_Core::getUser()->getId()))); $fg->addFilterGroup($fg1); $_filter->addFilterGroup($fg); } if (Tinebase_Core::getUser()->hasRight('Sipgate', Sipgate_Acl_Rights::MANAGE_SHARED_ACCOUNTS)) { $fg->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'type', 'operator' => 'equals', 'value' => 'shared'))); } }
public function printReceiptsByFilter($preview = false, $outputType, $filters, $userOptions, $types, $sort, $additionalOptions) { $additionalOptions = Zend_Json::decode($additionalOptions); if ($additionalOptions['addressLabels'] == true) { $this->printAddressLabelsByFilter($outputType, $filters, $userOptions, $types, $sort); return; } $sortField = 'creation_time'; $sortDir = 'ASC'; $sort = Zend_Json::decode($sort); $this->setUseSorting(true); if (is_array($sort) && array_key_exists('field', $sort) && array_key_exists('order', $sort)) { if (in_array($sort['field'], array('creation_time', 'order_nr'))) { $sortField = $sort['field']; } if (in_array($sort['order'], array('ASC', 'DESC'))) { $sortDir = $sort['order']; } } $this->setTypes(Zend_Json::decode($types)); $this->setOutputType($outputType); $this->setPreview($preview); $this->setFilters($filters); $this->setUserOptions($userOptions); if ($additionalOptions['preview'] == true) { $this->setPreview(true); } if ($additionalOptions['copy'] == true) { $this->setCopy(true); } $filters = $this->createFilters(); $firstGroup = new Tinebase_Model_Filter_FilterGroup(array(), 'AND'); $firstGroup->addFilterGroup($filters); if (!$this->preview && !$this->copy) { // only print receipts with empty print date! $firstGroup->addFilter(new Tinebase_Model_Filter_Date('print_date', 'isnull')); } $typesGroup = new Tinebase_Model_Filter_FilterGroup(array(), 'OR'); $inoviceFilter = null; $shippingFilter = null; if ($this->types['invoice'] == true) { $invoiceFilter = new Tinebase_Model_Filter_Text('type', 'equals', Billing_Model_Receipt::TYPE_INVOICE); } if ($this->types['credit'] == true) { $invoiceFilter = new Tinebase_Model_Filter_Text('type', 'equals', Billing_Model_Receipt::TYPE_CREDIT); } if ($this->types['shipping'] == true) { $shippingFilter = new Tinebase_Model_Filter_Text('type', 'equals', Billing_Model_Receipt::TYPE_SHIPPING); } if (!$invoiceFilter && !$shippingFilter) { $invoiceFilter = new Tinebase_Model_Filter_Text('type', 'equals', Billing_Model_Receipt::TYPE_INVOICE); } if ($invoiceFilter) { $typesGroup->addFilter($invoiceFilter); } if ($shippingFilter) { $typesGroup->addFilter($shippingFilter); } $firstGroup->addFilterGroup($typesGroup); $paging = new Tinebase_Model_Pagination(array('sort' => $sortField, 'dir' => $sortDir)); // -> get ids only $this->receiptIds = $this->_receiptController->search($firstGroup, $paging, false, TRUE); $this->runTransaction(self::PROCESS_RECEIPTS); }
public function directDebit($paymentTypeKeys, $filters) { $db = Tinebase_Core::getDb(); $tm = Tinebase_TransactionManager::getInstance(); try { require_once 'Payment/DTA.php'; if (!is_array($filters)) { $filters = Zend_Json::decode($filters); } if (!is_array($paymentTypeKeys)) { $paymentTypeKeys = Zend_Json::decode($paymentTypeKeys); } $filters[] = array('field' => 'banking_exp_date', 'operator' => 'isnull', 'value' => ''); $rawFilters = $filters; $paymentTypeCount = count($paymentTypeKeys); $filters[] = array('field' => 'payment_method_id', 'operator' => 'equals', 'value' => $paymentTypeKeys[1]); $filter1 = new Billing_Model_OpenItemFilter($filters, 'AND'); $filter = new Tinebase_Model_Filter_FilterGroup(array(), 'OR'); $filter->addFilterGroup($filter1); if ($paymentTypeCount > 1) { unset($paymentTypeKeys[1]); foreach ($paymentTypeKeys as $paymentTypeKey) { $newFilters = $rawFilters; $newFilters[] = array('field' => 'payment_method_id', 'operator' => 'equals', 'value' => $paymentTypeKey); $pFilterGroup = new Billing_Model_OpenItemFilter($newFilters, 'AND'); $filter->addFilterGroup($pFilterGroup); } } // start transaction $tId = $tm->startTransaction($db); // count membership matching filters $openItemIds = $this->search($filter, new Tinebase_Model_Pagination(array('sort' => 'due_date', 'dir' => 'ASC')), false, true); $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/'; $mandators = \Tinebase_Config::getInstance()->getConfig('mandators', NULL, TRUE)->value; $mandator = $mandators[1]['bankdata']; $hash = md5(serialize($mandator) . microtime()); $dtaFile = new DTA(DTA_DEBIT); $dtaFile->setAccountFileSender(array("name" => $mandator['account_holder'], "bank_code" => $mandator['bank_code'], "account_number" => $mandator['account_number'])); // create DTA file foreach ($openItemIds as $openItemId) { $openItem = $this->get($openItemId); // value $val = (double) $openItem->__get('open_sum'); $usage = $openItem->__get('usage'); $u = explode(',', $usage); $u1 = $u2 = ''; if (count($u) > 0) { $u1 = $u[0]; $u2 = $u[1]; } else { $u1 = $usage; } if ($val > 0) { $debitor = $openItem->getForeignRecordBreakNull('debitor_id', Billing_Controller_Debitor::getInstance()); if (!$debitor) { continue; } $contact = $debitor->getForeignRecordBreakNull('contact_id', Addressbook_Controller_Contact::getInstance()); if (!$contact) { continue; } $receipt = $openItem->getForeignRecordBreakNull('receipt_id', Billing_Controller_Receipt::getInstance()); $dtaFile->addExchange(array("name" => $contact->__get('bank_account_name'), "bank_code" => $contact->__get('bank_code'), "account_number" => $contact->__get('bank_account_number')), (string) $val, array($u1, $u2)); } $openItem->__set('banking_exp_date', new Zend_Date()); $this->update($openItem); } $dtaFile->saveFile($tempFilePath . 'DTAUS0' . $hash); $meta = $dtaFile->getMetaData(); $date = strftime("%d.%m.%y", $meta["date"]); $execDate = strftime("%d.%m.%y", $meta["exec_date"]); $count = $meta["count"]; $sumEUR = $meta["sum_amounts"]; $sumKto = $meta["sum_accounts"]; $sumBankCodes = $meta["sum_bankcodes"]; $sender = $mandator['account_holder']; $senderBank = $mandator['bank']; $senderBankCode = $mandator['bank_code']; $senderAccount = $mandator['account_number']; $handoutContent = "Datenträger-Begleitzettel\n\tErstellungsdatum: {$date} \n\tAusführungsdatum: {$execDate}\n\tAnzahl der Lastschriften: {$count}\n\tSumme der Beträge in EUR: {$sumEUR}\n\tKontrollsumme Kontonummern: {$sumKto}\n\tKontrollsumme Bankleitzahlen: {$sumBankCodes}\n\tAuftraggeber: {$sender}\n\tBeauftragtes Bankinstitut: {$senderBank}\n\tBankleitzahl: {$senderBankCode}\n\tKontonummer: {$senderAccount}"; $zip = new ZipArchive(); $filename = "{$tempFilePath}/DTAUS0-{$ogNr}.zip"; if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$filename}>\n"); } $zip->addFromString("begleitzettel.txt", $handoutContent); $zip->addFile($tempFilePath . 'DTAUS0' . $hash, 'DTAUS0'); $zip->close(); header("Content-type: application/zip;\n"); header("Content-Transfer-Encoding: binary"); $len = filesize($filename); header("Content-Length: {$len};\n"); $outname = "DTAUS0-{$ogNr}.zip"; header("Content-Disposition: attachment; filename=\"{$outname}\";\n\n"); readfile($filename); unlink($filename); $tm->commitTransaction($tId); } catch (Exception $e) { $tm->rollback($tId); } }