Пример #1
0
 public function index($page)
 {
     if (empty($page)) {
         $page = 'overview';
     }
     $stats = array();
     $document = JFactory::getDocument();
     $document->addCustomTag('<script type="text/javascript" src="' . JURI::root(true) . '/media/com_acctexp/js/d3/d3.min.js"></script>');
     $document->addCustomTag('<script type="text/javascript" src="' . JURI::root(true) . '/media/com_acctexp/js/d3/d3.time.min.js"></script>');
     $document->addCustomTag('<script type="text/javascript" src="' . JURI::root(true) . '/media/com_acctexp/js/d3/d3.layout.min.js"></script>');
     $document->addCustomTag('<script type="text/javascript" src="' . JURI::root(true) . '/media/com_acctexp/js/rickshaw/rickshaw.js"></script>');
     $document->addCustomTag('<link type="text/css" href="' . JURI::root(true) . '/media/com_acctexp/js/rickshaw/rickshaw.css" rel="stylesheet" />');
     $document->addCustomTag('<link type="text/css" href="' . JURI::root(true) . '/media/com_acctexp/js/colorbrewer/colorbrewer.css" rel="stylesheet" />');
     $query = 'SELECT count(*)' . ' FROM #__acctexp_log_history';
     $this->db->setQuery($query);
     $stats['sale_count'] = $this->db->loadResult();
     $query = 'SELECT DISTINCT(date(transaction_date)) AS date, count( * ) AS count' . ' FROM #__acctexp_log_history' . ' GROUP BY date' . ' ORDER BY count ASC';
     $this->db->setQuery($query);
     $sales_count = $this->db->loadObjectList();
     $stats['min_sale_count'] = $sales_count[0]->count;
     $stats['max_sale_count'] = $sales_count[count($sales_count) - 1]->count;
     $stats['avg_sale_count'] = $sales_count[(int) (count($sales_count) / 2)]->count;
     $query = 'SELECT amount' . ' FROM #__acctexp_log_history' . ' ORDER BY 0+`amount` DESC';
     $this->db->setQuery($query);
     $stats['max_sale_value'] = $this->db->loadResult();
     $query = 'SELECT MIN(amount)' . ' FROM #__acctexp_log_history' . ' WHERE amount > 0';
     $this->db->setQuery($query);
     $stats['min_sale_value'] = $this->db->loadResult();
     $query = 'SELECT SUM(amount)' . ' FROM #__acctexp_log_history';
     $this->db->setQuery($query);
     if ($stats['sale_count']) {
         $stats['avg_sale_value'] = round($this->db->loadResult() / $stats['sale_count'], 2);
     } else {
         $stats['avg_sale_value'] = 0;
     }
     $stats['avg_sale'] = $stats['avg_sale_count'] * $stats['avg_sale_value'] * 1.8;
     $query = 'SELECT MIN(transaction_date)' . ' FROM #__acctexp_log_history';
     $this->db->setQuery($query);
     $stats['first_sale'] = $this->db->loadResult();
     $query = 'SELECT id, name' . ' FROM #__acctexp_plans' . ' ORDER BY `id`';
     $this->db->setQuery($query);
     $rows = $this->db->loadObjectList();
     $mrow = count($rows) - 1;
     $i = 0;
     $stats['plan_names'] = array();
     for ($i = 0; $i <= $rows[$mrow]->id; $i++) {
         $stats['plan_names'][$i] = "";
         foreach ($rows as $rid => $row) {
             if ($row->id == $i) {
                 $stats['plan_names'][$i] = $row->name;
             }
         }
     }
     $query = 'SELECT id, name' . ' FROM #__acctexp_itemgroups' . ' ORDER BY `id`';
     $this->db->setQuery($query);
     $rows = $this->db->loadObjectList();
     $mrow = count($rows) - 1;
     $i = 0;
     $stats['group_names'] = array();
     for ($i = 0; $i <= $rows[$mrow]->id; $i++) {
         $stats['group_names'][$i] = "";
         foreach ($rows as $rid => $row) {
             if ($row->id == $i) {
                 $stats['group_names'][$i] = $row->name;
             }
         }
     }
     HTML_AcctExp::stats($page, $stats);
 }