[open-ils-commits] r16313 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq src/sql/Pg src/sql/Pg/upgrade web/css/skin/default web/js/dojo/openils/acq/nls web/templates/default/acq/search (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 26 15:58:08 EDT 2010


Author: senator
Date: 2010-04-26 15:58:03 -0400 (Mon, 26 Apr 2010)
New Revision: 16313

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0240.data.invoice_voucher.sql
Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
   trunk/Open-ILS/web/css/skin/default/acq.css
   trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
   trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
Log:
Acq: invoices are now printable from search results


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	2010-04-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	2010-04-26 19:58:03 UTC (rev 16313)
@@ -399,4 +399,49 @@
 }
 
 
+__PACKAGE__->register_method(
+    method      => "print_html_invoice",
+    api_name    => "open-ils.acq.invoice.print.html",
+    stream      => 1,
+    signature   => {
+        desc    => "Retrieve printable HTML vouchers for each given invoice",
+        params => [
+            {desc => "Authentication token", type => "string"},
+            {desc => "Invoice ID or a list of them", type => "mixed"},
+        ],
+        return => {
+            desc => q{One A/T event containing a printable HTML voucher for
+                each given invoice},
+            type => "object", class => "atev"}
+    }
+);
+
+
+sub print_html_invoice {
+    my ($self, $conn, $auth, $id_list) = @_;
+
+    my $e = new_editor("authtoken" => $auth);
+    return $e->die_event unless $e->checkauth;
+
+    $id_list = [$id_list] unless ref $id_list;
+
+    my $invoices = $e->search_acq_invoice({"id" => $id_list}) or
+        return $e->die_event;
+
+    foreach my $invoice (@$invoices) {
+        return $e->die_event unless
+            $e->allowed("VIEW_INVOICE", $invoice->receiver);
+
+        $conn->respond(
+            $U->fire_object_event(
+                undef, "format.acqinv.html", $invoice, $invoice->receiver,
+                "print-on-demand"
+            )
+        );
+    }
+
+    $e->disconnect;
+    undef;
+}
+
 1;

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-04-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-04-26 19:58:03 UTC (rev 16313)
@@ -60,7 +60,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0239'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0240'); -- senator
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,

Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql	2010-04-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql	2010-04-26 19:58:03 UTC (rev 16313)
@@ -3766,6 +3766,161 @@
     (21, 'type')
 ;
 
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+    VALUES (
+        'format.acqinv.html',
+        'acqinv',
+        'Formats invoices into a voucher',
+        TRUE
+    );
+
+INSERT INTO action_trigger.event_definition (
+        id, active, owner, name, hook,
+        validator, reactor, granularity, template
+    ) VALUES (
+        22,
+        TRUE,
+        1,
+        'Invoice',
+        'format.acqinv.html',
+        'NOOP_True',
+        'ProcessTemplate',
+        'print-on-demand',
+$$
+[% FILTER collapse %]
+[%- SET invoice = target -%]
+<!-- This lacks totals, info about funds (for invoice entries,
+    funds are per-LID!), and general refinement -->
+<div class="acq-invoice-voucher">
+    <h1>Invoice</h1>
+    <div>
+        <strong>No.</strong> [% invoice.inv_ident %]
+        [% IF invoice.inv_type %]
+            / <strong>Type:</strong>[% invoice.inv_type %]
+        [% END %]
+    </div>
+    <div>
+        <dl>
+            [% BLOCK ent_with_address %]
+            <dt>[% ent_label %]: [% ent.name %] ([% ent.code %])</dt>
+            <dd>
+                [% IF ent.addresses.0 %]
+                    [% SET addr = ent.addresses.0 %]
+                    [% addr.street1 %]<br />
+                    [% IF addr.street2 %][% addr.street2 %]<br />[% END %]
+                    [% addr.city %],
+                    [% IF addr.county %] [% addr.county %], [% END %]
+                    [% IF addr.state %] [% addr.state %] [% END %]
+                    [% IF addr.post_code %][% addr.post_code %][% END %]<br />
+                    [% IF addr.country %] [% addr.country %] [% END %]
+                [% END %]
+                <p>
+                    [% IF ent.phone %] Phone: [% ent.phone %]<br />[% END %]
+                    [% IF ent.fax_phone %] Fax: [% ent.fax_phone %]<br />[% END %]
+                    [% IF ent.url %] URL: [% ent.url %]<br />[% END %]
+                    [% IF ent.email %] E-mail: [% ent.email %] [% END %]
+                </p>
+            </dd>
+            [% END %]
+            [% INCLUDE ent_with_address
+                ent = invoice.provider
+                ent_label = "Provider" %]
+            [% INCLUDE ent_with_address
+                ent = invoice.shipper
+                ent_label = "Shipper" %]
+            <dt>Receiver</dt>
+            <dd>
+                [% invoice.receiver.name %] ([% invoice.receiver.shortname %])
+            </dd>
+            <dt>Received</dt>
+            <dd>
+                [% helpers.format_date(invoice.recv_date) %] by
+                [% invoice.recv_method %]
+            </dd>
+            [% IF invoice.note %]
+                <dt>Note</dt>
+                <dd>
+                    [% invoice.note %]
+                </dd>
+            [% END %]
+        </dl>
+    </div>
+    <ul>
+        [% FOR entry IN invoice.entries %]
+            <li>
+                [% IF entry.lineitem %]
+                    Title: [% helpers.get_li_attr(
+                        "title", "", entry.lineitem.attributes
+                    ) %]<br />
+                    Author: [% helpers.get_li_attr(
+                        "author", "", entry.lineitem.attributes
+                    ) %]
+                [% END %]
+                [% IF entry.purchase_order %]
+                    (PO: [% entry.purchase_order.name %])
+                [% END %]<br />
+                Invoice item count: [% entry.inv_item_count %]
+                [% IF entry.phys_item_count %]
+                    / Physical item count: [% entry.phys_item_count %]
+                [% END %]
+                <br />
+                [% IF entry.cost_billed %]
+                    Cost billed: [% entry.cost_billed %]
+                    [% IF entry.billed_per_item %](per item)[% END %]
+                    <br />
+                [% END %]
+                [% IF entry.actual_cost %]
+                    Actual cost: [% entry.actual_cost %]<br />
+                [% END %]
+                [% IF entry.amount_paid %]
+                    Amount paid: [% entry.amount_paid %]<br />
+                [% END %]
+                [% IF entry.note %]Note: [% entry.note %][% END %]
+            </li>
+        [% END %]
+        [% FOR item IN invoice.items %]
+            <li>
+                [% IF item.inv_item_type %]
+                    Item Type: [% item.inv_item_type %]<br />
+                [% END %]
+                [% IF item.title %]Title/Description:
+                    [% item.title %]<br />
+                [% END %]
+                [% IF item.author %]Author: [% item.author %]<br />[% END %]
+                [% IF item.purchase_order %]PO: [% item.purchase_order %]<br />[% END %]
+                [% IF item.note %]Note: [% item.note %]<br />[% END %]
+                [% IF item.cost_billed %]
+                    Cost billed: [% item.cost_billed %]<br />
+                [% END %]
+                [% IF item.actual_cost %]
+                    Actual cost: [% item.actual_cost %]<br />
+                [% END %]
+                [% IF item.amount_paid %]
+                    Amount paid: [% item.amount_paid %]<br />
+                [% END %]
+            </li>
+        [% END %]
+    </ul>
+</div>
+[% END %]
+$$
+);
+
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (22, 'provider'),
+    (22, 'provider.addresses'),
+    (22, 'shipper'),
+    (22, 'shipper.addresses'),
+    (22, 'receiver'),
+    (22, 'entries'),
+    (22, 'entries.purchase_order'),
+    (22, 'entries.lineitem'),
+    (22, 'entries.lineitem.attributes'),
+    (22, 'items')
+;
+
 SELECT SETVAL('action_trigger.event_definition_id_seq'::TEXT, 100);
 
 -- Org Unit Settings for configuring org unit weights and org unit max-loops for hold targeting

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0240.data.invoice_voucher.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0240.data.invoice_voucher.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0240.data.invoice_voucher.sql	2010-04-26 19:58:03 UTC (rev 16313)
@@ -0,0 +1,159 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0240'); -- senator
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+    VALUES (
+        'format.acqinv.html',
+        'acqinv',
+        'Formats invoices into a voucher',
+        TRUE
+    );
+
+INSERT INTO action_trigger.event_definition (
+        id, active, owner, name, hook,
+        validator, reactor, granularity, template
+    ) VALUES (
+        22,
+        TRUE,
+        1,
+        'Invoice',
+        'format.acqinv.html',
+        'NOOP_True',
+        'ProcessTemplate',
+        'print-on-demand',
+$$
+[% FILTER collapse %]
+[%- SET invoice = target -%]
+<!-- This lacks totals, info about funds (for invoice entries,
+    funds are per-LID!), and general refinement -->
+<div class="acq-invoice-voucher">
+    <h1>Invoice</h1>
+    <div>
+        <strong>No.</strong> [% invoice.inv_ident %]
+        [% IF invoice.inv_type %]
+            / <strong>Type:</strong>[% invoice.inv_type %]
+        [% END %]
+    </div>
+    <div>
+        <dl>
+            [% BLOCK ent_with_address %]
+            <dt>[% ent_label %]: [% ent.name %] ([% ent.code %])</dt>
+            <dd>
+                [% IF ent.addresses.0 %]
+                    [% SET addr = ent.addresses.0 %]
+                    [% addr.street1 %]<br />
+                    [% IF addr.street2 %][% addr.street2 %]<br />[% END %]
+                    [% addr.city %],
+                    [% IF addr.county %] [% addr.county %], [% END %]
+                    [% IF addr.state %] [% addr.state %] [% END %]
+                    [% IF addr.post_code %][% addr.post_code %][% END %]<br />
+                    [% IF addr.country %] [% addr.country %] [% END %]
+                [% END %]
+                <p>
+                    [% IF ent.phone %] Phone: [% ent.phone %]<br />[% END %]
+                    [% IF ent.fax_phone %] Fax: [% ent.fax_phone %]<br />[% END %]
+                    [% IF ent.url %] URL: [% ent.url %]<br />[% END %]
+                    [% IF ent.email %] E-mail: [% ent.email %] [% END %]
+                </p>
+            </dd>
+            [% END %]
+            [% INCLUDE ent_with_address
+                ent = invoice.provider
+                ent_label = "Provider" %]
+            [% INCLUDE ent_with_address
+                ent = invoice.shipper
+                ent_label = "Shipper" %]
+            <dt>Receiver</dt>
+            <dd>
+                [% invoice.receiver.name %] ([% invoice.receiver.shortname %])
+            </dd>
+            <dt>Received</dt>
+            <dd>
+                [% helpers.format_date(invoice.recv_date) %] by
+                [% invoice.recv_method %]
+            </dd>
+            [% IF invoice.note %]
+                <dt>Note</dt>
+                <dd>
+                    [% invoice.note %]
+                </dd>
+            [% END %]
+        </dl>
+    </div>
+    <ul>
+        [% FOR entry IN invoice.entries %]
+            <li>
+                [% IF entry.lineitem %]
+                    Title: [% helpers.get_li_attr(
+                        "title", "", entry.lineitem.attributes
+                    ) %]<br />
+                    Author: [% helpers.get_li_attr(
+                        "author", "", entry.lineitem.attributes
+                    ) %]
+                [% END %]
+                [% IF entry.purchase_order %]
+                    (PO: [% entry.purchase_order.name %])
+                [% END %]<br />
+                Invoice item count: [% entry.inv_item_count %]
+                [% IF entry.phys_item_count %]
+                    / Physical item count: [% entry.phys_item_count %]
+                [% END %]
+                <br />
+                [% IF entry.cost_billed %]
+                    Cost billed: [% entry.cost_billed %]
+                    [% IF entry.billed_per_item %](per item)[% END %]
+                    <br />
+                [% END %]
+                [% IF entry.actual_cost %]
+                    Actual cost: [% entry.actual_cost %]<br />
+                [% END %]
+                [% IF entry.amount_paid %]
+                    Amount paid: [% entry.amount_paid %]<br />
+                [% END %]
+                [% IF entry.note %]Note: [% entry.note %][% END %]
+            </li>
+        [% END %]
+        [% FOR item IN invoice.items %]
+            <li>
+                [% IF item.inv_item_type %]
+                    Item Type: [% item.inv_item_type %]<br />
+                [% END %]
+                [% IF item.title %]Title/Description:
+                    [% item.title %]<br />
+                [% END %]
+                [% IF item.author %]Author: [% item.author %]<br />[% END %]
+                [% IF item.purchase_order %]PO: [% item.purchase_order %]<br />[% END %]
+                [% IF item.note %]Note: [% item.note %]<br />[% END %]
+                [% IF item.cost_billed %]
+                    Cost billed: [% item.cost_billed %]<br />
+                [% END %]
+                [% IF item.actual_cost %]
+                    Actual cost: [% item.actual_cost %]<br />
+                [% END %]
+                [% IF item.amount_paid %]
+                    Amount paid: [% item.amount_paid %]<br />
+                [% END %]
+            </li>
+        [% END %]
+    </ul>
+</div>
+[% END %]
+$$
+);
+
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (22, 'provider'),
+    (22, 'provider.addresses'),
+    (22, 'shipper'),
+    (22, 'shipper.addresses'),
+    (22, 'receiver'),
+    (22, 'entries'),
+    (22, 'entries.purchase_order'),
+    (22, 'entries.lineitem'),
+    (22, 'entries.lineitem.attributes'),
+    (22, 'items')
+;
+
+COMMIT;

Modified: trunk/Open-ILS/web/css/skin/default/acq.css
===================================================================
--- trunk/Open-ILS/web/css/skin/default/acq.css	2010-04-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/web/css/skin/default/acq.css	2010-04-26 19:58:03 UTC (rev 16313)
@@ -230,6 +230,7 @@
 .acq-unified-terms-match { width: 15%; }
 .acq-unified-terms-remove { width: 5%; text-align: right; }
 .acq-unified-remover { color: #c00; }
+.acq-unified-result-specific-controls { margin-bottom: 8px; }
 
 #acq-eligible-li-table { margin: 10px 0; }
 #acq-eligible-li-table th { background-color: #ccc; border: 1px #333 inset; font-weight: bold; padding: 6px; }

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-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-04-26 19:58:03 UTC (rev 16313)
@@ -75,5 +75,6 @@
     'CANCELED': "Canceled",
     'RECVD': "Recv'd",
     'NOT_RECVD': "Not recv'd",
-    'PRINT': "Print"
+    'PRINT': "Print",
+    'INVOICES': "Invoices"
 }

Modified: trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-04-26 19:47:47 UTC (rev 16312)
+++ trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-04-26 19:58:03 UTC (rev 16313)
@@ -5,8 +5,9 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/acq/search/unified.js">
 </script>
 <script>
-    /* The only functions in this <script> element are for
-     * formatting/getting fields for autogrids. */
+    /* The functions in this <script> element are for formatting/getting
+        fields for autogrids, and doing misc operations on specific
+        result types. General unified search code is in unified.js. */
     function getName(rowIndex, item) {
         if (item) {
             return {
@@ -56,6 +57,45 @@
                 inv.id + "'>" + inv.inv_ident + "</a>";
         }
     }
+
+    /* XXX consider separate per-result-type .js files to separate functions
+     * like these into */
+    function printInvoiceVouchers() {
+        var inv_ids = dijit.byId("acq-unified-inv-grid").
+            getSelectedItems().map(function(o) {return o.id[0];});
+
+        /* XXX this business about opening a window and populating its
+         * body should be wrapped up in a simple dijit or something.
+         * consolidate with claim_voucher.js maybe. */
+        if (inv_ids.length) {
+            var win = null;
+            fieldmapper.standardRequest(
+                ["open-ils.acq", "open-ils.acq.invoice.print.html"], {
+                    "params": [openils.User.authtoken, inv_ids],
+                    "async": true,
+                    "onresponse": function(r) {
+                        if (r = openils.Util.readResponse(r)) {
+                            if (!win) {
+                                win = window.open(
+                                    "", "", "resizable,width=800," +
+                                    "height=600,scrollbars=1"
+                                );
+                                win.document.title = localeStrings.INVOICES;
+                                win.document.body.innerHTML =
+                                    "<style type='text/css'>.acq-invoice-" +
+                                    "voucher {page-break-after:always;}" +
+                                    "</style>\n";
+                            }
+                            win.document.body.innerHTML +=
+                                r.template_output().data();
+                        }
+                    },
+                    "oncomplete": function() { win.print(); }
+                }
+            );
+        }
+    }
+
 </script>
 <!-- later: "[% ctx.page_args.0 %]" -->
 <div id="acq-unified-body" class="hidden">
@@ -187,6 +227,11 @@
         </table>
     </div>
     <div id="acq-unified-results-invoice" class="hidden">
+        <div class="acq-unified-result-specific-controls">
+            <button onclick="printInvoiceVouchers();">
+                Print Selected Invoices
+            </button>
+        </div>
         <table
             id="acq-unified-inv-grid"
             autoHeight="true"



More information about the open-ils-commits mailing list