From 7c4b832bbf08bc23c10ce24038eb932119edc378 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 27 Apr 2010 16:53:33 +0000 Subject: [PATCH] Added support to invoice page for adding extra copies to an invoice than were ordered. The process creates new lineitem details and fund debits to accommodate the new copies. Fixed some typos TODO: update the li summary blob to treat the li title/author as a link to the details page for the lineitem git-svn-id: svn://svn.open-ils.org/ILS/trunk@16320 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Lineitem.pm | 5 +- .../src/perlmods/OpenILS/Application/Acq/Order.pm | 68 ++++++++++----- Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 + Open-ILS/web/js/ui/default/acq/invoice/view.js | 97 +++++++++++++++++++++- .../web/templates/default/acq/invoice/view.tt2 | 17 ++++ 5 files changed, 166 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm index c504769a3c..5cde9d7174 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm @@ -618,9 +618,12 @@ sub lineitem_search_ident { + +# this call duplicates a call in Order.pm and makes references to subs that don't exist. +# TODO: Verify then remove. __PACKAGE__->register_method( method => 'lineitem_detail_CUD_batch', - api_name => 'open-ils.acq.lineitem_detail.cud.batch', + api_name => 'open-ils.acq.lineitem_detail.cud.batch_', stream => 1, signature => { desc => q/Creates a new purchase order line item detail. diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index 1be5e37eba..b51bb75ff7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -644,7 +644,7 @@ sub create_lineitem_debits { # flesh li->provider # flesh lid->fund sub create_lineitem_detail_debit { - my ($mgr, $li, $lid, $dry_run) = @_; + my ($mgr, $li, $lid, $dry_run, $no_translate) = @_; my $li_id = ref($li) ? $li->id : $li; @@ -667,7 +667,7 @@ sub create_lineitem_detail_debit { } my $amount = $li->estimated_unit_price; - if($li->provider->currency_type ne $lid->fund->currency_type) { + if($li->provider->currency_type ne $lid->fund->currency_type and !$no_translate) { # At Fund debit creation time, translate into the currency of the fund # TODO: org setting to disable automatic currency conversion at debit create time? @@ -1034,7 +1034,7 @@ sub create_copy { $copy->isnew(1); $copy->loan_duration(2); $copy->fine_level(2); - $copy->status(OILS_COPY_STATUS_ON_ORDER); + $copy->status(($lid->recv_time) ? OILS_COPY_STATUS_IN_PROCESS : OILS_COPY_STATUS_ON_ORDER); $copy->barcode($lid->barcode); $copy->location($lid->location); $copy->call_number($volume->id); @@ -1546,30 +1546,39 @@ __PACKAGE__->register_method( params => [ {desc => 'Authentication token', type => 'string'}, {desc => 'List of lineitem_details to create', type => 'array'}, + {desc => 'Create Debits. Used for creating post-po-asset-creation debits', type => 'bool'}, ], return => {desc => 'Streaming response of current position in the array'} } ); sub lineitem_detail_CUD_batch { - my($self, $conn, $auth, $li_details) = @_; + 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); - # XXX perms - $mgr->total(scalar(@$li_details)); + my $li; my %li_cache; + my $evt; for my $lid (@$li_details) { - my $li = $li_cache{$lid->lineitem} || $e->retrieve_acq_lineitem($lid->lineitem); + unless($li = $li_cache{$lid->lineitem}) { + ($li, $evt) = fetch_and_check_li($e, $lid->lineitem, 'write'); + return $evt if $evt; + } if($lid->isnew) { - create_lineitem_detail($mgr, %{$lid->to_bare_hash}) or return $e->die_event; + $lid = create_lineitem_detail($mgr, %{$lid->to_bare_hash}) or return $e->die_event; + if($create_debits) { + $li->provider($e->retrieve_acq_provider($li->provider)) or return $e->die_event; + $lid->fund($e->retrieve_acq_fund($lid->fund)) or return $e->die_event; + create_lineitem_detail_debit($mgr, $li, $lid, 0, 1) or return $e->die_event; + } } elsif($lid->ischanged) { $e->update_acq_lineitem_detail($lid) or return $e->die_event; @@ -1891,20 +1900,8 @@ sub set_lineitem_price_api { return $e->die_event unless $e->checkauth; my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn); - my $li = $e->retrieve_acq_lineitem([ - $li_id, - { flesh => 1, - flesh_fields => {jub => ['purchase_order', 'picklist']} - } - ]) or return $e->die_event; - - if($li->purchase_order) { - return $e->die_event unless - $e->allowed('CREATE_PURCHASE_ORDER', $li->purchase_order->ordering_agency); - } else { - return $e->die_event unless - $e->allowed('CREATE_PICKLIST', $li->picklist->org_unit); - } + my ($li, $evt) = fetch_and_check_li($e, $li_id, 'write'); + return $evt if $evt; $li->estimated_unit_price($price); update_lineitem($mgr, $li) or return $e->die_event; @@ -2976,4 +2973,31 @@ sub po_note_CUD_batch { $e->commit and $conn->respond_complete or return $e->die_event; } + +# retrieves a lineitem, fleshes its PO and PL, checks perms +sub fetch_and_check_li { + my $e = shift; + my $li_id = shift; + my $perm_mode = shift || 'read'; + + my $li = $e->retrieve_acq_lineitem([ + $li_id, + { flesh => 1, + flesh_fields => {jub => ['purchase_order', 'picklist']} + } + ]) or return $e->die_event; + + if(my $po = $li->purchase_order) { + my $perms = ($perm_mode eq 'read') ? 'VIEW_PURCHASE_ORDER' : 'CREATE_PURCHASE_ORDER'; + return ($li, $e->die_event) unless $e->allowed($perms, $po->ordering_agency); + + } elsif(my $li = $li->picklist) { + my $perms = ($perm_mode eq 'read') ? 'VIEW_PICKLIST' : 'CREATE_PICKLIST'; + return ($li, $e->die_event) unless $e->allowed($perms, $li->picklist->org_unit); + } + + return ($li); +} + + 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 3471092c12..c1a53365fc 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -67,6 +67,9 @@ "PO#${13} ${18}" + "${15}", 'INVOICE_CONFIRM_PRORATE' : "Prorate charges?\n\nAny subsequent changes to the invoice that would affect prorated amounts should be resolved manually.", + 'INVOICE_EXTRA_COPIES' : "You are invoicing ${0} more copies than originally ordered.
The order will be updated to reflect the additional copies" + + "

After saving the invoice, you may finish editing and importing the new copies from the lineitem details page.", + //'INVOICE_EXTRA_COPIES_CATALOG' : "Add ${0} new copies to the catalog?", 'UNNAMED': "Unnamed", 'NO_FIND_INVOICE': "Could not find that invoice.\nNote that the Invoice # field is case-sensitive.", 'NO_LI_TO_CLAIM': "You have not selected any lineitems to claim.", diff --git a/Open-ILS/web/js/ui/default/acq/invoice/view.js b/Open-ILS/web/js/ui/default/acq/invoice/view.js index b80c207d93..abe6824fb4 100644 --- a/Open-ILS/web/js/ui/default/acq/invoice/view.js +++ b/Open-ILS/web/js/ui/default/acq/invoice/view.js @@ -32,6 +32,8 @@ var balanceOwedBox; var invoicePane; var itemTypes; var virtualId = -1; +var extraCopies = {}; +var extraCopiesFund; var widgetRegistry = {acqie : {}, acqii : {}}; function nodeByName(name, context) { @@ -60,6 +62,16 @@ function init() { } ); } + + extraCopiesFund = new openils.widget.AutoFieldWidget({ + fmField : 'fund', + fmClass : 'acqlid', + searchFilter : {active : 't'}, + labelFormat : fundLabelFormat, + searchFormat : fundSearchFormat, + parentNode : dojo.byId('acq-invoice-extra-copies-fund') + }); + extraCopiesFund.build(); } function renderInvoice() { @@ -385,7 +397,22 @@ function addInvoiceEntry(entry) { dijitArgs : dijitArgs, readOnly : invoice && openils.Util.isTrue(invoice.complete()), parentNode : nodeByName(field, row) - }) + }), + function(w) { + if(field == 'phys_item_count') { + dojo.connect(w, 'onChange', + function() { + // staff entered a higher number in the receive field than was originally ordered + if(Number(this.attr('value')) > entry.lineitem().item_count()) { + storeExtraCopies( + entry.lineitem().id(), + Number(this.attr('value')) - entry.lineitem().item_count() + ); + } + } + ) + } + } ); } ); @@ -425,6 +452,14 @@ function liMarcAttr(lineitem, name) { } function saveChanges(doProrate, doClose, doReopen) { + createExtraCopies( + function() { + saveChangesPartTwo(doProrate, doClose, doReopen); + } + ); +} + +function saveChangesPartTwo(doProrate, doClose, doReopen) { progressDialog.show(true); @@ -530,6 +565,66 @@ function prorateInvoice(invoice) { ); } +function storeExtraCopies(liId, numExtra) { + + dojo.byId('acq-invoice-extra-copies-message').innerHTML = + dojo.string.substitute( + localeStrings.INVOICE_EXTRA_COPIES, [numExtra]); + + var addCopyHandler; + addCopyHandler = dojo.connect( + extraCopiesGo, + 'onClick', + function() { + extraCopies[liId] = { + numExtra : numExtra, + fund : extraCopiesFund.widget.attr('value') + } + extraItemsDialog.hide(); + dojo.disconnect(addCopyHandler); + } + ); + + dojo.connect( + extraCopiesCancel, + 'onClick', + function() { extraItemsDialog.hide() } + ); + + extraItemsDialog.show(); +} + +function createExtraCopies(oncomplete) { + + var lids = []; + for(var liId in extraCopies) { + var data = extraCopies[liId]; + for(var i = 0; i < data.numExtra; i++) { + var lid = new fieldmapper.acqlid(); + lid.isnew(true); + lid.lineitem(liId); + lid.fund(data.fund); + lid.recv_time('now'); + lids.push(lid); + } + } + + if(lids.length == 0) + return oncomplete(); + + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'], + { + params : [openils.User.authtoken, lids, true], + oncomplete : function(r) { + if(openils.Util.readResponse(r)) + oncomplete(); + } + } + ); + +} + openils.Util.addOnLoad(init); diff --git a/Open-ILS/web/templates/default/acq/invoice/view.tt2 b/Open-ILS/web/templates/default/acq/invoice/view.tt2 index 6a8308787a..c269675d72 100644 --- a/Open-ILS/web/templates/default/acq/invoice/view.tt2 +++ b/Open-ILS/web/templates/default/acq/invoice/view.tt2 @@ -127,4 +127,21 @@
+
+
+
+
+ Select a fund for the new items:
+

+ +

+ + + + +
+
[% END %] -- 2.11.0