[open-ils-commits] r16320 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/dojo/openils/acq/nls web/js/ui/default/acq/invoice web/templates/default/acq/invoice (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Apr 27 12:53:36 EDT 2010


Author: erickson
Date: 2010-04-27 12:53:33 -0400 (Tue, 27 Apr 2010)
New Revision: 16320

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
   trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
   trunk/Open-ILS/web/js/ui/default/acq/invoice/view.js
   trunk/Open-ILS/web/templates/default/acq/invoice/view.tt2
Log:
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

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm	2010-04-27 16:23:19 UTC (rev 16319)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm	2010-04-27 16:53:33 UTC (rev 16320)
@@ -618,9 +618,12 @@
 
 
 
+
+# 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.  

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-04-27 16:23:19 UTC (rev 16319)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-04-27 16:53:33 UTC (rev 16320)
@@ -644,7 +644,7 @@
 # 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 @@
     }
 
     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 @@
     $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 @@
         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,21 +1900,9 @@
     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;
+    my ($li, $evt) = fetch_and_check_li($e, $li_id, 'write');
+    return $evt if $evt;
 
-    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);
-    }
-
     $li->estimated_unit_price($price);
     update_lineitem($mgr, $li) or return $e->die_event;
 
@@ -2976,4 +2973,31 @@
     $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;

Modified: trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-04-27 16:23:19 UTC (rev 16319)
+++ trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-04-27 16:53:33 UTC (rev 16320)
@@ -67,6 +67,9 @@
             "<a style='padding-right: 10px;' href='${11}/acq/po/view/${12}'>PO#${13} ${18}</a>" +
             "<a style='padding-right: 10px;' href='${11}/acq/picklist/view/${14}'>${15}</a></div>",
     '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 <b>${0}</b> more copies than originally ordered.  <br/>The order will be updated to reflect the additional copies" +
+        "<br/><br/>After saving the invoice, you may finish editing and importing the new copies from the lineitem details page.",
+    //'INVOICE_EXTRA_COPIES_CATALOG' : "Add <b>${0}</b> 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.",

Modified: trunk/Open-ILS/web/js/ui/default/acq/invoice/view.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/invoice/view.js	2010-04-27 16:23:19 UTC (rev 16319)
+++ trunk/Open-ILS/web/js/ui/default/acq/invoice/view.js	2010-04-27 16:53:33 UTC (rev 16320)
@@ -32,6 +32,8 @@
 var invoicePane;
 var itemTypes;
 var virtualId = -1;
+var extraCopies = {};
+var extraCopiesFund;
 var widgetRegistry = {acqie : {}, acqii : {}};
 
 function nodeByName(name, context) {
@@ -60,6 +62,16 @@
             }
         );
     }
+
+    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 @@
                     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 saveChanges(doProrate, doClose, doReopen) {
+    createExtraCopies(
+        function() {
+            saveChangesPartTwo(doProrate, doClose, doReopen);
+        }
+    );
+}
+
+function saveChangesPartTwo(doProrate, doClose, doReopen) {
     
     progressDialog.show(true);
 
@@ -530,7 +565,67 @@
     );
 }
 
+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);
 
 

Modified: trunk/Open-ILS/web/templates/default/acq/invoice/view.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/invoice/view.tt2	2010-04-27 16:23:19 UTC (rev 16319)
+++ trunk/Open-ILS/web/templates/default/acq/invoice/view.tt2	2010-04-27 16:53:33 UTC (rev 16320)
@@ -127,4 +127,21 @@
     </div>
 </div>
 <div dojoType='openils.widget.ProgressDialog' jsId='progressDialog'/>
+<div jsId='extraItemsDialog' dojoType="dijit.Dialog" title="Extra Items">
+    <div dojoType="dijit.layout.ContentPane" style='text-align:center;'>
+        <div id='acq-invoice-extra-copies-message'></div>
+        <br/>
+        Select a fund for the new items: <div id='acq-invoice-extra-copies-fund'></div>
+        <br/><br/>
+        <!--
+        <span id='acq-invoice-extra-copies-add-msg'></span>
+        <input dojoType='dijit.form.CheckBox' jsId='extraCopiesInCatalogCheckbox'></input>
+        -->
+        <br/><br/>
+        <span style='padding-right: 10px;'>
+            <button dojoType='dijit.form.Button' jsId='extraCopiesCancel'>Cancel</button>
+        </span>
+        <button dojoType='dijit.form.Button' jsId='extraCopiesGo'>Continue</button>
+    </div>
+</div>
 [% END %]



More information about the open-ils-commits mailing list