[open-ils-commits] SPAM: r10062 -
branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jul 17 17:24:16 EDT 2008
Author: erickson
Date: 2008-07-17 17:24:12 -0400 (Thu, 17 Jul 2008)
New Revision: 10062
Modified:
branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Log:
initial fund_debit creation from PO code
Modified: branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2008-07-17 04:42:46 UTC (rev 10061)
+++ branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2008-07-17 21:24:12 UTC (rev 10062)
@@ -557,11 +557,118 @@
$e->allowed('MANAGE_PROVIDER', $provider->owner, $provider);
$e->create_acq_purchase_order($p_order) or return $e->die_event;
+
$e->commit;
return $p_order->id;
}
+
+# returns (price, type), where type=1 is usr, type=2 is provider, type=3 is marc
+sub get_li_price {
+ my $li = shift;
+ my $attrs = $li->attributes;
+ my ($marc_price, $usr_estimated, $usr_actual, $prov_estimated, $prov_actual);
+
+ for my $attr (@$attrs) {
+ if($attr->attr_name eq 'price') { # marc attr
+ $marc_price = $attr->attr_value;
+
+ } elsif($attr->attr_name eq 'estimated_price') {
+ $usr_estimated = $attr->attr_value
+ if $attr->attr_type eq 'lineitem_usr_attr_definition';
+ $prov_estimated = $attr->attr_value
+ if $attr->attr_type eq 'lineitem_prov_attr_definition';
+
+ } elsif($attr->attr_name eq 'actual_price') {
+ $usr_actual = $attr->attr_value
+ if $attr->attr_type eq 'lineitem_usr_attr_definition';
+ $prov_actual = $attr->attr_value
+ if $attr->attr_type eq 'lineitem_prov_attr_definition';
+ }
+ }
+
+ return ($usr_actual, 1) if $usr_actual;
+ return ($prov_actual, 2) if $prov_actual;
+ return ($usr_estimated, 1) if $usr_estimated;
+ return ($prov_estimated, 2) if $prov_estimated;
+ return ($marc_price, 3);
+}
+
+
__PACKAGE__->register_method(
+ method => 'create_purchase_order_debits',
+ api_name => 'open-ils.acq.purchase_order.debits.create',
+ signature => {
+ desc => 'Creates debits associated with a PO',
+ params => [
+ {desc => 'Authentication token', type => 'string'},
+ {desc => 'purchase_order whose debits to create', type => 'number'},
+ {desc => 'arguments hash. Options include: encumbrance=bool', type => 'object'},
+ ],
+ return => {desc => 'The total amount of all created debits, Event on error'}
+ }
+);
+
+sub create_purchase_order_debits {
+ my($self, $conn, $auth, $po_id, $args) = @_;
+ my $e = new_editor(xact=>1, authtoken=>$auth);
+ return $e->die_event unless $e->checkauth;
+
+ my $total = 0;
+ my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->die_event;
+ # XXX which perms?
+
+ my $o = 0;
+ while(my $li = $e->search_acq_lineitem([
+ { purchase_order => $po_id},
+ { offset => $o++,
+ limit => 1,
+ flesh => 1,
+ flesh_fields => {jub => ['attributes']}}])->[0]) {
+
+ my ($price, $ptype) = get_li_price($li);
+ unless($price) {
+ $e->rollback;
+ return OpenILS::Event->new('ACQ_LINEITEM_NO_PRICE', payload => $li->id);
+ }
+
+ unless($li->provider) {
+ $e->rollback;
+ return OpenILS::Event->new('ACQ_LINEITEM_NO_PROVIDER', payload => $li->id);
+ }
+
+ my $oo = 0;
+ while(my $lid = $e->search_acq_lineitem_detail([
+ { lineitem => $li->id},
+ { offset => $oo++,
+ limit => 1,
+ flesh => 1,
+ flesh_fields => {acqlid => ['fund']}}])->[0]) {
+
+ my $debit = Fieldmapper::acq::fund_debut->new;
+ $debit->fund($lid->fund->id);
+ $debit->origin_amount($price);
+ if($ptype == 2) { # price from vendor
+ $debit->origin_currency_type($li->provider->currency_type);
+ $debit->amount(currency_conversion_impl(
+ $li->provider->currency_type, $lid->fund->currency_type, $price));
+ } else {
+ $debit->origin_currency_type($lid->fund->currency_type);
+ $debit->amount($price);
+ }
+ $debit->encumbrance($args->{encumbrance});
+ $debit->debit_type('purchase');
+ $e->create_acq_fund_debit($debit) or return $e->die_event;
+ $total += $debit->amount;
+ }
+ }
+
+ $e->commit;
+ return $total;
+}
+
+
+__PACKAGE__->register_method(
method => 'retrieve_all_user_purchase_order',
api_name => 'open-ils.acq.purchase_order.user.all.retrieve',
stream => 1,
More information about the open-ils-commits
mailing list