Added Monthly Charges report. Also, added a new area to the menu specifically for reports.

git-svn-id: file:///svn-source/pmgr/branches/v0.3_work/site@958 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2010-03-12 00:38:34 +00:00
parent 1f831551a1
commit 63511709a8
3 changed files with 75 additions and 7 deletions

View File

@@ -253,6 +253,53 @@ class StatementEntriesController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: chargesbymonth
* - Displays charges by month
*/
function chargesbymonth() {
$result = $this->StatementEntry->find
('all',
array('link' => array('Account' => array('fields' => 'name')),
'fields' => array('MONTHNAME(effective_date) AS month',
'YEAR(effective_date) AS year',
'SUM(amount) AS amount',
),
'conditions' => array('StatementEntry.type' => 'CHARGE',
'effective_date >=' => '2009-04-01',
'effective_date <= NOW()',
),
'group' => array('YEAR(effective_date), MONTH(effective_date)', 'Account.id'),
'order' => array('YEAR(effective_date), MONTH(effective_date)', 'Account.name'),
));
$overview = array('months' => array(), 'charges' => 0);
foreach ($result AS $row) {
$mname = $row[0]['month'] .', '. $row[0]['year'];
if (empty($overview['months'][$mname]))
$overview['months'][$mname] = array('name' => $mname,
'subs' => array(),
'charges' => 0);
$month = &$overview['months'][$mname];
$month['subs'][] = array('name' => $row['Account']['name'],
'charges' => $row[0]['amount']);
$month['charges'] += $row[0]['amount'];
$overview['charges'] += $row[0]['amount'];
}
// Enable the Reports menu section
$this->sideMenuAreaActivate('REPORT');
// Prepare to render.
$this->set('title', 'Monthly Charges');
$this->set(compact('overview'));
}
/**************************************************************************
**************************************************************************
**************************************************************************