From ef59e6228a43f9b651f3d7fdb422aad3d3db8107 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Fri, 14 Feb 2020 14:26:05 +1000 Subject: [PATCH] bug 14803: KOHA.Checkouts js object * Use javascript to: - update fines/checkouts info - show/hide checkouts form and messages * Created svc/fines --- circ/circulation.pl | 31 ---------- .../prog/en/includes/blocked-fines.inc | 12 ++-- .../prog/en/includes/checkouts-table.inc | 7 +-- .../prog/en/includes/checkouts.inc | 10 ++++ .../prog/en/includes/doc-head-close.inc | 6 +- .../prog/en/modules/circ/circulation.tt | 59 ++++++------------- .../prog/en/modules/members/moremember.tt | 15 ++--- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 50 +++++++++++++++- members/moremember.pl | 1 - svc/fines | 45 ++++++++++++++ 10 files changed, 135 insertions(+), 101 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/checkouts.inc create mode 100644 svc/fines diff --git a/circ/circulation.pl b/circ/circulation.pl index 3655ec16c3..1adbb09405 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -278,18 +278,12 @@ if ($findborrower) { } # get the borrower information..... -my $balance = 0; $patron ||= Koha::Patrons->find( $borrowernumber ) if $borrowernumber; if ($patron) { $template->param( borrowernumber => $patron->borrowernumber ); output_and_exit_if_error( $query, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); - my $overdues = $patron->get_overdues; - my $issues = $patron->checkouts; - $balance = $patron->account->balance; - - # if the expiry date is before today ie they have expired if ( $patron->is_expired ) { #borrowercard expired, no issues @@ -308,11 +302,6 @@ if ($patron) { $template->param("returnbeforeexpiry" => 1); } } - $template->param( - overduecount => $overdues->count, - issuecount => $issues->count, - finetotal => $balance, - ); if ( $patron and $patron->is_debarred ) { $template->param( @@ -447,11 +436,6 @@ if (@$barcodes) { ); } - - # FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue - $patron = Koha::Patrons->find( $borrowernumber ); - $template_params->{issuecount} = $patron->checkouts->count; - if ( $item ) { $template_params->{item} = $item; $template_params->{biblio} = $biblio; @@ -497,20 +481,6 @@ if ( $patron ) { $template->param( dbarred=> 1 ); $noissues = 1; } - my $account = $patron->account; - if( ( my $owing = $account->non_issues_charges ) > 0 ) { - my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why?? - $noissues ||= ( not C4::Context->preference("AllowFineOverride") and ( $owing > $noissuescharge ) ); - $template->param( - charges => 1, - chargesamount => $owing, - ) - } elsif ( $balance < 0 ) { - $template->param( - credits => 1, - creditsamount => -$balance, - ); - } my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees"); $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees ); @@ -615,7 +585,6 @@ $template->param( duedatespec => $duedatespec, restoreduedatespec => $restoreduedatespec, message => $message, - totaldue => sprintf('%.2f', $balance), # FIXME not used in template? inprocess => $inprocess, $view => 1, batch_allowed => $batch_allowed, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc index 4bba7f7ba9..0965c09366 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc @@ -1,13 +1,9 @@ -[% USE Price %] -[% SET NoIssuesCharge = Koha.Preference('noissuescharge') %] -[% IF fines and fines > 0 %] -
  • +
  • -[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc index 7b967bec89..e23071c8e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc @@ -1,6 +1,6 @@ [% USE Koha %]
    - [% IF ( issuecount ) %] + +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts.inc new file mode 100644 index 0000000000..75a40c20eb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts.inc @@ -0,0 +1,10 @@ +[% USE Koha %] +[% Asset.js("js/checkouts.js") | $raw %] + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc index 2988cb66c1..0b04200685 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -26,9 +26,9 @@ var Koha = {}; - - - + + + [% IF ( login ) %] [% Asset.css("css/login.css") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 1eeb19e3af..b46222c1c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -9,6 +9,7 @@ [% USE Price %] [% USE AuthorisedValues %] [% SET footerjs = 1 %] +[% SET show_barcode_input = (Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce')) || !noissues || forceallow %] [% INCLUDE 'doc-head-open.inc' %] [% Asset.css("lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css") | $raw %] [% SET destination = "circ" %] @@ -19,6 +20,10 @@ [% END %] [% INCLUDE 'doc-head-close.inc' %] + @@ -295,9 +300,7 @@ [% IF ( RESERVED || ISSUED_TO_ANOTHER ) && (CAN_user_reserveforothers_place_holds ) %] - [% UNLESS noissues %] - [% END %] [% END %] [% END # /NEEDSCONFIRMATION %] @@ -504,7 +507,6 @@ [% END %]
    - [% IF ( !noissues ) || ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') )%]
    @@ -543,7 +545,6 @@
    - [% UNLESS ( noissues && Koha.Preference('OnSiteCheckoutsForce') ) %] [% IF ( SpecifyDueDate ) %]
    Specify due date [% INCLUDE 'date-format.inc' %]:
    @@ -561,10 +562,8 @@
    [% END %] - [% END %] - [% UNLESS ( noissues ) %] -
    +
    [% IF NEEDSCONFIRMATION %] [% IF auto_renew %] @@ -599,23 +598,21 @@
    [% END %] - [% END %] [% IF Koha.Preference('OnSiteCheckouts') %]
    - [% IF noissues %] -
    +
    - [% ELSE %] +
    [% IF Koha.Preference('OnSiteCheckoutAutoCheck') && onsite_checkout == "on" %] [% ELSE %] [% END %] - [% END %] +
    [% END %] @@ -638,24 +635,13 @@
    - [% END #/IF !noissues %] - - [% IF ( noissues ) %] - [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %] -
    - [% ELSE %] -
    - [% END %] - [% ELSE %]
    - [% END %] - [% IF ( noissues ) %] +
    +

    Attention:

    +
    [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %] -
    - [% ELSE %]

    Checking out to [% INCLUDE 'patron-title.inc' %]

    -
    [% END %]

    Cannot check out! @@ -663,10 +649,7 @@ Only on-site checkouts are allowed [% END %]

    - [% ELSE %] -
    -

    Attention:

    - [% END %] +
      [% IF ( has_modifications ) %] @@ -730,8 +713,8 @@
      View restrictions - [% IF (noissues && patron && CAN_user_circulate_force_checkout) %] - + [% IF (patron && CAN_user_circulate_force_checkout) %] + Override restriction temporarily [% END %] @@ -748,9 +731,7 @@
    • Return claims: Patron has [% return_claims.count | html %] RETURN CLAIMS. [% END %] - [% IF ( charges ) %] - [% INCLUDE 'blocked-fines.inc' fines = chargesamount %] - [% END %] + [% INCLUDE 'blocked-fines.inc' %] [% IF age_limitations %] [% INCLUDE 'category-out-of-age-limit.inc' %] @@ -836,11 +817,7 @@
      • - [% IF ( issuecount ) %] - [% issuecount | html %] Checkout(s) - [% ELSE %] - 0 Checkouts - [% END %] + 0 Checkout(s)
      • [% IF relatives_issues_count %] @@ -1051,7 +1028,7 @@ var SuspendHoldsIntranet = [% ( Koha.Preference('SuspendHoldsIntranet') ) ? 1 : 0 | html %]; [% Asset.js("js/pages/circulation.js") | $raw %] - [% Asset.js("js/checkouts.js") | $raw %] + [% INCLUDE 'checkouts.inc' %] [% Asset.js("js/holds.js") | $raw %] [% Asset.js("js/circ-patron-search-results.js") | $raw %] [% Asset.js("js/pages/circulation.js") | $raw %] - [% Asset.js("js/checkouts.js") | $raw %] + [% INCLUDE 'checkouts.inc' %] [% Asset.js("js/holds.js") | $raw %] [% INCLUDE 'str/members-menu.inc' %] [% Asset.js("js/members-menu.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index 8ba3512d59..4169ff15ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -1,5 +1,49 @@ /* global PATRON_NOTE */ +if ( KOHA === undefined ) var KOHA = {}; +KOHA.Checkouts = { + BorrowerNumber: null, + NoIssuesCharge: null, + AllowFineOverride: false, + DisallowIssue: false, + ForceOnSiteCheckouts: false, + ToggleInput: function( allow_issue ) { + if (this.AllowFineOverride) allow_issue = true; + if (this.DisallowIssue) allow_issue = false; + + $(".issue-allow").toggle(allow_issue); + $(".issue-disallow").toggle(!allow_issue); + $("#mainform").toggle(allow_issue || this.ForceOnSiteCheckouts); + + if (!allow_issue) { + $(".circmessage.attention").removeClass("attention").addClass("warning"); + } + }, + UpdateCheckoutsAndFees: function() { + var self = this; + $.get( "/cgi-bin/koha/svc/fines", {borrowernumber: this.BorrowerNumber}, function( data ) { + $("#issuecount").text(data.issuecount); + var has_checkouts = data.issuecount > 0; + $(".has-checkouts").toggle(has_checkouts); + $(".no-checkouts").toggle(!has_checkouts); + + var has_outstanding = data.balance > 0; + var noissue = this.NoIssuesCharge !== null && data.balance >= this.NoIssuesCharge; + $(".outstanding-fees").toggle(has_outstanding); + $(".no-outstanding-fees").toggle(!has_outstanding); + $(".outstanding-fees-amount").text(data.balance_formatted); + $(".outstanding-fees-over-limit").toggle(noissue); + self.ToggleInput(!noissue); + } ); + }, + init: function(borrowernumber, noissuescharge) { + this.BorrowerNumber = borrowernumber; + this.NoIssuesCharge = noissuescharge; + + this.UpdateCheckoutsAndFees(); + } +} + $(document).ready(function() { $.ajaxSetup ({ cache: false }); @@ -117,7 +161,7 @@ $(document).ready(function() { content = ""; if ( data.returned ) { content = CIRCULATION_RETURNED; - $(id).parent().parent().addClass('ok'); + $(id).parent().parent().addClass('ok').find('.renew-td').text(''); $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED); if ( data.patronnote != null ) { $('.patron_note_' + data.itemnumber).html( PATRON_NOTE + ": " + data.patronnote); @@ -161,6 +205,7 @@ $(document).ready(function() { var content = ""; if ( data.renew_okay ) { + KOHA.Checkouts.UpdateCheckoutsAndFees(); issuesTable.api().ajax.reload(); content = CIRCULATION_RENEWED_DUE + " " + data.date_due; $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); @@ -536,7 +581,8 @@ $(document).ready(function() { content += ""; return content; - } + }, + "sClass": "renew-td" }, { "bSortable": false, diff --git a/members/moremember.pl b/members/moremember.pl index f083203d4a..35e0b63be4 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -201,7 +201,6 @@ $template->param( patron => $patron, issuecount => $patron->checkouts->count, holds_count => $patron->holds->count, - fines => $patron->account->balance, translated_language => $translated_language, detailview => 1, was_renewed => scalar $input->param('was_renewed') ? 1 : 0, diff --git a/svc/fines b/svc/fines new file mode 100644 index 0000000000..b783a7707b --- /dev/null +++ b/svc/fines @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# Copyright 2016 CatalystIT +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use C4::Service; +use Koha::Patrons; +use Koha::Number::Price; + +my ( $query, $response ) = C4::Service->init( borrowers => '*' ); + +my $borrowernumber = $query->param('borrowernumber') + or return C4::Service->return_error('input', "No 'borrowernumber'"); +my $patron = Koha::Patrons->find( $borrowernumber ) + or return C4::Service->return_error('input', "Invalid 'borrowernumber'", borrowernumber => $borrowernumber); + +my $od = $patron->get_overdues->count; +my $issues = $patron->checkouts->count; +my $balance = $patron->account->balance; + +$response->param( + overduecount => $od, + issuecount => $issues, + balance => $balance || 0.00, + balance_formatted => Koha::Number::Price->new( $balance )->format, +); + +C4::Service->return_success( $response ); -- 2.20.1