Files
pmgr/site/views/tenders/deposit.ctp

167 lines
5.9 KiB
PHP

<?php /* -*- mode:PHP -*- */
echo '<div class="tender deposit">' . "\n";
echo '<H2>Perform Bank Deposit</H2>' . "\n";
echo '<P>Make sure to select the checkboxes below for only those types of currency (Cash, Check, etc) which you intend to actually deposit (you can see all the individual items by dropping down the list below the checkbox). Then, select the Deposit Account where you will make the deposit, and click "Perform Deposit" to close the books on the selected currency types and reset them to a zero balance. On the next page, you will be provided with a deposit slip to prepare the actual deposit.' . "\n";
echo '<P><BR>' . "\n";
//pr(compact('depositTypes', 'depositAccounts'));
echo $form->create(null, array('id' => 'deposit-form',
'onsubmit' => 'return verifyRequest();',
'url' => array('controller' => 'transactions',
'action' => 'postDeposit')));
foreach ($depositTypes AS $type) {
$names = Inflector::pluralize($type['name']);
$radioOptions =
array('none' => " No {$names} will be deposited",
'all' => (" Deposit all {$names} (" .
FormatHelper::currency($type['stats']['undeposited']) .
")"),
'subset' => " Deposit {$names} from the list below",
);
echo "\n";
echo $form->input("TenderType.{$type['id']}.selection",
array('type' => 'radio',
'class' => "type-selection-{$type['id']}",
'separator' => '<BR>',
'onclick' => "switchSelection({$type['id']})",
'legend' => false,
// REVISIT <AP>: 20080811; Make opt-in, or opt-out?
'value' => $type['stats']['undeposited'] > 0 ? 'none' : 'none',
'disabled' => $type['stats']['undeposited'] <= 0,
'options' => $radioOptions,
));
// REVISIT <AP>: 20090729
// Would like to present an option for the user to close the ledger
// associated with the form of tender, or to just leave it open.
// For now, just close it.
echo "\n";
echo $form->input("TenderType.{$type['id']}.close",
array('type' => 'hidden',
'value' => true,
));
echo "\n";
echo $form->input("TenderType.{$type['id']}.amount",
array('type' => 'hidden',
'value' => $type['stats']['undeposited'],
));
echo "\n";
echo $form->input("TenderType.{$type['id']}.id",
array('type' => 'hidden',
'value' => $type['id'],
));
echo "\n";
echo $form->input("TenderType.{$type['id']}.name",
array('type' => 'hidden',
'value' => $type['name'],
));
echo "\n";
$grid_div_id = "tenders-{$type['id']}-list";
echo $this->element('tenders', array
(// Grid configuration
'config' => array
(
'grid_div_id' => $grid_div_id,
'grid_setup' =>
array('hiddengrid' => true,
'multiselect' => true),
'caption' => "{$names} on hand",
'filter' => array('deposit_transaction_id' => null,
'TenderType.id' => $type['id']),
'exclude' => array('Type'),
),
));
// Add a hidden item to hold the jqGrid selection,
// which we'll populate prior to form submission.
echo "\n";
echo $form->input("TenderType.{$type['id']}.items",
array('type' => 'hidden',
'value' => null
));
}
echo $form->input('Deposit.Account.id', array('label' => 'Deposit Account ',
'options' => $depositAccounts));
echo $form->end('Perform Deposit');
/* End page div */
echo '</div>' . "\n";
?>
<script type="text/javascript"><!--
$(document).ready(function(){
<?php foreach ($depositTypes AS $type): ?>
<?php /* Hide the multiselect column */ ?>
switchSelection(<?php echo $type['id']; ?>);
<?php endforeach; ?>
});
// pre-submit callback
function verifyRequest() {
<?php foreach ($depositTypes AS $type): ?>
var rows = $('#<?php echo "tenders-{$type['id']}-list-jqGrid"; ?>').getGridParam('selarrrow');
$('#<?php echo "TenderType{$type['id']}Items"; ?>').val(serialize(rows));
<?php endforeach; ?>
<?php
// REVISIT <AP>: 20090730
// Verify the request before submitting
?>
// return false to prevent the form from being submitted;
// anything other than false will allow submission.
return true;
}
function switchSelection(type_id) {
var grid_div_id = '#tenders-'+type_id+'-list';
var grid_id = grid_div_id+'-jqGrid';
var selection = $('.type-selection-'+type_id+':checked').val();
var gridstate = $(grid_id).getGridParam('gridstate');
<?php
// It seems that jqGrid doesn't work too well with multiselect
// dynamically enabled / disabled. What we'd like to do is:
/* if (selection == 'subset' && !multiselect) */
/* $(grid_id).setGridParam({multiselect:true}).showCol('cb'); */
/* if (selection != 'subset' && multiselect) */
/* $(grid_id).setGridParam({multiselect:false}).hideCol('cb'); */
// However, if the grid is reloaded (manually, or page switch) while
// multiselect is disabled, then it loads garbage. I have been able
// to work around this using the loadBeforeSend event to re-enable
// multiselect just for the load, then disable it again using this
// function after the load (using the gridComplete event).
//
// It seems terribly clunky though, and so as a workaround, I've
// found that I can leave multiselect enabled all the time, and just
// Tell the grid to allow selection through checkboxes only, after
// hiding the checkboxes. This essentially disables multiselection
// as well, without the grid having to disable the entire mechanism.
?>
// Configure multiselection
if (selection == 'subset')
$(grid_id).showCol('cb').setGridParam({multiboxonly: false});
else
$(grid_id).hideCol('cb').setGridParam({multiboxonly: true}).resetSelection();
// Show or hide the grid, as appropriate
if ((selection == 'subset') == (gridstate == 'hidden'))
$(grid_div_id + ' .HeaderButton').click();
}
--></script>