Nowhere near done yet, but checking in a snapshot of semi-working code. There is some simultaneous support for both with and without use of the Invoice/Receipt account. I want to do away with them completely, but will need to change how sitelink payments are mapped (right now, they split a payment into multiple parts to match the charge).
git-svn-id: file:///svn-source/pmgr/branches/single_AR_20090622/site@181 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -8,7 +8,6 @@ class Customer extends AppModel {
|
||||
);
|
||||
|
||||
var $belongsTo = array(
|
||||
'Account',
|
||||
'PrimaryContact' => array(
|
||||
'className' => 'Contact',
|
||||
),
|
||||
@@ -20,11 +19,19 @@ class Customer extends AppModel {
|
||||
'conditions' => 'CurrentLease.close_date IS NULL',
|
||||
),
|
||||
'Lease',
|
||||
'Transaction',
|
||||
'LedgerEntry',
|
||||
|
||||
// Cheat to get Account set as part of this class
|
||||
'Account',
|
||||
);
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Contact',
|
||||
'Transaction' => array(
|
||||
'joinTable' => 'ledger_entries',
|
||||
'foreignKey' => 'customer_id',
|
||||
'associationForeignKey' => 'transaction_id',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -80,16 +87,9 @@ class Customer extends AppModel {
|
||||
/* )); */
|
||||
|
||||
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
||||
($this->accountId($id),
|
||||
($this->Account->invoiceAccountID(),
|
||||
$this->Account->securityDepositAccountID(),
|
||||
true, null, $link);
|
||||
|
||||
foreach ($this->leaseIds($id) AS $lease_id) {
|
||||
$ledger_entries = $this->Lease->findSecurityDeposits($lease_id, $link);
|
||||
$this->statsMerge($entries['summary'], $ledger_entries['summary']);
|
||||
$entries['Entries'] = array_merge($entries['Entries'],
|
||||
$ledger_entries['Entries']);
|
||||
}
|
||||
true, array('LedgerEntry.customer_id' => $id), $link);
|
||||
|
||||
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
||||
/* 'args' => compact('id', 'link'), */
|
||||
@@ -110,22 +110,10 @@ class Customer extends AppModel {
|
||||
*/
|
||||
|
||||
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||
|
||||
$unreconciled = $this->Account->findUnreconciledLedgerEntries
|
||||
($this->accountId($id), $fundamental_type);
|
||||
|
||||
foreach ($this->leaseIds($id) AS $lease_id) {
|
||||
$unrec = $this->Lease->findUnreconciledLedgerEntries($lease_id,
|
||||
$fundamental_type);
|
||||
|
||||
foreach (array_keys($unreconciled) AS $type) {
|
||||
$left = &$unreconciled[$type];
|
||||
$right = &$unrec[$type];
|
||||
|
||||
$left['entry'] = array_merge($left['entry'], $right['entry']);
|
||||
$left['balance'] += $right['balance'];
|
||||
}
|
||||
}
|
||||
($this->Account->accountReceivableAccountID(),
|
||||
$fundamental_type,
|
||||
array('LedgerEntry.customer_id' => $id));
|
||||
|
||||
return $unreconciled;
|
||||
}
|
||||
@@ -146,25 +134,11 @@ class Customer extends AppModel {
|
||||
*/
|
||||
|
||||
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
||||
|
||||
$reconciled = $this->Account->reconcileNewLedgerEntry
|
||||
($this->accountId($id), $fundamental_type, $amount);
|
||||
|
||||
foreach ($this->leaseIds($id) AS $lease_id) {
|
||||
foreach (array_keys($reconciled) AS $type) {
|
||||
$rec = $this->Lease->reconcileNewLedgerEntry($lease_id,
|
||||
$fundamental_type,
|
||||
$reconciled[$type]['unapplied']);
|
||||
|
||||
$left = &$reconciled[$type];
|
||||
$right = &$rec[$type];
|
||||
|
||||
$left['entry'] = array_merge($left['entry'], $right['entry']);
|
||||
$left['balance'] += $right['balance'];
|
||||
$left['applied'] += $right['applied'];
|
||||
$left['unapplied'] = $right['unapplied'];
|
||||
}
|
||||
}
|
||||
($this->Account->accountReceivableAccountID(),
|
||||
$fundamental_type,
|
||||
$amount,
|
||||
array('LedgerEntry.customer_id' => $id));
|
||||
|
||||
return $reconciled;
|
||||
}
|
||||
@@ -189,7 +163,6 @@ class Customer extends AppModel {
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
),
|
||||
'Account',
|
||||
'Lease' =>
|
||||
array('Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
@@ -201,22 +174,12 @@ class Customer extends AppModel {
|
||||
'conditions' => array('Customer.id' => $id),
|
||||
));
|
||||
|
||||
// Add the lease balance to each lease.
|
||||
foreach ($customer['Lease'] AS &$lease) {
|
||||
$stats = $this->Lease->stats($lease['id']);
|
||||
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||
}
|
||||
|
||||
// Figure out the outstanding balance of the current lease.
|
||||
// Figure out the outstanding balance for this customer
|
||||
$customer['stats'] = $this->stats($id);
|
||||
|
||||
// Figure out the total security deposit for the current lease.
|
||||
$customer['deposits'] = $this->findSecurityDeposits($id);
|
||||
|
||||
// Add statistics into the customer account.
|
||||
$customer['Account'] = array_merge($customer['Account'],
|
||||
$customer['stats']['Account']['Ledger']);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
@@ -232,29 +195,11 @@ class Customer extends AppModel {
|
||||
if (!$id)
|
||||
return null;
|
||||
|
||||
// Get the basic information necessary
|
||||
$customer = $this->find('first',
|
||||
array('contain' =>
|
||||
array('Account' => array
|
||||
('fields' => array('Account.id')),
|
||||
|
||||
'Lease' => array
|
||||
('fields' => array('Lease.id'))
|
||||
),
|
||||
'conditions' => array
|
||||
(array('Customer.id' => $id))));
|
||||
|
||||
// Get stats from the customer account, and each lease
|
||||
$stats['Account'] = $this->Account->stats($customer['Account']['id']);
|
||||
foreach ($customer['Lease'] AS $lease) {
|
||||
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
|
||||
}
|
||||
|
||||
// Merge the stats from both the customer specific account, as
|
||||
// well as the leases. This will provide current customer standing.
|
||||
$this->statsMerge($stats, $stats['Account']['Ledger']);
|
||||
$this->statsMerge($stats, $stats['Lease']['Account']['Ledger']);
|
||||
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
|
||||
array('LedgerEntry.customer_id' => $id));
|
||||
|
||||
// Pull to the top level and return
|
||||
$stats = $stats['Ledger'];
|
||||
return $stats;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user