|
|
|
|
@@ -223,30 +223,105 @@ class Lease extends AppModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* /\************************************************************************** */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* * function: rentPaidThrough */
|
|
|
|
|
/* * - Determines the date that rent has been paid through */
|
|
|
|
|
/* * Returns one of: */
|
|
|
|
|
/* * null: There are gaps in the charges */
|
|
|
|
|
/* * false: There are not yet any charges */
|
|
|
|
|
/* * date: The date rent has been paid through */
|
|
|
|
|
/* *\/ */
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
**************************************************************************
|
|
|
|
|
**************************************************************************
|
|
|
|
|
* function: rentPaidThrough
|
|
|
|
|
* - Determines the date of the first unpaid rent
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* function rentPaidThrough($id) { */
|
|
|
|
|
/* if ($this->rentChargeGaps($id)) */
|
|
|
|
|
/* return null; */
|
|
|
|
|
function rentPaidThrough($id) {
|
|
|
|
|
|
|
|
|
|
/* $A = new Account(); */
|
|
|
|
|
/* $unrec_entries = $A->findUnreconciledLedgerEntries */
|
|
|
|
|
/* ($A->rentAccountID(), 'INCOME', array('LedgerEntry.lease_id' => $id)); */
|
|
|
|
|
// Income / Receipt / Money
|
|
|
|
|
// debit: A/R credit: Income <-- this entry
|
|
|
|
|
// debit: Receipt credit: A/R <-- ReceiptLedgerEntry, below
|
|
|
|
|
// debit: Money credit: Receipt <-- MoneyLedgerEntry, below
|
|
|
|
|
|
|
|
|
|
/* $unrec_ids */
|
|
|
|
|
/* = array_map(create_function('$data', */
|
|
|
|
|
/* 'return $data["id"];'), */
|
|
|
|
|
/* $unrec_entries); */
|
|
|
|
|
/* } */
|
|
|
|
|
$query = array
|
|
|
|
|
('link' => array
|
|
|
|
|
(
|
|
|
|
|
'CreditLedger' =>
|
|
|
|
|
array('fields' => array(),
|
|
|
|
|
'Account' =>
|
|
|
|
|
array('fields' => array(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// We're searching for the Receipt<->A/R entries,
|
|
|
|
|
// which are debits on the A/R account. Find the
|
|
|
|
|
// reconciling entries to that A/R debit.
|
|
|
|
|
'DebitReconciliationLedgerEntry' =>
|
|
|
|
|
array('alias' => 'ReceiptLedgerEntry',
|
|
|
|
|
'fields' => array(),
|
|
|
|
|
|
|
|
|
|
/* 'Transaction' => */
|
|
|
|
|
/* array('alias' => 'ReceiptTransaction', */
|
|
|
|
|
/* 'fields' => array(), */
|
|
|
|
|
/* ), */
|
|
|
|
|
|
|
|
|
|
// Credit Ledger should be A/R;
|
|
|
|
|
// Debit Ledger should be Receipt
|
|
|
|
|
/* 'DebitLedger' => */
|
|
|
|
|
/* array('alias' => 'ReceiptLedger', */
|
|
|
|
|
/* 'fields' => array(), */
|
|
|
|
|
/* 'Account' => array('alias' => 'ReceiptAccount' */
|
|
|
|
|
/* 'fields' => array(), */
|
|
|
|
|
/* ), */
|
|
|
|
|
/* ), */
|
|
|
|
|
|
|
|
|
|
// Finally, the Money (Cash/Check/etc) Entry is the one
|
|
|
|
|
// which reconciles our ReceiptLedgerEntry debit
|
|
|
|
|
'DebitReconciliationLedgerEntry' =>
|
|
|
|
|
array('alias' => 'MoneyLedgerEntry',
|
|
|
|
|
'linkalias' => 'MoneyLedgerEntryR',
|
|
|
|
|
'fields' => array('SUM(COALESCE(MoneyLedgerEntryR.amount,0)) AS paid'),
|
|
|
|
|
//'fields' => array('MoneyLedgerEntryR.amount AS paid'),
|
|
|
|
|
|
|
|
|
|
/* // Credit Ledger should be Receipt; */
|
|
|
|
|
/* // Debit Ledger should be our Money Account */
|
|
|
|
|
/* 'DebitLedger' => */
|
|
|
|
|
/* array('alias' => 'MoneyLedger', */
|
|
|
|
|
/* 'fields' => array(), */
|
|
|
|
|
|
|
|
|
|
/* 'Account' => */
|
|
|
|
|
/* array('alias' => 'MoneyAccount', */
|
|
|
|
|
/* 'fields' => array(), */
|
|
|
|
|
/* ), */
|
|
|
|
|
/* ), */
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
//'fields' => array('LedgerEntry.*, MoneyLedgerEntryR.*'),
|
|
|
|
|
//'MAX(ReceiptTransaction.stamp) AS last_paid';
|
|
|
|
|
|
|
|
|
|
'fields' => array('LedgerEntry.amount',
|
|
|
|
|
'DATE_SUB(LedgerEntry.effective_date, INTERVAL 1 DAY) AS paid_through',
|
|
|
|
|
),
|
|
|
|
|
// 'group' => 'LedgerEntry.id',
|
|
|
|
|
'group' => 'LedgerEntry.id HAVING paid <> LedgerEntry.amount',
|
|
|
|
|
'conditions' => array(array('LedgerEntry.lease_id' => $id),
|
|
|
|
|
array('Account.id' => $this->LedgerEntry->Ledger->Account->rentAccountID()),
|
|
|
|
|
//array('paid =' => 'LedgerEntry.amount'),
|
|
|
|
|
//array('NOT' => array(array('MoneyLedgerEntry.id' => null))),
|
|
|
|
|
),
|
|
|
|
|
'order' => array('LedgerEntry.effective_date',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$rent = $this->LedgerEntry->find('first', $query);
|
|
|
|
|
if ($rent)
|
|
|
|
|
return $rent[0]['paid_through'];
|
|
|
|
|
|
|
|
|
|
$query['fields'] = 'LedgerEntry.through_date';
|
|
|
|
|
$query['order'] = 'LedgerEntry.through_date DESC';
|
|
|
|
|
$query['group'] = 'LedgerEntry.id';
|
|
|
|
|
$rent = $this->LedgerEntry->find('first', $query);
|
|
|
|
|
if ($rent)
|
|
|
|
|
return $rent['LedgerEntry']['through_date'];
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
|