Added income / expense reports that produce results suitable for entry into quickbooks as per the current paradigm
git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1009 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -278,8 +278,14 @@ class AppController extends Controller {
|
||||
$this->addSideMenuLink('Unit Summary',
|
||||
array('controller' => 'units', 'action' => 'overview'), null,
|
||||
'REPORT');
|
||||
$this->addSideMenuLink('Monthly Charges',
|
||||
array('controller' => 'statement_entries', 'action' => 'chargesbymonth'), null,
|
||||
$this->addSideMenuLink('Monthly Income',
|
||||
array('controller' => 'statement_entries', 'action' => 'incomebymonth'), null,
|
||||
'REPORT');
|
||||
$this->addSideMenuLink('Monthly Expenses',
|
||||
array('controller' => 'statement_entries', 'action' => 'expensebymonth'), null,
|
||||
'REPORT');
|
||||
$this->addSideMenuLink('Monthly Net',
|
||||
array('controller' => 'statement_entries', 'action' => 'netbymonth'), null,
|
||||
'REPORT');
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -260,38 +260,65 @@ class StatementEntriesController extends AppController {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: chargesbymonth
|
||||
* - Displays charges by month
|
||||
* action: incexpbymonth
|
||||
* - Displays income and/or expenses by month
|
||||
*/
|
||||
|
||||
function chargesbymonth($months = 12) {
|
||||
function incexpbymonth($accts, $security_deposits, $months) {
|
||||
$datefrom = 'DATE(NOW() - INTERVAL '.($months-1).' MONTH - INTERVAL DAY(NOW())-1 DAY)';
|
||||
$dateto = 'NOW()';
|
||||
/* $datefrom = '"2009-01-01"'; */
|
||||
/* $dateto = '"2011-12-31"'; */
|
||||
|
||||
$result = $this->StatementEntry->find
|
||||
('all',
|
||||
array('link' => array('Account' => array('fields' => 'name')),
|
||||
'fields' => array_merge(array('MONTHNAME(effective_date) AS month',
|
||||
'YEAR(effective_date) AS year'),
|
||||
$this->StatementEntry->chargeDisbursementFields(true)),
|
||||
'conditions' => array('Account.type' => 'INCOME',
|
||||
'effective_date >= DATE(NOW() - INTERVAL '.($months-1).' MONTH - INTERVAL DAY(NOW())-1 DAY)',
|
||||
'effective_date <= NOW()',
|
||||
'conditions' => array('Account.type' => $accts,
|
||||
"effective_date >= $datefrom",
|
||||
"effective_date <= $dateto",
|
||||
),
|
||||
'group' => array('YEAR(effective_date)', 'MONTH(effective_date)', 'Account.id'),
|
||||
'order' => array('YEAR(effective_date) DESC', 'MONTH(effective_date) DESC', 'Account.name'),
|
||||
'order' => array('YEAR(effective_date) DESC', 'MONTH(effective_date) DESC', 'Account.type',
|
||||
'IF(Account.id = '.$this->StatementEntry->Account->rentAccountID().', "---", Account.name)'),
|
||||
));
|
||||
|
||||
$overview = array('months' => array(), 'charges' => 0);
|
||||
foreach ($result AS $row) {
|
||||
if ($security_deposits) {
|
||||
$sdresult = $this->StatementEntry->Transaction->LedgerEntry->find
|
||||
('all',
|
||||
array('link' => array('Transaction' => array('StatementEntry' => array('fields' => 'effective_date'),
|
||||
'fields' => array()),
|
||||
'Account' => array('fields' => 'name')),
|
||||
'fields' => array_merge(array('MONTHNAME(effective_date) AS month',
|
||||
'YEAR(effective_date) AS year'),
|
||||
$this->StatementEntry->Transaction->LedgerEntry->debitCreditFields(true)),
|
||||
'conditions' => array('LedgerEntry.account_id' => $this->StatementEntry->Account->securityDepositAccountID(),
|
||||
"effective_date >= $datefrom",
|
||||
"effective_date <= $dateto",
|
||||
'StatementEntry.id = (SELECT MIN(id) FROM pmgr_statement_entries WHERE transaction_id = `Transaction`.id)'
|
||||
),
|
||||
'group' => array('YEAR(effective_date)', 'MONTH(effective_date)', 'Account.id'),
|
||||
'order' => array('YEAR(effective_date) DESC', 'MONTH(effective_date) DESC', 'Account.type', 'Account.name'),
|
||||
));
|
||||
} else {
|
||||
$sdresult = array();
|
||||
}
|
||||
|
||||
$overview = array('months' => array(), 'amount' => 0);
|
||||
foreach (array_merge($result, $sdresult) AS $row) {
|
||||
$mname = $row[0]['month'] .', '. $row[0]['year'];
|
||||
if (empty($overview['months'][$mname]))
|
||||
$overview['months'][$mname] = array('name' => $mname,
|
||||
'subs' => array(),
|
||||
'charges' => 0);
|
||||
'amount' => 0);
|
||||
$month = &$overview['months'][$mname];
|
||||
$month['subs'][] = array('name' => $row['Account']['name'],
|
||||
'charges' => $row[0]['balance']);
|
||||
'amount' => $row[0]['balance']);
|
||||
|
||||
$month['charges'] += $row[0]['balance'];
|
||||
$overview['charges'] += $row[0]['balance'];
|
||||
$month['amount'] += $row[0]['balance'];
|
||||
$overview['amount'] += $row[0]['balance'];
|
||||
}
|
||||
|
||||
// Enable the Reports menu section
|
||||
@@ -299,8 +326,26 @@ class StatementEntriesController extends AppController {
|
||||
|
||||
// Prepare to render.
|
||||
$this->set('months', $months);
|
||||
$this->set('title', 'Monthly Charges');
|
||||
$this->set(compact('overview'));
|
||||
$this->render('chargesbymonth');
|
||||
}
|
||||
|
||||
function incomebymonth($months = 12) {
|
||||
$this->set('title', 'Monthly Gross Income');
|
||||
$this->set('reptype', 'Gross Income');
|
||||
$this->incexpbymonth(array('INCOME'), true, $months);
|
||||
}
|
||||
|
||||
function expensebymonth($months = 12) {
|
||||
$this->set('title', 'Gross Monthly Expenses');
|
||||
$this->set('reptype', 'Gross Expenses');
|
||||
$this->incexpbymonth(array('EXPENSE'), false, $months);
|
||||
}
|
||||
|
||||
function netbymonth($months = 12) {
|
||||
$this->set('title', 'Net Monthly Income');
|
||||
$this->set('reptype', 'Net Income');
|
||||
$this->incexpbymonth(array('INCOME', 'EXPENSE'), true, $months);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ echo '<div class="statement_entry overview">' . "\n";
|
||||
*/
|
||||
|
||||
$rows = array();
|
||||
$rows[] = array("$months Month Charges", FormatHelper::currency($overview['charges']));
|
||||
$rows[] = array("$months Month Total", FormatHelper::currency($overview['amount']));
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item statement_entry detail',
|
||||
'caption' => 'Monthly Charges',
|
||||
'caption' => $reptype,
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value')));
|
||||
|
||||
@@ -38,11 +38,11 @@ foreach ($overview['months'] AS $month) {
|
||||
$odd = 1;
|
||||
foreach ($month['subs'] AS $sub) {
|
||||
$row_class[] = array('subitem', $odd ? 'oddrow' : 'evenrow');
|
||||
$rows[] = array($sub['name'], FormatHelper::currency($sub['charges']));
|
||||
$rows[] = array($sub['name'], FormatHelper::currency($sub['amount']));
|
||||
$odd = !$odd;
|
||||
}
|
||||
$row_class[] = 'grand';
|
||||
$rows[] = array('Total for '.$month['name'], FormatHelper::currency($month['charges']));
|
||||
$rows[] = array('Total for '.$month['name'], FormatHelper::currency($month['amount']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
|
||||
Reference in New Issue
Block a user