Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 743

Přidáno uživatelem Michal Kliment před téměř 14 roky(ů)

Napsana nova metoda incoming_member_payment v kontroleru stats, zobrazujici stav prichozich clenskych prispevku do sdruzeni.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'in hours' => 'V hodinách',
'inactive' => 'Neaktivní',
'inbound' => 'Příchozí',
'incoming member payment in the period' => 'Příchozí členské příspěvky v období',
'increase of members' => 'Přírůstek členů',
'indefinitely' => 'Na neurčito',
'information' => 'Informace',
freenetis/trunk/kohana/application/helpers/num.php
return round($number / $nearest) * $nearest;
}
/**
* @author Michal Kliment
* Fill number with nulls (on start)
* @param int $number
* @param int $position
* @return string
*/
public static function null_fill($number, $position)
{
$len = strlen($number);
......
return $null_str.$number;
}
/**
* @author Michal Kliment
* Replace decimal comma with decimal point
* @param int $number
* @return string
*/
public static function decimal_point($number)
{
return str_replace(',', '.', $number);
}
}
freenetis/trunk/kohana/application/models/transfer.php
ORDER BY t.datetime DESC
");
}
/**
* @author Michal Kliment
* Gets all monthly amounts of incoming member payment for stats
* @return MySQL_Result object
*/
public function get_all_monthly_amounts_of_incoming_member_payment()
{
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 t.origin_id = 8 AND (t.destination_id = 1 OR t.destination_id = 9)
GROUP BY date");
}
}
freenetis/trunk/kohana/application/controllers/stats.php
$array[] = html::anchor(url_lang::base().'stats/members_increase',url_lang::lang('texts.Increase of members'));
$array[] = html::anchor(url_lang::base().'stats/members_decrease',url_lang::lang('texts.Decrease of members'));
$array[] = html::anchor(url_lang::base().'stats/members_growth',url_lang::lang('texts.Growth of members'));
$array[] = html::anchor(url_lang::base().'stats/incoming_member_payment',url_lang::lang('texts.Incoming member payment'));
$this->links = implode(' | ',$array);
}
......
$view->render(TRUE);
}
/**
* @author Michal Kliment
* Function to show graph of imcoming member payment
* @param <type> $start_year
* @param <type> $end_year
*/
public function incoming_member_payment($start_year = NULL, $end_year = NULL)
{
// access control
if (!$this->acl_check_edit('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(url_lang::base().'stats/incoming_member_payment/'.$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(1);
$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");
$years = array();
for($i=$association_entrance_date['year'];$i<=date("Y");$i++)
$years[$i] = $i;
$transfer_model = new Transfer_Model();
$amounts = $transfer_model->get_all_monthly_amounts_of_incoming_member_payment();
// 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] = url_lang::lang('texts.'.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));
$view = new View('main');
$view->title = url_lang::lang('texts.Stats').' - '.url_lang::lang('texts.Incoming member payment in the period').' '.$start_year.'-'.$end_year;
$view->content = new View('stats_incoming_member_payment');
$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/trunk/kohana/application/views/stats_incoming_member_payment.php
<h2><?php echo url_lang::lang('texts.Stats') ?> - <?php echo url_lang::lang('texts.Incoming member payment in the period').' '.$start_year.'-'.$end_year ?></h2>
<?php echo $link_back ?><br /><br />
<?php echo form::open() ?>
<?php echo form::label('start_year', url_lang::lang('texts.From')).': ' ?>
<?php echo form::dropdown('start_year', $years, $start_year) ?>
<?php echo form::label('end_year', url_lang::lang('texts.Until')).': ' ?>
<?php echo form::dropdown('end_year', $years, $end_year) ?>
<?php echo form::submit('submit', url_lang::lang('texts.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 url_lang::lang('texts.Table') ?></h3>
<table class="main tablesorter">
<thead>
<tr><th><?php echo url_lang::lang('texts.Month') ?></th><th><?php echo url_lang::lang('texts.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