Changed the deposit to use a grouped double entry instead of individual ones for each tender deposited
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@414 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -40,6 +40,7 @@ class TendersController extends AppController {
|
|||||||
return array
|
return array
|
||||||
('link' =>
|
('link' =>
|
||||||
array('TenderType',
|
array('TenderType',
|
||||||
|
'Customer',
|
||||||
'LedgerEntry' =>
|
'LedgerEntry' =>
|
||||||
array('Transaction',
|
array('Transaction',
|
||||||
),
|
),
|
||||||
@@ -58,6 +59,7 @@ class TendersController extends AppController {
|
|||||||
|
|
||||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||||
$links['Tender'] = array('name', 'id');
|
$links['Tender'] = array('name', 'id');
|
||||||
|
$links['Customer'] = array('name');
|
||||||
$links['TenderType'] = array('name');
|
$links['TenderType'] = array('name');
|
||||||
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class DoubleEntry extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(($entry1['crdr'] === 'DEBIT' && $entry2['crdr'] === 'CREDIT') ||
|
if (!(($entry1['crdr'] === 'DEBIT' && $entry2['crdr'] === 'CREDIT') ||
|
||||||
($entry1['crdr'] === 'CREDIT' && $entry2['crdr'] === 'DEBIT'))) {
|
($entry1['crdr'] === 'CREDIT' && $entry2['crdr'] === 'DEBIT')) ||
|
||||||
|
($entry1['amount'] != $entry2['amount'])) {
|
||||||
/* pr(array("DoubleEntry::verifyDoubleEntry()" */
|
/* pr(array("DoubleEntry::verifyDoubleEntry()" */
|
||||||
/* => "Double Entry verification failed")); */
|
/* => "Double Entry verification failed")); */
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -112,11 +112,6 @@ class Transaction extends AppModel {
|
|||||||
$deposit['customer_id'] = null;
|
$deposit['customer_id'] = null;
|
||||||
$deposit['lease_id'] = null;
|
$deposit['lease_id'] = null;
|
||||||
|
|
||||||
// Go through the statement entries and flag as credits
|
|
||||||
foreach ($data['Entry'] AS &$entry) {
|
|
||||||
$entry['crdr'] = 'CREDIT';
|
|
||||||
}
|
|
||||||
|
|
||||||
// For some reason, $data is being modified by the
|
// For some reason, $data is being modified by the
|
||||||
// addTransaction call, even though we're not passing by
|
// addTransaction call, even though we're not passing by
|
||||||
// reference. Not all items in $data['Entry'] are being
|
// reference. Not all items in $data['Entry'] are being
|
||||||
@@ -131,6 +126,18 @@ class Transaction extends AppModel {
|
|||||||
'return $item["tender_id"];'),
|
'return $item["tender_id"];'),
|
||||||
$data['Entry']);
|
$data['Entry']);
|
||||||
|
|
||||||
|
// Go through the statement entries and re-group by account id
|
||||||
|
$group = array();
|
||||||
|
foreach ($data['Entry'] AS &$entry) {
|
||||||
|
if (!isset($group[$entry['account_id']]))
|
||||||
|
$group[$entry['account_id']] =
|
||||||
|
array('account_id' => $entry['account_id'],
|
||||||
|
'crdr' => 'CREDIT',
|
||||||
|
'amount' => 0);
|
||||||
|
$group[$entry['account_id']]['amount'] += $entry['amount'];
|
||||||
|
}
|
||||||
|
$data['Entry'] = $group;
|
||||||
|
|
||||||
$ids = $this->addTransaction($data);
|
$ids = $this->addTransaction($data);
|
||||||
if (isset($ids['transaction_id']))
|
if (isset($ids['transaction_id']))
|
||||||
$ids['deposit_id'] = $ids['transaction_id'];
|
$ids['deposit_id'] = $ids['transaction_id'];
|
||||||
@@ -251,7 +258,7 @@ class Transaction extends AppModel {
|
|||||||
|
|
||||||
function addTransaction($data) {
|
function addTransaction($data) {
|
||||||
/* pr(array("Transaction::addTransaction()" */
|
/* pr(array("Transaction::addTransaction()" */
|
||||||
/* => compact('data', 'customer_id', 'lease_id'))); */
|
/* => compact('data'))); */
|
||||||
|
|
||||||
// Verify that we have a transaction and entries
|
// Verify that we have a transaction and entries
|
||||||
if (empty($data['Transaction']) || empty($data['Entry']))
|
if (empty($data['Transaction']) || empty($data['Entry']))
|
||||||
@@ -353,7 +360,8 @@ class Transaction extends AppModel {
|
|||||||
foreach ($data['Entry'] AS $e_index => &$entry) {
|
foreach ($data['Entry'] AS $e_index => &$entry) {
|
||||||
extract($entry);
|
extract($entry);
|
||||||
$le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id'];
|
$le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id'];
|
||||||
$le1_tender['customer_id'] = $transaction['customer_id'];
|
if (isset($le1_tender))
|
||||||
|
$le1_tender['customer_id'] = $transaction['customer_id'];
|
||||||
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
|
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
|
||||||
$ret['entries'][$e_index]['DoubleEntry'] = $result;
|
$ret['entries'][$e_index]['DoubleEntry'] = $result;
|
||||||
if ($result['error']) {
|
if ($result['error']) {
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
$cols = array();
|
$cols = array();
|
||||||
//$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id');
|
//$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id');
|
||||||
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
|
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
|
||||||
$cols['Name'] = array('index' => 'Tender.name', 'formatter' => 'longname');
|
$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname');
|
||||||
|
$cols['Item'] = array('index' => 'Tender.name', 'formatter' => 'longname');
|
||||||
$cols['Type'] = array('index' => 'TenderType.name', 'formatter' => 'name');
|
$cols['Type'] = array('index' => 'TenderType.name', 'formatter' => 'name');
|
||||||
$cols['Comment'] = array('index' => 'Tender.comment', 'formatter' => 'comment');
|
$cols['Comment'] = array('index' => 'Tender.comment', 'formatter' => 'comment');
|
||||||
$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency');
|
$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency');
|
||||||
|
|||||||
@@ -88,11 +88,28 @@ echo $this->element('ledger_entries', array
|
|||||||
'config' => array
|
'config' => array
|
||||||
(
|
(
|
||||||
'caption' => 'Ledger Entries',
|
'caption' => 'Ledger Entries',
|
||||||
'filter' => array('transaction_id' => $transaction['id']),
|
'filter' => array('transaction_id' => $transaction['id'],
|
||||||
|
'Account.id !=' => $account['id']),
|
||||||
'exclude' => array('Transaction'),
|
'exclude' => array('Transaction'),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* Tenders Deposited
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($transaction['type'] === 'DEPOSIT') {
|
||||||
|
echo $this->element('tenders', array
|
||||||
|
(// Grid configuration
|
||||||
|
'config' => array
|
||||||
|
(
|
||||||
|
'caption' => 'Deposited Items',
|
||||||
|
'filter' => array('Tender.deposit_transaction_id' => $transaction['id']),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End "detail supporting" div */
|
/* End "detail supporting" div */
|
||||||
echo '</div>' . "\n";
|
echo '</div>' . "\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user