From 374843aeeeb581cb955cccf1151fbe1843165d78 Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 8 Jun 2009 03:32:07 +0000 Subject: [PATCH] Finally added a format helper, which has been long intended. There may be still be conversion issues, it hasn't been tested much. git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@77 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 2 +- site/views/accounts/view.ctp | 32 +------ site/views/contacts/view.ctp | 28 +----- site/views/customers/view.ctp | 134 +++------------------------ site/views/elements/accounts.ctp | 28 ++---- site/views/elements/contacts.ctp | 18 ++-- site/views/elements/customers.ctp | 16 +++- site/views/elements/ledger.ctp | 48 ++++------ site/views/elements/ledgers.ctp | 13 ++- site/views/elements/maps.ctp | 16 +++- site/views/elements/transactions.ctp | 8 +- site/views/elements/units.ctp | 15 ++- site/views/helpers/format.php | 66 +++++++++++++ site/views/ledgers/view.ctp | 34 +------ site/views/transactions/view.ctp | 24 +---- site/views/units/view.ctp | 45 ++------- 16 files changed, 178 insertions(+), 349 deletions(-) create mode 100644 site/views/helpers/format.php diff --git a/site/app_controller.php b/site/app_controller.php index 9d4a328..19af659 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -35,7 +35,7 @@ * @subpackage cake.app */ class AppController extends Controller { - var $helpers = array('Html', 'Number', 'Time'); + var $helpers = array('Html', 'Format'); function sideMenuLinks() { return array( diff --git a/site/views/accounts/view.ctp b/site/views/accounts/view.ctp index 8d252da..2a56256 100644 --- a/site/views/accounts/view.ctp +++ b/site/views/accounts/view.ctp @@ -5,36 +5,6 @@ element('table',
- Account Balance: + Account Balance:
diff --git a/site/views/contacts/view.ctp b/site/views/contacts/view.ctp index a4986a1..ceb91c9 100644 --- a/site/views/contacts/view.ctp +++ b/site/views/contacts/view.ctp @@ -3,31 +3,7 @@
element('table', $headers = array('Phone', 'Preference', 'Comment'); $rows = array(); foreach($contact['ContactPhone'] AS $phone) { - $rows[] = array(phone($phone['phone']) . + $rows[] = array(FormatHelper::phone($phone['phone']) . ($phone['ext'] ? " x".$phone['ext'] : ""), $phone['ContactsMethod']['preference'] . " / " . $phone['ContactsMethod']['type'] . " / " . diff --git a/site/views/customers/view.ctp b/site/views/customers/view.ctp index f55c9ec..c37ff22 100644 --- a/site/views/customers/view.ctp +++ b/site/views/customers/view.ctp @@ -3,31 +3,7 @@
element('table', ?>
- Security Deposit: + Security Deposit:
- Balance: + Balance:
@@ -80,108 +56,22 @@ echo $this->element('contacts', 'contacts' => $customer['Contact'])); -/* foreach ($customer['Contact'] AS $contact) { */ - -/* /\********************************************************************** */ -/* * Phones */ -/* *\/ */ -/* $headers = array('Phone', 'Preference', 'Comment'); */ -/* $rows = array(); */ -/* foreach($contact['ContactPhone'] AS $phone) { */ -/* $rows[] = array(phone($phone['phone']) . */ -/* ($phone['ext'] ? " x".$phone['ext'] : ""), */ -/* $phone['ContactsMethod']['preference'] . " / " . */ -/* $phone['ContactsMethod']['type'] . " / " . */ -/* $phone['type'], */ -/* $phone['comment']); */ -/* } */ - -/* echo $this->element('table', */ -/* array('class' => 'item phone list', */ -/* 'caption' => 'Phone', */ -/* 'headers' => $headers, */ -/* 'rows' => $rows, */ -/* 'column_class' => $headers)); */ - - -/* /\********************************************************************** */ -/* * Emails */ -/* *\/ */ -/* $headers = array('Email', 'Preference', 'Comment'); */ -/* $rows = array(); */ -/* foreach($contact['ContactEmail'] AS $email) { */ -/* $rows[] = array($email['email'], */ -/* $email['ContactsMethod']['preference'] . " / " . */ -/* $email['ContactsMethod']['type'], */ -/* $email['comment']); */ -/* } */ - -/* echo $this->element('table', */ -/* array('class' => 'item email list', */ -/* 'caption' => 'Email', */ -/* 'headers' => $headers, */ -/* 'rows' => $rows, */ -/* 'column_class' => $headers)); */ - - -/* /\********************************************************************** */ -/* * Addresses */ -/* *\/ */ -/* $headers = array('Address', 'Preference', 'Comment'); */ -/* $rows = array(); */ -/* foreach($contact['ContactAddress'] AS $address) { */ -/* $rows[] = array(preg_replace("/\n/", "
\n", $address['address']) . "
\n" . */ -/* $address['city'] . ", " . */ -/* $address['state'] . " " . */ -/* $address['postcode'], */ -/* //. ? "
\n" . $address['country'], */ -/* $address['ContactsMethod']['preference'] . " / " . */ -/* $address['ContactsMethod']['type'], */ -/* $address['comment']); */ -/* } */ - -/* echo $this->element('table', */ -/* array('class' => 'item address list', */ -/* 'caption' => 'Address', */ -/* 'headers' => $headers, */ -/* 'rows' => $rows, */ -/* 'column_class' => $headers)); */ - - /********************************************************************** * Lease History */ -$headers = array('Lease', 'Unit', 'Signed', 'Move-In', 'Move-Out', 'Rent', 'Deposit', 'Comment'); -$rows = array(); -foreach($customer['Lease'] AS $lease) { - $rows[] = array('#'.$lease['number'], - $html->link($lease['Unit']['name'], - array('controller' => 'units', - 'action' => 'view', - $lease['Unit']['id'])), - datefmt($lease['lease_date']), - datefmt($lease['movein_date']), - datefmt($lease['moveout_date']), - $lease['amount'], - $lease['deposit'], - $lease['comment']); -} - -echo $this->element('table', - array('class' => 'item lease list', - 'caption' => 'Lease History', - 'headers' => $headers, - 'rows' => $rows, - 'column_class' => $headers)); +echo $this->element('leases', + array('caption' => 'Lease History', + 'leases' => $customer['Lease'])); /********************************************************************** - * Ledger History + * Account */ -echo $this->element('ledger', - array('caption' => 'Ledger History', - 'transactions' => $customer['Transaction'], - 'ledger' => array('mix'=>1))); + +echo $this->element('accounts', + array('caption' => 'Account', + 'accounts' => array($customer['Account']))); + /* End "detail supporting" DIV */ ?>
diff --git a/site/views/elements/accounts.ctp b/site/views/elements/accounts.ctp index aaf9452..1d312f0 100644 --- a/site/views/elements/accounts.ctp +++ b/site/views/elements/accounts.ctp @@ -2,28 +2,17 @@ if (isset($heading)) echo $heading; -else +elseif (!isset($caption)) echo '

'.__('Accounts',true).'

'; -function currency($number) { - if ($number < 0) - return "($ " . number_format(-1*$number, 2) . ")"; - else - return "$ " . number_format($number, 2); -} - -function datefmt($date) { - $date_fmt = 'm/d/Y'; - return ($date - ? date_format(date_create($date), $date_fmt) - : null); -} - $headers = array('Name', 'Type', 'Ext. Name', 'Ext. Account', 'Entries', 'Debits', 'Credits', 'Balance', 'Comment'); $column_class = array(); -foreach (array_intersect($column_class, array('Debits', 'Credits', 'Balance')) AS $k => $v) { +foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) { $column_class[$k] = 'currency'; } +foreach (array_intersect($headers, array('Comment')) AS $k => $v) { + $column_class[$k] = 'slack'; +} if (isset($paginator)) { echo $paginator->counter(array( @@ -61,15 +50,16 @@ foreach ($accounts as $account) { $account['external_name'], $account['external_account'], $account['entries'], - currency($account['debits']), - currency($account['credits']), - currency($account['balance']), + FormatHelper::currency($account['debits']), + FormatHelper::currency($account['credits']), + FormatHelper::currency($account['balance']), $account['comment'], ); } echo $this->element('table', array('class' => 'item account list', + 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, 'column_class' => $column_class)); diff --git a/site/views/elements/contacts.ctp b/site/views/elements/contacts.ctp index 54c10c3..cdb4c5f 100644 --- a/site/views/elements/contacts.ctp +++ b/site/views/elements/contacts.ctp @@ -5,9 +5,17 @@ if (isset($heading)) elseif (!isset($caption)) echo '

'.__('Contacts',true).'

'; -$headers_manual = array_merge(array('Id', 'Last Name', 'First Name', 'Company'), - isset($contacts[0]['ContactsCustomer']) ? array('Type', 'Active') : array(), - array('Comment')); +$headers = array_merge(array('ID', 'Last Name', 'First Name', 'Company'), + isset($contacts[0]['ContactsCustomer']) ? array('Type', 'Active') : array(), + array('Comment')); + +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'; +} + if (isset($paginator)) { echo $paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); @@ -21,8 +29,6 @@ if (isset($paginator)) { $paginator->sort('active')) : array()), array($paginator->sort('comment'))); -} else { - $headers = $headers_manual; } $rows = array(); @@ -55,7 +61,7 @@ echo $this->element('table', 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, - 'column_class' => $headers_manual)); + 'column_class' => $column_class)); if (isset($paginator)) { echo('
' . "\n"); diff --git a/site/views/elements/customers.ctp b/site/views/elements/customers.ctp index 38cf034..471e203 100644 --- a/site/views/elements/customers.ctp +++ b/site/views/elements/customers.ctp @@ -2,10 +2,18 @@ if (isset($heading)) echo $heading; -else +elseif (!isset($caption)) echo '

'.__('Customers',true).'

'; -$headers_manual = array('Id', 'Name', 'Comment'); +$headers = array('ID', 'Name', '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'; +} + if (isset($paginator)) { echo $paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); @@ -13,8 +21,6 @@ if (isset($paginator)) { $headers = array($paginator->sort('id'), $paginator->sort('name'), $paginator->sort('comment')); -} else { - $headers = $headers_manual; } $rows = array(); @@ -38,7 +44,7 @@ echo $this->element('table', 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, - 'column_class' => $headers_manual)); + 'column_class' => $column_class)); if (isset($paginator)) { echo('
' . "\n"); diff --git a/site/views/elements/ledger.ctp b/site/views/elements/ledger.ctp index 4ae5d62..4128277 100644 --- a/site/views/elements/ledger.ctp +++ b/site/views/elements/ledger.ctp @@ -1,26 +1,22 @@ '.__('Ledger',true).''; + $headers = array('Transaction', 'Entry', 'Date', 'Customer', 'Comment', 'Debit', 'Credit', 'Total'); -$column_class = $headers; -foreach (array_intersect($column_class, array('Transaction', 'Entry')) AS $k => $v) { +$column_class = array(); +foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) { $column_class[$k] = array($column_class[$k], 'id'); } -foreach (array_intersect($column_class, array('Debits', 'Credits', 'Total')) AS $k => $v) { +foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) { $column_class[$k] = array($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))); */ +foreach (array_intersect($headers, array('Comment')) AS $k => $v) { + $column_class[$k] = 'slack'; +} -/* $headers = array($paginator->sort('Transaction', 'transaction_id'), */ -/* $paginator->sort('entry_id'), */ -/* $paginator->sort('Date', 'stamp'), */ -/* $paginator->sort('customer_id'), */ -/* $paginator->sort('comment'), */ -/* $paginator->sort('debit'), */ -/* $paginator->sort('credit'), */ -/* $paginator->sort('total')); */ -/* } */ $rows = array(); $running_total = 0; @@ -48,33 +44,23 @@ foreach($entries AS $entry) { array('controller' => 'ledger_entries', 'action' => 'view', $entry['id'])), - datefmt($transaction['stamp']), + FormatHelper::date($transaction['stamp']), $html->link($customer['name'], array('controller' => 'customers', 'action' => 'view', $customer['id'])), - comment(array($transaction['comment'], $entry['comment'])), - currency($debit), - currency($credit), - currency($running_total) + 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' => $caption, + 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, 'column_class' => $column_class)); -/* if (isset($paginator)) { */ -/* echo('
' . "\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('
' . "\n"); */ -/* } */ - ?> diff --git a/site/views/elements/ledgers.ctp b/site/views/elements/ledgers.ctp index 13c4219..4155126 100644 --- a/site/views/elements/ledgers.ctp +++ b/site/views/elements/ledgers.ctp @@ -11,8 +11,11 @@ $headers = array_merge(array('Name'), : array()), array('Entries', 'Debits', 'Credits', 'Balance', 'Closed', 'Comment')); $column_class = array(); -foreach (array_intersect($column_class, array('Comment')) AS $k => $v) { - $column_class[$k] = 'comment'; +foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) { + $column_class[$k] = 'currency'; +} +foreach (array_intersect($headers, array('Comment')) AS $k => $v) { + $column_class[$k] = 'slack'; } if (isset($paginator)) { @@ -52,9 +55,9 @@ foreach ($ledgers as $ledger) { $account['id']))) : array()), array($ledger['entries'], - currency($ledger['debits']), - currency($ledger['credits']), - currency($ledger['balance']), + FormatHelper::currency($ledger['debits']), + FormatHelper::currency($ledger['credits']), + FormatHelper::currency($ledger['balance']), $ledger['closed'] ? 'Closed' : 'Open', $ledger['comment'])); } diff --git a/site/views/elements/maps.ctp b/site/views/elements/maps.ctp index ee148c9..dc475fb 100644 --- a/site/views/elements/maps.ctp +++ b/site/views/elements/maps.ctp @@ -2,10 +2,18 @@ if (isset($heading)) echo $heading; -else +elseif (!isset($caption)) echo '

'.__('Maps',true).'

'; -$headers_manual = array('Id', 'Name', 'Area', 'Width', 'Depth', 'Comment'); +$headers = array('ID', 'Name', 'Area', 'Width', 'Depth', '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] = 'slack'; +} + if (isset($paginator)) { echo $paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); @@ -16,8 +24,6 @@ if (isset($paginator)) { $paginator->sort('width'), $paginator->sort('depth'), $paginator->sort('comment')); -} else { - $headers = $headers_manual; } $rows = array(); @@ -40,7 +46,7 @@ echo $this->element('table', array('class' => 'item map list', 'headers' => $headers, 'rows' => $rows, - 'column_class' => $headers_manual)); + 'column_class' => $column_class)); if (isset($paginator)) { echo('
' . "\n"); diff --git a/site/views/elements/transactions.ctp b/site/views/elements/transactions.ctp index abf2535..556e71b 100644 --- a/site/views/elements/transactions.ctp +++ b/site/views/elements/transactions.ctp @@ -8,7 +8,7 @@ elseif (!isset($caption)) $headers = array('Id', 'Timestamp', 'Comment'); $column_class = array(); foreach (array_intersect($headers, array('Comment')) AS $k => $v) { - $column_class[$k] = 'comment'; + $column_class[$k] = 'slack'; } foreach (array_intersect($headers, array('Id')) AS $k => $v) { $column_class[$k] = 'id'; @@ -41,9 +41,9 @@ foreach ($transactions as $transaction) { array('controller' => 'customers', 'action' => 'view', $customer['id'])), - datefmt($transaction['stamp']), - datefmt($transaction['through_date']), - datefmt($transaction['due_date']), + FormatHelper::date($transaction['stamp']), + FormatHelper::date($transaction['through_date']), + FormatHelper::date($transaction['due_date']), $transaction['comment']); } diff --git a/site/views/elements/units.ctp b/site/views/elements/units.ctp index d0f90ee..6376a3c 100644 --- a/site/views/elements/units.ctp +++ b/site/views/elements/units.ctp @@ -5,7 +5,15 @@ if (isset($heading)) else echo '

'.__('Units',true).'

'; -$headers_manual = array('Id', 'Unit', 'Size', 'Status', 'Comment'); +$headers = array('ID', 'Unit', 'Size', 'Status', '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] = 'slack'; +} + if (isset($paginator)) { echo $paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); @@ -15,8 +23,6 @@ if (isset($paginator)) { $paginator->sort('unit_size_id'), $paginator->sort('status'), $paginator->sort('comment')); -} else { - $headers = $headers_manual; } $rows = array(); @@ -36,9 +42,10 @@ foreach ($units as $unit) { echo $this->element('table', array('class' => 'item unit list', + 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, - 'column_class' => $headers_manual)); + 'column_class' => $column_class)); if (isset($paginator)) { echo('
' . "\n"); diff --git a/site/views/helpers/format.php b/site/views/helpers/format.php new file mode 100644 index 0000000..4b93bab --- /dev/null +++ b/site/views/helpers/format.php @@ -0,0 +1,66 @@ +currency($amount) + : null); + +/* if ($money < 0) */ +/* return "($ " . number_format(-1*$money, 2) . ")"; */ +/* else */ +/* return "$ " . number_format($money, 2); */ + } + + function date($date) { + $date_fmt = 'm/d/Y'; + return (isset($date) + ? self::$time->format($date_fmt, $date) + //? date_format(date_create($date), $date_fmt) + : null); + } + + function datetime($datetime) { + if (!$date) return null; + return self::$time->nice($datetime); + } + + function phone($phone) { + if (!isset($phone)) + return null; + + $phone = preg_replace("/\D/", "", $phone); + if(strlen($phone) == 7) + return preg_replace("/(\d{3})(\d{4})/", "$1-$2", $phone); + elseif(strlen($phone) == 10) + return preg_replace("/(\d{3})(\d{3})(\d{4})/", "$1-$2-$3", $phone); + else + return $phone; + } + + function comment($comment) { + if (isset($comment) && is_array($comment)) { + foreach (array_keys($comment) AS $k) { + if (!$comment[$k]) + unset($comment[$k]); + } + return implode('; ', $comment); + } + + return $comment; + } + +} diff --git a/site/views/ledgers/view.ctp b/site/views/ledgers/view.ctp index 63320e3..0cddc40 100644 --- a/site/views/ledgers/view.ctp +++ b/site/views/ledgers/view.ctp @@ -5,36 +5,6 @@ 'accounts', 'action' => 'view', $ledger['Account']['id']))), - array('Closed', $ledger['Ledger']['closed']), + array('Status', $ledger['Ledger']['closed'] ? 'Closed' : 'Open'), array('Comment', $ledger['Ledger']['comment'])); echo $this->element('table', @@ -66,7 +36,7 @@ echo $this->element('table',
- Ledger Balance: + Ledger Balance:
diff --git a/site/views/transactions/view.ctp b/site/views/transactions/view.ctp index 3a9e87f..4771455 100644 --- a/site/views/transactions/view.ctp +++ b/site/views/transactions/view.ctp @@ -3,21 +3,7 @@
element('table', ?>
- Debits: + Debits:
- Credits: + Credits:
@@ -83,8 +69,8 @@ foreach($transaction['LedgerEntry'] AS $entry) { 'action' => 'view', $entry['CreditLedger']['id'])), $entry['comment'], - currency($entry['amount']), - currency($running_total) + FormatHelper::currency($entry['amount']), + FormatHelper::currency($running_total) ); } diff --git a/site/views/units/view.ctp b/site/views/units/view.ctp index 5bc79ce..e6b79fe 100644 --- a/site/views/units/view.ctp +++ b/site/views/units/view.ctp @@ -3,22 +3,7 @@
element('table', ?>
- Security Deposit: + Security Deposit:
- Balance: + Balance:
@@ -67,28 +52,10 @@ echo $this->element('table', /********************************************************************** * Lease History */ -$headers = array('Lease', 'Tenant', 'Signed', 'Move-In', 'Move-Out', 'Rent', 'Deposit', 'Comment'); -$rows = array(); -foreach($unit['Lease'] AS $lease) { - $rows[] = array('#'.$lease['number'], - $html->link($lease['Customer']['name'], - array('controller' => 'customers', - 'action' => 'view', - $lease['Customer']['id'])), - datefmt($lease['lease_date']), - datefmt($lease['movein_date']), - datefmt($lease['moveout_date']), - currency($lease['amount']), - currency($lease['deposit']), - $lease['comment']); -} -echo $this->element('table', - array('class' => 'item lease list', - 'caption' => 'Lease History', - 'headers' => $headers, - 'rows' => $rows, - 'column_class' => $headers)); +echo $this->element('leases', + array('caption' => 'Lease History', + 'leases' => $unit['Lease'])); /**********************************************************************