From 7805e4d229dafec86100ff35f47b21f69a52d360 Mon Sep 17 00:00:00 2001 From: abijah Date: Thu, 28 May 2009 11:26:09 +0000 Subject: [PATCH] Added preliminary support for units. The queries are giving me a heck of a time, so I've cheated in some places. For the most part though, it's working. Also, something went wrong with svn, and view/contacts/view.ctp was not right (a checkin seems to have been omitted on it). This checking brings it up to date. git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@28 97e9348a-65ac-dc4b-aefc-98561f571b83 --- controllers/units_controller.php | 123 ++++++++++++++++++++++++ models/unit_size.php | 1 - models/unit_type.php | 1 - views/contacts/view.ctp | 156 ++++++++++++++++++++++++++++--- views/elements/units.ctp | 59 ++++++++++++ views/units/index.ctp | 3 + views/units/view.ctp | 113 ++++++++++++++++++++++ 7 files changed, 439 insertions(+), 17 deletions(-) create mode 100644 controllers/units_controller.php create mode 100644 views/elements/units.ctp create mode 100644 views/units/index.ctp create mode 100644 views/units/view.ctp diff --git a/controllers/units_controller.php b/controllers/units_controller.php new file mode 100644 index 0000000..fe21434 --- /dev/null +++ b/controllers/units_controller.php @@ -0,0 +1,123 @@ + 100, + 'order' => array('Unit.sort_order' => 'ASC')); + + function index() { + $this->all(); + } + + function vacant() { + $this->Unit->recursive = 0; + $this->Unit->bindModel(array('hasOne' => array('UnitsLease', + 'Lease' => array( + 'foreignKey' => false, + 'conditions' => array('Lease.id = UnitsLease.lease_id') + ))), + false); + + $this->set('units', $this->paginate(array('Lease.close_date IS NULL', + 'UnitsLease.type != "ALTERNATE"'))); + $this->render('index'); + } + + function occupied() { + $this->Unit->recursive = 0; + $this->Unit->bindModel(array('hasOne' => array('UnitsLease', + 'Lease' => array( + 'foreignKey' => false, + 'conditions' => array('Lease.id = UnitsLease.lease_id') + ))), + false); + + $this->set('units', $this->paginate(array('Lease.close_date IS NULL', + 'UnitsLease.type != "ALTERNATE"'))); + $this->render('index'); + } + + function all() { + $this->Unit->recursive = 2; +/* $this->Unit->UnitSize->unbindModel(array('hasMany' => array('Unit'))); */ +/* $this->Unit->UnitSize->UnitType->unbindModel(array('hasMany' => array('UnitSize'))); */ + //$this->Unit->bindModel(array('hasOne' => array('UnitType'))); + //function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null) { + $this->set('units', $this->paginate(null, null, null, null, null, 2)); + $this->render('index'); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'')); + } + $this->Unit->recursive = 4; + $this->Unit->UnitSize->unbindModel(array('hasMany' => array('Unit'))); + $this->Unit->UnitSize->UnitType->unbindModel(array('hasMany' => array('UnitSize'))); + $this->Unit->Lease->unbindModel(array('belongsTo' => array('Unit'))); + $this->Unit->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease'))); + $this->Unit->Lease->Charge->unbindModel(array('belongsTo' => array('Lease'))); + $this->Unit->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge'))); + $this->Unit->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt'))); + +/* //$this->Unit->Lease->unbindModel(array('hasMany' => array('Contact'))); */ +/* $this->Unit->Lease->unbindModel(array('hasAndBelongsToMany' => array('Contact'))); */ +/* //$this->Unit->Lease->unbindModel(array('hasOne' => array('Contact'))); */ +/* //$this->Unit->Lease->unbindModel(array('belongsTo' => array('Contact'))); */ +/* //$this->Unit->Lease->bindModel(array('hasOne' => array('ContactsLease'))); */ +/* //$this->Unit->Lease->bindModel(array('hasOne' => array('Contact'))); */ +/* /\* $this->Unit->Lease->bindModel(array('hasOne' => array('ContactsLease', *\/ */ +/* /\* 'Contact' => array( *\/ */ +/* /\* 'foreignKey' => false, *\/ */ +/* /\* 'conditions' => *\/ */ +/* /\* array('Contact.id = ContactsLease.contact_id', *\/ */ +/* /\* //'ContactsLease.type = "TENANT"' *\/ */ +/* /\* ))))); *\/ */ + +/* $this->Unit->bindModel(array('hasOne' => array('Lease' => array( */ +/* 'foreignKey' => false, */ +/* 'conditions' => array('Lease.unit_id = Unit.id') */ +/* ), */ +/* 'ContactsLease' => array( */ +/* 'foreignKey' => false, */ +/* 'conditions' => array('ContactsLease.lease_id = Lease.id') */ +/* ), */ +/* 'Contact' => array( */ +/* 'foreignKey' => false, */ +/* 'conditions' => array('Contact.id = ContactsLease.contact_id') */ +/* ))), */ +/* false); */ + + +/* $this->Unit->Lease->bindModel(array('hasOne' => array('Contact' => array( */ +/* 'className' => 'ContactsLease', */ +/* 'foreignKey' => false, */ +/* 'conditions' => */ +/* array('ContactsLease.lease_id = Lease.id', */ +/* 'ContactsLease.type = "TENANT"'))))); */ + +/* # 'hasOne' => array( */ +/* # 'RecipesTag', */ +/* # 'FilterTag' => array( */ +/* # 'className' => 'Tag', */ +/* # 'foreignKey' => false, */ +/* # 'conditions' => array('FilterTag.id = RecipesTag.tag_id') */ +/* # )))); */ + + $this->set('unit', $this->Unit->read(null, $id)); +/* $this->Unit->id = $id; */ +/* if ($id !== null && $id !== false) { */ +/* $this->Unit->data = $this->Unit->find('first', */ +/* array('conditions' => array( */ +/* $this->Unit->alias . '.' . $this->Unit->primaryKey => $id, */ +/* 'ContactsLease.type = "TENANT"' */ +/* ) */ +/* )); */ +/* $this->set('unit', $this->Unit->data); */ +/* } */ + } +} + +?> \ No newline at end of file diff --git a/models/unit_size.php b/models/unit_size.php index 5bb39f8..29d1a2f 100644 --- a/models/unit_size.php +++ b/models/unit_size.php @@ -13,7 +13,6 @@ class UnitSize extends AppModel { 'amount' => array('money') ); - //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'UnitType' => array( 'className' => 'UnitType', diff --git a/models/unit_type.php b/models/unit_type.php index 06f59e4..8488ca0 100644 --- a/models/unit_type.php +++ b/models/unit_type.php @@ -8,7 +8,6 @@ class UnitType extends AppModel { 'name' => array('notempty') ); - //The Associations below have been created with all possible keys, those that are not needed can be removed var $hasMany = array( 'UnitSize' => array( 'className' => 'UnitSize', diff --git a/views/contacts/view.ctp b/views/contacts/view.ctp index 18d6021..5d6e968 100644 --- a/views/contacts/view.ctp +++ b/views/contacts/view.ctp @@ -6,22 +6,145 @@ $val) { - $rows[] = array(array($col, 'width=1%'), $val); +function phone($phone) { + $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 datefmt($date) { + $date_fmt = 'm/d/Y'; + return ($date + ? date_format(date_create($date), $date_fmt) + : null); +} + +/********************************************************************** + * Tenant Info + */ echo('' . "\n"); echo(' ' . "\n"); -echo $html->tableCells($rows, null, array('class' => "altrow")); +echo $html->tableCells(array(array('Name', $tenant['Contact']['display_name']), + array('Company', $tenant['Contact']['company_name']), + array('SSN', $tenant['Contact']['id_federal']), + array('ID', $tenant['Contact']['id_num'] + . ($tenant['Contact']['id_state'] + ? " - ".$tenant['Contact']['id_state'] + : "")), + array('Comment', $tenant['Contact']['comment'])), + null, array('class' => "altrow"), false, false); echo('
Tenant Info
' . "\n"); + +/********************************************************************** + * Phones + */ +$headers = array('Location', 'Preference', 'Type', 'Phone', 'Extension', 'Comment'); +$rows = array(); +foreach($tenant['ContactPhone'] AS $phone) { + $rows[] = array($phone['ContactsMethod']['type'], + $phone['ContactsMethod']['preference'], + $phone['type'], + phone($phone['phone']), + $phone['ext'], + $phone['comment']); +} + +if (count($rows)) { + echo('' . "\n"); + echo(' ' . "\n"); + echo $html->tableHeaders($headers); + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); + echo('
Phone
' . "\n"); +} + + +/********************************************************************** + * Emails + */ +$headers = array('Location', 'Preference', 'Email', 'Comment'); +$rows = array(); +foreach($tenant['ContactEmail'] AS $email) { + $rows[] = array($email['ContactsMethod']['type'], + $email['ContactsMethod']['preference'], + $email['email'], + $email['comment']); +} + +if (count($rows)) { + echo('' . "\n"); + echo(' ' . "\n"); + echo $html->tableHeaders($headers); + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); + echo('
Email
' . "\n"); +} + + +/********************************************************************** + * Addresses + */ +$headers = array('Location', 'Preference', 'Address', 'City', 'State', 'Zip', 'Country', 'Comment'); +$rows = array(); +foreach($tenant['ContactAddress'] AS $address) { + $rows[] = array($address['ContactsMethod']['type'], + $address['ContactsMethod']['preference'], + $address['address'], + $address['city'], + $address['state'], + $address['postcode'], + $address['country'], + $address['comment']); +} + +if (count($rows)) { + echo('' . "\n"); + echo(' ' . "\n"); + echo $html->tableHeaders($headers); + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); + echo('
Address
' . "\n"); +} + + +/********************************************************************** + * Lease History + */ +$headers = array('Lease', 'Unit', 'Signed', 'Move-In', 'Move-Out', 'Rent', 'Deposit', 'Comment'); +$rows = array(); +foreach($tenant['Lease'] AS $lease) { + $rows[] = array('#'.$lease['id'], + $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('' . "\n"); +echo(' ' . "\n"); +echo $html->tableHeaders($headers); +echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); +echo('
Lease History
' . "\n"); + + +/********************************************************************** + * Ledger History + */ +$security_deposit = 0; $grand_total = 0; foreach($tenant['Lease'] AS $lease) { $headers = array('Date', /*'Through',*/ /*'Charge/Receipt'*/'ID', 'Type', 'Comment', 'Amount', 'Total'); @@ -31,8 +154,7 @@ foreach($tenant['Lease'] AS $lease) { foreach($lease['Charge'] AS $charge) { $amount = $charge['total']; $running_total += $amount; - $rows[] = array(date_format(date_create($charge['charge_date']), 'm-d-Y') . ' - ' . - date_format(date_create($charge['charge_to_date']), 'm-d-Y'), + $rows[] = array(datefmt($charge['charge_date']) .' - '. datefmt($charge['charge_to_date']), '#'.$charge['id'], $charge['ChargeType']['name'], $charge['comment'], @@ -42,10 +164,13 @@ foreach($tenant['Lease'] AS $lease) { foreach ($charge['Receipt'] AS $receipt) { $amount = -1 * $receipt['ChargesReceipt']['amount']; $running_total += $amount; - $rows[] = array(' -- ' .date_format(date_create($receipt['stamp']), 'm-d-Y'), - //null, + // REVISIT 20090527: + // Using hardcoded value for security deposit... can't be good! + if ($charge['charge_type_id'] == 1) + $security_deposit += $receipt['ChargesReceipt']['amount']; + $rows[] = array(' -- ' . datefmt($receipt['stamp']), '#'.$receipt['id'], - 'Receipt', + 'Payment/Receipt', $receipt['comment'], currency($amount), currency($running_total)); @@ -54,13 +179,14 @@ foreach($tenant['Lease'] AS $lease) { $grand_total += $running_total; echo('' . "\n"); - echo(' ' . "\n"); + echo(' ' . "\n"); echo $html->tableHeaders($headers); - echo $html->tableCells($rows, null, array('class' => "altrow")); + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); echo('
Lease #'.$lease['number'].' (Unit '.$lease['Unit']['name'].')Lease #'.$lease['number'].' ('.$lease['Unit']['name'].')
' . "\n"); } ?> -

Grand Total:

+

Total Security Deposit:

+

Outstanding Balance:

diff --git a/views/elements/units.ctp b/views/elements/units.ctp new file mode 100644 index 0000000..ca3b714 --- /dev/null +++ b/views/elements/units.ctp @@ -0,0 +1,59 @@ + + +

+'.__('Units',true).''; +?> +

+ + + + counter(array( + 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); + + $rows = array($paginator->sort('id'), + $paginator->sort('name'), + $paginator->sort('unit_size_id'), + $paginator->sort('status'), + $paginator->sort('comment')); + } else { + $rows = array('Id', 'Name', 'Size', 'Status', 'Comment'); + } + echo $html->tableHeaders($rows); + + $rows = array(); + foreach ($units as $unit) { + $rows[] = array($html->link($unit['Unit']['id'], + array('controller' => 'units', + 'action' => 'view', + $unit['Unit']['id'])), + $html->link($unit['Unit']['name'], + array('controller' => 'units', + 'action' => 'view', + $unit['Unit']['id'])), + $unit['UnitSize']['name'], + $unit['Unit']['status'], + $unit['Unit']['comment']); + } + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); + } +?> +
+ +' . "\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/views/units/index.ctp b/views/units/index.ctp new file mode 100644 index 0000000..df3021c --- /dev/null +++ b/views/units/index.ctp @@ -0,0 +1,3 @@ +
+element('units') ?> +
diff --git a/views/units/view.ctp b/views/units/view.ctp new file mode 100644 index 0000000..6e2c113 --- /dev/null +++ b/views/units/view.ctp @@ -0,0 +1,113 @@ + + +
+

+ + $val) { + $rows[] = array(array($col, 'width=1%'), $val); +} + +echo('' . "\n"); +echo(' ' . "\n"); +echo $html->tableCells(array(array('Name', $unit['Unit']['name']), + array('Status', $unit['Unit']['status']), + array('Comment', $unit['Unit']['comment'])), + null, array('class' => "altrow"), false, false); +echo('
Unit Info
' . "\n"); + + +/********************************************************************** + * Lease History + */ +$headers = array('Lease', 'Tenant', 'Signed', 'Move-In', 'Move-Out', 'Rent', 'Deposit', 'Comment'); +$rows = array(); +foreach($unit['Lease'] AS $lease) { + $rows[] = array('#'.$lease['id'], + $html->link($lease['Contact'][0]['display_name'], + array('controller' => 'contacts', + 'action' => 'view', + $lease['Contact'][0]['id'])), + datefmt($lease['lease_date']), + datefmt($lease['movein_date']), + datefmt($lease['moveout_date']), + $lease['amount'], + $lease['deposit'], + $lease['comment']); +} + +echo('' . "\n"); +echo(' ' . "\n"); +echo $html->tableHeaders($headers); +echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); +echo('
Lease History
' . "\n"); + + +/********************************************************************** + * Ledger History + */ +$security_deposit = 0; +$grand_total = 0; +foreach($unit['Lease'] AS $lease) { + $headers = array('Date', /*'Through',*/ /*'Charge/Receipt'*/'ID', 'Type', 'Comment', 'Amount', 'Total'); + + $rows = array(); + $running_total = 0; + foreach($lease['Charge'] AS $charge) { + $amount = $charge['total']; + $running_total += $amount; + $rows[] = array(datefmt($charge['charge_date']) .' - '. datefmt($charge['charge_to_date']), + '#'.$charge['id'], + $charge['ChargeType']['name'], + $charge['comment'], + currency($amount), + currency($running_total)); + + foreach ($charge['Receipt'] AS $receipt) { + $amount = -1 * $receipt['ChargesReceipt']['amount']; + $running_total += $amount; + // REVISIT 20090527: + // Using hardcoded value for security deposit... can't be good! + if ($charge['charge_type_id'] == 1) + $security_deposit += $receipt['ChargesReceipt']['amount']; + $rows[] = array(' -- ' . datefmt($receipt['stamp']), + '#'.$receipt['id'], + 'Payment/Receipt', + $receipt['comment'], + currency($amount), + currency($running_total)); + } + } + $grand_total += $running_total; + + echo('' . "\n"); + echo(' ' . "\n"); + echo $html->tableHeaders($headers); + echo $html->tableCells($rows, null, array('class' => "altrow"), false, false); + echo('
Lease #'.$lease['number'].' ('.$lease['Contact'][0]['display_name'].')
' . "\n"); + +} +?> + +

Total Security Deposit:

+

Outstanding Balance:

+