3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
31 use C4
::Dates qw
/format_date/;
33 use C4
::Branch
; # GetBranches
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
38 template_name
=> "opac-user.tmpl",
42 flagsrequired
=> { borrow
=> 1 },
47 my $patronupdate = $query->param('patronupdate');
49 # get borrower information ....
50 my ( $borr, $flags ) = GetMemberDetails
( $borrowernumber );
52 $borr->{'dateenrolled'} = format_date
( $borr->{'dateenrolled'} );
53 $borr->{'expiry'} = format_date
( $borr->{'expiry'} );
54 $borr->{'dateofbirth'} = format_date
( $borr->{'dateofbirth'} );
55 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
57 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
58 $borr->{'flagged'} = 1;
60 # $make flagged available everywhere in the template
61 my $patron_flagged = $borr->{'flagged'};
62 if ( $borr->{'amountoutstanding'} > 5 ) {
63 $borr->{'amountoverfive'} = 1;
65 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
66 $borr->{'amountoverzero'} = 1;
68 if ( $borr->{'amountoutstanding'} < 0 ) {
69 $borr->{'amountlessthanzero'} = 1;
70 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
73 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
78 $template->param( BORROWER_INFO
=> \
@bordat,
79 borrowernumber
=> $borrowernumber,
80 patron_flagged
=> $patron_flagged,
83 #get issued items ....
84 my ($countissues,$issues) = GetPendingIssues
($borrowernumber);
88 my $overdues_count = 0;
91 my $imgdir = getitemtypeimagesrc
();
92 my $itemtypes = GetItemTypes
();
93 foreach my $issue ( @
$issues ) {
94 if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
96 my ( $restype, $res ) = CheckReserves
( $issue->{'itemnumber'} );
98 $issue->{'reserved'} = 1;
101 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
103 foreach my $ac (@
$accts) {
104 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
105 $charges += $ac->{'amountoutstanding'}
106 if $ac->{'accounttype'} eq 'F';
107 $charges += $ac->{'amountoutstanding'}
108 if $ac->{'accounttype'} eq 'L';
111 $issue->{'charges'} = $charges;
113 # get publictype for icon
115 my $publictype = $issue->{'publictype'};
116 $issue->{$publictype} = 1;
118 # check if item is renewable
119 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
120 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
122 $issue->{'status'} = $status;
124 if ( $issue->{'overdue'} ) {
125 push @overdues, $issue;
127 $issue->{'overdue'} = 1;
130 $issue->{'issued'} = 1;
133 my $itemtype = $issue->{'itemtype'};
135 $issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
136 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
138 push @issuedat, $issue;
142 $template->param( ISSUES
=> \
@issuedat );
143 $template->param( issues_count
=> $count );
145 $template->param( OVERDUES
=> \
@overdues );
146 $template->param( overdues_count
=> $overdues_count );
149 my $branches = GetBranches
();
151 for my $branch_hash (sort keys %$branches ) {
152 my $selected=(C4
::Context
->userenv && ($branch_hash eq C4
::Context
->userenv->{branch
})) if (C4
::Context
->preference('SearchMyLibraryFirst'));
155 value
=> "branch: $branch_hash",
156 branchname
=> $branches->{$branch_hash}->{'branchname'},
157 selected
=> $selected
160 $template->param( branchloop
=> \
@branch_loop, "mylibraryfirst"=>C4
::Context
->preference("SearchMyLibraryFirst"));
162 # now the reserved items....
163 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
164 foreach my $res (@reserves) {
165 $res->{'reservedate'} = format_date
( $res->{'reservedate'} );
166 my $publictype = $res->{'publictype'};
167 $res->{$publictype} = 1;
168 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
169 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
170 my $biblioData = GetBiblioData
($res->{'biblionumber'});
171 $res->{'reserves_title'} = $biblioData->{'title'};
175 # warn Dumper(@reserves);
177 $template->param( RESERVES
=> \
@reserves );
178 $template->param( reserves_count
=> $#reserves+1 );
182 foreach my $res (@reserves) {
183 if ( $res->{'itemnumber'} ) {
184 my $item = GetItem
( $res->{'itemnumber'});
185 $res->{'holdingbranch'} =
186 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
187 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
188 # get document reserve status
189 my $biblioData = GetBiblioData
($res->{'biblionumber'});
190 $res->{'waiting_title'} = $biblioData->{'title'};
191 if ( ( $res->{'found'} eq 'W' ) ) {
192 my $item = $res->{'itemnumber'};
193 $item = GetBiblioFromItemNumber
($item,undef);
195 $res->{'holdingbranch'}=$item->{'holdingbranch'};
196 $res->{'biblionumber'}=$item->{'biblionumber'};
197 $res->{'barcodenumber'} = $item->{'barcode'};
198 $res->{'wbrcode'} = $res->{'branchcode'};
199 $res->{'itemnumber'} = $res->{'itemnumber'};
200 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
201 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
202 $res->{'atdestination'} = 1;
204 # set found to 1 if reserve is waiting for patron pickup
205 $res->{'found'} = 1 if $res->{'found'} eq 'W';
212 $template->param( WAITING
=> \
@waiting );
214 # current alert subscriptions
215 my $alerts = getalert
($borrowernumber);
216 foreach ( @
$alerts ) {
217 $_->{ $_->{type
} } = 1;
218 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
222 waiting_count
=> $wcount,
223 textmessaging
=> $borr->{textmessaging
},
224 patronupdate
=> $patronupdate,
225 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
228 output_html_with_http_headers
$query, $cookie, $template->output;