my $activate_po = $args->{activate_po};
my $vandelay = $args->{vandelay};
my $ordering_agency = $args->{ordering_agency} || $e->requestor->ws_ou;
+ my $fiscal_year = $args->{fiscal_year} || DateTime->now->year;
my $po;
my $evt;
$mgr->respond;
$li->provider($provider); # flesh it, we'll need it later
- import_lineitem_details($mgr, $ordering_agency, $li) or return $mgr->editor->die_event;
+ import_lineitem_details($mgr, $ordering_agency, $li, $fiscal_year)
+ or return $mgr->editor->die_event;
$mgr->respond;
push(@li_list, $li->id);
}
sub import_lineitem_details {
- my($mgr, $ordering_agency, $li) = @_;
+ my($mgr, $ordering_agency, $li, $fiscal_year) = @_;
my $holdings = $mgr->editor->json_query({from => ['acq.extract_provider_holding_data', $li->id]});
return 1 unless @$holdings;
while(1) {
# create a lineitem detail for each copy in the data
- my $compiled = extract_lineitem_detail_data($mgr, $org_path, $holdings, $idx);
+ my $compiled = extract_lineitem_detail_data($mgr, $org_path, $holdings, $idx, $fiscal_year);
last unless defined $compiled;
return 0 unless $compiled;
# return hash on success, 0 on error, undef on no more holdings
sub extract_lineitem_detail_data {
- my($mgr, $org_path, $holdings, $index) = @_;
+ my($mgr, $org_path, $holdings, $index, $fiscal_year) = @_;
my @data_list = grep { $_->{holding} eq $index } @$holdings;
return undef unless @data_list;
# search up the org tree for the most appropriate fund
for my $org (@$org_path) {
$fund = $mgr->editor->search_acq_fund(
- {org => $org, code => $code, year => DateTime->now->year}, {idlist => 1})->[0];
+ {org => $org, code => $code, year => $fiscal_year}, {idlist => 1})->[0];
last if $fund;
}
}
function init() {
dojo.byId('acq-pl-upload-ses').value = openils.User.authtoken;
+ loadYearSelector();
+
new openils.widget.AutoFieldWidget({
fmClass : 'acqpo',
fmField : 'provider',
ordering_agency : orderAgencyWidget.attr('value'),
create_po : acqPlUploadCreatePo.attr('value'),
activate_po : acqPlUploadActivatePo.attr('value'),
- vandelay : vlAgent.values()
+ vandelay : vlAgent.values(),
+ fiscal_year : acqUploadYearSelector.attr('value')
};
fieldmapper.standardRequest(
);
}
+function loadYearSelector() {
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.fund.org.years.retrieve'],
+ { async : true,
+ params : [openils.User.authtoken, {}, {limit_perm : 'VIEW_FUND'}],
+ oncomplete : function(r) {
+
+ var yearList = openils.Util.readResponse(r);
+ if(!yearList) return;
+ yearList = yearList.map(function(year){return {year:year+''};}); // dojo wants strings
+
+ var yearStore = {identifier:'year', name:'year', items:yearList};
+ 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());
+ }
+ }
+ );
+}
+
+
openils.Util.addOnLoad(init);