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/site@343 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -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_gaps', $this->Lease->rentChargeGaps($id));
|
||||||
$this->set('charge_through', $this->Lease->rentChargeThrough($id));
|
$this->set('charge_through', $this->Lease->rentChargeThrough($id));
|
||||||
|
|
||||||
|
|||||||
117
models/lease.php
117
models/lease.php
@@ -223,30 +223,105 @@ class Lease extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* /\************************************************************************** */
|
/**************************************************************************
|
||||||
/* ************************************************************************** */
|
**************************************************************************
|
||||||
/* ************************************************************************** */
|
**************************************************************************
|
||||||
/* * function: rentPaidThrough */
|
* function: rentPaidThrough
|
||||||
/* * - Determines the date that rent has been paid through */
|
* - Determines the date of the first unpaid rent
|
||||||
/* * 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($id) { */
|
function rentPaidThrough($id) {
|
||||||
/* if ($this->rentChargeGaps($id)) */
|
|
||||||
/* return null; */
|
|
||||||
|
|
||||||
/* $A = new Account(); */
|
// Income / Receipt / Money
|
||||||
/* $unrec_entries = $A->findUnreconciledLedgerEntries */
|
// debit: A/R credit: Income <-- this entry
|
||||||
/* ($A->rentAccountID(), 'INCOME', array('LedgerEntry.lease_id' => $id)); */
|
// debit: Receipt credit: A/R <-- ReceiptLedgerEntry, below
|
||||||
|
// debit: Money credit: Receipt <-- MoneyLedgerEntry, below
|
||||||
|
|
||||||
/* $unrec_ids */
|
$query = array
|
||||||
/* = array_map(create_function('$data', */
|
('link' => array
|
||||||
/* 'return $data["id"];'), */
|
(
|
||||||
/* $unrec_entries); */
|
'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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ $cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'form
|
|||||||
if (!isset($group_by_tx))
|
if (!isset($group_by_tx))
|
||||||
$group_by_tx = false;
|
$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))
|
if (isset($transaction_id) || isset($reconcile_id))
|
||||||
$grid->invalidFields('Transaction');
|
$grid->invalidFields('Transaction');
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ $rows = array(array('ID', $lease['id']),
|
|||||||
array('Closed', FormatHelper::date($lease['close_date'], true)),
|
array('Closed', FormatHelper::date($lease['close_date'], true)),
|
||||||
array('Deposit', FormatHelper::currency($lease['deposit'])),
|
array('Deposit', FormatHelper::currency($lease['deposit'])),
|
||||||
array('Rent', FormatHelper::currency($lease['rent'])),
|
array('Rent', FormatHelper::currency($lease['rent'])),
|
||||||
|
array('Paid Through', FormatHelper::date($lease['paid_through'], true)),
|
||||||
array('Comment', $lease['comment']));
|
array('Comment', $lease['comment']));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user