From 5cb1486ea03118595c0c7b9bd2f59579ab9da97e Mon Sep 17 00:00:00 2001 From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Mon, 21 Dec 2009 16:46:37 +0000 Subject: [PATCH] move the credit card payable balance summary into the the public circ service git-svn-id: svn://svn.open-ils.org/ILS/trunk@15209 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Circ/Money.pm | 79 ++++++++++++++++++++++ .../src/perlmods/OpenILS/Application/CreditCard.pm | 76 --------------------- 2 files changed, 79 insertions(+), 76 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index 3d763a41b8..ae4dd35344 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -750,4 +750,83 @@ sub user_payments { return $data; } + +__PACKAGE__->register_method( + method => 'retrieve_credit_payable_balance', + api_name => 'open-ils.circ.credit.payable_balance.retrieve', + authoritative => 1, + signature => { + desc => q/Returns the total amount the patron can pay via credit card/, + params => [ + { desc => 'Authentication token', type => 'string' }, + { desc => 'User id', type => 'number' } + ], + return => { desc => 'The ID of the new provider' } + } +); + +sub retrieve_credit_payable_balance { + my ( $self, $conn, $auth, $user_id ) = @_; + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $user = $e->retrieve_actor_user($user_id) + or return $e->event; + + if($e->requestor->id != $user_id) { + return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS', $user->home_ou) + } + + my $circ_orgs = $e->json_query({ + "select" => {circ => ["circ_lib"]}, + from => "circ", + "where" => {usr => $user_id, xact_finish => undef}, + distinct => 1 + }); + + my $groc_orgs = $e->json_query({ + "select" => {mg => ["billing_location"]}, + from => "mg", + "where" => {usr => $user_id, xact_finish => undef}, + distinct => 1 + }); + + my %hash; + for my $org ( @$circ_orgs, @$groc_orgs ) { + my $o = $org->{billing_location}; + $o = $org->{circ_lib} unless $o; + next if $hash{$o}; # was $hash{$org}, but that doesn't make sense. $org is a hashref and $o gets added in the next line. + $hash{$o} = $U->ou_ancestor_setting_value($o, 'credit.payments.allow', $e); + } + + my @credit_orgs = map { $hash{$_} ? ($_) : () } keys %hash; + $logger->debug("credit: relevant orgs that allow credit payments => @credit_orgs"); + + my $xact_summaries = + OpenILS::Application::AppUtils->simplereq('open-ils.actor', + 'open-ils.actor.user.transactions.have_charge', $auth, $user_id); + + my $sum = 0.0; + + for my $xact (@$xact_summaries) { + + # make two lists and grab them in batch XXX + if ( $xact->xact_type eq 'circulation' ) { + my $circ = $e->retrieve_action_circulation($xact->id) or return $e->event; + next unless grep { $_ == $circ->circ_lib } @credit_orgs; + + } elsif ($xact->xact_type eq 'grocery') { + my $bill = $e->retrieve_money_grocery($xact->id) or return $e->event; + next unless grep { $_ == $bill->billing_location } @credit_orgs; + } elsif ($xact->xact_type eq 'reservation') { + my $bill = $e->retrieve_booking_reservation($xact->id) or return $e->event; + next unless grep { $_ == $bill->pickup_lib } @credit_orgs; + } + $sum += $xact->balance_owed(); + } + + return $sum; +} + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/CreditCard.pm b/Open-ILS/src/perlmods/OpenILS/Application/CreditCard.pm index 843540e5b2..35e66a5018 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/CreditCard.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/CreditCard.pm @@ -296,80 +296,4 @@ sub dispatch { } -__PACKAGE__->register_method( - method => 'retrieve_payable_balance', - api_name => 'open-ils.credit.payable_balance.retrieve', - signature => { - desc => q/Returns the total amount of the patron can pay via credit card/, - params => [ - { desc => 'Authentication token', type => 'string' }, - { desc => 'User id', type => 'number' } - ], - return => { desc => 'The ID of the new provider' } - } -); - -sub retrieve_payable_balance { - my ( $self, $conn, $auth, $user_id ) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; - - my $user = $e->retrieve_actor_user($user_id) - or return $e->event; - - if($e->requestor->id != $user_id) { - return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS', $user->home_ou) - } - - my $circ_orgs = $e->json_query({ - "select" => {circ => ["circ_lib"]}, - from => "circ", - "where" => {usr => $user_id, xact_finish => undef}, - distinct => 1 - }); - - my $groc_orgs = $e->json_query({ - "select" => {mg => ["billing_location"]}, - from => "mg", - "where" => {usr => $user_id, xact_finish => undef}, - distinct => 1 - }); - - my %hash; - for my $org ( @$circ_orgs, @$groc_orgs ) { - my $o = $org->{billing_location}; - $o = $org->{circ_lib} unless $o; - next if $hash{$o}; # was $hash{$org}, but that doesn't make sense. $org is a hashref and $o gets added in the next line. - $hash{$o} = $U->ou_ancestor_setting_value($o, CREDIT_NS . '.payments.allow', $e); - } - - my @credit_orgs = map { $hash{$_} ? ($_) : () } keys %hash; - $logger->debug("credit: relevant orgs that allow credit payments => @credit_orgs"); - - my $xact_summaries = - OpenILS::Application::AppUtils->simplereq('open-ils.actor', - 'open-ils.actor.user.transactions.have_charge', $auth, $user_id); - - my $sum = 0.0; - - for my $xact (@$xact_summaries) { - - # make two lists and grab them in batch XXX - if ( $xact->xact_type eq 'circulation' ) { - my $circ = $e->retrieve_action_circulation($xact->id) or return $e->event; - next unless grep { $_ == $circ->circ_lib } @credit_orgs; - - } elsif ($xact->xact_type eq 'grocery') { - my $bill = $e->retrieve_money_grocery($xact->id) or return $e->event; - next unless grep { $_ == $bill->billing_location } @credit_orgs; - } elsif ($xact->xact_type eq 'reservation') { - my $bill = $e->retrieve_booking_reservation($xact->id) or return $e->event; - next unless grep { $_ == $bill->pickup_lib } @credit_orgs; - } - $sum += $xact->balance_owed(); - } - - return $sum; -} - 1; -- 2.11.0