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:
abijah
2009-07-15 09:18:56 +00:00
parent 405e20f37f
commit 0c8649d1c5
4 changed files with 106 additions and 21 deletions

View File

@@ -441,6 +441,9 @@ class LeasesController extends AppController {
)
);
$lease['Lease']['paid_through'] = $this->Lease->rentPaidThrough($id);
$this->set('charge_gaps', $this->Lease->rentChargeGaps($id));
$this->set('charge_through', $this->Lease->rentChargeThrough($id));

View File

@@ -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;
}
/**************************************************************************

View File

@@ -45,6 +45,12 @@ $cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'form
if (!isset($group_by_tx))
$group_by_tx = false;
// REVISIT <AP>: 20090715
// If we really want to group by transaction, we need
// a transaction listing, not a ledger_entry listing.
// switch controllers... don't overload this one.
$group_by_tx = false;
if (isset($transaction_id) || isset($reconcile_id))
$grid->invalidFields('Transaction');

View File

@@ -37,6 +37,7 @@ $rows = array(array('ID', $lease['id']),
array('Closed', FormatHelper::date($lease['close_date'], true)),
array('Deposit', FormatHelper::currency($lease['deposit'])),
array('Rent', FormatHelper::currency($lease['rent'])),
array('Paid Through', FormatHelper::date($lease['paid_through'], true)),
array('Comment', $lease['comment']));