From 53b113dc33dff18735fe205ac73031cbdf31df08 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 ++- .../intranet-tmpl/prog/en/includes/checkouts.inc | 10 ++++ .../prog/en/modules/circ/circulation.tt | 56 +++++++--------------- .../prog/en/modules/members/moremember.tt | 21 +++----- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 50 ++++++++++++++++++- members/moremember.pl | 1 - svc/fines | 45 +++++++++++++++++ 9 files changed, 133 insertions(+), 100 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 ee3878ca13..31a2ac7d2f 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -253,18 +253,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 @@ -283,11 +277,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( @@ -429,11 +418,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; @@ -479,20 +463,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, - ); - } # Check the debt of this patrons guarantors *and* the guarantees of those guarantors my $no_issues_charge_guarantors = C4::Context->preference("NoIssuesChargeGuarantorsWithGuarantees"); @@ -610,7 +580,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 ccb5ed2df6..84d42edd9f 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 38a4700416..d27153ffe7 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/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index a4f7369bb2..0f955711e9 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' %] + @@ -305,9 +310,7 @@ [% IF ( RESERVED || ISSUED_TO_ANOTHER ) && (CAN_user_reserveforothers_place_holds ) %] - [% UNLESS noissues %] - [% END %] [% END %] [% END # /NEEDSCONFIRMATION %] @@ -519,7 +522,6 @@ [% END %]
    - [% IF ( !noissues ) || ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') )%]
    @@ -558,7 +560,6 @@
    - [% UNLESS ( noissues && Koha.Preference('OnSiteCheckoutsForce') ) %] [% IF ( SpecifyDueDate ) %]
    Specify due date [% INCLUDE 'date-format.inc' %]:
    @@ -576,10 +577,8 @@
    [% END %] - [% END %] - [% UNLESS ( noissues ) %] -
    +
    [% IF NEEDSCONFIRMATION %] [% IF auto_renew %] [% IF patron.autorenew_checkouts %] @@ -622,23 +621,21 @@
    [% END %] - [% END %] [% IF Koha.Preference('OnSiteCheckouts') %]
    - [% IF noissues %] -
    +
    - [% ELSE %] +
    [% IF Koha.Preference('OnSiteCheckoutAutoCheck') && onsite_checkout == "on" %] [% ELSE %] [% END %] - [% END %] +
    [% END %] @@ -660,24 +657,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! @@ -685,10 +671,7 @@ Only on-site checkouts are allowed [% END %]

    - [% ELSE %] -
    -

    Attention:

    - [% END %] +
      [% IF ( has_modifications ) %] @@ -752,8 +735,8 @@
      View restrictions - [% IF (noissues && patron && CAN_user_circulate_force_checkout) %] - + [% IF (patron && CAN_user_circulate_force_checkout) %] + Override restriction temporarily [% END %] @@ -770,7 +753,6 @@
    • Return claims: Patron has [% return_claims.count | html %] RETURN CLAIMS. [% END %] - [% IF age_limitations %] [% INCLUDE 'category-out-of-age-limit.inc' %] [% END %] @@ -866,11 +848,7 @@
      • - [% IF ( issuecount ) %] - [% issuecount | html %] Checkout(s) - [% ELSE %] - 0 Checkouts - [% END %] + 0 Checkout(s)
      • [% IF relatives_issues_count %] @@ -1096,7 +1074,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 43d5c74987..ca38221da6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -1,5 +1,49 @@ /* global __ */ +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 = __("Checked in"); - $(id).parent().parent().addClass('ok'); + $(id).parent().parent().addClass('ok').find('.renew-td').text(''); $('#date_due_' + data.itemnumber).html( __("Checked in") ); if ( data.patronnote != null ) { $('.patron_note_' + data.itemnumber).html( __("Patron note") + ": " + data.patronnote); @@ -176,6 +220,7 @@ $(document).ready(function() { var content = ""; if ( data.renew_okay ) { + KOHA.Checkouts.UpdateCheckoutsAndFees(); issuesTable.api().ajax.reload(); content = __("Renewed, due:") + " " + data.date_due; $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); @@ -567,7 +612,8 @@ $(document).ready(function() { } return content; - } + }, + "sClass": "renew-td" }, { "bSortable": false, diff --git a/members/moremember.pl b/members/moremember.pl index 8f6e959850..6f0f2843ac 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -200,7 +200,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.11.0