From 4066e6606250b5a07cae2b7e20632ada21db9da2 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 20 Aug 2010 14:11:27 +0000 Subject: [PATCH] propagate estimated price to created copy as copy price (aka list price or replacement price); propagate invoiced amount to created copy as copy cost (aka library cost); caveats and consderations noted in the code. git-svn-id: svn://svn.open-ils.org/ILS/trunk@17284 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Acq/Invoice.pm | 33 +++++++++++++++++-- .../perlmods/OpenILS/Application/Acq/Order.pm | 8 +++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm index 69e7430208..63f1252cd8 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm @@ -163,11 +163,11 @@ sub rollback_entry_debits { my $lineitem = $e->retrieve_acq_lineitem($entry->lineitem) or return $e->die_event; for my $debit (@$debits) { - # revert to the original estimated amount re-encumber $debit->encumbrance('t'); $debit->amount($lineitem->estimated_unit_price()); $e->update_acq_fund_debit($debit) or return $e->die_event; + update_copy_cost($e, $debit) or return $e->die_event; # clear the cost } return undef; @@ -188,14 +188,43 @@ sub update_entry_debits { } for my $debit (@$debits) { - $debit->amount(entry_amount_per_item($entry)); + my $amount = entry_amount_per_item($entry); + $debit->amount($amount); $debit->encumbrance('f'); $e->update_acq_fund_debit($debit) or return $e->die_event; + + # TODO: this does not reflect ancillary charges, like taxes, etc. + # We may need a way to indicate whether the amount attached to an + # invoice_item should be prorated and included in the copy cost. + # Note that acq.invoice_item_type.prorate does not necessarily + # mean a charge should be included in the copy price, only that + # it should spread accross funds. + update_copy_cost($e, $debit, $amount) or return $e->die_event; } return undef; } +# update the linked copy to reflect the amount paid for the item +# returns true on success, false on error +sub update_copy_cost { + my ($e, $debit, $amount) = @_; + + my $lid = $e->search_acq_lineitem_detail([ + {fund_debit => $debit->id}, + {flesh => 1, flesh_fields => {acqlid => ['eg_copy_id']}} + ])->[0]; + + if($lid and my $copy = $lid->eg_copy_id) { + defined $amount and $copy->cost($amount) or $copy->clear_cost; + $copy->editor($e->requestor->id); + $copy->edit_date('now'); + $e->update_asset_copy($copy) or return 0; + } + + return 1; +} + sub entry_amount_per_item { my $entry = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index f7418bdee4..044e5d166a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -986,7 +986,7 @@ sub create_lineitem_assets { $volume = create_volume($mgr, $li, $lid) or return 0; $mgr->cache($org, "cn.$bibid.$label", $volume); } - create_copy($mgr, $volume, $lid) or return 0; + create_copy($mgr, $volume, $lid, $li) or return 0; } return { li => $li, new_bib => $new_bib }; @@ -1034,7 +1034,7 @@ sub create_volume { } sub create_copy { - my($mgr, $volume, $lid) = @_; + my($mgr, $volume, $lid, $li) = @_; my $copy = Fieldmapper::asset::copy->new; $copy->isnew(1); $copy->loan_duration(2); @@ -1046,6 +1046,10 @@ sub create_copy { $copy->circ_lib($volume->owning_lib); $copy->circ_modifier($lid->circ_modifier); + # AKA list price. We might need a $li->list_price field since + # estimated price is not necessarily the same as list price + $copy->price($li->estimated_unit_price); + my $evt = OpenILS::Application::Cat::AssetCommon->create_copy($mgr->editor, $volume, $copy); if($evt) { $mgr->editor->event($evt); -- 2.43.2