This is the remainder of the previous, invalid, partial checkin.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@419 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-29 23:25:03 +00:00
parent a8862ea3fd
commit ccf7a5fccd
4 changed files with 207 additions and 132 deletions

View File

@@ -12,7 +12,9 @@ class AccountsController extends AppController {
array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')), array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')),
array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')), array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')),
array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')), array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')),
array('name' => 'Bank Deposit', 'url' => array('controller' => 'accounts', 'action' => 'deposit')), array('name' => 'Deposits', 'header' => true),
array('name' => 'Prior Deposits', 'url' => array('controller' => 'transactions', 'action' => 'deposit')),
array('name' => 'New Deposit', 'url' => array('controller' => 'tenders', 'action' => 'deposit')),
); );

View File

@@ -92,87 +92,6 @@ class TendersController extends AppController {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* 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
('Customer',
'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'],
'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;
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -7,6 +7,9 @@ class TransactionsController extends AppController {
var $sidemenu_links = var $sidemenu_links =
array(array('name' => 'Transactions', 'header' => true), array(array('name' => 'Transactions', 'header' => true),
array('name' => 'All', 'url' => array('controller' => 'transactions', 'action' => 'all')), array('name' => 'All', 'url' => array('controller' => 'transactions', 'action' => 'all')),
array('name' => 'Invoices', 'url' => array('controller' => 'transactions', 'action' => 'invoice')),
array('name' => 'Receipts', 'url' => array('controller' => 'transactions', 'action' => 'receipt')),
array('name' => 'Deposits', 'url' => array('controller' => 'transactions', 'action' => 'deposit')),
); );
@@ -30,6 +33,9 @@ class TransactionsController extends AppController {
function index() { $this->all(); } function index() { $this->all(); }
function all() { $this->gridView('All Transactions', 'all'); } function all() { $this->gridView('All Transactions', 'all'); }
function invoice() { $this->gridView('Invoices'); }
function receipt() { $this->gridView('Receipts'); }
function deposit() { $this->gridView('Deposits'); }
/************************************************************************** /**************************************************************************
@@ -48,57 +54,34 @@ class TransactionsController extends AppController {
function gridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $this->gridDataCountTables($params, $model); $link = $this->gridDataCountTables($params, $model);
$link['link']['StatementEntry'] = array('fields' => array()); $link['link']['StatementEntry'] = array('fields' => array());
$link['link']['DepositTender'] = array('fields' => array());
return $link; return $link;
} }
function gridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$fields = parent::gridDataFields($params, $model); $fields = parent::gridDataFields($params, $model);
$fields[] = 'COUNT(StatementEntry.id) AS entries'; //$fields[] = 'COUNT(StatementEntry.id) AS entries';
$fields[] = ("IF(Transaction.type = 'DEPOSIT'," .
" COUNT(DepositTender.id)," .
" COUNT(StatementEntry.id)) AS entries");
return $fields; return $fields;
} }
function gridDataConditions(&$params, &$model) {
$conditions = parent::gridDataConditions($params, $model);
if (in_array($params['action'], array('invoice', 'receipt', 'deposit')))
$conditions[] = array('Transaction.type' => strtoupper($params['action']));
return $conditions;
}
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id'); $links['Transaction'] = array('id');
return parent::gridDataPostProcessLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific transaction
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$transaction = $this->Transaction->find
('first',
array('contain' =>
array(// Models
'Account' =>
array('fields' => array('Account.id',
'Account.name'),
),
'Ledger' =>
array('fields' => array('Ledger.id',
'Ledger.name'),
),
),
'conditions' => array('Transaction.id' => $id),
));
// OK, prepare to render.
$title = 'Transaction #' . $transaction['Transaction']['id'];
$this->set(compact('transaction', 'title'));
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -161,7 +144,183 @@ class TransactionsController extends AppController {
$this->layout = null; $this->layout = null;
$this->autoLayout = false; $this->autoLayout = false;
$this->autoRender = false; $this->autoRender = false;
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: postDeposit
* - handles the creation of a deposit transaction
*/
function postDeposit() {
if (!$this->RequestHandler->isPost()) {
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
return;
}
//pr($this->data);
// Start building data for our deposit
$deposit = array('close_id' => null,
'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->Transaction->DepositTender->find
('all',
array('contain' => array
('TenderType', 'LedgerEntry'),
'conditions' => array(array('DepositTender.deposit_transaction_id' => null),
array('TenderType.id' => $type_id)),
));
// Prepare for the actual deposit
foreach ($tenders AS $tender) {
$deposit['Entry'][] =
array('tender_id' => $tender['DepositTender']['id'],
'account_id' => $tender['LedgerEntry']['account_id'],
'amount' => $tender['LedgerEntry']['amount'],
);
}
if (!empty($type['close']) && !empty($tenders)) {
// Close the associated ledger
$result = $this->Transaction->Account->closeCurrentLedger
($tenders[0]['TenderType']['account_id'], $deposit['close_id']);
if (!$result['error'] && empty($deposit['close_id']))
$deposit['close_id'] = $result['close_id'];
}
}
$result = $this->Transaction->addDeposit
($deposit, $this->data['Deposit']['Account']['id']);
//pr(compact('deposit', 'result'));
if ($result['error']) {
$this->Session->setFlash(__('Unable to Create Deposit', true));
$this->redirect(array('controller' => 'tenders', 'action'=>'deposit'));
}
$this->redirect(array('controller' => 'transactions',
'action' => 'deposit_slip',
$result['transaction_id']));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific transaction
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$transaction = $this->Transaction->find
('first',
array('contain' =>
array(// Models
'Account' =>
array('fields' => array('Account.id',
'Account.name'),
),
'Ledger' =>
array('fields' => array('Ledger.id',
'Ledger.name'),
),
),
'conditions' => array('Transaction.id' => $id),
));
if ($transaction['Transaction']['type'] === 'DEPOSIT') {
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'View Slip', 'url' => array('action' => 'deposit_slip', $id));
}
// OK, prepare to render.
$title = 'Transaction #' . $transaction['Transaction']['id'];
$this->set(compact('transaction', 'title'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit_slip
* - Special presentation
* Processes the user input and updates the database
*/
function deposit_slip($id) {
// Build a container for the deposit slip data
$deposit = array('types' => array());
$this->id = $id;
$deposit +=
$this->Transaction->find('first', array('contain' => false));
// Get a summary of all forms of tender in the deposit
$result = $this->Transaction->find
('all',
array('link' => array('DepositTender' =>
array('fields' => array(),
'TenderType',
'LedgerEntry' =>
array('fields' => array()))),
'fields' => array(//'TenderType.id', 'TenderType.name',
"COUNT(DepositTender.id) AS 'count'",
"SUM(LedgerEntry.amount) AS 'total'"),
//'conditions' => array(array('DepositTender.deposit_transaction_id' => $id)),
'conditions' => array(array('Transaction.id' => $id)),
'group' => 'TenderType.id',
));
if (empty($result)) {
die();
$this->Session->setFlash(__('Invalid Deposit.', true));
$this->redirect(array('action'=>'deposit'));
}
// Add the summary to our deposit slip data container
foreach ($result AS $type) {
$deposit['types'][$type['TenderType']['id']] =
$type['TenderType'] + $type[0];
}
// For each form of tender in the deposit, get the deposit items
/* foreach ($deposit['types'] AS $type_id => &$type) { */
/* $type['entries'] = $this->Transaction->DepositTender->find */
/* ('all', */
/* array('contain' => array('Customer', 'LedgerEntry'), */
/* 'conditions' => array(array('DepositTender.deposit_transaction_id' => $id), */
/* array('DepositTender.tender_type_id' => $type_id)), */
/* )); */
/* } */
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'View Transaction', 'url' => array('action' => 'view', $id));
$title = 'Deposit Slip';
$this->set(compact('title', 'deposit'));
$this->render('deposit_slip');
return;
}
} }

View File

@@ -9,6 +9,10 @@ class Transaction extends AppModel {
var $hasMany = array( var $hasMany = array(
'LedgerEntry', 'LedgerEntry',
'StatementEntry', 'StatementEntry',
'DepositTender' => array(
'className' => 'Tender',
'foreignKey' => 'deposit_transaction_id',
),
'Charge' => array( 'Charge' => array(
'className' => 'StatementEntry', 'className' => 'StatementEntry',
@@ -112,18 +116,9 @@ class Transaction extends AppModel {
$deposit['customer_id'] = null; $deposit['customer_id'] = null;
$deposit['lease_id'] = null; $deposit['lease_id'] = null;
// For some reason, $data is being modified by the // Save the list of IDs, so that we can mark their
// addTransaction call, even though we're not passing by // deposit transaction after it has been created.
// reference. Not all items in $data['Entry'] are being $tender_ids = array_map(create_function('$item', 'return $item["tender_id"];'),
// stomped on... only the last one in the list :-/
// Save off all the tender ids now, before calling
// addTransaction, to make sure we don't lose any.
$tender_ids = array_map(create_function('$item',
/* 'if (!isset($item))' . */
/* ' pr("NO ITEM");' . */
/* 'if (!isset($item["tender_id"]))' . */
/* ' pr(array("BAD ITEM" => compact("item")));' . */
'return $item["tender_id"];'),
$data['Entry']); $data['Entry']);
// Go through the statement entries and re-group by account id // Go through the statement entries and re-group by account id