From: erickson Date: Thu, 6 May 2010 16:04:38 +0000 (+0000) Subject: added batch lineitem fund updater from lineitem table ui X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fe10616b7210fccf6cf4a0626fae7d56a6f00c93;p=evergreen%2Ftadl.git added batch lineitem fund updater from lineitem table ui git-svn-id: svn://svn.open-ils.org/ILS/trunk@16396 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index a59031dd01..76ae409b94 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -1539,8 +1539,42 @@ sub create_purchase_order_api { } + +__PACKAGE__->register_method( + method => 'update_lineitem_fund_batch', + api_name => 'open-ils.acq.lineitem.fund.update.batch', + stream => 1, + signature => { + desc => q/ + Given a set of lineitem IDS, updates the fund for all attached + lineitem details + / + } +); + +sub update_lineitem_fund_batch { + my($self, $conn, $auth, $li_ids, $fund_id) = @_; + my $e = new_editor(xact=>1, authtoken=>$auth); + return $e->die_event unless $e->checkauth; + my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn); + for my $li_id (@$li_ids) { + my ($li, $evt) = fetch_and_check_li($e, $li_id, 'write'); + return $evt if $evt; + my $li_details = $e->search_acq_lineitem_detail({lineitem => $li_id}); + $_->fund($fund_id) and $_->ischanged(1) for @$li_details; + $evt = lineitem_detail_CUD_batch($mgr, $li_details); + return $evt if $evt; + $mgr->add_li; + $mgr->respond; + } + $e->commit; + return $mgr->respond_complete; +} + + + __PACKAGE__->register_method( - method => 'lineitem_detail_CUD_batch', + method => 'lineitem_detail_CUD_batch_api', api_name => 'open-ils.acq.lineitem_detail.cud.batch', stream => 1, signature => { @@ -1556,7 +1590,7 @@ __PACKAGE__->register_method( ); __PACKAGE__->register_method( - method => 'lineitem_detail_CUD_batch', + method => 'lineitem_detail_CUD_batch_api', api_name => 'open-ils.acq.lineitem_detail.cud.batch.dry_run', stream => 1, signature => { @@ -1569,15 +1603,24 @@ __PACKAGE__->register_method( ); -sub lineitem_detail_CUD_batch { +sub lineitem_detail_CUD_batch_api { my($self, $conn, $auth, $li_details, $create_debits) = @_; - my $e = new_editor(xact=>1, authtoken=>$auth); return $e->die_event unless $e->checkauth; my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn); my $dry_run = ($self->api_name =~ /dry_run/o); + my $evt = lineitem_detail_CUD_batch($mgr, $li_details, $create_debits, $dry_run); + return $evt if $evt; + $e->commit; + return $mgr->respond_complete; +} + + +sub lineitem_detail_CUD_batch { + my($mgr, $li_details, $create_debits, $dry_run) = @_; $mgr->total(scalar(@$li_details)); + my $e = $mgr->editor; my $li; my %li_cache; @@ -1610,8 +1653,7 @@ sub lineitem_detail_CUD_batch { $li_cache{$lid->lineitem} = $li; } - $e->commit; - return $mgr->respond_complete; + return undef; } sub handle_changed_lid { diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index d05fb4758c..aefc83799b 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -1895,6 +1895,10 @@ function AcqLiTable() { this.chooseExportAttr(); break; + case 'batch_apply_funds': + this.applyBatchLiFunds(); + break; + case 'add_brief_record': if(this.isPO) location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO; @@ -1925,7 +1929,7 @@ function AcqLiTable() { }; break; } - } + }; this.changeClaimPolicy = function(li_list, value, callback) { li_list.forEach( @@ -2240,6 +2244,56 @@ function AcqLiTable() { ); } + this.batchFundWidget = null; + + this.applyBatchLiFunds = function() { + + var liIds = this.getSelected().map(function(li) { return li.id(); }); + if(liIds.length == 0) return; // warn? + + var self = this; + batchFundUpdateDialog.show(); + + if(!this.batchFundWidget) { + this.batchFundWidget = new openils.widget.AutoFieldWidget({ + fmClass : 'acqf', + selfReference : true, + labelFormat : fundLabelFormat, + searchFormat : fundSearchFormat, + searchFilter : {"active": "t"}, + parentNode : dojo.byId('acq-lit-batch-fund-selector'), + orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'], + dijitArgs : { "required": true, "labelType": "html" }, + forceSync : true + }); + this.batchFundWidget.build(); + } + + dojo.connect(batchFundUpdateCancel, 'onClick', function() { batchFundUpdateDialog.hide(); }); + dojo.connect(batchFundUpdateSubmit, 'onClick', + function() { + + // TODO: call .dry_run first to test thresholds + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.lineitem.fund.update.batch'], + { + params : [ + openils.User.authtoken, + liIds, + self.batchFundWidget.widget.attr('value') + ], + oncomplete : function(r) { + var resp = openils.Util.readResponse(r); + if(resp) { + location.href = location.href; + } + } + } + ) + } + ); + } + this._deleteLiList = function(list, idx) { if(idx == null) idx = 0; if(idx >= list.length) return; diff --git a/Open-ILS/web/templates/default/acq/common/li_table.tt2 b/Open-ILS/web/templates/default/acq/common/li_table.tt2 index b2526585fa..955eaaa356 100644 --- a/Open-ILS/web/templates/default/acq/common/li_table.tt2 +++ b/Open-ILS/web/templates/default/acq/common/li_table.tt2 @@ -21,6 +21,7 @@ + @@ -395,6 +396,27 @@
[% INCLUDE "default/acq/common/final_claim_dialog.tt2" %]
+
+
+ This will update the fund for all copies attached to these lineitems.
+ This will also update any existing encumbered or spent debits. +
+
+ + + + + + + + + +
+ Select a new fund: + +
+
+