From eabb716a07256c351b0f81fbb175cc6f9c1e8873 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 16 Apr 2009 15:29:54 +0000 Subject: [PATCH] implemented PO receive rollback and api's for li and lid rollback. li/lid ui to come git-svn-id: svn://svn.open-ils.org/ILS/trunk@12892 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Acq/Order.pm | 166 ++++++++++++++++++++- Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 +- Open-ILS/web/js/ui/default/acq/common/li_table.js | 21 +++ .../web/templates/default/acq/common/li_table.tt2 | 1 + 4 files changed, 188 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index abc23cd34e..dd9fc2ce84 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -276,6 +276,22 @@ sub receive_lineitem { return check_purchase_order_received($mgr, $li->purchase_order); } +sub rollback_receive_lineitem { + my($mgr, $li_id) = @_; + my $li = $mgr->editor->retrieve_acq_lineitem($li_id) or return 0; + + my $lid_ids = $mgr->editor->search_acq_lineitem_detail( + {lineitem => $li_id, recv_time => {'!=' => undef}}, {idlist => 1}); + + for my $lid_id (@$lid_ids) { + rollback_receive_lineitem_detail($mgr, $lid_id, 1) or return 0; + } + + $mgr->add_li; + $li->state('on-order'); + return update_lineitem($mgr, $li); +} + # ---------------------------------------------------------------------------- # Lineitem Detail # ---------------------------------------------------------------------------- @@ -367,6 +383,39 @@ sub receive_lineitem_detail { } +sub rollback_receive_lineitem_detail { + my($mgr, $lid_id) = @_; + my $e = $mgr->editor; + + my $lid = $e->retrieve_acq_lineitem_detail([ + $lid_id, + { flesh => 1, + flesh_fields => { + acqlid => ['fund_debit'] + } + } + ]) or return 0; + + return 1 unless $lid->recv_time; + + $lid->clear_recv_time; + $e->update_acq_lineitem_detail($lid) or return 0; + + my $copy = $e->retrieve_asset_copy($lid->eg_copy_id) or return 0; + $copy->status(OILS_COPY_STATUS_ON_ORDER); + $copy->edit_date('now'); + $copy->editor($e->requestor->id); + $e->update_asset_copy($copy) or return 0; + + if($lid->fund_debit) { + $lid->fund_debit->encumbrance('t'); + $e->update_acq_fund_debit($lid->fund_debit) or return 0; + } + + $mgr->add_lid; + return $lid; +} + # ---------------------------------------------------------------------------- # Lineitem Attr # ---------------------------------------------------------------------------- @@ -1296,11 +1345,11 @@ sub lineitem_detail_CUD_batch { __PACKAGE__->register_method( - method => 'receive_po', + method => 'receive_po_api', api_name => 'open-ils.acq.purchase_order.receive' ); -sub receive_po { +sub receive_po_api { my($self, $conn, $auth, $po_id) = @_; my $e = new_editor(xact => 1, authtoken => $auth); return $e->die_event unless $e->checkauth; @@ -1400,5 +1449,118 @@ sub receive_lineitem_api { } +__PACKAGE__->register_method( + method => 'rollback_receive_po_api', + api_name => 'open-ils.acq.purchase_order.receive.rollback' +); + +sub rollback_receive_po_api { + my($self, $conn, $auth, $po_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); + + my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->die_event; + return $e->die_event unless $e->allowed('RECEIVE_PURCHASE_ORDER', $po->ordering_agency); + + my $li_ids = $e->search_acq_lineitem({purchase_order => $po_id}, {idlist => 1}); + + for my $li_id (@$li_ids) { + rollback_receive_lineitem($mgr, $li_id) or return $e->die_event; + $mgr->respond; + } + + $po->state('on-order'); + update_purchase_order($mgr, $po) or return $e->die_event; + + $e->commit; + return $mgr->respond_complete; +} + + +__PACKAGE__->register_method( + method => 'rollback_receive_lineitem_detail_api', + api_name => 'open-ils.acq.lineitem_detail.receive.rollback', + signature => { + desc => 'Mark a lineitem_detail as received', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'lineitem detail ID', type => 'number'} + ], + return => {desc => '1 on success, Event on error'} + } +); + +sub rollback_receive_lineitem_detail_api { + my($self, $conn, $auth, $lid_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); + + my $lid = $e->retrieve_acq_lineitem_detail([ + $lid_id, { + flesh => 2, + flesh_fields => { + acqlid => ['lineitem'], + jub => ['purchase_order'] + } + } + ]); + my $li = $lid->lineitem; + my $po = $li->purchase_order; + + return $e->die_event unless $e->allowed('RECEIVE_PURCHASE_ORDER', $po->ordering_agency); + rollback_receive_lineitem_detail($mgr, $lid_id) or return $e->die_event; + + $li->state('on-order'); + $po->state('on-order'); + udpate_lineitem($mgr, $li) or return $e->die_event; + udpate_purchase_order($mgr, $po) or return $e->die_event; + + $e->commit; + return 1; +} + +__PACKAGE__->register_method( + method => 'rollback_receive_lineitem_api', + api_name => 'open-ils.acq.lineitem.receive.rollback', + signature => { + desc => 'Mark a lineitem as received', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'lineitem detail ID', type => 'number'} + ], + return => {desc => '1 on success, Event on error'} + } +); + +sub rollback_receive_lineitem_api { + my($self, $conn, $auth, $li_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); + + my $li = $e->retrieve_acq_lineitem_detail([ + $li_id, { + flesh => 1, + flesh_fields => { + jub => ['purchase_order'] + } + } + ]); + my $po = $li->purchase_order; + + return $e->die_event unless $e->allowed('RECEIVE_PURCHASE_ORDER', $po->ordering_agency); + + rollback_receive_lineitem($mgr, $li_id) or return $e->die_event; + + $po->state('on-order'); + update_purchase_order($mgr, $po) or return $e->die_event; + + $e->commit; + return 1; +} 1; diff --git a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js index 9f18e383b5..5a12092a1b 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -1,3 +1,4 @@ { - 'CREATE_PO_ASSETS_CONFIRM' : "This will create bibliographic, call number, and copy records for this purchase order in the ILS.\n\nContinue?" + 'CREATE_PO_ASSETS_CONFIRM' : "This will create bibliographic, call number, and copy records for this purchase order in the ILS.\n\nContinue?", + 'ROLLBACK_PO_RECEIVE_CONFIRM' : "This will rollback receipt of all copies for this purchase order.\n\nContinue?" } 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 9f88534f44..f8b760bc38 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 @@ -485,6 +485,10 @@ function AcqLiTable() { this.receivePO(); break; + case 'rollback_receive_po': + this.rollbackPoReceive(); + break; + case 'create_assets': this.createAssets(); break; @@ -544,6 +548,23 @@ function AcqLiTable() { ); } + this.rollbackPoReceive = function() { + if(!this.isPO) return; + if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return; + this.show('acq-lit-progress-numbers'); + var self = this; + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'], + { async: true, + params: [this.authtoken, this.isPO], + onresponse : function(r) { + var resp = openils.Util.readResponse(r); + self._updateProgressNumbers(resp, true); + }, + } + ); + } + this._updateProgressNumbers = function(resp, reloadOnComplete) { if(!resp) return; dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li; 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 caeee1647b..9288d4cb2f 100644 --- a/Open-ILS/web/templates/default/acq/common/li_table.tt2 +++ b/Open-ILS/web/templates/default/acq/common/li_table.tt2 @@ -18,6 +18,7 @@ + -- 2.11.0