Re-implemented the deposit functionality. This is mostly working, although I'd like to get customer added to the tenders table, and probably change to a single deposit ledger entry for each tender type. A single entry would require that all tender types have been recorded to the same account, something that isn't mandated at the present, but is likely to be true most of the time. Perhaps they could just be grouped by account id, which should work in all cases and yet align with tender type 99% of the time. I'll have to think about it.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@412 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-29 08:55:09 +00:00
parent cdba179d79
commit 2ffe04e3e4
10 changed files with 318 additions and 174 deletions

View File

@@ -39,19 +39,138 @@ class TendersController extends AppController {
function gridDataTables(&$params, &$model) {
return array
('link' =>
array('LedgerEntry' =>
array('TenderType',
'LedgerEntry' =>
array('Transaction',
),
),
);
}
function gridDataRecordsExecute(&$params, &$model, $query) {
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['fields'] = array("SUM(COALESCE(LedgerEntry.amount,0)) AS 'total'");
$total = $model->find('first', $tquery);
$params['userdata']['total'] = $total[0]['total'];
return parent::gridDataRecordsExecute($params, $model, $query);
}
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Tender'] = array('name', 'id');
$links['Tender'] = array('name', 'id');
$links['TenderType'] = array('name');
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit
* - Prepares the books for a bank deposit
*/
function deposit() {
// Prepare a close page...
$deposit_types = $this->Tender->TenderType->depositTypes(
// Testing... limit to only one type
//array('limit' => 1)
);
$deposit_accounts = $this->Tender->TenderType->Account->depositAccounts();
foreach ($deposit_types AS $type_id => &$type)
$type = array('id' => $type_id,
'name' => $type,
'stats' => $this->Tender->TenderType->stats($type_id));
//pr(compact('deposit_types', 'deposit_accounts'));
$title = 'Prepare Deposit';
$this->set(compact('title', 'deposit_types', 'deposit_accounts'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit_slip
* - The followup to the action 'deposit'.
* Processes the user input and updates the database
*/
function deposit_slip() {
if (!$this->data) {
$this->Session->setFlash(__('Invalid Action', true));
$this->redirect(array('action'=>'deposit'));
}
pr($this->data);
// Start building data for our deposit
$deposit = array('close_id' => null,
'total' => 0,
'types' => array(),
'Transaction' => array(),
'Entry' => array());
// Go through each type of tender presented to the user
foreach ($this->data['TenderType'] AS $type_id => $type) {
if (!$type['checked'])
continue;
$tenders = $this->Tender->find
('all',
array('contain' => array
('LedgerEntry',
),
'conditions' => array(array('Tender.deposit_transaction_id' => null),
array('Tender.tender_type_id' => $type_id)),
));
// Prepare for both the actual deposit, as well as the deposit slip
$deposit['types'][$type_id]['name'] = $type['name'];
$deposit['types'][$type_id]['entries'] = array();
$deposit['types'][$type_id]['total'] = 0;
foreach ($tenders AS $tender) {
$deposit['Entry'][] =
array('tender_id' => $tender['Tender']['id'],
//'ledger_entry_id' => $tender['LedgerEntry']['id'],
'account_id' => $tender['LedgerEntry']['account_id'],
'amount' => $tender['LedgerEntry']['amount'],
);
$deposit['types'][$type_id]['entries'][] =
array('name' => $tender['Tender']['name'],
//'customer' => $tender['Customer']['name'],
'customer' => 'Not Yet',
'amount' => $tender['LedgerEntry']['amount']);
$deposit['types'][$type_id]['total'] += $tender['LedgerEntry']['amount'];
}
// Add into the grand total
$deposit['total'] += $deposit['types'][$type_id]['total'];
if (!empty($type['close'])) {
// Close the associated ledger
$result = $this->Tender->LedgerEntry->Account->closeCurrentLedger
($type['account_id'], $deposit['close_id']);
if (!$result['error'] && empty($deposit['close_id']))
$deposit['close_id'] = $result['close_id'];
}
}
$result = $this->Tender->DepositTransaction->addDeposit
($deposit, $this->data['Deposit']['Account']['id']);
//pr(compact('deposit', 'result'));
$title = 'Deposit Slip';
$this->set(compact('title', 'deposit'));
$this->render('deposit_slip');
return;
}
/**************************************************************************
**************************************************************************
**************************************************************************