Bug 12224: Some code improvements
[koha-ffzg.git] / members / printslip.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
22 =head1 moremember.pl
23
24  script to do a borrower enquiry/bring up borrower details etc
25  Displays all the details about a borrower
26  written 20/12/99 by chris@katipo.co.nz
27  last modified 21/1/2000 by chris@katipo.co.nz
28  modified 31/1/2001 by chris@katipo.co.nz
29    to not allow items on request to be renewed
30
31  needs html removed and to use the C4::Output more, but its tricky
32
33 =cut
34
35 use Modern::Perl;
36 use CGI qw ( -utf8 );
37 use C4::Context;
38 use C4::Auth qw/:DEFAULT get_session/;
39 use C4::Output;
40 use C4::Members;
41 use C4::Koha;
42 use Koha::DateUtils;
43
44 #use Smart::Comments;
45 #use Data::Dumper;
46
47 use vars qw($debug);
48
49 BEGIN {
50         $debug = $ENV{DEBUG} || 0;
51 }
52
53 my $input = CGI->new;
54 my $sessionID = $input->cookie("CGISESSID");
55 my $session = get_session($sessionID);
56
57 $debug or $debug = $input->param('debug') || 0;
58 my $print = $input->param('print');
59 my $error = $input->param('error');
60
61 # circ staff who process checkouts but can't edit
62 # patrons still need to be able to print receipts
63 my $flagsrequired = { circulate => "circulate_remaining_permissions" };
64
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66     {
67         template_name   => "circ/printslip.tt",
68         query           => $input,
69         type            => "intranet",
70         flagsrequired   => $flagsrequired,
71         debug           => 1,
72     }
73 );
74
75 my $borrowernumber = $input->param('borrowernumber');
76
77 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
78 my $patron         = Koha::Patrons->find( $borrowernumber );
79 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
80
81 my $branch=C4::Context->userenv->{'branch'};
82 my ($slip, $is_html);
83 if ( $print eq 'checkinslip' ) {
84     my $checkinslip_branch = $session->param('branch') ? $session->param('branch') : $branch;
85
86     # get today's checkins
87     my $dtf = Koha::Database->new->schema->storage->datetime_parser;
88     my $today = dt_from_string;
89     my $today_start = $today->clone->set( hour => 0, minute => 0, second => 0 );
90     my $today_end   = $today->clone->set( hour => 23, minute => 59, second => 0 );
91     $today_start = $dtf->format_datetime( $today_start );
92     $today_end   = $dtf->format_datetime( $today_end );
93     my @todays_checkins = $patron->old_checkouts->search({
94         returndate => {
95             '>=' => $today_start,
96             '<=' => $today_end,
97         },
98         branchcode => $checkinslip_branch,
99     });
100
101     my %loops = (
102         old_issues => [ map { $_->itemnumber } @todays_checkins ],
103     );
104
105     my $letter = C4::Letters::GetPreparedLetter(
106         module      => 'circulation',
107         letter_code => 'CHECKINSLIP',
108         branchcode  => $checkinslip_branch,
109         lang        => $patron->lang,
110         tables      => {
111             branches  => $checkinslip_branch,
112             borrowers => $borrowernumber,
113         },
114         loops                  => \%loops,
115         message_transport_type => 'print'
116     );
117
118     $slip    = $letter->{content};
119     $is_html = $letter->{is_html};
120
121 } elsif (my $letter = IssueSlip ($session->param('branch') || $branch, $borrowernumber, $print eq "qslip")) {
122     $slip = $letter->{content};
123     $is_html = $letter->{is_html};
124 }
125
126 $template->param(
127     slip => $slip,
128     plain => !$is_html,
129     borrowernumber => $borrowernumber,
130     caller => 'members',
131     stylesheet => C4::Context->preference("SlipCSS"),
132     error           => $error,
133 );
134
135 $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS' ) );
136
137 output_html_with_http_headers $input, $cookie, $template->output;