Skip to content

Commit

Permalink
Outlay reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoliy committed Jan 31, 2010
1 parent baa3600 commit 63c8e14
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
27 changes: 21 additions & 6 deletions app/controller/outlay.php
Expand Up @@ -178,16 +178,31 @@ function create() {
}

function report() {
$data = db_fetch_all('
SELECT min(created_at) as date, sum(value) as sum
$categories = db_fetch_all('SELECT * FROM outlay_category');
$summary->label = 'Все расходы';
$summary->data = db_fetch_all('
SELECT year(`created_at`) as year, month(`created_at`) as month, sum(value) as sum
FROM outlay
WHERE outlay_category_id = 6
GROUP BY year(created_at), month(created_at)
');
foreach ($data as $i => $p) {
$data[$i]->time = strtotime($p->date);
$reports = array($summary);
foreach ($categories as $category) {
$c = new stdClass();
$c->label = $category->name;
$c->data = db_fetch_all('
SELECT year(`created_at`) as year, month(`created_at`) as month, sum(`value`) as sum
FROM `outlay`
WHERE `outlay_category_id` = ' . (int)$category->id . '
GROUP BY year(`created_at`), month(`created_at`)
');
$reports[] = $c;
}
$this->tpl->add('data', $data);
foreach ($reports as $r => $report) {
foreach ($report->data as $i => $p) {
$reports[$r]->data[$i]->time = mktime(0, 0, 0, $p->month, 1, $p->year);
}
}
$this->tpl->add('reports', $reports);
}

function edit() {
Expand Down
32 changes: 15 additions & 17 deletions app/view/outlay.report.tpl
Expand Up @@ -2,25 +2,23 @@
<script language="javascript" type="text/javascript" src="/scripts/flot/jquery.flot.js"></script>

<script>
var data = [
{foreach from=$data item=point name=report}
[{$point->time}000, {$point->sum}]{if !$smarty.foreach.report.last},{/if}
{/foreach}
];
var reports = [
{foreach from=$reports item=r name=reports}
{ldelim}
label: '{$r->label}',
data: [
{foreach from=$r->data item=point name=report}[{$point->time}000, {$point->sum}]{if !$smarty.foreach.report.last},{/if}{/foreach}
]
{rdelim}{if !$smarty.foreach.reports.last},{/if}
{/foreach}
]
{literal}
$(function () {
$.plot($("#placeholder"), [ data]);
$.plot($("#placeholder"), [
{
data: data,
label: "Outlays"
}
],
$.plot($("#placeholder"), reports,
{
xaxis: {
mode: "time",
timeformat: "%y %b"
timeformat: "%b %y"
},
yaxis: {
min: 0
Expand All @@ -29,13 +27,13 @@ $(function () {
tickFormatter: function (v, axis) { return v.toFixed(axis.tickDecimals) +"р." }
},
legend: {
position: 'sw'
}
position: 'nw'
}
}
);
});
{/literal}
</script>
<div id="placeholder" style="width:600px;height:300px;"></div>
<div id="placeholder" style="width:800px;height:300px;"></div>

0 comments on commit 63c8e14

Please sign in to comment.