Significant changes to work with the new account/ledger structure. Removed much of the auto-generated model association code. Added helper functions into the models to perform model related work, such as model 'stats' (a bad name for a function to return a summary of pertinent financial information from a given model instance). There is a ton of cleanup to do, but first I want to get it all captured.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@81 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -31,17 +31,16 @@ if (isset($paginator)) {
|
||||
|
||||
$rows = array();
|
||||
foreach ($accounts as $account) {
|
||||
$extra = null;
|
||||
if (isset($account[0])) {
|
||||
$extra = $account[0];
|
||||
unset($account[0]);
|
||||
}
|
||||
//pr($account);
|
||||
if (isset($account[0]))
|
||||
$stats = $account[0];
|
||||
else
|
||||
$stats = $account;
|
||||
|
||||
// Move our pointer to the meat
|
||||
if (isset($account['Account']))
|
||||
$account = $account['Account'];
|
||||
|
||||
if (isset($extra))
|
||||
$account = array_merge($account, $extra);
|
||||
|
||||
$rows[] = array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
@@ -49,10 +48,10 @@ foreach ($accounts as $account) {
|
||||
$account['type'],
|
||||
$account['external_name'],
|
||||
$account['external_account'],
|
||||
$account['entries'],
|
||||
FormatHelper::currency($account['debits']),
|
||||
FormatHelper::currency($account['credits']),
|
||||
FormatHelper::currency($account['balance']),
|
||||
$stats['entries'],
|
||||
FormatHelper::currency($stats['debits']),
|
||||
FormatHelper::currency($stats['credits']),
|
||||
FormatHelper::currency($stats['balance']),
|
||||
$account['comment'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ foreach ($contacts as $contact) {
|
||||
$contact['company_name']),
|
||||
(isset($contact['ContactsCustomer'])
|
||||
? array($contact['ContactsCustomer']['type'],
|
||||
$contact['ContactsCustomer']['active'],
|
||||
$contact['ContactsCustomer']['active'] ? 'Yes' : 'No',
|
||||
$contact['ContactsCustomer']['comment'])
|
||||
: array($contact['comment'])));
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ if (isset($heading))
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Customers',true).'</h2>';
|
||||
|
||||
$headers = array('ID', 'Name', 'Comment');
|
||||
$headers = array_merge(array('Name'),
|
||||
isset($customers[0]['ContactsCustomer'])
|
||||
? array('Relationship')
|
||||
: array(),
|
||||
array('Comment'));
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('ID')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'comment';
|
||||
}
|
||||
@@ -18,25 +19,30 @@ if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$headers = array($paginator->sort('id'),
|
||||
$paginator->sort('name'),
|
||||
$paginator->sort('comment'));
|
||||
$headers = array_merge(array($paginator->sort('name')),
|
||||
isset($customers[0]['ContactsCustomer'])
|
||||
? array($paginator->sort('Relationship', 'type'))
|
||||
: array(),
|
||||
array($paginator->sort('comment')));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($customers as $customer) {
|
||||
$contacts_customer = null;
|
||||
if (isset($customer['ContactsCustomer']))
|
||||
$contacts_customer = $customer['ContactsCustomer'];
|
||||
|
||||
if (isset($customer['Customer']))
|
||||
$customer = $customer['Customer'];
|
||||
|
||||
$rows[] = array($html->link($customer['id'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
$html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
$customer['comment']);
|
||||
$rows[] = array_merge(array($html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id']))),
|
||||
isset($contacts_customer)
|
||||
? array($contacts_customer['type'])
|
||||
: array(),
|
||||
array($customer['comment']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
|
||||
82
views/elements/leases.ctp
Normal file
82
views/elements/leases.ctp
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Leases',true).'</h2>';
|
||||
|
||||
$headers = array_merge(array('Lease'),
|
||||
isset($leases[0]['Unit'])
|
||||
? array('Unit')
|
||||
: array('Customer'),
|
||||
array('Signed', 'Move-In', 'Move-Out', 'Balance', 'Comment'));
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Lease', 'Unit')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Balance')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$headers = array_merge(array($paginator->sort('Lease')),
|
||||
isset($leases[0]['Unit'])
|
||||
? $paginator->sort('Unit', 'Unit.id')
|
||||
: $paginator->sort('Customer.id'),
|
||||
array($paginator->sort('Signed', 'lease_date'),
|
||||
$paginator->sort('Move-In', 'movein_date'),
|
||||
$paginator->sort('Move-Out', 'moveout_date'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('comment')));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach($leases AS $lease) {
|
||||
$unit = $customer = null;
|
||||
|
||||
if (isset($lease['Unit']))
|
||||
$unit = $lease['Unit'];
|
||||
else
|
||||
$customer = $lease['Customer'];
|
||||
|
||||
if (isset($lease['Lease']))
|
||||
$lease = $lease['Lease'];
|
||||
|
||||
$rows[] = array_merge(array($html->link('#'.$lease['number'],
|
||||
array('controller' => 'leases',
|
||||
'action' => 'view',
|
||||
$lease['id']))),
|
||||
isset($unit)
|
||||
? array($html->link($unit['name'],
|
||||
array('controller' => 'units',
|
||||
'action' => 'view',
|
||||
$unit['id'])))
|
||||
: array($html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id']))),
|
||||
array(FormatHelper::date($lease['lease_date']),
|
||||
FormatHelper::date($lease['movein_date']),
|
||||
FormatHelper::date($lease['moveout_date']),
|
||||
FormatHelper::currency($lease['balance']),
|
||||
$lease['comment']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item lease list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo('<div class="paging">' . "\n");
|
||||
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
|
||||
echo(' | ');
|
||||
echo $paginator->numbers();
|
||||
echo(' | ');
|
||||
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
|
||||
echo('</div>' . "\n");
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledger',true).'</h2>';
|
||||
|
||||
$headers = array('Transaction', 'Entry', 'Date', 'Customer', 'Comment', 'Debit', 'Credit', 'Total');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) {
|
||||
$column_class[$k] = array($column_class[$k], 'id');
|
||||
}
|
||||
foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) {
|
||||
$column_class[$k] = array($column_class[$k], 'currency');
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
}
|
||||
|
||||
|
||||
$rows = array();
|
||||
$running_total = 0;
|
||||
foreach($entries AS $entry) {
|
||||
$transaction = $entry['Transaction'];
|
||||
$customer = $entry['Customer'];
|
||||
|
||||
$credit = $debit = null;
|
||||
$running_total += $entry['balance'];
|
||||
|
||||
if (isset($entry['debit']))
|
||||
$debit = $entry['debit'];
|
||||
if (isset($entry['credit']))
|
||||
$credit = $entry['credit'];
|
||||
|
||||
// Now that we've extracted top level 'entry' data
|
||||
// move our variable to the meat of 'LedgerEntry' for clarity
|
||||
$entry = $entry['LedgerEntry'];
|
||||
|
||||
$rows[] = array($html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id'])),
|
||||
$html->link('#'.$entry['id'],
|
||||
array('controller' => 'ledger_entries',
|
||||
'action' => 'view',
|
||||
$entry['id'])),
|
||||
FormatHelper::date($transaction['stamp']),
|
||||
$html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
FormatHelper::comment(array($transaction['comment'], $entry['comment'])),
|
||||
FormatHelper::currency($debit),
|
||||
FormatHelper::currency($credit),
|
||||
FormatHelper::currency($running_total)
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item account ledger list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
?>
|
||||
69
views/elements/ledger_entries.ctp
Normal file
69
views/elements/ledger_entries.ctp
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledger Entries',true).'</h2>';
|
||||
|
||||
$headers = array('Transaction', 'Entry', 'Date', 'Comment', 'Debit', 'Credit', 'Total');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
}
|
||||
|
||||
|
||||
$rows = array();
|
||||
$running_total = 0;
|
||||
foreach($ledger_entries AS $entry) {
|
||||
$credit = $debit = null;
|
||||
$running_total += $entry[0]['balance'];
|
||||
|
||||
if (isset($entry[0]['debit']))
|
||||
$debit = $entry[0]['debit'];
|
||||
if (isset($entry[0]['credit']))
|
||||
$credit = $entry[0]['credit'];
|
||||
|
||||
// local references to linked tables
|
||||
$transaction = $entry['Transaction'];
|
||||
|
||||
// Now that we've extracted top level 'LedgerEntry' data
|
||||
// move our variable to the meat of 'LedgerEntry' for clarity
|
||||
if (isset($entry['LedgerEntry']))
|
||||
$entry = $entry['LedgerEntry'];
|
||||
|
||||
$rows[] = array(isset($transaction['id'])
|
||||
? $html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id']))
|
||||
: null,
|
||||
|
||||
isset($entry['id'])
|
||||
? $html->link('#'.$entry['id'],
|
||||
array('controller' => 'ledger_entries',
|
||||
'action' => 'view',
|
||||
$entry['id']))
|
||||
: null,
|
||||
|
||||
FormatHelper::date($transaction['stamp']),
|
||||
FormatHelper::comment(array($transaction['comment'], $entry['comment'])),
|
||||
FormatHelper::currency($debit),
|
||||
FormatHelper::currency($credit),
|
||||
FormatHelper::currency($running_total)
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger-entries list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
?>
|
||||
@@ -5,12 +5,15 @@ if (isset($heading))
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledgers',true).'</h2>';
|
||||
|
||||
$headers = array_merge(array('Name'),
|
||||
$headers = array_merge(array('Sequence'), //array('Name'),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array('Account')
|
||||
: array()),
|
||||
array('Entries', 'Debits', 'Credits', 'Balance', 'Closed', 'Comment'));
|
||||
array('Entries', 'Debits', 'Credits', 'Balance', 'Close Date', 'Comment'));
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('ID', 'Sequence')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
@@ -22,7 +25,7 @@ if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$headers = array_merge(array($paginator->sort('name')),
|
||||
$headers = array_merge(array($paginator->sort('sequence')), //array($paginator->sort('name')),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array($paginator->sort('Account', 'Account.name'))
|
||||
: array()),
|
||||
@@ -30,35 +33,40 @@ if (isset($paginator)) {
|
||||
$paginator->sort('debits'),
|
||||
$paginator->sort('credits'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('closed'),
|
||||
$paginator->sort('Close Date', 'close_stamp'),
|
||||
$paginator->sort('comment')));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($ledgers as $ledger) {
|
||||
$account = null;
|
||||
$stats = null;
|
||||
|
||||
if (isset($ledger[0]))
|
||||
$ledger = array_merge($ledger[0], array_diff_key($ledger, array(0=>1)));
|
||||
if (isset($ledger['Ledger']))
|
||||
$ledger = array_merge($ledger['Ledger'], array_diff_key($ledger, array('Ledger'=>1)));
|
||||
$stats = $ledger[0];
|
||||
else
|
||||
$stats = $ledger;
|
||||
|
||||
if (isset($ledger['Account']))
|
||||
$account = $ledger['Account'];
|
||||
if (isset($ledger['Ledger']))
|
||||
$ledger = $ledger['Ledger'];
|
||||
|
||||
$rows[] = array_merge(array($html->link($ledger['name'],
|
||||
$rows[] = array_merge(array($html->link('#'.$ledger['sequence'],//$ledger['name'],
|
||||
array('controller' => 'ledgers',
|
||||
'action' => 'view',
|
||||
$ledger['id']))),
|
||||
(isset($ledger['Account'])
|
||||
(isset($account)
|
||||
? array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
$account['id'])))
|
||||
: array()),
|
||||
array($ledger['entries'],
|
||||
FormatHelper::currency($ledger['debits']),
|
||||
FormatHelper::currency($ledger['credits']),
|
||||
FormatHelper::currency($ledger['balance']),
|
||||
$ledger['closed'] ? 'Closed' : 'Open',
|
||||
array($stats['entries'],
|
||||
FormatHelper::currency($stats['debits']),
|
||||
FormatHelper::currency($stats['credits']),
|
||||
FormatHelper::currency($stats['balance']),
|
||||
FormatHelper::datetime($ledger['close_stamp']),
|
||||
$ledger['comment']));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user