dojo.require('openils.Event');
dojo.require('openils.Util');
dojo.require('openils.User');
+dojo.require('openils.CGI');
dojo.require('openils.acq.Fund');
dojo.require('openils.widget.AutoGrid');
dojo.require('openils.widget.ProgressDialog');
+dojo.require('fieldmapper.OrgUtils');
dojo.requireLocalization('openils.acq', 'acq');
var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
var contextOrg;
+var rolloverResponses;
+var rolloverMode = false;
function getBalanceInfo(rowIndex, item) {
if(!item) return '';
function initPage() {
+ contextOrg = openils.User.user.ws_ou();
+
var connect = function() {
dojo.connect(contextOrgSelector, 'onChange',
function() {
contextOrg = this.attr('value');
- lfGrid.resetStore();
- loadFundGrid(fundFilterYearSelect.attr('value'));
+ dojo.byId('oils-acq-rollover-ctxt-org').innerHTML =
+ fieldmapper.aou.findOrgUnit(contextOrg).shortname();
+ rolloverMode = false;
+ gridDataLoader();
}
);
};
+ dojo.connect(refreshButton, 'onClick', function() { rolloverMode = false; gridDataLoader(); });
+
new openils.User().buildPermOrgSelector(
- 'ADMIN_ACQ_FUND', contextOrgSelector, null, connect);
+ 'ADMIN_ACQ_FUND', contextOrgSelector, contextOrg, connect);
+
+ dojo.byId('oils-acq-rollover-ctxt-org').innerHTML =
+ fieldmapper.aou.findOrgUnit(contextOrg).shortname();
loadYearSelector();
- loadFundGrid();
+ lfGrid.dataLoader = gridDataLoader;
+ loadFundGrid(new openils.CGI().param('year') || new Date().getFullYear().toString());
tagManager = new TagManager(lfGrid);
}
+function gridDataLoader() {
+ lfGrid.resetStore();
+ if(rolloverMode) {
+ var offset = lfGrid.displayOffset;
+ for(var i = offset; i < (offset + lfGrid.displayLimit - 1); i++) {
+ var fund = rolloverResponses[i];
+ if(!fund) break;
+ lfGrid.store.newItem(fieldmapper.acqf.toStoreItem(fund));
+ }
+ } else {
+ loadFundGrid();
+ }
+}
+
function loadFundGrid(year) {
openils.Util.hide('acq-fund-list-rollover-summary');
- lfGrid.resetStore();
- year = year || new Date().getFullYear().toString();
- lfGrid.dataLoader = function() { loadFundGrid(year); };
-
- if(contextOrg == null)
- contextOrg = openils.User.user.ws_ou();
+ year = year || fundFilterYearSelect.attr('value');
fieldmapper.standardRequest(
[ 'open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
var yearStore = {identifier:'year', name:'year', items:yearList};
yearStore.items = yearStore.items.sort().reverse();
- fundFilterYearSelect.store = new dojo.data.ItemFileReadStore({data:yearStore});
+ fundFilterYearSelect.store = new dojo.data.ItemFileWriteStore({data:yearStore});
// default to this year
fundFilterYearSelect.setValue(new Date().getFullYear().toString());
dojo.connect(
fundFilterYearSelect,
'onChange',
- function() {
- loadFundGrid(fundFilterYearSelect.attr('value'));
+ function() {
+ rolloverMode = false;
+ gridDataLoader();
}
);
}
function performRollover(args) {
- lfGrid.resetStore();
+ rolloverMode = true;
progressDialog.show(true, "Processing...");
+ rolloverResponses = [];
var method = 'open-ils.acq.fiscal_rollover';
method += '.propagate';
}
- if(args.dry_run[0] == 'on')
- method += '.dry_run';
+ var dryRun = args.dry_run[0] == 'on';
+ if(dryRun) method += '.dry_run';
var count = 0;
var amount_rolled = 0;
var year = fundFilterYearSelect.attr('value'); // TODO alternate selector?
+
fieldmapper.standardRequest(
['open-ils.acq', method],
{
openils.User.authtoken,
year,
contextOrg,
- false, // TODO: checkbox in dialog
+ (args.child_orgs[0] == 'on')
],
onresponse : function(r) {
var resp = openils.Util.readResponse(r);
+ rolloverResponses.push(resp.fund);
count += 1;
amount_rolled += resp.rollover_amount;
- lfGrid.store.newItem(fieldmapper.acqf.toStoreItem(resp.fund));
},
oncomplete : function() {
var nextYear = Number(year) + 1;
+ rolloverResponses = rolloverResponses.sort(
+ function(a, b) {
+ if(a.code() > b.code())
+ return 1;
+ return -1;
+ }
+ )
dojo.byId('acq-fund-list-rollover-summary-header').innerHTML =
dojo.string.substitute(
[nextYear, amount_rolled]
);
- if(!args.dry_run) {
+ if(!dryRun) {
openils.Util.hide('acq-fund-list-rollover-summary-dry-run');
+
+ // add the new year to the year selector if it's not already there
+ fundFilterYearSelect.store.fetch({
+ query : {year : nextYear},
+ onComplete:
+ function(list) {
+ if(list && list.length > 0) return;
+ fundFilterYearSelect.store.newItem({year : nextYear});
+ }
+ });
}
- openils.Util.show('acq-fund-list-rollover-summary');
-
+ openils.Util.show('acq-fund-list-rollover-summary');
progressDialog.hide();
+ gridDataLoader();
}
}
);
<div dojoType="dijit.form.DropDownButton">
<span>Fund Propagation & Rollover</span>
<div dojoType="dijit.TooltipDialog" execute="performRollover(arguments[0]);">
- <table class='dijitTooltipTable'>
+ <table class='dijitTooltipTable' id='oils-acq-rollover-tooltip-table'>
<tr>
<td colspan='2'>
- <div style='width:400px;border-bottom:2px solid #888'>
+ <div style='width:400px;'>
Propagation creates new funds for the sugsequent fiscal year based on the
funds for the selected fiscal year. Only funds with the propagate setting
enabled will be affected. No money or encumbrances are altered
</tr>
<tr>
<td colspan='2'>
- <div style='width:400px;border-bottom:2px solid #888'>
+ <div style='width:400px;'>
The year end close out operation moves encumbrances from the selected fiscal
year to the analogous funds in the subsequent fiscal year and it deactivates
funds for the selected fiscal year. Additionally, for all funds that have
</td>
</tr>
<tr>
+ <td>Context Org Unit:</td>
+ <td><span id='oils-acq-rollover-ctxt-org'></span></td>
+ </tr>
+ <tr>
+ <td>Include Funds for Descendant Org Units:</td>
+ <td><input dojoType=dijit.form.CheckBox name='child_orgs'/></td>
+ </tr>
+ <tr>
<td><label for="dry_run">Dry Run: </label></td>
<td>
<input dojoType="dijit.form.CheckBox" name="dry_run" checked='checked'> </input>
</tr>
<tr>
<td colspan='2'>
- <div style='width:400px;border-bottom:2px solid #888'>
+ <div style='width:400px;'>
When Dry Run is selected, the system will generate a summary of
the changes that would occur during the selected operation(s).
No data will be changed.
labelAttr="year"
searchAttr="year">
</select>
+
+ <div dojoType='dijit.form.Button' jsId='refreshButton'>Refresh</div>
</div>
<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
- <div style='width:98%; margin-top:20px;'>
- <div id='acq-fund-list-rollover-summary' class='hidden' style='width:50%; margin-left:auto; margin-right:auto;text-align:center;border:1px solid #888;'>
+ <div id='acq-fund-list-rollover-summary-wrapper'>
+ <div id='acq-fund-list-rollover-summary' class='hidden'>
<div id='acq-fund-list-rollover-summary-header'> </div>
<ul>
<li id='acq-fund-list-rollover-summary-dry-run'>These changes have <span class='oils-notify-text'>not</span> been committed yet.</li>