From: Bill Erickson Date: Fri, 10 Aug 2012 18:59:50 +0000 (-0400) Subject: Default to current fiscal year in ACQ order upload X-Git-Url: http://git.equinoxoli.org/?p=transitory.git;a=commitdiff_plain;h=1d5912e670a328c951a41e333c1a2c0ad564cbbd Default to current fiscal year in ACQ order upload * Adds a new API call to determine the current fiscal year for a given org unit: open-ils.acq.org_unit.current_fiscal_year * Use open-ils.acq.org_unit.current_fiscal_year to populate the correct fiscal year in the ACQ order upload selector. This addresses part 2 of LP 1031927 Signed-off-by: Bill Erickson Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm index df0d3bc..217013a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm @@ -1347,6 +1347,43 @@ sub process_fiscal_rollover { return undef; } +__PACKAGE__->register_method( + method => 'org_fiscal_year', + api_name => 'open-ils.acq.org_unit.current_fiscal_year', + signature => { + desc => q/ + Returns the current fiscal year for the given org unit. + If no fiscal year is configured, the current calendar + year is returned. + /, + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'Org unit ID', type => 'number'} + ], + return => {desc => 'Year as a string (e.g. "2012")'} + } +); + +sub org_fiscal_year { + my($self, $conn, $auth, $org_id) = @_; + + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $year = $e->json_query({ + select => {acqfy => ['year']}, + from => {acqfy => {acqfc => {join => 'aou'}}}, + where => { + '+acqfy' => { + year_begin => {'<=' => 'now'}, + year_end => {'>=' => 'now'}, + }, + '+aou' => {id => $org_id} + } + })->[0]; + + return $year ? $year->{year} : DateTime->now->year; +} 1; diff --git a/Open-ILS/web/js/ui/default/acq/picklist/upload.js b/Open-ILS/web/js/ui/default/acq/picklist/upload.js index 1361685..1eb2933 100644 --- a/Open-ILS/web/js/ui/default/acq/picklist/upload.js +++ b/Open-ILS/web/js/ui/default/acq/picklist/upload.js @@ -39,7 +39,10 @@ function init() { orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'], parentNode : dojo.byId('acq-pl-upload-agency'), }).build( - function(w) { orderAgencyWidget = w } + function(w) { + orderAgencyWidget = w + dojo.connect(orderAgencyWidget, 'onChange', setDefaultFiscalYear); + } ); vlAgent = new VLAgent(); @@ -58,6 +61,24 @@ function init() { ); } +function setDefaultFiscalYear(org) { + org = org || orderAgencyWidget.attr('value'); + + if (org) { + + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.org_unit.current_fiscal_year'], + { params : [openils.User.authtoken, org], + async : true, + oncomplete : function(r) { + var year = openils.Util.readResponse(r); + acqUploadYearSelector.attr('value', year); + } + } + ); + } +} + function acqUploadRecords() { openils.Util.show('acq-pl-upload-progress'); var picklist = acqPlUploadPlSelector.attr('value'); @@ -180,9 +201,9 @@ function loadYearSelector() { yearStore.items = yearStore.items.sort().reverse(); acqUploadYearSelector.store = new dojo.data.ItemFileReadStore({data:yearStore}); - // default to this year - // TODO: current fiscal year - acqUploadYearSelector.setValue(new Date().getFullYear().toString()); + // until an ordering agency is selected, default to the + // fiscal year of the workstation + setDefaultFiscalYear(new openils.User().user.ws_ou()); } } );