From bba3af8163b22be6ff9d606b48b7b06288a73fa0 Mon Sep 17 00:00:00 2001 From: abijah Date: Fri, 7 Aug 2009 22:52:01 +0000 Subject: [PATCH] Some of the finer detail work, mostly around pre-populating the move-in invoice with useful and correct data, and allowing the lease rent and deposit to be set at movein. git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@503 97e9348a-65ac-dc4b-aefc-98561f571b83 --- controllers/leases_controller.php | 32 +++++++-- controllers/units_controller.php | 4 +- models/statement_entry.php | 2 +- models/transaction.php | 4 ++ models/unit.php | 46 ++++++++++++ views/elements/form_table.ctp | 2 +- views/elements/table.ctp | 5 +- views/elements/units.ctp | 3 +- views/leases/invoice.ctp | 115 ++++++++++++++++++++++++++---- views/leases/move.ctp | 23 +++++- 10 files changed, 213 insertions(+), 23 deletions(-) diff --git a/controllers/leases_controller.php b/controllers/leases_controller.php index c52f982..4e043c8 100644 --- a/controllers/leases_controller.php +++ b/controllers/leases_controller.php @@ -135,17 +135,22 @@ class LeasesController extends AppController { // Handle the move in based on the data given //pr(array('Move-in data', $this->data)); + foreach (array('deposit', 'rent') AS $currency) { + $this->data['Lease'][$currency] + = str_replace('$', '', $this->data['Lease'][$currency]); + } $lid = $this->Lease->moveIn($this->data['Lease']['customer_id'], $this->data['Lease']['unit_id'], - null, null, + $this->data['Lease']['deposit'], + $this->data['Lease']['rent'], $this->data['Lease']['movein_date'], $this->data['Lease']['comment'] ); // Since this is a new lease, go to the invoice // screen so we can start assessing charges. - $this->redirect(array('action'=>'invoice', $lid)); + $this->redirect(array('action'=>'invoice', $lid, 'move-in')); // For debugging, only if the redirect above have been // commented out, otherwise this section isn't reached. @@ -362,13 +367,30 @@ class LeasesController extends AppController { $A = new Account(); $charge_accounts = $A->invoiceAccounts(); $default_account = $A->rentAccountID(); - $this->set(compact('charge_accounts', 'default_account')); + $rent_account = $A->rentAccountID(); + $security_deposit_account = $A->securityDepositAccountID(); + $this->set(compact('charge_accounts', 'default_account', + 'rent_account', 'security_deposit_account')); // REVISIT 20090705: // Of course, the late charge should come from the late_schedule - $default_rent = $lease['Lease']['rent']; $default_late = 10; - $this->set(compact('default_rent', 'default_late')); + $this->set(compact('default_late')); + + if ($type === 'move-in') { + $movein = array(); + $movein['time'] = strtotime($lease['Lease']['movein_date']); + $movein['effective_time'] = strtotime($lease['Lease']['movein_date']); + $movein_date = getdate($movein['effective_time']); + $movein['through_time'] = mktime(0, 0, 0, $movein_date['mon'] + 1, 0, $movein_date['year']); + $days_in_month = idate('d', $movein['through_time']); + $movein['prorated_days'] = $days_in_month - $movein_date['mday'] + 1; + $movein['prorated_rent'] = $lease['Lease']['rent'] * $movein['prorated_days'] / $days_in_month; + $movein['prorated'] = $movein['prorated_days'] != $days_in_month; + $movein['deposit'] = $lease['Lease']['deposit']; + $this->set(compact('movein')); + } + $title = ('Lease #' . $lease['Lease']['number'] . ': ' . $lease['Unit']['name'] . ': ' . diff --git a/controllers/units_controller.php b/controllers/units_controller.php index 699d23a..5b452d7 100644 --- a/controllers/units_controller.php +++ b/controllers/units_controller.php @@ -245,10 +245,12 @@ class UnitsController extends AppController { $this->sidemenu_links[] = array('name' => 'Move-Out', 'url' => array('action' => 'move_out', $id)); - } else { + } elseif ($this->Unit->available($unit['Unit']['status'])) { $this->sidemenu_links[] = array('name' => 'Move-In', 'url' => array('action' => 'move_in', $id)); + } else { + // Unit is unavailable (dirty, damaged, reserved, business-use, etc) } if (isset($unit['CurrentLease']['id']) && diff --git a/models/statement_entry.php b/models/statement_entry.php index c8bad09..22aeb4f 100644 --- a/models/statement_entry.php +++ b/models/statement_entry.php @@ -656,7 +656,7 @@ class StatementEntry extends AppModel { * - Returns summary data from the requested statement entry */ function stats($id = null, $query = null) { - $this->prFunctionLevel(array('log' => 19, 'show' => 10)); + //$this->prFunctionLevel(array('log' => 19, 'show' => 10)); $this->prEnter(compact('id', 'query')); $this->queryInit($query); diff --git a/models/transaction.php b/models/transaction.php index 4e4de98..c58f4b1 100644 --- a/models/transaction.php +++ b/models/transaction.php @@ -475,6 +475,10 @@ class Transaction extends AppModel { // accidentally pick up stale data. $le1 = $le1_tender = $le2 = $se = null; + // Really, data should be sanitized at the controller, + // and not here. However, it's a one stop cleanup. + $entry['amount'] = str_replace('$', '', $entry['amount']); + // Add entry amount into the transaction total $transaction['amount'] += $entry['amount']; diff --git a/models/unit.php b/models/unit.php index 9e2396b..bd42691 100644 --- a/models/unit.php +++ b/models/unit.php @@ -55,10 +55,50 @@ class Unit extends AppModel { return $this->statusValue('OCCUPIED'); } + function statusCheck($id_or_enum, + $min = null, $min_strict = false, + $max = null, $max_strict = false) + { + $this->prEnter(compact('id_or_enum', 'min', 'min_strict', 'max', 'max_strict')); + + if (is_int($id_or_enum)) { + $this->id = $id_or_enum; + $id_or_enum = $this->field('status'); + } + + $enum_val = $this->statusValue($id_or_enum); + if (isset($min) && is_string($min)) + $min = $this->statusValue($min); + if (isset($max) && is_string($max)) + $max = $this->statusValue($max); + + $this->pr(17, compact('enum_val', 'min', 'min_strict', 'max', 'max_strict')); + + if (isset($min) && + ($enum_val < $min || + ($min_strict && $enum_val == $min))) + return $this->prReturn(false); + + if (isset($max) && + ($enum_val > $max || + ($max_strict && $enum_val == $max))) + return $this->prReturn(false); + + return $this->prReturn(true); + } + + function occupied($enum) { + return $this->statusCheck($enum, 'OCCUPIED', false, null, false); + } + function conditionOccupied() { return ('Unit.status >= ' . $this->statusValue('OCCUPIED')); } + function vacant($enum) { + return $this->statusCheck($enum, 'UNAVAILABLE', true, 'OCCUPIED', true); + } + function conditionVacant() { return ('Unit.status BETWEEN ' . ($this->statusValue('UNAVAILABLE')+1) . @@ -66,10 +106,16 @@ class Unit extends AppModel { ($this->statusValue('OCCUPIED')-1)); } + function unavailable($enum) { + return $this->statusCheck($enum, null, false, 'UNAVAILABLE', false); + } + function conditionUnavailable() { return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE')); } + function available($enum) { return $this->vacant($enum); } + /************************************************************************** ************************************************************************** diff --git a/views/elements/form_table.ctp b/views/elements/form_table.ctp index 8a9b5fa..7394f83 100644 --- a/views/elements/form_table.ctp +++ b/views/elements/form_table.ctp @@ -123,7 +123,7 @@ foreach ($fields AS $field => $config) { } echo $this->element('table', - compact('class', 'caption', 'headers', + compact('id', 'class', 'caption', 'headers', 'rows', 'row_class', 'suppress_alternate_rows', 'column_class') ); diff --git a/views/elements/table.ctp b/views/elements/table.ctp index 7f2433f..aef240a 100644 --- a/views/elements/table.ctp +++ b/views/elements/table.ctp @@ -64,7 +64,10 @@ if (isset($rows) && is_array($rows) && count($rows)) { $class = implode(' ', $class); // OK, output the table HTML - echo('' . "\n"); + echo('' . "\n"); if (isset($caption)) echo(' ' . $caption . '' . "\n"); diff --git a/views/elements/units.ctp b/views/elements/units.ctp index cd1c523..b5b5220 100644 --- a/views/elements/units.ctp +++ b/views/elements/units.ctp @@ -8,6 +8,7 @@ $cols['ID'] = array('index' => 'Unit.id', 'formatter' => 'id'); $cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'shortname'); $cols['Size'] = array('index' => 'UnitSize.name', 'formatter' => 'shortname'); $cols['Rent'] = array('index' => 'Unit.rent', 'formatter' => 'currency'); +$cols['Deposit'] = array('index' => 'Unit.deposit', 'formatter' => 'currency'); $cols['Status'] = array('index' => 'Unit.status', 'formatter' => 'name'); // We have enough real estate $cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency'); $cols['Comment'] = array('index' => 'Unit.comment', 'formatter' => 'comment'); @@ -19,4 +20,4 @@ $grid ->defaultFields(array('Sort', 'ID', 'Unit')) ->searchFields(array('Unit', 'Size', 'Status')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array('Walk', 'Comment'))); + array_diff(array_keys($cols), array('Walk', 'Deposit', 'Comment'))); diff --git a/views/leases/invoice.ctp b/views/leases/invoice.ctp index 0e530d6..fd74ac2 100644 --- a/views/leases/invoice.ctp +++ b/views/leases/invoice.ctp @@ -4,6 +4,13 @@ element('leases', array ('config' => array @@ -205,7 +286,7 @@ echo $this->element('leases', array 'grid_div_class' => 'text-below', 'caption' => ('Select Lease'), - 'grid_setup' => array('hiddengrid' => isset($lease['Lease']['id'])), + 'grid_setup' => array('hiddengrid' => isset($lease['id'])), 'grid_events' => array('onSelectRow' => array('ids' => 'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'), @@ -285,7 +366,17 @@ echo $form->submit('Generate Invoice') . "\n";

Response

Output

+ +