Bug 34478: Move writeoff-individual to paycollect.pl
[koha.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( get_session get_template_and_user );
39 use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
40 use C4::Members qw( IssueSlip );
41
42 my $input = CGI->new;
43 my $sessionID = $input->cookie("CGISESSID");
44 my $session = get_session($sessionID);
45
46 my $print = $input->param('print');
47 my $error = $input->param('error');
48
49 # circ staff who process checkouts but can't edit
50 # patrons still need to be able to print receipts
51 my $flagsrequired = { circulate => "circulate_remaining_permissions" };
52
53 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54     {
55         template_name   => "circ/printslip.tt",
56         query           => $input,
57         type            => "intranet",
58         flagsrequired   => $flagsrequired,
59     }
60 );
61
62 my $borrowernumber = $input->param('borrowernumber');
63
64 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
65 my $patron         = Koha::Patrons->find( $borrowernumber );
66 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
67
68 my $branch=C4::Context->userenv->{'branch'};
69 my ( $letter, $slip, $is_html );
70 if ( $print eq 'checkinslip' ) {
71     my $checkinslip_branch = $session->param('branch') ? $session->param('branch') : $branch;
72
73     # get today's checkins
74     my @issue_ids = $patron->old_checkouts->filter_by_todays_checkins->get_column('issue_id');
75     my %loops     = (
76         old_issues => \@issue_ids,
77     );
78
79     $letter = C4::Letters::GetPreparedLetter(
80         module      => 'circulation',
81         letter_code => 'CHECKINSLIP',
82         branchcode  => $checkinslip_branch,
83         lang        => $patron->lang,
84         tables      => {
85             branches  => $checkinslip_branch,
86             borrowers => $borrowernumber,
87         },
88         loops                  => \%loops,
89         message_transport_type => 'print'
90     );
91
92 } elsif ( $print eq 'issueslip' ) {
93     $letter = IssueSlip( $session->param('branch') || $branch, $borrowernumber, 0 );
94 } elsif ( $print eq 'issueqslip' ) {
95     $letter = IssueSlip( $session->param('branch') || $branch, $borrowernumber, 1 );
96 } else {
97     $letter = C4::Letters::GetPreparedLetter(
98         module      => 'patron_slip',
99         letter_code => $print,
100         branchcode  => $branch,
101         lang        => $patron->lang,
102         tables      => {
103             branches  => $branch,
104             borrowers => $borrowernumber
105         },
106         message_transport_type => 'print'
107     );
108 }
109
110
111 $slip    = $letter->{content};
112 $is_html = $letter->{is_html};
113
114
115 $template->param(
116     slip => $slip,
117     plain => !$is_html,
118     borrowernumber => $borrowernumber,
119     caller => 'members',
120     stylesheet => C4::Context->preference("SlipCSS"),
121     error           => $error,
122 );
123
124 $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS' ) );
125
126 output_html_with_http_headers $input, $cookie, $template->output;