array('numeric'), 'number' => array('alphanumeric'), 'lease_type_id' => array('numeric'), 'unit_id' => array('numeric'), 'late_schedule_id' => array('numeric'), 'lease_date' => array('date'), 'movein_planned_date' => array('date'), 'movein_date' => array('date'), 'moveout_date' => array('date'), 'moveout_planned_date' => array('date'), 'notice_given_date' => array('date'), 'notice_received_date' => array('date'), 'close_date' => array('date'), 'deposit' => array('money'), 'amount' => array('money'), 'next_amount' => array('money'), 'next_amount_date' => array('date') ); var $belongsTo = array( 'LeaseType', 'Unit', 'Customer', 'LateSchedule', ); var $hasMany = array( 'LedgerEntry', ); /************************************************************************** ************************************************************************** ************************************************************************** * function: accountId * - Returns the accountId of the given lease */ function accountId($id) { $A = new Account(); return $A->invoiceAccountID(); } /************************************************************************** ************************************************************************** ************************************************************************** * function: findAccountEntries * - Returns an array of ledger entries from the account of the given * lease. */ function findAccountEntries($id, $all = false, $cond = null, $link = null) { /* pr(array('function' => 'Lease::findAccountEntries', */ /* 'args' => compact('id', 'all', 'cond', 'link'), */ /* )); */ if (!isset($cond)) $cond = array(); $cond[] = array('LedgerEntry.lease_id' => $id); $A = new Account(); $entries = $A->findLedgerEntries($this->accountId($id), $all, $cond, $link); /* pr(array('function' => 'Lease::findAccountEntries', */ /* 'args' => compact('id', 'all', 'cond', 'link'), */ /* 'vars' => compact('lease'), */ /* 'return' => compact('entries'), */ /* )); */ return $entries; } /************************************************************************** ************************************************************************** ************************************************************************** * function: findSecurityDeposits * - Returns an array of security deposit entries */ function findSecurityDeposits($id, $link = null) { /* pr(array('function' => 'Lease::findSecurityDeposits', */ /* 'args' => compact('id', 'link'), */ /* )); */ $A = new Account(); $entries = $A->findLedgerEntriesRelatedToAccount ($this->accountId($id), $A->securityDepositAccountID(), true, array('LedgerEntry.lease_id' => $id), $link); /* pr(array('function' => 'Lease::findSecurityDeposits', */ /* 'args' => compact('id', 'link'), */ /* 'vars' => compact('lease'), */ /* 'return' => compact('entries'), */ /* )); */ return $entries; } /************************************************************************** ************************************************************************** ************************************************************************** * function: findUnreconciledLedgerEntries * - Returns ledger entries that are not yet reconciled * (such as charges not paid). */ function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) { $A = new Account(); return $A->findUnreconciledLedgerEntries ($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id)); } /************************************************************************** ************************************************************************** ************************************************************************** * function: reconcileNewLedgerEntry * - Returns which ledger entries a new credit/debit would * reconcile, and how much. * * - REVISIT 20090617 * This should be subject to different algorithms, such * as apply to oldest charges first, newest first, to fees * before rent, etc. Until we get there, I'll hardcode * whatever algorithm is simplest. */ function reconcileNewLedgerEntry($id, $fundamental_type, $amount) { $A = new Account(); return $A->reconcileNewLedgerEntry ($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id)); } /************************************************************************** ************************************************************************** ************************************************************************** * function: moveOut * - Moves the customer out of the specified lease */ function moveOut($id = null, $status = 'VACANT', $stamp = null, $close = false) { $this->create(false); $this->id = $id; // Use NOW if not given a moveout date if (!isset($stamp)) $stamp = date('Y-m-d G:i:s'); // Move customer out of the lease, and possibly close it $this->data['Lease']['moveout_date'] = $stamp; if ($close) $this->data['Lease']['close_date'] = $stamp; // Save it! $this->save($this->data, false); // Finally, update the unit status $this->recursive = -1; $this->read(); $this->Unit->updateStatus($this->data['Lease']['unit_id'], $status); } /************************************************************************** ************************************************************************** ************************************************************************** * function: stats * - Returns summary data from the requested lease. */ function stats($id = null) { if (!$id) return null; $A = new Account(); $stats = $A->stats($A->accountReceivableAccountID(), true, array('LedgerEntry.lease_id' => $id)); // Pull to the top level and return $stats = $stats['Ledger']; return $stats; } } ?>