Skip to content

Commit

Permalink
Added some stats
Browse files Browse the repository at this point in the history
  • Loading branch information
lillem4n committed Jul 17, 2014
1 parent 7122470 commit 78006bd
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 2 deletions.
4 changes: 2 additions & 2 deletions classes/controller/admin/accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function action_index()
if ($_GET['cash_position'] != 'All')
$where .= ' AND cash_position = '.$pdo->quote($_GET['cash_position']);

$transactions = Transactions::get(NULL, $order_by, $where, TRUE);
$balances = array(
$transactions = Transactions::get(NULL, $order_by, $where, TRUE);
$balances = array(
'balance' => 0,
'balance_all' => 0,
'vat_balance' => 0,
Expand Down
54 changes: 54 additions & 0 deletions classes/controller/admin/stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

class Controller_Admin_Stats extends Admincontroller
{

public function before()
{
xml::to_XML(array('admin_page' => 'Stats'), $this->xml_meta);
}

public function action_index()
{
$where = 'accounting_date <= \''.date('Y-12-31').'\'';
$order_by = 'IF(accounting_date = 0,1,0),accounting_date;';
$transactions = Transactions::get(NULL, $order_by, $where, TRUE);

$profit = array();
$balance = 0;
$balance_by_month = array();
$turnover = array();

foreach ($transactions as $transaction)
{
if (date('Ym') != date('Ym', strtotime($transaction['accounting_date'])))
{
$balance += ($transaction['sum'] - $transaction['vat']);

$month = 'month'.date('Y-m', strtotime($transaction['accounting_date']));

$balance_by_month[$month] = $balance; // Update until all is accounted for

if ( ! isset($profit[$month]))
$profit[$month] = 0;

$profit[$month] += ($transaction['sum'] - $transaction['vat']);

if ( ! isset($turnover[$month]))
$turnover[$month] = 0;

if (($transaction['sum'] - $transaction['vat']) > 0)
$turnover[$month] += ($transaction['sum'] - $transaction['vat']);
}
}

xml::to_XML(array('balance_by_month' => $balance_by_month), $this->xml_content);
xml::to_XML(array('profit' => $profit), $this->xml_content);
xml::to_XML(array('turnover' => $turnover), $this->xml_content);

//$accounting_node = $this->xml_content->appendChild($this->dom->createElement('accounting'));

//xml::to_XML($transactions, $accounting_node, 'entry', 'id');
}

}
7 changes: 7 additions & 0 deletions config/admin_menu_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@
'href' => 'wages',
'position' => 5,
),
'stats' => array(
'name' => 'Stats',
'@category' => 'Economy',
'description' => 'Stats',
'href' => 'stats',
'position' => 6,
),
);
Loading

0 comments on commit 78006bd

Please sign in to comment.