git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@328 97e9348a-65ac-dc4b-aefc-98561f571b83
178 lines
5.7 KiB
PHP
178 lines
5.7 KiB
PHP
<?php
|
|
class MonetarySource extends AppModel {
|
|
|
|
var $name = 'MonetarySource';
|
|
var $validate = array(
|
|
'id' => array('numeric'),
|
|
'name' => array('notempty'),
|
|
'tillable' => array('boolean')
|
|
);
|
|
|
|
var $belongsTo = array(
|
|
);
|
|
|
|
var $hasMany = array(
|
|
'LedgerEntry',
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: nsf
|
|
* - Flags the ledger entry as having insufficient funds
|
|
* - NOTE: nsf only works if given the monetary source id
|
|
* to transaction t2b, below
|
|
*
|
|
* FEE RENT A/R RECEIPT CHECK NSF BANK
|
|
* ------- ------- ------- ------- ------- ------- -------
|
|
* | |50 50| | | | | t1
|
|
* | | | | | | |
|
|
* | | |50 50| | | | t2a
|
|
* | | | |50 50| | | t2b
|
|
* | | | | | | |
|
|
* | | | | |50 | 50| t3
|
|
* | | | | | | |
|
|
* | | | | | 50| |50 t4a
|
|
* | | 50| | | |50 | t4b
|
|
* |35 | 35| | | | | t4b
|
|
*
|
|
*/
|
|
|
|
function nsf($id) {
|
|
pr(array('MonetarySource::nsf',
|
|
compact('id')));
|
|
|
|
$A = new Account();
|
|
|
|
// Get the LedgerEntries that use this monetary source
|
|
$entries = $this->find
|
|
('all',
|
|
array('contain' =>
|
|
array(/* t2b */
|
|
'LedgerEntry' =>
|
|
array('Transaction.id',
|
|
'MonetarySource.id',
|
|
'Customer.id',
|
|
'Lease.id',
|
|
|
|
/* e.g. CHECK */
|
|
'DebitLedger' =>
|
|
array('fields' => array(),
|
|
'Account' =>
|
|
array('fields' => array('id', 'name'),
|
|
'conditions' =>
|
|
/* array(array('Account.payable' => 1), */
|
|
/* array('Account.type' => 'ASSET')), */
|
|
array('Account.payable' => 1,
|
|
'Account.type' => 'ASSET'),
|
|
),
|
|
),
|
|
|
|
/* e.g. RECEIPT */
|
|
'CreditLedger' =>
|
|
array('fields' => array(),
|
|
'Account' =>
|
|
array('fields' => array('id', 'name'),
|
|
'conditions' =>
|
|
array('Account.id' => $A->receiptAccountID()),
|
|
),
|
|
),
|
|
|
|
/* t3 */
|
|
'CreditReconciliationLedgerEntry' =>
|
|
array(/* e.g. BANK */
|
|
'DebitLedger' =>
|
|
array('fields' => array(),
|
|
'Account' =>
|
|
array('fields' => array('id', 'name'),
|
|
'conditions' =>
|
|
array('Account.depositable' => 1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
/* 'fields' => array('LedgerEntry.*'), */
|
|
|
|
'conditions' => array(array('MonetarySource.id' => $id),
|
|
),
|
|
));
|
|
pr($entries);
|
|
die();
|
|
|
|
if (!isset($amount))
|
|
$amount = $entry['LedgerEntry']['amount'];
|
|
|
|
$ids = $this->Ledger->Account->postLedgerEntry
|
|
(array('transaction_id' => $transaction_id),
|
|
null,
|
|
array('debit_ledger_id' => $A->currentLedgerID($entry['CreditLedger']['account_id']),
|
|
'credit_ledger_id' => $A->currentLedgerID($entry['DebitLedger']['account_id']),
|
|
'effective_date' => $entry['LedgerEntry']['effective_date'],
|
|
//'effective_date' => $entry['LedgerEntry']['effective_date'],
|
|
'amount' => $amount,
|
|
'lease_id' => $entry['Lease']['id'],
|
|
'customer_id' => $entry['Customer']['id'],
|
|
'comment' => "Reversal of Ledger Entry #{$id}",
|
|
),
|
|
array('debit' => array(array('LedgerEntry' => array('id' => $entry['LedgerEntry']['id'],
|
|
'amount' => $amount,
|
|
))),
|
|
'credit' => array(array('LedgerEntry' => array('id' => $entry['LedgerEntry']['id'],
|
|
'amount' => $amount,
|
|
))),
|
|
));
|
|
|
|
if ($ids['error'])
|
|
return null;
|
|
|
|
$tid = $ids['transaction_id'];
|
|
|
|
/* pr(compact('entry')); */
|
|
|
|
foreach (array('Debit', 'Credit') AS $dc_type) {
|
|
foreach ($entry[$dc_type . 'ReconciliationLedgerEntry'] AS $RLE) {
|
|
/* pr(array('checkpoint' => "Reverse $dc_type LE", */
|
|
/* compact('id', 'RLE'))); */
|
|
if ($RLE['id'] == $rec_id)
|
|
continue;
|
|
|
|
if (!$this->reverse($RLE['id'], $RLE['Reconciliation']['amount'], $tid, $id))
|
|
$ids['error'] = true;
|
|
|
|
/* $rids = $this->Ledger->Account->postLedgerEntry */
|
|
/* (array('transaction_id' => $tid), */
|
|
/* null, */
|
|
/* array('debit_ledger_id' => $A->currentLedgerID($RLE['CreditLedger']['account_id']), */
|
|
/* 'credit_ledger_id' => $A->currentLedgerID($RLE['DebitLedger']['account_id']), */
|
|
/* 'effective_date' => $RLE['effective_date'], */
|
|
/* //'effective_date' => $RLE['effective_date'], */
|
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
|
/* 'lease_id' => $entry['Lease']['id'], */
|
|
/* 'customer_id' => $entry['Customer']['id'], */
|
|
/* 'comment' => "Reversal of Ledger Entry #{$RLE['id']}", */
|
|
/* ), */
|
|
/* array('debit' => array(array('LedgerEntry' => array('id' => $RLE['id'], */
|
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
|
/* ))), */
|
|
/* 'credit' => array(array('LedgerEntry' => array('id' => $RLE['id'], */
|
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
|
/* ))), */
|
|
/* )); */
|
|
|
|
/* if ($rids['error']) */
|
|
/* $ids['error'] = true; */
|
|
}
|
|
}
|
|
|
|
if ($ids['error'])
|
|
return null;
|
|
|
|
return $ids['id'];
|
|
}
|
|
|
|
|
|
}
|
|
?>
|