Revize 1940
Přidáno uživatelem Ondřej Fibich před více než 11 roky(ů)
freenetis/branches/1.1/application/models/transfer.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Gets amount of all member fees grouped by month for stats
|
||
*
|
||
* @author Ondřej Fibich
|
||
* @return MySQL_Result object
|
||
*/
|
||
public function get_grouped_monthly_member_fees()
|
||
{
|
||
$operating = ORM::factory('account')->where(
|
||
'account_attribute_id', Account_attribute_Model::OPERATING
|
||
)->find();
|
||
|
||
return $this->db->query("
|
||
SELECT SUBSTR(datetime, 1, 7) AS date, SUBSTR(datetime, 1, 4) AS year,
|
||
SUBSTR(datetime, 6, 2) AS month, SUM(amount) AS amount
|
||
FROM transfers t
|
||
WHERE type = ? AND destination_id = ?
|
||
GROUP BY year, month
|
||
", self::DEDUCT_MEMBER_FEE, $operating->id);
|
||
}
|
||
|
||
/**
|
||
* Gets datime of last transfer by type
|
||
*
|
||
* @author Michal Kliment
|
freenetis/branches/1.1/application/controllers/stats.php | ||
---|---|---|
$array[] = html::anchor(
|
||
'stats/incoming_member_payment', __('Incoming member payment')
|
||
);
|
||
|
||
$array[] = html::anchor('stats/members_fees', __('Member fees'));
|
||
|
||
$this->links = implode(' | ', $array);
|
||
}
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* Function to show graph of imcoming member payment
|
||
* Function to show graph of incoming member payment
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $start_year
|
||
... | ... | |
*/
|
||
public function incoming_member_payment($start_year = NULL, $end_year = NULL)
|
||
{
|
||
|
||
// access control
|
||
if (!$this->acl_check_view('Settings_Controller', 'system'))
|
||
Controller::error(ACCESS);
|
||
... | ... | |
$max = 0;
|
||
|
||
// creates instance of member ID=1 (Association)
|
||
$association = new Member_Model(1);
|
||
$association = new Member_Model(Member_Model::ASSOCIATION);
|
||
$association_entrance_date = date_parse($association->entrance_date);
|
||
|
||
// start year is not set, use date of creation of association
|
||
... | ... | |
// end year is not set, use current year
|
||
if (!$end_year)
|
||
$end_year = date("Y");
|
||
|
||
// check end year
|
||
if ($end_year < $start_year)
|
||
$end_year = $start_year;
|
||
|
||
$years = array();
|
||
|
||
... | ... | |
$view = new View('main');
|
||
$view->title = __('Incoming member payment');
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('stats/incoming_member_payment');
|
||
$view->content = new View('stats/members_monthly_payments_and_fees');
|
||
$view->content->headline = __('Incoming member payment');
|
||
$view->content->x_rate = $x_rate;
|
||
$view->content->y_rate = $y_rate;
|
||
$view->content->link_back = $this->links;
|
||
... | ... | |
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Function to show graph of member member fees by month
|
||
*
|
||
* @author Michal Kliment, Ondřej Fibich
|
||
* @param integer $start_year
|
||
* @param integer $end_year
|
||
*/
|
||
public function members_fees($start_year = NULL, $end_year = NULL)
|
||
{
|
||
// access control
|
||
if (!$this->acl_check_view('Settings_Controller', 'system'))
|
||
Controller::error(ACCESS);
|
||
|
||
// form is posted
|
||
if (isset($_POST) && $_POST)
|
||
{
|
||
$start_year = $_POST['start_year'];
|
||
$end_year = $_POST['end_year'];
|
||
|
||
if ($end_year < $start_year)
|
||
$end_year = $start_year;
|
||
|
||
// redirect to this method with correct parameters
|
||
url::redirect(
|
||
'stats/members_fees/' . $start_year . '/' . $end_year
|
||
);
|
||
}
|
||
|
||
$values = array();
|
||
$labels = array();
|
||
$months = array();
|
||
$x = 0;
|
||
$max = 0;
|
||
|
||
// creates instance of member ID=1 (Association)
|
||
$association = new Member_Model(Member_Model::ASSOCIATION);
|
||
$association_entrance_date = date_parse($association->entrance_date);
|
||
|
||
// start year is not set, use date of creation of association
|
||
if (!$start_year)
|
||
$start_year = $association_entrance_date['year'];
|
||
|
||
// end year is not set, use current year
|
||
if (!$end_year)
|
||
$end_year = date('Y');
|
||
|
||
// check end year
|
||
if ($end_year < $start_year)
|
||
$end_year = $start_year;
|
||
|
||
$years = array();
|
||
|
||
for ($i = $association_entrance_date['year']; $i <= date('Y'); $i++)
|
||
$years[$i] = $i;
|
||
|
||
$transfer_model = new Transfer_Model();
|
||
$amounts = $transfer_model->get_grouped_monthly_member_fees();
|
||
|
||
// gets all amount of member payment by months
|
||
$arr_amounts = array();
|
||
foreach ($amounts as $amount)
|
||
$arr_amounts[$amount->year][(int) $amount->month] = $amount->amount;
|
||
|
||
// we draw graph
|
||
for ($i = $start_year; $i <= $end_year; $i++)
|
||
{
|
||
for ($j = 1; $j <= 12; $j++)
|
||
{
|
||
// draw label only 12 times
|
||
if ($x % ($end_year - $start_year + 1) == 0)
|
||
// we draw label only for first month of year
|
||
$labels[$x] = $j . ' / ' . substr($i, 2, 2);
|
||
else
|
||
$labels[$x] = ' ';
|
||
|
||
$values[$x] = (isset($arr_amounts[$i][$j])) ? $arr_amounts[$i][$j] : 0;
|
||
|
||
// finding max, important for drawing graph
|
||
if ($values[$x] > $max)
|
||
$max = $values[$x];
|
||
|
||
if ((
|
||
$i > $association_entrance_date['year'] &&
|
||
$i < date("Y")
|
||
) || (
|
||
$i == date("Y") &&
|
||
$j <= date("m")
|
||
) || (
|
||
$i == $association_entrance_date['year'] &&
|
||
$j >= $association_entrance_date['month']
|
||
))
|
||
{
|
||
$months[$x] = __('' . date::$months[$j]) . ' ' . $i;
|
||
}
|
||
|
||
$x++;
|
||
}
|
||
}
|
||
|
||
// round max
|
||
$max = (substr($max, 0, 2) + 1) . num::null_fill(0, strlen($max) - 2);
|
||
|
||
// calculation of correct rates of axes
|
||
$y_count = substr($max, 0, 2);
|
||
|
||
while ($y_count > 25)
|
||
$y_count /= 2;
|
||
|
||
$x_rate = num::decimal_point(round(100 / (($end_year - $start_year + 1) * 12 - 1), 5));
|
||
$y_rate = num::decimal_point(round(100 / $y_count, 5));
|
||
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->text('Stats')
|
||
->text('Member fees')
|
||
->disable_translation()
|
||
->text($start_year . '-' . $end_year);
|
||
|
||
$view = new View('main');
|
||
$view->title = __('Member fees');
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('stats/members_monthly_payments_and_fees');
|
||
$view->content->headline = __('Member fees');
|
||
$view->content->x_rate = $x_rate;
|
||
$view->content->y_rate = $y_rate;
|
||
$view->content->link_back = $this->links;
|
||
$view->content->labels = $labels;
|
||
$view->content->values = $values;
|
||
$view->content->months = $months;
|
||
$view->content->max = $max;
|
||
$view->content->start_year = $start_year;
|
||
$view->content->end_year = $end_year;
|
||
$view->content->years = $years;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
}
|
freenetis/branches/1.1/application/views/stats/incoming_member_payment.php | ||
---|---|---|
<h2><?php echo __('Incoming member payment') ?></h2>
|
||
<?php echo $link_back ?><br /><br />
|
||
<?php echo form::open() ?>
|
||
<?php echo form::label('start_year', __('From')) . ': ' ?>
|
||
<?php echo form::dropdown('start_year', $years, $start_year) ?>
|
||
<?php echo form::label('end_year', __('Until')) . ': ' ?>
|
||
<?php echo form::dropdown('end_year', $years, $end_year) ?>
|
||
<?php echo form::submit('submit', __('Send')) ?>
|
||
<?php echo form::close() ?>
|
||
<br />
|
||
<a href="http://chart.apis.google.com/chart?chg=<?php echo $x_rate ?>,<?php echo $y_rate ?>,5,5&cht=lc&chd=t:<?php echo implode(',', $values) ?>&chs=750x400&chl=<?php echo implode('|', $labels) ?>&chxt=x,y&chxr=1,0,<?php echo $max ?>&chds=0,<?php echo $max ?>" target="_blank">
|
||
<img src='http://chart.apis.google.com/chart?chg=<?php echo $x_rate ?>,<?php echo $y_rate ?>,5,5&cht=lc&chd=t:<?php echo implode(',', $values) ?>&chs=750x300&chl=<?php echo implode('|', $labels) ?>&chxt=x,y&chxr=1,0,<?php echo $max ?>&chds=0,<?php echo $max ?>'>
|
||
</a>
|
||
<br />
|
||
<br />
|
||
<h3><?php echo __('Table') ?></h3><br />
|
||
<table class="main tablesorter">
|
||
<thead>
|
||
<tr><th><?php echo __('Month') ?></th><th><?php echo __('Amount') ?></th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($months as $i => $month): ?>
|
||
<tr><td class="center"><?php echo $month ?></td><td class="center"><?php echo $values[$i] ?></td></tr>
|
||
<?php endforeach ?>
|
||
</tbody>
|
||
</table>
|
freenetis/branches/1.1/application/views/stats/members_monthly_payments_and_fees.php | ||
---|---|---|
<h2><?php echo $headline ?></h2>
|
||
<?php echo $link_back ?><br /><br />
|
||
<?php echo form::open() ?>
|
||
<?php echo form::label('start_year', __('From')) . ': ' ?>
|
||
<?php echo form::dropdown('start_year', $years, $start_year) ?>
|
||
<?php echo form::label('end_year', __('Until')) . ': ' ?>
|
||
<?php echo form::dropdown('end_year', $years, $end_year) ?>
|
||
<?php echo form::submit('submit', __('Send')) ?>
|
||
<?php echo form::close() ?>
|
||
<br />
|
||
<a href="http://chart.apis.google.com/chart?chg=<?php echo $x_rate ?>,<?php echo $y_rate ?>,5,5&cht=lc&chd=t:<?php echo implode(',', $values) ?>&chs=730x400&chl=<?php echo implode('|', $labels) ?>&chxt=x,y&chxr=1,0,<?php echo $max ?>&chds=0,<?php echo $max ?>" target="_blank">
|
||
<img src='http://chart.apis.google.com/chart?chg=<?php echo $x_rate ?>,<?php echo $y_rate ?>,5,5&cht=lc&chd=t:<?php echo implode(',', $values) ?>&chs=730x300&chl=<?php echo implode('|', $labels) ?>&chxt=x,y&chxr=1,0,<?php echo $max ?>&chds=0,<?php echo $max ?>'>
|
||
</a>
|
||
<br />
|
||
<br />
|
||
<h3><?php echo __('Table') ?></h3><br />
|
||
<table class="main tablesorter">
|
||
<thead>
|
||
<tr><th><?php echo __('Month') ?></th><th><?php echo __('Amount') ?></th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($months as $i => $month): ?>
|
||
<tr><td class="center"><?php echo $month ?></td><td class="center"><?php echo $values[$i] ?></td></tr>
|
||
<?php endforeach ?>
|
||
</tbody>
|
||
</table>
|
Také k dispozici: Unified diff
Novinky:
- closes #558: Statistika - Soucet strzenych prispevku za mesic