[open-ils-commits] r18584 - in branches/rel_2_0/Open-ILS/src: perlmods/OpenILS/Application/Acq sql/Pg sql/Pg/upgrade (senator)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Nov 2 12:28:36 EDT 2010
Author: senator
Date: 2010-11-02 12:28:33 -0400 (Tue, 02 Nov 2010)
New Revision: 18584
Added:
branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0457.data.acqinv.print.sql
Modified:
branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
Backport r18583 from trunk, fund totals on an invoice voucher
Modified: branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
===================================================================
--- branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm 2010-11-02 16:27:23 UTC (rev 18583)
+++ branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm 2010-11-02 16:28:33 UTC (rev 18584)
@@ -233,7 +233,45 @@
return $entry->amount_paid / $entry->phys_item_count;
}
+sub easy_money { # TODO XXX replace with something from a library
+ my ($val) = @_;
+ my $rounded = int($val * 100) / 100.0;
+ if ($rounded == $val) {
+ return sprintf("%.02f", $val);
+ } else {
+ return sprintf("%g", $val);
+ }
+}
+
+# 0 on failure (caller should call $e->die_event), array on success
+sub amounts_spent_per_fund {
+ my ($e, $inv_id) = @_;
+
+ my $entries = $e->search_acq_invoice_entry({"invoice" => $inv_id}) or
+ return 0;
+
+ my %totals_by_fund;
+ foreach my $entry (@$entries) {
+ my $debits = find_entry_debits($e, $entry, "f") or return 0;
+ foreach (@$debits) {
+ $totals_by_fund{$_->fund} ||= 0.0;
+ $totals_by_fund{$_->fund} += $_->amount;
+ }
+ }
+
+ my @totals;
+ foreach my $fund_id (keys %totals_by_fund) {
+ my $fund = $e->retrieve_acq_fund($fund_id) or return 0;
+ push @totals, {
+ "fund" => $fund->to_bare_hash,
+ "total" => easy_money($totals_by_fund{$fund_id})
+ };
+ }
+
+ return \@totals;
+}
+
# there is no direct link between invoice_entry and fund debits.
# when we need to retrieve the related debits, we have to do some searching
sub find_entry_debits {
@@ -496,10 +534,13 @@
return $e->die_event unless
$e->allowed("VIEW_INVOICE", $invoice->receiver);
+ my $amounts = amounts_spent_per_fund($e, $invoice->id) or
+ return $e->die_event;
+
$conn->respond(
$U->fire_object_event(
undef, "format.acqinv.html", $invoice, $invoice->receiver,
- "print-on-demand"
+ "print-on-demand", $amounts
)
);
}
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-11-02 16:27:23 UTC (rev 18583)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-11-02 16:28:33 UTC (rev 18584)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0456'); -- gmc
+INSERT INTO config.upgrade_log (version) VALUES ('0457'); -- senator
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-11-02 16:27:23 UTC (rev 18583)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-11-02 16:28:33 UTC (rev 18584)
@@ -4565,10 +4565,8 @@
'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 -->
+<!-- This lacks general refinement -->
<div class="acq-invoice-voucher">
<h1>Invoice</h1>
<div>
@@ -4679,9 +4677,19 @@
</li>
[% END %]
</ul>
+ <div>
+ Amounts spent per fund:
+ <table>
+ [% FOR blob IN user_data %]
+ <tr>
+ <th style="text-align: left;">[% blob.fund.code %] ([% blob.fund.year %]):</th>
+ <td>$[% blob.total %]</td>
+ </tr>
+ [% END %]
+ </table>
+ </div>
</div>
-[% END %]
-$$
+[% END %]$$
);
Copied: branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0457.data.acqinv.print.sql (from rev 18583, trunk/Open-ILS/src/sql/Pg/upgrade/0457.data.acqinv.print.sql)
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0457.data.acqinv.print.sql (rev 0)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0457.data.acqinv.print.sql 2010-11-02 16:28:33 UTC (rev 18584)
@@ -0,0 +1,132 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log VALUES ('0457');
+
+UPDATE action_trigger.event_definition SET template = $$[% FILTER collapse %]
+[%- SET invoice = target -%]
+<!-- This lacks 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>
+ Amounts spent per fund:
+ <table>
+ [% FOR blob IN user_data %]
+ <tr>
+ <th style="text-align: left;">[% blob.fund.code %] ([% blob.fund.year %]):</th>
+ <td>$[% blob.total %]</td>
+ </tr>
+ [% END %]
+ </table>
+ </div>
+</div>
+[% END %]$$ WHERE id = 22;
+
+COMMIT;
More information about the open-ils-commits
mailing list