Example #1
0
 public function getContraBookings()
 {
     $bookingId = $this->getForeignId('booking_id');
     $type = $this->__get('type');
     $aTypes = array('DEBIT' => 'CREDIT', 'CREDIT' => 'DEBIT');
     return Billing_Controller_AccountBooking::getInstance()->getAccountBookingsByType($bookingId, $aTypes[$type]);
 }
Example #2
0
 /**
  * the singleton pattern
  *
  * @return SoEventManager_Controller_SoEvent
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #3
0
 public function updateAccountBookings()
 {
     $accountBookings = Billing_Controller_AccountBooking::getInstance()->getByBookingId($this->getId());
     foreach ($accountBookings as $accountBooking) {
         $accountBooking->__set('booking_date', $this->__get('booking_date'));
         Billing_Controller_AccountBooking::getInstance()->update($accountBooking);
     }
 }
 public static function accountBookingsToExternalArray(array $ids, &$debSum, &$credSum)
 {
     $result = array();
     foreach ($ids as $id) {
         $ab = Billing_Controller_AccountBooking::getInstance()->get($id);
         $result[] = self::accountBookingToExternalArray($ab, &$debSum, &$credSum);
     }
     return $result;
 }
 /**
  * appends sql to given select statement
  *
  * @param Zend_Db_Select                $_select
  * @param Tinebase_Backend_Sql_Abstract $_backend
  */
 public function appendFilterSql($_select, $_backend)
 {
     if ($this->_value) {
         $filter = array(array('field' => 'debitor_id', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $this->_value))));
         /*$filter = array(array(
          		'field' => 'debitor_id',
          		'operator' => $this->_operator,
          		'value' => $this->_value
          	));*/
         $abFilter = new Billing_Model_AccountBookingFilter($filter, 'AND');
         $abs = Billing_Controller_AccountBooking::getInstance()->search($abFilter);
         $bookingIds = $abs->__getFlattened('booking_id');
         //print_r($bookingIds);
         if (!is_array($bookingIds) || count($bookingIds) == 0) {
             $bookingIds = array('0', null);
         }
         $filter1 = new Billing_Model_BookingFilter(array(), 'AND');
         $filter1->addFilter(new Tinebase_Model_Filter_Id('id', 'in', $bookingIds));
         Tinebase_Backend_Sql_Filter_FilterGroup::appendFilters($_select, $filter1, $_backend);
         //	echo $_select->assemble();
     }
 }
Example #6
0
 public function improveBookingsValid()
 {
     set_time_limit(0);
     try {
         $aInvalidBookingIds = Billing_Controller_AccountBooking::getInstance()->getInvalidBookingIds();
         if (count($aInvalidBookingIds) > 0) {
             foreach ($aInvalidBookingIds as $bookingId) {
                 $booking = $this->get($bookingId);
                 $booking->__set('valid', 0);
                 $this->update($booking);
             }
         }
         return array('state' => 'success', 'result' => array('count' => count($aInvalidBookingIds)));
     } catch (Exception $e) {
         return array('state' => 'failure', 'result' => null, 'errorInfo' => array('message' => $e->getMessage(), 'trace' => $e->getTrace()));
     }
 }
Example #7
0
 public function multiCreateAccountBookings($bookingId, $data)
 {
     try {
         Billing_Controller_AccountBooking::getInstance()->multiCreateAccountBookings($bookingId, $data);
         return array('success' => true, 'result' => null);
     } catch (Exception $e) {
         return array('success' => false, 'result' => null);
     }
 }
Example #8
0
 public function printFibu($filters, $data, $accountBookingFilters)
 {
     set_time_limit(0);
     ignore_user_abort(true);
     $definition = Billing_Custom_PrintFibuDefinition::create($filters, $data, $accountBookingFilters);
     $action = $definition->getPrintAction();
     $filters = $definition->getFilters();
     $filter = new Billing_Model_AccountSystemFilter($filters, 'AND');
     $paging = new Tinebase_Model_Pagination(array('sort' => 'number', 'dir' => 'ASC'));
     if ($action == 'PRINT_ACTION_STATEMENT') {
         $accountIds = $this->search($filter, $paging, false, true);
         $beginDate = $definition->getStartDate(new Zend_Date());
         $beginSaldoDate = $definition->getStartDate(new Zend_Date());
         $beginSaldoDate->subDay(1);
         $endDate = $definition->getEndDate(new Zend_Date());
         $processArray = array();
         foreach ($accountIds as $accountId) {
             $account = $this->get($accountId);
             $accountBookingFilters = $definition->getAccountBookingFilters();
             $accountBookingFilters[] = array('field' => 'account_system_id', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $accountId)));
             $accountBookingFilters[] = array('field' => 'booking_date', 'operator' => 'afterOrAt', 'value' => $beginDate->toString('yyyy-MM-dd'));
             $accountBookingFilters[] = array('field' => 'booking_date', 'operator' => 'beforeOrAt', 'value' => $endDate->toString('yyyy-MM-dd'));
             $accountBookingFilter = new Billing_Model_AccountBookingFilter($accountBookingFilters, 'AND');
             $paging = new Tinebase_Model_Pagination(array('sort' => array('booking_date', 'booking_id'), 'dir' => 'ASC'));
             $accountBookingIds = Billing_Controller_AccountBooking::getInstance()->search($accountBookingFilter, $paging, false, true);
             $count = count($accountBookingIds);
             $account = $this->get($accountId);
             $credSum = 0;
             $debSum = 0;
             $aBeginSaldoFilter = array();
             $select = null;
             $aBeginSaldo = $this->getSummation(array(), null, $beginSaldoDate, array($accountId), &$select);
             $values = Billing_Custom_PrintFibuHelper::accountBookingsToExternalArray($accountBookingIds, &$debSum, &$credSum);
             //exit;
             $beginSaldo = $aBeginSaldo['total'] + $account->__get('begin_credit_saldo') - $account->__get('begin_debit_saldo');
             $beginSaldoS = $beginSaldo < 0 ? number_format(abs($beginSaldo), 2, ',', '.') : '';
             $beginSaldoH = $beginSaldo >= 0 ? number_format(abs($beginSaldo), 2, ',', '.') : '';
             $endSaldo = $beginSaldo + $credSum - $debSum;
             $endSaldoS = $endSaldo < 0 ? number_format(abs($endSaldo), 2, ',', '.') : '';
             $endSaldoH = $endSaldo >= 0 ? number_format(abs($endSaldo), 2, ',', '.') : '';
             $resultSum = $endSaldo - $beginSaldo;
             $resultF = number_format($resultSum, 2, ',', '.');
             $processArray[] = array('values' => $values, 'sums' => array(), 'header' => array('number' => $account->__get('number'), 'name' => $account->__get('name'), 'begin_saldo' => number_format($beginSaldo, 2, ',', '.'), 'begin_saldo_h' => $beginSaldoH, 'begin_saldo_s' => $beginSaldoS, 'end_saldo' => number_format($endSaldo, 2, ',', '.'), 'end_saldo_h' => $endSaldoH, 'end_saldo_s' => $endSaldoS, 'change_sum' => $resultF, 'begin_date' => $beginDate->toString('dd.MM.yyyy'), 'end_date' => $endDate->toString('dd.MM.yyyy'), 'deb_sum_f' => $debSum != 0 ? number_format($debSum, 2, ',', '.') : '', 'cred_sum_f' => $credSum != 0 ? number_format($credSum, 2, ',', '.') : '', 'count' => $count));
         }
     } elseif ($action == 'PRINT_ACTION_ADD1') {
         $beginDate = $definition->getStartDate(new Zend_Date());
         $period = $beginDate->get(Zend_Date::YEAR);
         $values = $this->getDonationAndMemberFeeSums($period, $definition, &$fixValues, &$resultArray);
         $processArray[] = array('values' => $resultArray, 'sums' => array(), 'header' => $fixValues);
     } elseif ($action == 'PRINT_ACTION_ADD2') {
         $beginDate = $definition->getStartDate(new Zend_Date());
         $period = $beginDate->get(Zend_Date::YEAR);
         $values = $this->printLists($period, $definition, &$processArray);
     } else {
         // get account classes
         $classes = Billing_Controller_AccountClass::getInstance()->getAll('key', 'ASC');
         $processArray = array();
         $arr = array();
         foreach ($classes as $class) {
             // get accounts within class
             try {
                 $classAccounts = $this->getByClassId($class->getId());
             } catch (Exception $e) {
                 continue;
             }
             $result = $this->getSusaSummation(null, $class->getId(), $definition->getSusaBeginDate(), $definition->getSusaEndDate());
             /**
             * 
             * 
             				from_begin and actual 
             				array(
             					'total' => $total['credit_total'] - $total['debit_total'],
             					'debit_total' => $total['debit_total'],
             					'credit_total' => $total['credit_total'],
             					'totalcount' => $totalCount
             				)
             * 
             */
             $arr[] = array('class' => $class->__get('key') . ' ' . $class->__get('name'), 'account' => '', 'total1' => $result['from_begin']['total'] != 0 ? number_format($result['from_begin']['total'], 2, ',', '.') : '', 'debit_total1' => $result['from_begin']['debit_total'] != 0 ? number_format($result['from_begin']['debit_total'], 2, ',', '.') : '', 'credit_total1' => $result['from_begin']['credit_total'] != 0 ? number_format($result['from_begin']['credit_total'], 2, ',', '.') : '', 'totalcount1' => $result['from_begin']['totalcount'] != 0 ? number_format($result['from_begin']['totalcount'], 2, ',', '.') : '', 'total2' => $result['actual']['total'] != 0 ? number_format($result['actual']['total'], 2, ',', '.') : '', 'debit_total2' => $result['actual']['debit_total'] != 0 ? number_format($result['actual']['debit_total'], 2, ',', '.') : '', 'credit_total2' => $result['actual']['credit_total'] != 0 ? number_format($result['actual']['credit_total'], 2, ',', '.') : '', 'totalcount2' => $result['actual']['totalcount'] != 0 ? number_format($result['actual']['totalcount'], 2, ',', '.') : '');
             foreach ($classAccounts as $account) {
                 $result = $this->getSusaSummation($account->getId(), null, $definition->getSusaBeginDate(), $definition->getSusaEndDate());
                 $arr[] = array('class' => '', 'account' => $account->__get('number') . ' ' . $account->__get('name'), 'total1' => $result['from_begin']['total'] != 0 ? number_format($result['from_begin']['total'], 2, ',', '.') : '', 'debit_total1' => $result['from_begin']['debit_total'] != 0 ? number_format($result['from_begin']['debit_total'], 2, ',', '.') : '', 'credit_total1' => $result['from_begin']['credit_total'] != 0 ? number_format($result['from_begin']['credit_total'], 2, ',', '.') : '', 'totalcount1' => $result['from_begin']['totalcount'] != 0 ? number_format($result['from_begin']['totalcount'], 2, ',', '.') : '', 'total2' => $result['actual']['total'] != 0 ? number_format($result['actual']['total'], 2, ',', '.') : '', 'debit_total2' => $result['actual']['debit_total'] != 0 ? number_format($result['actual']['debit_total'], 2, ',', '.') : '', 'credit_total2' => $result['actual']['credit_total'] != 0 ? number_format($result['actual']['credit_total'], 2, ',', '.') : '', 'totalcount2' => $result['actual']['totalcount'] != 0 ? number_format($result['actual']['totalcount'], 2, ',', '.') : '');
             }
         }
         $processArray[] = array('values' => $arr, 'sums' => array(), 'header' => array());
     }
     $outputType = 'pdf';
     try {
         $outputType = $definition->getOutputType();
     } catch (Exception $e) {
     }
     if (in_array($action, array('PRINT_ACTION_ADD2')) && $outputType == "excel") {
         Billing_Controller_Excel::getInstance()->export($processArray, $definition);
     } else {
         Billing_Controller_PrintFibu::getInstance()->printResult($processArray, $definition);
     }
 }