From 84194ad10dc1c2078274f9413637eb9177a5ec15 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 20 Apr 2009 00:44:51 +0000 Subject: [PATCH] added option to flesh total spent/encumbered for a PO git-svn-id: svn://svn.open-ils.org/ILS/trunk@12912 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Financials.pm | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm index e0486771d7..fd56710d12 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm @@ -917,6 +917,7 @@ sub retrieve_purchase_order_impl { my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->event; if($$options{flesh_lineitems}) { + my $items = $e->search_acq_lineitem([ {purchase_order => $po_id}, { @@ -935,13 +936,44 @@ sub retrieve_purchase_order_impl { } $po->lineitems($items); - } + $po->lineitem_count(scalar(@$items)); + + } elsif( $$options{flesh_lineitem_count} ) { - if($$options{flesh_lineitem_count}) { my $items = $e->search_acq_lineitem({purchase_order => $po_id}, {idlist=>1}); $po->lineitem_count(scalar(@$items)); } + if($$options{flesh_price_summary}) { + + # fetch the fund debits for this purchase order + my $debits = $e->json_query({ + select => {acqfdeb => ["encumbrance", "amount"]}, + from => { + acqlid => { + jub => {fkey => "lineitem", field => "id", + join => {acqpo => {fkey => "purchase_order", field => "id"}} + }, + acqfdeb => {fkey => "fund_debit", field =>"id"} + } + }, + where => {'+acqpo' => {id => $po_id}} + }); + + my $enc = 0; + my $spent = 0; + for my $deb (@$debits) { + if($U->is_true($deb->{encumbrance})) { + $enc += $deb->{amount}; + } else { + $spent += $deb->{amount}; + } + } + + $po->amount_encumbered($enc); + $po->amount_spent($spent); + } + return $po; } -- 2.11.0