From f35304b6ed28e18835b72d60b88e0cbd78714266 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 25 Sep 2023 15:56:48 -0300 Subject: [PATCH] [ALTERNATE] Bug 34277: Add option to embed balance details on GET /patrons --- Koha/Patron.pm | 30 ++++++++++++++++++++++++++ api/v1/swagger/definitions/patron.yaml | 5 +++++ api/v1/swagger/paths/patrons.yaml | 1 + 3 files changed, 36 insertions(+) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 7b4f8c8f09f..9fd4ebc62c3 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2374,6 +2374,36 @@ sub account_balance { return $self->account->balance; } +=head3 balance_details + + my $balance_details = $patron->balance_details + +Return the patron's account balance details. + +=cut + +sub balance_details { + my ($self) = @_; + + my $account = $self->account; + + # get outstanding debits and credits + my $debits = $account->outstanding_debits; + my $credits = $account->outstanding_credits; + + return { + balance => $account->balance, + outstanding_debits => { + total => $debits->total_outstanding, + lines => $debits->to_api, + }, + outstanding_credits => { + total => $credits->total_outstanding, + lines => $credits->to_api, + } + }; +} + =head3 notify_library_of_registration $patron->notify_library_of_registration( $email_patron_registrations ); diff --git a/api/v1/swagger/definitions/patron.yaml b/api/v1/swagger/definitions/patron.yaml index 7967722db74..a05f7eaa9bf 100644 --- a/api/v1/swagger/definitions/patron.yaml +++ b/api/v1/swagger/definitions/patron.yaml @@ -369,6 +369,11 @@ properties: - number - "null" description: Balance of the patron's account + balance_details: + type: + - object + - "null" + description: Detail for outstanding debits and credits library: type: - object diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 1f46a68a972..ef5a9f828d7 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -368,6 +368,7 @@ - checkouts+count - overdues+count - account_balance + - balance_details - library collectionFormat: csv responses: -- 2.42.0