Пример #1
0
 /**
  * the singleton pattern
  *
  * @return SoBillingManager_Controller_SoBilling
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Пример #2
0
 public static function create($type, $debitorId, $date, $amount, $paymentMethod = null, $erpContextId = 'ERP')
 {
     if (is_null($paymentMethod)) {
         $paymentMethod = Billing_Controller_PaymentMethod::getInstance()->getDefaultPaymentMethod();
     }
     if ($paymentMethod instanceof Billing_Model_PaymentMethod) {
         $paymentMethod = $paymentMethod->getId();
     }
     $obj = new self();
     $obj->__set('debitor_id', $debitorId);
     $obj->__set('amount', $amount);
     $obj->__set('payment_date', $date);
     $obj->__set('type', $type);
     $obj->__set('payment_method_id', $paymentMethod);
     return $obj;
 }
Пример #3
0
 /**
  * 
  * Extract and provide data to be delivered to template
  * @param array $dataObjects
  * @param array $textBlocks	Reference to template inherent textblocks (can be manipulated here)
  */
 protected static function getUniversalReceiptData(array $dataObjects, &$textBlocks)
 {
     self::getDataObjects($dataObjects, &$contact, &$receipt, &$job, &$order, &$debitor, &$creditor, &$sums, &$aPositions, &$sumTable, &$sumData, &$addData);
     $letterDrawee = $contact->getLetterDrawee();
     $shippingDrawee = $contact->getShippingDrawee();
     $invoiceDrawee = $contact->getInvoiceDrawee();
     $alternativeShippingDrawee = '';
     if ($invoiceDrawee !== $shippingDrawee) {
         $alternativeShippingDrawee = 'Lieferung an:' . chr(13) . chr(10) . $shippingDrawee->toText(true);
     }
     $totalBrutto = $sums['total']['sum']['brutto'];
     $monitionFee = $receipt->__get('monition_fee');
     $totalSum = $totalBrutto + $monitionFee;
     // overwrite payment conditions, if these are set in the record
     // otherwise use text from docmanager template
     $paymentMethod = $receipt->getForeignRecord('payment_method_id', Billing_Controller_PaymentMethod::getInstance());
     // if order state: PAYED -> get tb2 from payment method otherwise tb2
     if ($order->__get('payment_state') == 'PAYED') {
         $textBlocks['ZAHLUNGSBEDINGUNGEN'] = $paymentMethod->__get('text1');
     } else {
         $textBlocks['ZAHLUNGSBEDINGUNGEN'] = $paymentMethod->__get('text2');
     }
     if ($receipt->__get('payment_conditions')) {
         $textBlocks['ZAHLUNGSBEDINGUNGEN'] = $receipt->__get('payment_conditions');
     }
     $sumPositions = $sumTable['POSITIONS'];
     $aVat = array();
     foreach ($sumPositions as $sp) {
         $name = (string) 'vat' . floor($sp['vn_vatindex']);
         $aVat[$name] = $sp['vn_vat'];
     }
     $userContact = $dataObjects['userContact'];
     $user = $dataObjects['user'];
     $userName = $userContact->__get('n_family');
     $payerName = $contact->__get('n_fileas');
     $payerBankAccountNumber = $contact->__get('bank_account_number');
     $payerBankCode = $contact->__get('bank_code');
     $payerBankAccountName = $contact->__get('bank_account_name');
     $payerBankName = $contact->__get('bank_name');
     $cpInvoiceDrawee = $contact->getInvoiceDrawee()->toText();
     $cpShippingDrawee = $contact->getShippingDrawee()->toText();
     if ($receipt->hasAdditionalItem('contactPersonId')) {
         try {
             $contactPerson = Addressbook_Controller_ContactPerson::getInstance()->get((int) $receipt->getAdditionalItem('contactPersonId'));
             $cpInvoiceDrawee = $contact->getInvoiceDrawee()->setContactPerson($contactPerson)->toText();
             $cpShippingDrawee = $contact->getShippingDrawee()->setContactPerson($contactPerson)->toText();
         } catch (Exception $e) {
             echo $e;
             exit;
             //
         }
     }
     $result = array('JOB_NR' => $job ? $job->__get('job_nr') : null, 'ORDER_NR' => $order->__get('order_nr'), 'CALC_NR' => $receipt->__get('calc_nr'), 'BID_NR' => $receipt->__get('bid_nr'), 'BID_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('bid_date')), 'BID_SHIP_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('bid_shipping_date')), 'CONFIRM_NR' => $receipt->__get('confirm_nr'), 'CONFIRM_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('order_confirm_date')), 'INV_NR' => $receipt->__get('invoice_nr'), 'INV_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('invoice_date')), 'DUE_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('due_date')), 'CUST_NR' => $debitor->__get('debitor_nr'), 'SHIP_NR' => $receipt->__get('ship_nr'), 'SHIP_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('shipping_date')), 'CREDIT_NR' => $receipt->__get('credit_nr'), 'CREDIT_DATE' => \org\sopen\app\util\format\Date::format($receipt->__get('credit_date')), 'MONITION_NR' => $receipt->__get('monition_nr'), 'MONITION_LEVEL' => $receipt->__get('monition_level'), 'MONITION_DATE' => strftime('%d.%m.%Y'), 'TEXT1' => $receipt->__get('upper_textblock'), 'TEXT2' => $receipt->__get('lower_textblock'), 'SHIPPING_COND' => $receipt->__get('shipping_conditions'), 'PAYMENT_COND' => $receipt->__get('payment_conditions'), 'TODAY' => strftime('%d.%m.%Y'), 'NOW' => strftime('%d.%m.%Y %H:%M:%S'), 'CONTACT' => $contact, 'CONTACT_NR' => $contact->__get('id'), 'ADRESS' => array('ALTERNATIVE_SHIPPING_DRAWEE' => $alternativeShippingDrawee, 'LETTER_DRAWEE' => $contact->getLetterDrawee()->toText(), 'SHIPPING_DRAWEE' => $contact->getShippingDrawee()->toText(), 'INVOICE_DRAWEE' => $contact->getInvoiceDrawee()->toText(), 'SALUTATION' => $contact->__get('letter_salutation'), 'AP_INVOICE_DRAWEE' => $cpInvoiceDrawee, 'AP_SHIPPING_DRAWEE' => $cpShippingDrawee), 'POSDATA' => $sumTable['POSDATA'], 'POS_TABLE' => $aPositions, 'SUM_TABLE' => $sumTable, 'VALUES' => array_merge(array('vn_netto_sum' => number_format($sums['total']['sum']['netto'], 2, ',', '.'), 'vn_vat_sum' => number_format($sums['total']['sum']['vat'], 2, ',', '.'), 'vn_brutto_sum' => number_format($sums['total']['sum']['brutto'], 2, ',', '.'), 'add_perc' => $receipt->__get('add_percentage')), $aVat), 'SUMS' => $sumData, 'monition_fee' => number_format($monitionFee, 2, ',', '.'), 'total_sum' => number_format($totalSum, 2, ',', '.'), 'USER' => array('N' => $userName, 'NUPPER' => strtoupper($userName), 'NFULL' => $userContact->__get('n_fileas'), 'NFORE' => $userContact->__get('n_given'), 'NLAST' => $userContact->__get('n_family'), 'PHONE' => $userContact->__get('tel_work'), 'FAX' => $userContact->__get('tel_fax'), 'MAIL' => $userContact->__get('email')), 'INVOICE_DRAWEE' => $invoiceDrawee->toText(true), 'PAYER_NAME' => $payerName, 'P_ACC' => $payerBankAccountNumber, 'P_ACCOUNT_NAME' => $payerBankAccountName, 'P_ACCOUNT_NR' => $payerBankAccountNumber, 'P_BANK_CODE' => $payerBankCode, 'P_BANK_NAME' => $payerBankName, 'UST_ID' => $debitor->__get('ust_id'));
     $additionalData = $receipt->getAdditionalData();
     /*if(is_array($additionalData)){
     			if(array_key_exists('BALANCE', $additionalData)){
     				if((float)$additionalData['BALANCE']<0){
     					$additionalData['REMINDER'] = 'Wir erinnern höflich an den noch ausstehenden Jahresbeitrag 2012:';
     					$additionalData['remind'] = number_format(abs((float)$additionalData['BALANCE']),2,',','.') . ' EUR';
     				}elseif((float)$additionalData['BALANCE']>0){
     					$additionalData['REMINDER'] = 'davon bereits bezahlt:';
     					$additionalData['remind'] = number_format(abs((float)$additionalData['BALANCE']),2,',','.') . ' EUR';
     				}
     			}
     			$result = array_merge($result, $additionalData );
     		}*/
     if (is_array($additionalData)) {
         if (array_key_exists('OPEN', $additionalData)) {
             if ((double) $additionalData['OPEN'] > 0) {
                 $additionalData['OPEN_EUR'] = $additionalData['OPEN_EUR'] . ' EUR';
                 //$additionalData['REMINDER'] = 'Wir erinnern höflich an den noch ausstehenden Jahresbeitrag 2012:';
                 //$additionalData['remind'] = number_format(abs((float)$additionalData['BALANCE']),2,',','.') . ' EUR';
             } else {
                 $additionalData['OPEN_EUR'] = '';
             }
         }
         $result = array_merge($result, $additionalData);
     }
     $result = array_merge($result, $addData);
     //print_r($result);
     //exit;
     return $result;
 }
Пример #4
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::create()
  */
 public function create(Tinebase_Record_Interface $_record)
 {
     // if no explicit payment method given:
     // inherit payment method from order, or get default
     $order = $_record->getForeignRecord('order_id', Billing_Controller_Order::getInstance());
     if (!$_record->__get('payment_method_id')) {
         $paymentMethodId = Billing_Controller_PaymentMethod::getInstance()->getPaymentMethodFromRecordOrDefault($order, 'payment_method_id')->getId();
         $_record->__set('payment_method_id', $paymentMethodId);
     }
     $record = parent::create($_record);
     /*$type = $_record->__get('type');
     	 	
     		switch($type){
     			case Billing_Model_Receipt::TYPE_INVOICE:
     			case Billing_Model_Receipt::TYPE_CREDIT:
     				$receipt = $this->get($record->getId());
     				
     				Tinebase_Event::fireEvent(new Billing_Events_BillableReceiptCreated($receipt));
     				
     			break;
     		}*/
     return $record;
 }
Пример #5
0
 public function getPaymentMethods()
 {
     return Billing_Controller_PaymentMethod::getInstance()->getAllPaymentMethods();
 }
Пример #6
0
 public function calculateDueDate()
 {
     $dueDate = new Zend_Date();
     $paymentMethod = $this->getForeignRecordBreakNull('payment_method_id', Billing_Controller_PaymentMethod::getInstance());
     if ($paymentMethod instanceof Billing_Model_PaymentMethod) {
         $dueInDays = $paymentMethod->__get('due_in_days');
         if ($dueInDays > 0) {
             $dueDate->add($dueInDays, Zend_Date::DAY);
         }
     }
     $this->__set('due_date', $dueDate);
 }
Пример #7
0
 public function printDtaExportPrepare($jobId, $filteredList, $filteredListData, $dtaProtocol = false, array $batchJobDtaIds = 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/DTA.php';
         $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/';
         if ($dtaProtocol) {
             $outputFileName = $tempFilePath . 'Protokoll-SEPA-' . $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_BatchJobDtaFilter($filters, 'AND');
             // count membership matching filters
             $batchJobDtaIds = $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($batchJobDtaIds);
         $subSums = array();
         foreach ($batchJobDtaIds as $batchJobDataId) {
             $batchJobData = $this->get($batchJobDataId);
             // keep out item which are diffed
             //if(!$filteredList &&($batchJobData->__get('bank_valid')!='YES' || abs((float)$batchJobData->__get('diff_saldation'))>0.005)|| abs((float)$batchJobData->__get('total_sum')==0)){
             if (!$filteredList && ($batchJobData->__get('bank_valid') != 'YES' || abs((double) $batchJobData->__get('total_sum') == 0))) {
                 continue;
             }
             $count++;
             $batchJobDataItems = Billing_Controller_BatchJobDtaItem::getInstance()->getByBatchJobDtaId($batchJobData->getId());
             $contact = $batchJobData->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance());
             //$bankAccount = Billing_Api_BankAccount::getFromBatchJobDta($batchJobData);
             $bankAccount = $batchJobData->getForeignRecordBreakNull('bank_account_id', Billing_Controller_BankAccount::getInstance());
             $strOP = '';
             if (!$bankAccount) {
                 continue;
             }
             foreach ($batchJobDataItems as $item) {
                 // Kontext / Fällig am / Beleg / Betrag
                 $openItem = $item->getForeignRecord('open_item_id', Billing_Controller_OpenItem::getInstance());
                 $receipt = $openItem->getForeignRecord('receipt_id', Billing_Controller_Receipt::getInstance());
                 $paymentMethod = $receipt->getForeignRecordBreakNull('payment_method_id', Billing_Controller_PaymentMethod::getInstance());
                 if (!$paymentMethod) {
                     $paymentMethodId = 'NOVALUE';
                     $strPaymentMethod = '...keine Auswahl...';
                 } else {
                     $paymentMethodId = $paymentMethod->getId();
                     $strPaymentMethod = $paymentMethod->__get('name');
                 }
                 /*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.');
                 		}*/
                 $receiptNr = $receipt->__get('invoice_nr');
                 if ($receipt->getAdditionalItem('MNR')) {
                     $receiptNr = $receipt->getAdditionalItem('MNR');
                 }
                 $dueDate = $receipt->__get('due_date');
                 $erpContext = $contexts[$receipt->__get('erp_context_id')];
                 $sum = $item->__get('total_sum');
                 $context = $receipt->__get('erp_context_id');
                 $strOP .= $erpContext . "<text:tab/><text:tab/>" . \org\sopen\app\util\format\Date::format($dueDate) . "<text:tab/><text:tab/>" . $receiptNr . "<text:tab/><text:tab/>" . number_format($sum, 2, ',', '.') . "<text:line-break/>";
                 if (!array_key_exists($context, $subSums)) {
                     $subSums[$context] = array('context' => $erpContext, 'method' => $strPaymentMethod, 'count' => 0, 'sum' => 0);
                 }
                 $subSums[$context]['sum'] += $sum;
                 $subSums[$context]['count']++;
             }
             $usage = array();
             $contactNr = $batchJobData->getForeignId('contact_id');
             $usage[] = 'Adr.Nr ' . $contactNr;
             $this->extractUsageFromDtaItems($batchJobDataItems, $usage, $contexts);
             $strUsage = implode('<text:line-break/>', $usage);
             $arr = array('YES' => 1, 'NO' => 0, 'UNKNOWN' => 0);
             $sepaDate = null;
             if ($batchJobData->__get('sepa_signature_date')) {
                 $sepaDate = \org\sopen\app\util\format\Date::format($batchJobData->__get('sepa_signature_date'));
             }
             /*
             				 ##MNR##
             				 ##LASTNAME##
             				 ##FORENAME##
             				 ##BANKVALID##
             				 ##ACC##
             				 ##BCODE##
             				 ##HOLDER##
             				 ##BANK##
             				 ##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') : ''), 'BANKVALID' => $arr[$batchJobData->__get('bank_valid')], 'SEPA' => $sepaDate, 'IBAN' => \worg\wsf\util\format\IBAN::formatQuadruple($bankAccount->getIBAN()), 'BIC' => $bankAccount->getBIC(), 'ACC' => $bankAccount->getNumber(), 'BCODE' => $bankAccount->getBankCode(), 'HOLDER' => $bankAccount->getName(), 'BANK' => $bankAccount->getBank(), 'USAGE' => $strUsage, 'OPENITEMS' => $strOP, 'DIFF' => number_format($batchJobData->__get('diff_saldation'), 2, ',', '.'), 'SALDO' => number_format($batchJobData->__get('total_saldation'), 2, ',', '.'), 'AMOUNT' => 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_DTA_DEBIT_PREPARE);
         Billing_Controller_PrintJobRecordData::getInstance()->export($fullData, $templateId, 'Vorbereitungsliste-' . $job->getId() . '.pdf', true, $outputFileName);
         if (!$dtaProtocol) {
             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-SEPA-' . $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()));
     }
 }
Пример #8
0
 /**
  * 
  * Trigger the order billing process
  * @param int $orderId
  * @param array $params
  * @return bool	true|false success yes|no
  */
 public function billOrder($orderId, $params)
 {
     if (!array_key_exists('receipt_type', $params['data'])) {
         $receiptType = Billing_Model_Receipt::TYPE_INVOICE;
     } else {
         $receiptType = $params['data']['receipt_type'];
     }
     $receipt = Billing_Model_Receipt::create($receiptType);
     // set base data of receipt
     if (array_key_exists('data', $params)) {
         $receipt->setFromArray($params['data']);
     }
     // if there is additional data given, in order to be injected into template
     if (array_key_exists('additionalTemplateData', $params)) {
         $receipt->setAdditionalData($params['additionalTemplateData']);
     }
     // set invoice date
     switch ($receiptType) {
         case Billing_Model_Receipt::TYPE_INVOICE:
             if (array_key_exists('invoice_date', $params['data'])) {
                 // set given daten for invoice date
                 $receipt->__set('invoice_date', new Zend_Date($params['data']['invoice_date']));
             } else {
                 // set current date for invoice date
                 $receipt->__set('invoice_date', new Zend_Date());
             }
             break;
         case Billing_Model_Receipt::TYPE_CREDIT:
             if (array_key_exists('credit_date', $params['data'])) {
                 // set given daten for invoice date
                 $receipt->__set('credit_date', new Zend_Date($params['data']['invoice_date']));
             } else {
                 // set current date for invoice date
                 $receipt->__set('credit_date', new Zend_Date());
             }
             break;
     }
     // set due date
     // 1) grab due_in_days from payment method
     // 2) add to invoice_date
     // shitty name chosen for paymentmethod of receipt -> payment_type
     // hack around it
     if (array_key_exists('payment_method_id', $params['data'])) {
         $receipt->__set('payment_method_id', $params['data']['payment_method_id']);
     }
     $dueDate = new Zend_Date();
     $paymentMethod = $receipt->getForeignRecordBreakNull('payment_method_id', Billing_Controller_PaymentMethod::getInstance());
     if ($paymentMethod instanceof Billing_Model_PaymentMethod) {
         $dueInDays = $paymentMethod->__get('due_in_days');
         if ($dueInDays > 0) {
             $dueDate->add($dueInDays, Zend_Date::DAY);
         }
     }
     $receipt->__set('due_date', $dueDate);
     // finally attach receipt to order
     return $this->attachReceipt($receipt, $orderId, $params);
 }