From ed75ae1a7f773443445899022b6b1445b34e8303 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 29 Sep 2009 22:00:27 +0000 Subject: [PATCH] new API call wich returns fleshed payments by user with start/end date filters and optional sort columns git-svn-id: svn://svn.open-ils.org/ILS/trunk@14211 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Circ.pm | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index fa3f1995e3..bc64731672 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -1201,6 +1201,79 @@ sub test_batch_circ_events { +__PACKAGE__->register_method( + method => "user_payments_list", + api_name => "open-ils.circ.user_payments.list", + stream => 1, + signature => { + desc => q/Returns a fleshed, date-limited set of all payments a user + has made. By default, ordered by payment date. Optionally + ordered by any other column in the top-level "mp" object/, + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'User ID', type => 'number'}, + {desc => 'Order by column(s), optional. Array of "mp" class columns', type => 'array'} + ], + return => {desc => q/List of "mp" objects, fleshed with the billable transaction and the related fully-realized payment object (e.g money.cash_payment)/} + } +); + +sub user_payments_list { + my($self, $conn, $auth, $user_id, $start_date, $end_date, $order_by) = @_; + + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $user = $e->retrieve_actor_user($user_id) or return $e->event; + return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $user->home_ou); + + $order_by ||= ['payment_ts']; + + # all payments by user, between start_date and end_date + my $payments = $e->json_query({ + select => {mp => ['id']}, + from => { + mp => { + mbt => { + fkey => 'xact', field => 'id'} + } + }, + where => { + '+mbt' => {usr => $user_id}, + '+mp' => {payment_ts => {'<' => 'now'}} + }, + order_by => {mp => $order_by} + }); + + for my $payment_id (@$payments) { + my $payment = $e->retrieve_money_payment([ + $payment_id->{id}, + { + flesh => 2, + flesh_fields => { + mp => [ + 'xact', + 'cash_payment', + 'credit_card_payment', + 'credit_payment', + 'check_payment', + 'work_payment', + 'forgive_payment', + 'goods_payment' + ], + mbt => [ + 'circulation', + 'grocery' + ] + } + } + ]); + $conn->respond($payment); + } + + return undef; +} + # {"select":{"acp":["id"],"circ":[{"aggregate":true,"transform":"count","alias":"count","column":"id"}]},"from":{"acp":{"circ":{"field":"target_copy","fkey":"id","type":"left"},"acn"{"field":"id","fkey":"call_number"}}},"where":{"+acn":{"record":200057}} -- 2.11.0