Added a paid-through field for leases. Now I just need to add it to the grid query, although it's a change that can wait.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@343 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user