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:
abijah
2009-06-10 02:41:23 +00:00
parent 3dcd83229b
commit ffd1b64580
41 changed files with 1441 additions and 916 deletions

View File

@@ -51,13 +51,22 @@ echo $this->element('table',
/**********************************************************************
* Ledger
* Ledgers
*/
echo $this->element('ledgers',
array('caption' => $account['Account']['name'] . " Ledgers",
'ledgers' => $account['Ledger']));
/**********************************************************************
* Current Ledger
*/
echo $this->element('ledger_entries',
array('caption' => "Current Ledger: (#{$account['CurrentLedger']['sequence']})",
'ledger_entries' => $account['CurrentLedger']['LedgerEntry']));
/* End "detail supporting" DIV */ ?>
</DIV>

View File

@@ -12,7 +12,9 @@
* Contact Detail Main Section
*/
$rows = array(array('Name', $contact['Contact']['display_name']),
$rows = array(array('First Name', $contact['Contact']['first_name']),
array('Middle Name', $contact['Contact']['middle_name']),
array('Last Name', $contact['Contact']['last_name']),
array('Company', $contact['Contact']['company_name']),
array('SSN', $contact['Contact']['id_federal']),
array('ID', ($contact['Contact']['id_local']

View File

@@ -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'],
);
}

View File

@@ -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'])));
}

View File

@@ -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
View 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");
}

View File

@@ -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));
?>

View 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));
?>

View File

@@ -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']));
}

View File

@@ -13,7 +13,8 @@ class FormatHelper extends AppHelper {
function currency($amount) {
if (!isset($amount))
return null;
return '-';
//return null;
return (isset($amount)
? self::$number->currency($amount)
@@ -34,7 +35,7 @@ class FormatHelper extends AppHelper {
}
function datetime($datetime) {
if (!$date) return null;
if (!$datetime) return null;
return self::$time->nice($datetime);
}

View File

@@ -56,11 +56,9 @@ echo $this->element('table',
* Ledger
*/
echo $this->element('ledger',
echo $this->element('ledger_entries',
array('caption' => $ledger['Ledger']['name'],
'ledger' => array('id' => $ledger['Ledger']['id'],
'type' => $ledger['Account']['type']),
'entries' => $ledger['LedgerEntry']));
'ledger_entries' => $ledger['LedgerEntry']));
/* End "detail supporting" DIV */ ?>
</DIV>

View File

@@ -1,13 +1,3 @@
<div class="transactions index">
<?php
function datefmt($date) {
$date_fmt = 'm/d/Y';
return ($date
? date_format(date_create($date), $date_fmt)
: null);
}
?>
<?php echo $this->element('transactions', array('heading' => '<h2>'.$heading.'</h2>')) ?>
</div>

View File

@@ -13,7 +13,7 @@
*/
$rows = array(array('ID', $transaction['Transaction']['id']),
array('Timestamp', datefmt($transaction['Transaction']['stamp'])),
array('Timestamp', FormatHelper::datetime($transaction['Transaction']['stamp'])),
array('Comment', $transaction['Transaction']['comment']));
echo $this->element('table',

View File

@@ -61,14 +61,14 @@ echo $this->element('leases',
/**********************************************************************
* Ledger History
*/
foreach($unit['Lease'] AS $lease) {
pr($lease);
$caption = 'Lease #'.$lease['number'].' (Tenant: '.$lease['Customer']['name'].')';
echo $this->element('ledger',
array('caption' => $caption,
'entries' => $lease['Customer']['Transaction'],
'ledger' => array('mix'=>1)));
}
/* foreach($unit['Lease'] AS $lease) { */
/* pr($lease); */
/* $caption = 'Lease #'.$lease['number'].' (Tenant: '.$lease['Customer']['name'].')'; */
/* echo $this->element('lease', */
/* array('caption' => $caption, */
/* 'entries' => $lease['Customer']['Transaction'], */
/* 'ledger' => array('mix'=>1))); */
/* } */
/* End "detail supporting" DIV */ ?>
</DIV>