From be624faec1be38cc614c12c2f72c2c2be0287315 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 9 Jul 2012 13:34:26 -0400 Subject: [PATCH] Attach multiple lineitems / POs to invoice Adds support to the Invoice interface for attaching multiple lineitems or POs via the existing attach_li and attach_po URL params. These can be used by other invoice create/link UIs for batch linking. Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/acq/invoice/view.js | 45 +++++++++++++++++--------- 1 file changed, 30 insertions(+), 15 deletions(-) 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 a326299e06..1be0afd9fe 100644 --- a/Open-ILS/web/js/ui/default/acq/invoice/view.js +++ b/Open-ILS/web/js/ui/default/acq/invoice/view.js @@ -42,8 +42,13 @@ function nodeByName(name, context) { function init() { - attachLi = cgi.param('attach_li'); - attachPo = cgi.param('attach_po'); + attachLi = cgi.param('attach_li') || []; + if (!dojo.isArray(attachLi)) + attachLi = [attachLi]; + + attachPo = cgi.param('attach_po') || []; + if (!dojo.isArray(attachPo)) + attachPo = [attachPo]; itemTypes = pcrud.retrieveAll('aiit'); @@ -78,7 +83,7 @@ function init() { function renderInvoice() { // in create mode, let the LI or PO render the invoice with seed data - if( !(cgi.param('create') && (attachPo || attachLi)) ) { + if( !(cgi.param('create') && (attachPo.length || attachLi.length)) ) { invoicePane = drawInvoicePane(dojo.byId('acq-view-invoice-div'), invoice); } @@ -125,8 +130,8 @@ function renderInvoice() { ); } - if(attachLi) doAttachLi(); - if(attachPo) doAttachPo(); + if(attachLi.length) doAttachLi(); + if(attachPo.length) doAttachPo(0); } function doAttachLi() { @@ -134,10 +139,11 @@ function doAttachLi() { //var invoiceArgs = {provider : lineitem.provider(), shipper : lineitem.provider()}; if(cgi.param('create')) { + // use the first LI in the list to determine the default provider fieldmapper.standardRequest( ['open-ils.acq', 'open-ils.acq.lineitem.retrieve.authoritative'], { - params : [openils.User.authtoken, attachLi, {clear_marc:1}], + params : [openils.User.authtoken, attachLi[0], {clear_marc:1}], oncomplete : function(r) { var li = openils.Util.readResponse(r); invoicePane = drawInvoicePane( @@ -149,27 +155,34 @@ function doAttachLi() { ); } - var entry = new fieldmapper.acqie(); - entry.id(virtualId--); - entry.isnew(true); - entry.lineitem(attachLi); - addInvoiceEntry(entry); + dojo.forEach(attachLi, + function(li) { + var entry = new fieldmapper.acqie(); + entry.id(virtualId--); + entry.isnew(true); + entry.lineitem(li); + addInvoiceEntry(entry); + } + ); } -function doAttachPo() { +function doAttachPo(idx) { + + if (idx == attachPo.length) return; + var poId = attachPo[idx]; fieldmapper.standardRequest( ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'], { async: true, params: [ - openils.User.authtoken, attachPo, + openils.User.authtoken, poId, {flesh_lineitem_ids : true, flesh_po_items : true} ], oncomplete: function(r) { var po = openils.Util.readResponse(r); - if(cgi.param('create')) { - // render the invoice using some seed data from the PO + if(cgi.param('create') && idx == 0) { + // render the invoice using some seed data from the first PO var invoiceArgs = {provider : po.provider(), shipper : po.provider()}; invoicePane = drawInvoicePane(dojo.byId('acq-view-invoice-div'), null, invoiceArgs); } @@ -200,6 +213,8 @@ function doAttachPo() { addInvoiceItem(item); } ); + + doAttachPo(++idx); } } ); -- 2.11.0