[open-ils-commits] r16396 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/ui/default/acq/common web/templates/default/acq/common (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu May 6 12:04:41 EDT 2010


Author: erickson
Date: 2010-05-06 12:04:38 -0400 (Thu, 06 May 2010)
New Revision: 16396

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
   trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
Log:
added batch lineitem fund updater from lineitem table ui

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-05-06 16:00:37 UTC (rev 16395)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-05-06 16:04:38 UTC (rev 16396)
@@ -1539,8 +1539,42 @@
 }
 
 
+
 __PACKAGE__->register_method(
-	method => 'lineitem_detail_CUD_batch',
+	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_api',
 	api_name => 'open-ils.acq.lineitem_detail.cud.batch',
     stream => 1,
 	signature => {
@@ -1556,7 +1590,7 @@
 );
 
 __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 @@
 );
 
 
-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 @@
         $li_cache{$lid->lineitem} = $li;
     }
 
-    $e->commit;
-    return $mgr->respond_complete;
+    return undef;
 }
 
 sub handle_changed_lid {

Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-05-06 16:00:37 UTC (rev 16395)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-05-06 16:04:38 UTC (rev 16396)
@@ -1895,6 +1895,10 @@
                 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 @@
                 };
                 break;
         }
-    }
+    };
 
     this.changeClaimPolicy = function(li_list, value, callback) {
         li_list.forEach(
@@ -2240,6 +2244,56 @@
         );
     }
 
+    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;

Modified: trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2010-05-06 16:00:37 UTC (rev 16395)
+++ trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2010-05-06 16:04:38 UTC (rev 16396)
@@ -21,6 +21,7 @@
                                             <option mask='*'  value='delete_selected'>Delete Selected Items</option>
                                             <option mask='*'  value='add_brief_record'>Add Brief Record</option>
                                             <option mask='*'  value='export_attr_list'>Export Single Attribute List</option>
+                                            <option mask='*'  value='batch_apply_funds'>Apply Funds to Selected Items</option>
                                             <option mask='po' value='' disabled='disabled'>----PO----</option>
                                             <option mask='sr|pl' value='create_order'>Create Purchase Order</option>
                                             <option mask='po' value='create_assets'>Load Bibs and Items</option>
@@ -395,6 +396,27 @@
         <div dojoType="dijit.Dialog" jsId="finalClaimDialog">
             [% INCLUDE "default/acq/common/final_claim_dialog.tt2" %]
         </div>
+        <div dojoType="dijit.Dialog" jsId="batchFundUpdateDialog" title="Batch Update Funds">
+            <div>
+                This will update the fund for all copies attached to these lineitems.<br/>
+                This will also update any existing encumbered or spent debits.
+            </div>
+            <br/>
+            <table class='oils-generic-table'>
+                <tr>
+                    <td>
+                        <span>Select a new fund:</span>
+                    </td>
+                    <td>
+                        <div id='acq-lit-batch-fund-selector'></div>
+                    </td>
+                </tr>
+                <tr>
+                    <td><button dojoType='dijit.form.Button' jsId='batchFundUpdateCancel'>Cancel</button></td>
+                    <td><button dojoType='dijit.form.Button' jsId='batchFundUpdateSubmit'>Submit</button></td>
+                </tr>
+            </table>
+        </div>
     </div>
 
     <div dojoType="dijit.Dialog" jsId='acqLitChangeLiStateDialog'>



More information about the open-ils-commits mailing list