public function __construct(Xhb $xhb, $data = array()) { parent::__construct($data); $this->_xhb = $xhb; $i18n = I18n::instance(); $this->setPlaceholder($i18n->tr('Search...')); $this->addClass('search'); }
public static function getConsumptionData(Xhb $xhb, \DatePeriod $period, $categoryIds) { $vehicleCostReport = new \Xhb\Model\Report\VehicleCost($xhb); $consumptionData = $vehicleCostReport->getPeriodConsumptionData($period, $categoryIds); $return = array('labels' => array(), 'datasets' => array()); $return['datasets'][0] = array('label' => I18n::instance()->tr('Consumption'), 'strokeColor' => Output::rgbToCss(Chart::getColor(self::CONSUMPTION_CHART_COLOR_IDX)), 'pointColor' => Output::rgbToCss(Chart::getColor(self::CONSUMPTION_CHART_COLOR_IDX)), 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#bbb', 'data' => array()); foreach ($consumptionData as $cd) { $return['datasets'][0]['data'][] = array('x' => $cd['date']->getTimestamp(), 'y' => $cd['per-100']); } return $return; }
public function __construct(Xhb $xhb, $data = array()) { $this->setLabel('Range'); parent::__construct($data); $this->_xhb = $xhb; $i18n = I18n::instance(); $periods = AccountOperation::getStaticCollectionFilters()['period']; $options = array(); foreach ($periods['values'] as $k => $p) { $options[$k] = array('label' => $i18n->tr($p)); } $this->setOptions($options); }
public function doLoadAction() { $this->setPageConfig(array('template' => 'data/json.phtml', 'mime' => 'application/json')); try { $config = Main::app()->getConfig('XHB'); $adapter = new XhbAdapter($this->_fw, $this->getXhbSession()->get('xhb_file'), $config); $xhb = $adapter->loadXhb(true); $this->getSession()->addMessage(I18n::instance()->tr('XHB imported to database successfully!'), Session::MESSAGE_INFO); $this->getView()->setData('DATA', array('status' => 'success', 'message' => '')); } catch (\Exception $e) { $response = array('status' => 'error', 'message' => $e->getMessage()); if ($this->_fw->get('DEBUG') > 0) { $response['trace'] = $e->getTraceAsString(); } $this->getView()->setData('DATA', $response); } }
protected function _setup() { ini_set('max_execution_time', 60); if ($this->_fw->get('DEBUG')) { ini_set('display_errors', 1); } // Setup i18n $i18n = I18n::instance(); $i18n->setLocale($this->getSession()->getLocale()); $i18n->setCurrencyCode($this->getSession('xhb')->getCurrencyCode()); // Set HTML lang according to defined locale $this->_fw->set('HTML_LANG', $i18n->getLocaleCountryCodeISO2()); // Load XHB $this->getSession('xhb')->set('xhb_file', $this->_xhbFile); // Avoid decimal separator issues when casting double and float values to strings setlocale(LC_NUMERIC, 'C'); if ($theme = $this->getSession()->getTheme()) { Design::instance()->setTheme($theme); } Design::instance()->init(); if ($this->_xhbFile == 'data/example.xhb') { $this->getSession()->addMessage($i18n->tr("It seems you're using the default <span class=\"mono\">example.xhb</span> file. " . "You may want to change it by editing <span class=\"mono\">etc/local.ini</span>."), Session::MESSAGE_INFO, array('no_escape' => true)); } }
/** * @return I18n */ public function i18n() { return I18n::instance(); }
public function __($string, $vars = null) { return I18n::instance()->tr($string, $vars); }
/** * @param Collection $collection * @param array $collectionFilters * @param array $accountIds * @return array */ public static function getBalanceReportData(Xhb $xhb, array $collectionFilters, array $accountIds, $withGrandTotal = false) { $return = array('labels' => array(), 'datasets' => array()); $operationCollection = $xhb->getOperationCollection()->setFlag('skip_aggregated_fields', true); $processedFilters = AccountOperation::applyFiltersOnCollection($operationCollection, $collectionFilters); $firstOp = $operationCollection->getFirstItem(); if (!$firstOp) { return $return; } $startDate = isset($processedFilters['start_date']) ? $processedFilters['start_date'] : $firstOp->getDateModel(); $endDate = isset($processedFilters['end_date']) ? $processedFilters['end_date'] : new \DateTime('last day of this month'); $datePeriod = self::getDatePeriod($xhb, $startDate, $endDate); $rawBalanceData = array(); foreach ($accountIds as $accountId) { $calculator = new Calculator($xhb, $accountId); $rawBalanceData[$accountId] = $calculator->getBalanceByDate($datePeriod); } $now = new \DateTime(); $idx = 0; $addLabels = true; $grandTotal = array(); foreach ($rawBalanceData as $accountId => $accountBalanceData) { $periodIdx = 0; if (!isset($grandTotal[$idx])) { $grandTotal[$idx] = array(); } $return['datasets'][$idx] = array('label' => $xhb->getAccount($accountId)->getName(), 'strokeColor' => Output::rgbToCss(Chart::getColor($idx)), 'pointColor' => Output::rgbToCss(Chart::getColor($idx)), 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#bbb', 'data' => array()); foreach ($accountBalanceData as $periodBalance) { if ($addLabels) { $return['labels'][] = I18n::instance()->date($periodBalance['date']); } if ($periodBalance['date'] < $now) { $return['datasets'][$idx]['data'][$periodIdx] = array('x' => $periodBalance['date']->getTimestamp(), 'y' => $periodBalance['balance']); $grandTotal[$periodIdx][] = array('x' => $periodBalance['date'], 'y' => $periodBalance['balance']); } else { $return['datasets'][$idx]['data'][$periodIdx] = array('x' => $periodBalance['date']->getTimestamp()); $grandTotal[$periodIdx][] = array('x' => $periodBalance['date']); } $periodIdx++; } $addLabels = false; $idx++; } if ($withGrandTotal) { $return['datasets'][$idx] = array('label' => I18n::instance()->tr('Grand Total'), 'strokeColor' => Output::rgbToCss(array(0, 0, 0)), 'pointColor' => Output::rgbToCss(array(0, 0, 0)), 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#bbb', 'data' => array()); $periodIdx = 0; foreach ($grandTotal as $periodAccountsBalance) { $balance = array_sum(array_column($periodAccountsBalance, 'y')); $date = current($periodAccountsBalance)['x']; $balanceData = array('x' => $date->getTimestamp()); if ($date < $now) { $balanceData['y'] = $balance; } $return['datasets'][$idx]['data'][$periodIdx] = $balanceData; $periodIdx++; } } return $return; }