Making progress. Much still to do, but there are hints of functionality finally returning so I'm snapshotting.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@360 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
148
models/lease.php
148
models/lease.php
@@ -9,7 +9,7 @@ class Lease extends AppModel {
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'DoubleEntry',
|
||||
'StatementEntry',
|
||||
);
|
||||
|
||||
|
||||
@@ -22,21 +22,19 @@ class Lease extends AppModel {
|
||||
function securityDeposits($id, $query = null) {
|
||||
$this->queryInit($query);
|
||||
|
||||
$this->id = $id;
|
||||
$this->recursive = -1;
|
||||
$this->read();
|
||||
$A = new Account();
|
||||
|
||||
if (!isset($query['link']['DoubleEntry']))
|
||||
$query['link']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Lease']))
|
||||
$query['link']['DoubleEntry']['Lease'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Lease']['fields']))
|
||||
$query['link']['DoubleEntry']['Lease']['fields'] = array();
|
||||
if (!isset($query['link']['Lease']))
|
||||
$query['link']['Lease'] = array();
|
||||
if (!isset($query['link']['Lease']['fields']))
|
||||
$query['link']['Lease']['fields'] = array();
|
||||
|
||||
$query['conditions'][] = array('Lease.id' => $id);
|
||||
$query['conditions'][] = array('StatementEntry.account_id' => $A->securityDepositAccountID());
|
||||
|
||||
return $this->Customer->securityDeposits
|
||||
($this->data['Lease']['customer_id'], $query);
|
||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query);
|
||||
//pr(compact('set'));
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,40 +50,28 @@ class Lease extends AppModel {
|
||||
*/
|
||||
|
||||
function rentLastCharges($id) {
|
||||
$rent_account_id = $this->DoubleEntry->Entry->Account->rentAccountID();
|
||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||
$entries = $this->find
|
||||
('all',
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'DoubleEntry' =>
|
||||
array('Entry'// =>
|
||||
//array('fields'),
|
||||
),
|
||||
'StatementEntry' => array(),
|
||||
|
||||
'DEx' =>
|
||||
array('class' => 'DoubleEntry',
|
||||
'SEx' =>
|
||||
array('class' => 'StatementEntry',
|
||||
'conditions' => array
|
||||
('DEx.effective_date = DATE_ADD(Entry.through_date, INTERVAL 1 day)',
|
||||
'DEx.lease_id = DoubleEntry.lease_id',
|
||||
('SEx.effective_date = DATE_ADD(StatementEntry.through_date, INTERVAL 1 day)',
|
||||
'SEx.lease_id = StatementEntry.lease_id',
|
||||
),
|
||||
|
||||
'Ex' =>
|
||||
array('class' => 'Entry',
|
||||
'type' => 'INNER',
|
||||
'conditions' => array
|
||||
('Ex.account_id = Entry.account_id',
|
||||
'Ex.type = Entry.type',
|
||||
'Ex.crdr = Entry.crdr'),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//'fields' => array('id', 'amount', 'effective_date', 'through_date'),
|
||||
'fields' => array(),
|
||||
'conditions' => array(array('Lease.id' => $id),
|
||||
array('Entry.type' => 'CHARGE'),
|
||||
array('Entry.account_id' => $rent_account_id),
|
||||
array('DEx.id' => null),
|
||||
array('StatementEntry.type' => 'CHARGE'),
|
||||
array('StatementEntry.account_id' => $rent_account_id),
|
||||
array('SEx.id' => null),
|
||||
),
|
||||
)
|
||||
);
|
||||
@@ -125,7 +111,7 @@ class Lease extends AppModel {
|
||||
return false;
|
||||
if (count($entries) != 1)
|
||||
return null;
|
||||
return $entries[0]['DoubleEntry']['through_date'];
|
||||
return $entries[0]['StatementEntry']['through_date'];
|
||||
}
|
||||
|
||||
|
||||
@@ -137,76 +123,77 @@ class Lease extends AppModel {
|
||||
*/
|
||||
|
||||
function rentPaidThrough($id) {
|
||||
$rent_account_id = $this->DoubleEntry->Entry->Account->rentAccountID();
|
||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||
|
||||
$rent = $this->DoubleEntry->Entry->reconciledSet
|
||||
$rent = $this->StatementEntry->reconciledSet
|
||||
('CHARGE',
|
||||
array('fields' =>
|
||||
array('DATE_SUB(DoubleEntry.effective_date, INTERVAL 1 DAY) AS paid_through',
|
||||
array('StatementEntry.*',
|
||||
'DATE_SUB(StatementEntry.effective_date, INTERVAL 1 DAY) AS paid_through',
|
||||
),
|
||||
'conditions' =>
|
||||
array(array('DoubleEntry.lease_id' => $id),
|
||||
array('Entry.account_id' => $rent_account_id)),
|
||||
array(array('StatementEntry.lease_id' => $id),
|
||||
array('StatementEntry.account_id' => $rent_account_id)),
|
||||
|
||||
'order' => array('DoubleEntry.effective_date'),
|
||||
'order' => array('StatementEntry.effective_date'),
|
||||
),
|
||||
true);
|
||||
|
||||
/* $query = array */
|
||||
/* ('link' => */
|
||||
/* array(// Models */
|
||||
/* 'DoubleEntry' => */
|
||||
/* 'StatementEntry' => */
|
||||
/* array('Entry' => */
|
||||
/* array(), */
|
||||
/* 'fields' => array('SUM(COALESCE(MoneyDoubleEntryR.amount,0)) AS paid'), */
|
||||
/* 'fields' => array('SUM(COALESCE(MoneyStatementEntryR.amount,0)) AS paid'), */
|
||||
/* ), */
|
||||
/* ), */
|
||||
|
||||
/* // Finally, the Money (Cash/Check/etc) Entry is the one */
|
||||
/* // which reconciles our ReceiptDoubleEntry debit */
|
||||
/* 'DebitReconciliationDoubleEntry' => */
|
||||
/* array('alias' => 'MoneyDoubleEntry', */
|
||||
/* 'linkalias' => 'MoneyDoubleEntryR', */
|
||||
/* // which reconciles our ReceiptStatementEntry debit */
|
||||
/* 'DebitReconciliationStatementEntry' => */
|
||||
/* array('alias' => 'MoneyStatementEntry', */
|
||||
/* 'linkalias' => 'MoneyStatementEntryR', */
|
||||
/* ), */
|
||||
/* ), */
|
||||
/* ), */
|
||||
|
||||
/* 'fields' => array('DoubleEntry.amount', */
|
||||
/* 'DATE_SUB(DoubleEntry.effective_date, INTERVAL 1 DAY) AS paid_through', */
|
||||
/* 'fields' => array('StatementEntry.amount', */
|
||||
/* 'DATE_SUB(StatementEntry.effective_date, INTERVAL 1 DAY) AS paid_through', */
|
||||
/* ), */
|
||||
|
||||
/* 'group' => 'DoubleEntry.id HAVING paid <> DoubleEntry.amount', */
|
||||
/* 'group' => 'StatementEntry.id HAVING paid <> StatementEntry.amount', */
|
||||
|
||||
/* 'conditions' => array(array('DoubleEntry.lease_id' => $id), */
|
||||
/* array('Account.id' => $this->DoubleEntry->Ledger->Account->rentAccountID()), */
|
||||
/* 'conditions' => array(array('StatementEntry.lease_id' => $id), */
|
||||
/* array('Account.id' => $this->StatementEntry->Ledger->Account->rentAccountID()), */
|
||||
/* ), */
|
||||
/* 'order' => array('DoubleEntry.effective_date', */
|
||||
/* 'order' => array('StatementEntry.effective_date', */
|
||||
/* ), */
|
||||
/* ); */
|
||||
|
||||
/* $rent = $this->DoubleEntry->find('first', $query); */
|
||||
/* $rent = $this->StatementEntry->find('first', $query); */
|
||||
//pr($rent);
|
||||
if ($rent['entries'])
|
||||
return $rent['entries'][0]['DoubleEntry']['paid_through'];
|
||||
return $rent['entries'][0]['StatementEntry']['paid_through'];
|
||||
|
||||
$rent = $this->DoubleEntry->Entry->reconciledSet
|
||||
$rent = $this->StatementEntry->reconciledSet
|
||||
('CHARGE',
|
||||
array('conditions' =>
|
||||
array(array('DoubleEntry.lease_id' => $id),
|
||||
array('Entry.account_id' => $rent_account_id)),
|
||||
array(array('StatementEntry.lease_id' => $id),
|
||||
array('StatementEntry.account_id' => $rent_account_id)),
|
||||
|
||||
'order' => array('Entry.through_date DESC'),
|
||||
),
|
||||
false);
|
||||
if ($rent)
|
||||
return $rent[0]['Entry']['through_date'];
|
||||
return $rent[0]['StatementEntry']['through_date'];
|
||||
|
||||
/* $query['fields'] = 'Entry.through_date'; */
|
||||
/* $query['order'] = 'Entry.through_date DESC'; */
|
||||
/* $query['group'] = 'DoubleEntry.id'; */
|
||||
/* $rent = $this->DoubleEntry->find('first', $query); */
|
||||
/* $query['group'] = 'StatementEntry.id'; */
|
||||
/* $rent = $this->StatementEntry->find('first', $query); */
|
||||
/* if ($rent) */
|
||||
/* return $rent['DoubleEntry']['through_date']; */
|
||||
/* return $rent['StatementEntry']['through_date']; */
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -416,43 +403,28 @@ class Lease extends AppModel {
|
||||
$this->queryInit($query);
|
||||
|
||||
//$query['link'] = array('Lease' => $query['link']);
|
||||
if (!isset($query['link']['DoubleEntry']))
|
||||
$query['link']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['Charge']))
|
||||
$query['link']['Charge'] = array();
|
||||
if (!isset($query['link']['Charge']['DoubleEntry']))
|
||||
$query['link']['Charge']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['Charge']['DoubleEntry']['Invoice']))
|
||||
$query['link']['Charge']['DoubleEntry']['Invoice'] = array();
|
||||
if (!isset($query['link']['Charge']['Account']))
|
||||
$query['link']['Charge']['Account'] = array();
|
||||
/* if (!isset($query['link']['StatementEntry'])) */
|
||||
/* $query['link']['StatementEntry'] = array(); */
|
||||
/* if (!isset($query['link']['StatementEntry']['ChargeEntry'])) */
|
||||
/* $query['link']['StatementEntry']['ChargeEntry'] = array(); */
|
||||
|
||||
/* $query['link']['DoubleEntry']['fields'] = array(); */
|
||||
/* $query['link']['Charge']['fields'] = array(); */
|
||||
/* $query['link']['Charge']['Account']['fields'] = array(); */
|
||||
/* $query['link']['Charge']['DoubleEntry']['fields'] = array(); */
|
||||
/* $query['link']['Charge']['DoubleEntry']['Invoice']['fields'] = array(); */
|
||||
|
||||
$query['link']['Charge']['Account']['alias'] = 'ChargeAccount';
|
||||
$query['link']['Charge']['DoubleEntry']['alias'] = 'ChargeDoubleEntry';
|
||||
/* $query['link']['StatementEntry']['fields'] = array(); */
|
||||
/* $query['link']['ChargeEntry']['fields'] = array(); */
|
||||
/* $query['link']['ChargeEntry']['Account']['fields'] = array(); */
|
||||
/* $query['link']['ChargeEntry']['StatementEntry']['fields'] = array(); */
|
||||
/* $query['link']['ChargeEntry']['StatementEntry']['Invoice']['fields'] = array(); */
|
||||
|
||||
if (!isset($query['fields']))
|
||||
$query['fields'] = array();
|
||||
|
||||
$query['fields'] = array_merge($query['fields'],
|
||||
$this->DoubleEntry->Entry->chargePaymentFields(false));
|
||||
$this->StatementEntry->chargePaymentFields(true));
|
||||
|
||||
$query['conditions'][] = array('OR' =>
|
||||
array(array(array('Entry.type' => 'CHARGE'),
|
||||
array('DoubleEntry.lease_id' => $id)),
|
||||
array(array('Entry.type' => 'PAYMENT'),
|
||||
array('ChargeDoubleEntry.lease_id' => $id)),
|
||||
),
|
||||
);
|
||||
$query['conditions'][] = array('StatementEntry.lease_id' => $id);
|
||||
|
||||
$query['group'] = null;
|
||||
|
||||
$stats = $this->DoubleEntry->Entry->find('all', $query);
|
||||
$stats = $this->StatementEntry->find('first', $query);
|
||||
pr(compact('query', 'stats'));
|
||||
|
||||
// The fields are all tucked into the [0] index,
|
||||
|
||||
Reference in New Issue
Block a user