Initial work to determine whether or not a lease has charge gaps, and when the lease has been charged through.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@286 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -306,6 +306,9 @@ class LeasesController extends AppController {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->set('charge_gaps', $this->Lease->rentChargeGaps($id));
|
||||||
|
$this->set('charge_through', $this->Lease->rentChargeThrough($id));
|
||||||
|
|
||||||
// Obtain the overall lease balance
|
// Obtain the overall lease balance
|
||||||
$this->Lease->statsMerge($lease['Lease'],
|
$this->Lease->statsMerge($lease['Lease'],
|
||||||
array('stats' => $this->Lease->stats($id)));
|
array('stats' => $this->Lease->stats($id)));
|
||||||
|
|||||||
@@ -137,6 +137,93 @@ class Lease extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentLastCharges
|
||||||
|
* - Returns a list of rent charges from this lease that
|
||||||
|
* do not have sequential followup charges. Under normal
|
||||||
|
* circumstances, there would only be one entry, which is
|
||||||
|
* the most recent rent charge. However, it's possible
|
||||||
|
* that there are several, indicating a problem with lease.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentLastCharges($id) {
|
||||||
|
$A = new Account();
|
||||||
|
$entries = $this->find
|
||||||
|
('all',
|
||||||
|
array('link' =>
|
||||||
|
array(// Models
|
||||||
|
'LedgerEntry' => array
|
||||||
|
('Ledger' => array
|
||||||
|
('fields' => array(),
|
||||||
|
'Account' => array
|
||||||
|
('fields' => array(),
|
||||||
|
'Ledger' => array
|
||||||
|
('alias' => 'Lx',
|
||||||
|
'fields' => array(),
|
||||||
|
'LedgerEntry' => array
|
||||||
|
('alias' => 'LEx',
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array
|
||||||
|
('LEx.effective_date = DATE_ADD(LedgerEntry.through_date, INTERVAL 1 day)',
|
||||||
|
'LEx.lease_id = LedgerEntry.lease_id',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
//'fields' => array('id', 'amount', 'effective_date', 'through_date'),
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Account.id' => $A->rentAccountID()),
|
||||||
|
array('LEx.id' => null),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentChargeGaps
|
||||||
|
* - Checks for gaps in rent charges
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentChargeGaps($id) {
|
||||||
|
$entries = $this->rentLastCharges($id);
|
||||||
|
if ($entries && count($entries) > 1)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentChargeThrough
|
||||||
|
* - Determines the date that rent has been charged through
|
||||||
|
* Returns one of:
|
||||||
|
* null: There are gaps in the charges
|
||||||
|
* false: There are not yet any charges
|
||||||
|
* date: The date rent has been charged through
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentChargeThrough($id) {
|
||||||
|
$entries = $this->rentLastCharges($id);
|
||||||
|
if (!$entries)
|
||||||
|
return false;
|
||||||
|
if (count($entries) != 1)
|
||||||
|
return null;
|
||||||
|
return $entries[0]['LedgerEntry']['through_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user