From 2fa555d30fac179f8ac1255b6021652b6902ca97 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 1 Oct 2012 13:53:27 -0400 Subject: [PATCH] Acq: When creating invoices, let the user know if they're repeating an ID Invoices have a field for Vendor Invoice ID, which is required to be unique for invoices associated with a given provider (vendor). In practice users may mistakenly try to create an invoice more than once, so this gives them an indication that a given Vnedor Invoice ID has already been used before they fill out the whole invoice. Users do have to have the fields labeled "Vendor Invoice ID", "Provider", and "Receiver" filled out before validation can occur (the last field is needed because of how permissions are checked when searching for invoices). It is still possible to see a database error at save time if another invoice is created between the time you started yours and the time somebody else saved theirs. Also, while we're at it, this commit gets rid of acq/invoice/common.js and moves its last function into acq/invoice/view.js, since both are actually used only by the one interface. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Kathy Lussier --- Open-ILS/src/templates/acq/invoice/view.tt2 | 2 +- Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 +- Open-ILS/web/js/dojo/openils/widget/EditPane.js | 6 ++ Open-ILS/web/js/ui/default/acq/invoice/common.js | 75 ------------- Open-ILS/web/js/ui/default/acq/invoice/view.js | 128 +++++++++++++++++++++++ 5 files changed, 137 insertions(+), 77 deletions(-) delete mode 100644 Open-ILS/web/js/ui/default/acq/invoice/common.js diff --git a/Open-ILS/src/templates/acq/invoice/view.tt2 b/Open-ILS/src/templates/acq/invoice/view.tt2 index a4a60fb8e4..a54621abf5 100644 --- a/Open-ILS/src/templates/acq/invoice/view.tt2 +++ b/Open-ILS/src/templates/acq/invoice/view.tt2 @@ -34,6 +34,7 @@
+
@@ -326,6 +327,5 @@ - [% END %] 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 f323a0ef34..fd7949ff84 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -86,5 +86,6 @@ "INVOICE_NUMBER": "Invoice #${0}", "COPIES_TO_RECEIVE": "Number of copies to receive: ", "CREATE_PO_INVALID": "A purchase order must have an ordering agency and a provider.", - "INVOICE_COPY_COUNT_INFO": "Copies received on this invoice: ${0} out of ${1}." + "INVOICE_COPY_COUNT_INFO": "Copies received on this invoice: ${0} out of ${1}.", + "INVOICE_IDENT_COLLIDE": "There is already an invoice in the system with the given combination of 'Vendor Invoice ID' and 'Provider,' which is not allowed." } diff --git a/Open-ILS/web/js/dojo/openils/widget/EditPane.js b/Open-ILS/web/js/dojo/openils/widget/EditPane.js index 6876dd3b69..5bde239237 100644 --- a/Open-ILS/web/js/dojo/openils/widget/EditPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/EditPane.js @@ -237,6 +237,12 @@ if(!dojo._hasResource['openils.widget.EditPane']) { } }, + getFieldWidget : function(field) { + for (var i in this.fieldList) + if (field == this.fieldList[i].name) + return this.fieldList[i].widget; + }, + setFieldValue : function(field, val) { for(var i in this.fieldList) { if(field == this.fieldList[i].name) { diff --git a/Open-ILS/web/js/ui/default/acq/invoice/common.js b/Open-ILS/web/js/ui/default/acq/invoice/common.js deleted file mode 100644 index 0980fca978..0000000000 --- a/Open-ILS/web/js/ui/default/acq/invoice/common.js +++ /dev/null @@ -1,75 +0,0 @@ -dojo.require('dojo.date.stamp'); -dojo.require('openils.User'); -dojo.require('openils.widget.EditPane'); - -function drawInvoicePane(parentNode, inv, args) { - args = args || {}; - var pane; - - var override = {}; - if(!inv) { - override = { - recv_date : {widgetValue : dojo.date.stamp.toISOString(new Date())}, - //receiver : {widgetValue : openils.User.user.ws_ou()}, - recv_method : {widgetValue : 'PPR'} - }; - } - - dojo.mixin(override, { - provider : { - dijitArgs : { - store_options : { base_filter : { active :"t" } }, - onChange : function(val) { - pane.setFieldValue('shipper', val); - } - } - }, - shipper : { dijitArgs : { store_options : { base_filter : { active :"t" } } } } - }); - - for(var field in args) { - override[field] = {widgetValue : args[field]}; - } - - // push the name of the invoice into the name display field after update - override.inv_ident = dojo.mixin( - override.inv_ident, - {dijitArgs : {onChange : - function(newVal) { - if (dojo.byId('acq-invoice-summary-name')) - dojo.byId('acq-invoice-summary-name').innerHTML = newVal; - } - }} - ); - - - pane = new openils.widget.EditPane({ - fmObject : inv, - paneStackCount : 2, - fmClass : 'acqinv', - mode : (inv) ? 'edit' : 'create', - hideActionButtons : true, - overrideWidgetArgs : override, - readOnly : (inv) && openils.Util.isTrue(inv.complete()), - requiredFields : [ - 'inv_ident', - 'recv_date', - 'provider', - 'shipper' - ], - fieldOrder : [ - 'inv_ident', - 'recv_date', - 'recv_method', - 'inv_type', - 'provider', - 'shipper' - ], - suppressFields : ['id', 'complete'] - }); - - pane.startup(); - parentNode.appendChild(pane.domNode); - return pane; -} - 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 2036f6f5ff..6c306dba5c 100644 --- a/Open-ILS/web/js/ui/default/acq/invoice/view.js +++ b/Open-ILS/web/js/ui/default/acq/invoice/view.js @@ -1022,6 +1022,134 @@ function storeExtraCopies(entry, numExtra) { extraItemsDialog.show(); } +function validateInvIdent(inv_ident, provider, receiver) { + if (!(inv_ident && provider && receiver)) { + console.info("not enough information to pre-validate inv_ident"); + return; + } + + openils.Util.show("ident-validation-spinner", "inline"); + var pcrud = new openils.PermaCrud(); + pcrud.search( + "acqinv", {"inv_ident": inv_ident, "provider": provider}, { + "oncomplete": function(r) { + openils.Util.hide("ident-validation-spinner"); + + /* This could throw an event about the user not having perms, + * but in such a case the whole interface is already busted + * anyway. */ + r = openils.Util.readResponse(r); + + var w = invoicePane.getFieldWidget("inv_ident").widget; + if (r.length) { + alert(localeStrings.INVOICE_IDENT_COLLIDE); + w.validator = function() { return false; }; + w.validate(); + } else { + w.validator = function() { return true; }; + w.validate(); + } + w.focus(); + pcrud.disconnect(); + } + } + ); +} + +function drawInvoicePane(parentNode, inv, args) { + args = args || {}; + var pane; + + var override = {}; + if(!inv) { + override = { + recv_date : {widgetValue : dojo.date.stamp.toISOString(new Date())}, + //receiver : {widgetValue : openils.User.user.ws_ou()}, + receiver : { + "dijitArgs": { + "onChange": function(val) { + validateInvIdent( + invoicePane && invoicePane.getFieldValue("inv_ident"), + invoicePane && invoicePane.getFieldValue("provider"), + val + ); + } + } + }, + recv_method : {widgetValue : 'PPR'} + }; + } + + dojo.mixin(override, { + provider : { + dijitArgs : { + store_options : { base_filter : { active :"t" } }, + onChange : function(val) { + pane.setFieldValue('shipper', val); + validateInvIdent( + invoicePane && invoicePane.getFieldValue("inv_ident"), + val, + invoicePane && invoicePane.getFieldValue("receiver") + ); + } + } + }, + shipper : { dijitArgs : { store_options : { base_filter : { active :"t" } } } } + }); + + for(var field in args) { + override[field] = {widgetValue : args[field]}; + } + + // push the name of the invoice into the name display field after update + override.inv_ident = dojo.mixin( + override.inv_ident, + {dijitArgs : {onChange : + function(newVal) { + validateInvIdent( + newVal, + invoicePane && invoicePane.getFieldValue("provider"), + invoicePane && invoicePane.getFieldValue("receiver") + ); + + if (dojo.byId('acq-invoice-summary-name')) + dojo.byId('acq-invoice-summary-name').innerHTML = newVal; + } + }} + ); + + + pane = new openils.widget.EditPane({ + fmObject : inv, + paneStackCount : 2, + fmClass : 'acqinv', + mode : (inv) ? 'edit' : 'create', + hideActionButtons : true, + overrideWidgetArgs : override, + readOnly : (inv) && openils.Util.isTrue(inv.complete()), + requiredFields : [ + 'inv_ident', + 'recv_date', + 'provider', + 'shipper' + ], + fieldOrder : [ + 'inv_ident', + 'recv_date', + 'recv_method', + 'inv_type', + 'provider', + 'shipper' + ], + suppressFields : ['id', 'complete'] + }); + + pane.startup(); + parentNode.appendChild(pane.domNode); + return pane; +} + + function createExtraCopies(oncomplete) { var lids = []; -- 2.11.0