From e4ccf73422b9764d0cd9e1d88b4c6f629e87beb9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 11 Feb 2022 10:58:14 +0100 Subject: [PATCH] Bug 30063: Overdues count --- Koha/Patron.pm | 8 +++++ api/v1/swagger/definitions/patron.yaml | 10 ++++++ api/v1/swagger/paths/patrons.yaml | 2 ++ .../prog/en/includes/patron-search.inc | 31 +++++++++++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 9968d363505..416e1a3f155 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1206,6 +1206,8 @@ sub get_overdues { ); } +sub overdues { my $self = shift; return $self->get_overdues(@_); } + =head3 get_routing_lists my $routinglists = $patron->get_routing_lists @@ -2054,6 +2056,12 @@ sub safe_to_delete { return Koha::Result::Boolean->new(1); } +sub account_balance { + my ($self) = @_; + return $self->account->balance; +} + + =head2 Internal methods =head3 _type diff --git a/api/v1/swagger/definitions/patron.yaml b/api/v1/swagger/definitions/patron.yaml index d23129b1add..77b1cb03955 100644 --- a/api/v1/swagger/definitions/patron.yaml +++ b/api/v1/swagger/definitions/patron.yaml @@ -333,6 +333,16 @@ properties: - integer - "null" description: Number of checkouts + overdues_count: + type: + - integer + - "null" + description: Number of overdued checkouts + account_balance: + type: + - number + - "null" + description: Balance of the patron's account additionalProperties: false required: - surname diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 17fe506fffb..b3be0826588 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -386,6 +386,8 @@ x-koha-embed: - extended_attributes - checkouts+count + - overdues+count + - account_balance post: x-mojo-to: Patrons#add operationId: addPatron diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 3f8e6752eee..8efb1e2a290 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -106,6 +106,7 @@ [% CASE 'borrowernotes' %]Notes [% CASE 'phone' %]Phone [% CASE 'checkouts' %]Checkouts + [% CASE 'account_balance' %]Fines [% CASE 'action' %]  [% END %] [% END %] @@ -225,7 +226,7 @@ return json.data; } }, - embed: ['extended_attributes', 'checkouts+count'], + embed: ['extended_attributes', 'checkouts+count', 'overdues+count', 'account_balance'], "drawCallback": function( settings ) { var api = this.api(); var data = api.data(); @@ -385,9 +386,35 @@ "searchable": false, "orderable": false, "render": function( data, type, row, meta ) { - return escape_str(row.checkouts_count); + if ( row.overdues_count ) { + return ""+row.overdues_count + ""; + } else { + return "0 / " + row.checkouts_count; + } } } + [% CASE 'account_balance' %] + { + "data": "", + "searchable": false, + "orderable": false, + "render": function( data, type, row, meta ) { + let r = ""; + let balance_str = row.account_balance || 0; + balance_str = balance_str.escapeHtml().format_price(); + if ( row.account_balance < 0 ) { + // FIXME Format price here + r += "" + balance_str + ""; + } else if ( row.account_balance > 0 ) { + r += "" + balance_str + "" + } else { + r += balance_str; + } + r += ""; + return r; + } + } + [% CASE 'action' %] { "data": function( row, type, val, meta ) { -- 2.25.1