Bug 21772: Add holds and account information to SCO
authorAgustin Moyano <agustinmoyano@theke.io>
Thu, 7 Mar 2019 18:58:41 +0000 (15:58 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 28 Mar 2019 18:16:48 +0000 (18:16 +0000)
This patch introduces holds and account information to the SCO page. It
uses the introduced include files that are also used in OPAC
(opac-user.pl and opac-account.pl).

To test:
1) Have a patron that has holds and account lines
2) Enable the SCO module
3) Use the patron's cardnumber to get to its details
=> SUCCESS: New tabs are presented, and they display holds and account
information as expected
4) Sign off :-D

Sponsored-by: City of Portsmouth Public Library

Signed-off-by: Sarah Cornell <sbcornell@cityofportsmouth.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt
opac/sco/sco-main.pl

index 317a8d3..68bbacf 100644 (file)
         <div class="container-fluid">
             <div class="row-fluid">
                     <div class="span12">
-                        <div id="borrowerdetails">
-                            [% IF ( issues_count ) %]
-                                <table id="loanTable" class="table table-bordered table-striped">
-                                    <caption>Checkouts for [% borrowername | html %] <span class="count">([% issues_count | html %] total)</span></caption>
-                                    <!-- ISSUES TABLE ROWS -->
-                                    <thead>
-                                        <tr>
-                                            <th class="noshow">Checked out on</th>
-                                            <th class="anti-the">Title</th>
-                                            <th>Call no.</th>
-                                            <th class="title-string">Due</th>
-                                            <th class="nosort">Renew</th>
-                                            [% UNLESS ( nofines ) %]
-                                                <th>Fines</th>
-                                            [% END %]
-                                        </tr>
-                                    </thead>
-                                    <tbody>
-                                        [% FOREACH ISSUE IN ISSUES %]
-                                            <tr>
-                                                <td>[% ISSUE.issuedate | html %]</td>
-                                                <td>
-                                                    [% UNLESS ( noitemlinks ) %]
-                                                        <a href="/cgi-bin/koha/opac-detail.pl?bib=[% ISSUE.  biblionumber | uri %]">[% ISSUE.title | html %]</a>
-                                                    [% ELSE %]
-                                                        <strong>[% ISSUE.title | html %]</strong>
-                                                    [% END %]
-                                                    [% IF ( newissues.match(ISSUE.barcode)) %]
-                                                        <span class="label label-info">NEW</span>
-                                                    [% END %]
-                                                    <span class="item-details">[% ISSUE.author | html %]</span>
-                                                    ([% ISSUE.barcode | html %])
-                                                </td>
-                                                <td>[% ISSUE.itemcallnumber | html %]</td>
-                                                [% IF ( ISSUE.overdue ) %]
-                                                    <td class="overdue"><span title="[% ISSUE.date_due | html %]">[% ISSUE.date_due | $KohaDates  as_due_date => 1 %]</span></td>
-                                                [% ELSE   %]
-                                                    <td><span title="[% ISSUE.date_due | html %]">[% ISSUE.date_due | $KohaDates  as_due_date => 1 %]</span></td>
-                                                [% END %]
-                                                <td>
-                                                    <form action="/cgi-bin/koha/sco/sco-main.pl" method="post">
-                                                        <input type="hidden" name="patronid" value="[% patronid | html %]" />
-                                                        <input type="hidden" name="barcode" value="[% ISSUE.barcode | html %]" />
-                                                        <input type="hidden" name="newissues" value="[% newissues | html %]" />
-                                                        [% IF ISSUE.can_be_renewed %]
-                                                            <input type="hidden" name="op" value="renew" />
-                                                            <input type="hidden" name="confirmed" value="1" />
-                                                            [% UNLESS ( ISSUE.renew ) %]
-                                                                <input type="submit" value="Renew item"  name="confirm  " class="btn renew" />
-                                                            [% ELSE %]
-                                                                <input type="submit" value="Renew item" class="btn renew" />
-                                                            [% END %]
-                                                        [% ELSE %]
-                                                            [% IF ISSUE.renew_error == 'auto_renew' OR ISSUE.renew_error == 'auto_too_soon' %]
-                                                                <span>This item has been scheduled for automatic renewal and cannot be renewed</span>
-                                                            [% ELSIF ISSUE.renew_error == 'onsite_checkout' %]
-                                                                <span>This is a on-site checkout, it cannot be renewed.</span>
-                                                            [% ELSE %]
-                                                                <span>No renewals allowed</span>
+                        <div class="tabbable">
+                            <ul class="nav nav-tabs">
+                                <li class="active"><a href="#checkouts-tab" data-toggle="tab">Checkouts</a></li>
+                                <li><a href="#holds-tab" data-toggle="tab">Holds</a></li>
+                                <li><a href="#account-tab" data-toggle="tab">Fines and charges</a></li>
+                            </ul>
+                            <div class="tab-content">
+                                <div id="checkouts-tab" class="tab-pane active">
+                                    <div id="borrowerdetails">
+                                        [% IF ( issues_count ) %]
+                                            <table id="loanTable" class="table table-bordered table-striped">
+                                                <caption>Checkouts for [% borrowername | html %] <span class="count">([% issues_count | html %] total)</span></caption>
+                                                <!-- ISSUES TABLE ROWS -->
+                                                <thead>
+                                                    <tr>
+                                                        <th class="noshow">Checked out on</th>
+                                                        <th class="anti-the">Title</th>
+                                                        <th>Call no.</th>
+                                                        <th class="title-string">Due</th>
+                                                        <th class="nosort">Renew</th>
+                                                        [% UNLESS ( nofines ) %]
+                                                            <th>Fines</th>
+                                                        [% END %]
+                                                    </tr>
+                                                </thead>
+                                                <tbody>
+                                                    [% FOREACH ISSUE IN ISSUES %]
+                                                        <tr>
+                                                            <td>[% ISSUE.issuedate | html %]</td>
+                                                            <td>
+                                                                [% UNLESS ( noitemlinks ) %]
+                                                                    <a href="/cgi-bin/koha/opac-detail.pl?bib=[% ISSUE.  biblionumber | uri %]">[% ISSUE.title | html %]</a>
+                                                                [% ELSE %]
+                                                                    <strong>[% ISSUE.title | html %]</strong>
+                                                                [% END %]
+                                                                [% IF ( newissues.match(ISSUE.barcode)) %]
+                                                                    <span class="label label-info">NEW</span>
+                                                                [% END %]
+                                                                <span class="item-details">[% ISSUE.author | html %]</span>
+                                                                ([% ISSUE.barcode | html %])
+                                                            </td>
+                                                            <td>[% ISSUE.itemcallnumber | html %]</td>
+                                                            [% IF ( ISSUE.overdue ) %]
+                                                                <td class="overdue"><span title="[% ISSUE.date_due | html %]">[% ISSUE.date_due | $KohaDates  as_due_date => 1 %]</span></td>
+                                                            [% ELSE   %]
+                                                                <td><span title="[% ISSUE.date_due | html %]">[% ISSUE.date_due | $KohaDates  as_due_date => 1 %]</span></td>
                                                             [% END %]
-                                                            [% IF Koha.Preference('AllowSelfCheckReturns') %]
-                                                                <input type="submit" value="Check in item" name="confirm" class="btn return" />
-                                                                <input type="hidden" name="op" value="returnbook" />
-                                                                <input type="hidden" name="confirmed" value=""  />
+                                                            <td>
+                                                                <form action="/cgi-bin/koha/sco/sco-main.pl" method="post">
+                                                                    <input type="hidden" name="patronid" value="[% patronid | html %]" />
+                                                                    <input type="hidden" name="barcode" value="[% ISSUE.barcode | html %]" />
+                                                                    <input type="hidden" name="newissues" value="[% newissues | html %]" />
+                                                                    [% IF ISSUE.can_be_renewed %]
+                                                                        <input type="hidden" name="op" value="checkout" />
+                                                                        <input type="hidden" name="confirmed" value="1" />
+                                                                        [% UNLESS ( ISSUE.renew ) %]
+                                                                            <input type="submit" value="Renew item"  name="confirm  " class="btn renew" />
+                                                                        [% ELSE %]
+                                                                            <input type="submit" value="Renew item" class="btn renew" />
+                                                                        [% END %]
+                                                                    [% ELSE %]
+                                                                        [% IF ISSUE.renew_error == 'auto_renew' OR ISSUE.renew_error == 'auto_too_soon' %]
+                                                                            <span>This item has been scheduled for automatic renewal and cannot be renewed</span>
+                                                                        [% ELSIF ISSUE.renew_error == 'onsite_checkout' %]
+                                                                            <span>This is a on-site checkout, it cannot be renewed.</span>
+                                                                        [% ELSE %]
+                                                                            <span>No renewals allowed</span>
+                                                                        [% END %]
+                                                                        [% IF Koha.Preference('AllowSelfCheckReturns') %]
+                                                                            <input type="submit" value="Check in item" name="confirm" class="btn return" />
+                                                                            <input type="hidden" name="op" value="returnbook" />
+                                                                            <input type="hidden" name="confirmed" value=""  />
+                                                                        [% END %]
+                                                                    [% END %]
+                                                                </form>
+                                                            </td>
+                                                            [% UNLESS ( nofines ) %]
+                                                                <td>
+                                                                    [% IF ( ISSUE.charges ) %]Yes[% ELSE %]No[% END %]
+                                                                </td>
                                                             [% END %]
-                                                        [% END %]
-                                                    </form>
-                                                </td>
-                                                [% UNLESS ( nofines ) %]
-                                                    <td>
-                                                        [% IF ( ISSUE.charges ) %]Yes[% ELSE %]No[% END %]
-                                                    </td>
-                                                [% END %]
-                                            </tr>
-                                        [% END # / FOREACH ISSUE %]
-                                    </tbody>
-                                </table>
-                            [% ELSE %]
-                                <h3>You currently have nothing checked out.</h3>
-                            [% END # / IF issues_count %]
-                        </div> <!-- / #borrowerdetails -->
+                                                        </tr>
+                                                    [% END # / FOREACH ISSUE %]
+                                                </tbody>
+                                            </table>
+                                        [% ELSE %]
+                                            <h3>You currently have nothing checked out.</h3>
+                                        [% END # / IF issues_count %]
+                                    </div> <!-- / #borrowerdetails -->
+                                </div>
+                                <div id="holds-tab" class="tab-pane">
+                                    [% IF HOLDS.count > 0 %]
+                                        [% PROCESS 'holds-table.inc' HOLDS = HOLDS, SuspendHoldsOpac = SuspendHoldsOpac, showpriority = showpriority, AutoResumeSuspendedHolds = AutoResumeSuspendedHolds, onlyinfo = 'true' %]
+                                    [% ELSE %]
+                                        <h3>You currently have no pending holds.</h3>
+                                    [% END %]
+                                </div>
+                                <div id="account-tab" class="tab-pane">
+                                    [% PROCESS 'account-table.inc' %]
+                                </div>
+                            </div>
+                        </div>
                         [% ELSE # IF validuser %]
                             <div class="sco_entry" >
                                 <form id="mainform" action="/cgi-bin/koha/sco/sco-main.pl" name="mainform" method="post">
index 9ec8642..458e52e 100755 (executable)
@@ -272,17 +272,52 @@ if ($borrower) {
         push @checkouts, $checkout;
     }
 
+    my $show_priority;
+    for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
+        m/priority/ and $show_priority = 1;
+    }
+
+    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
+    my $total = $patron->account->balance;
+    my $accts = Koha::Account::Lines->search(
+        { borrowernumber => $borrower->{borrowernumber} },
+        { order_by       => { -desc => 'accountlines_id' } }
+    );
+
+    my @accountlines;
+    while ( my $line = $accts->next ) {
+        my $accountline = $line->unblessed;
+        $accountline->{'amount'} = sprintf( "%.2f", $accountline->{'amount'} || '0.00');
+        if ( $accountline->{'amount'} >= 0 ) {
+            $accountline->{'amountcredit'} = 1;
+        }
+        $accountline->{'amountoutstanding'} =
+        sprintf( "%.2f", $accountline->{'amountoutstanding'} || '0.00' );
+        if ( $accountline->{'amountoutstanding'} >= 0 ) {
+            $accountline->{'amountoutstandingcredit'} = 1;
+        }
+        push @accountlines, $accountline;
+    }
+
+    my $holds = $patron->holds;
+
     $template->param(
         validuser => 1,
         borrowername => $borrowername,
         issues_count => scalar(@checkouts),
         ISSUES => \@checkouts,
+        HOLDS => $holds,
         newissues => join(',',@newissueslist),
         patronid => $patronid,
         patronlogin => $patronlogin,
         patronpw => $patronpw,
         noitemlinks => 1 ,
         borrowernumber => $borrower->{'borrowernumber'},
+        SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
+        AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
+        showpriority   => $show_priority,
+        ACCOUNT_LINES => \@accountlines,
+        total => sprintf( "%.2f", $total ),
     );
 
     my $patron_messages = Koha::Patron::Messages->search(