From fe7a63027353d143a448ad2e56b7d49a64037aa6 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Séverine Queune Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/Patron.pm | 16 ++++++++++ api/v1/swagger/definitions/patron.yaml | 10 ++++++ api/v1/swagger/paths/patrons.yaml | 2 ++ .../prog/en/includes/patron-search.inc | 31 +++++++++++++++++-- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 0c16079fa9..58f600c0a9 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1207,6 +1207,8 @@ sub get_overdues { ); } +sub overdues { my $self = shift; return $self->get_overdues(@_); } + =head3 get_routing_lists my $routinglists = $patron->get_routing_lists @@ -2063,6 +2065,20 @@ sub recalls { return Koha::Recalls->search({ borrowernumber => $self->borrowernumber }); } +=head3 account_balance + + my $balance = $patron->account_balance + +Return the patron's account balance + +=cut + +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 9185b90a51..256430ae6c 100644 --- a/api/v1/swagger/definitions/patron.yaml +++ b/api/v1/swagger/definitions/patron.yaml @@ -349,6 +349,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 7afce6892b..eab50f5af8 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 16681de048..ebe1d0c315 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 %] @@ -385,15 +386,41 @@ return escape_str(data); } } - [% CASE 'checkouts' %][% embed.push('checkouts+count') %] + [% CASE 'checkouts' %][% embed.push('checkouts+count', 'overdues+count') %] { "data": "", "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' %][% embed.push('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.39.5