Bug 12852: The "preview" param can be removed serials/claims.pl
[koha.git] / serials / claims.pl
1 #!/usr/bin/perl
2
3 # Parts Copyright 2010 Biblibre
4
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Auth;
24 use C4::Serials;
25 use C4::Acquisition;
26 use C4::Output;
27 use C4::Bookseller qw( GetBookSeller );
28 use C4::Context;
29 use C4::Letters;
30 use C4::Branch;    # GetBranches GetBranchesLoop
31 use C4::Csv qw( GetCsvProfiles );
32
33 my $input = CGI->new;
34
35 my $serialid = $input->param('serialid');
36 my $op = $input->param('op');
37 my $claimletter = $input->param('claimletter');
38 my $supplierid = $input->param('supplierid');
39 my $suppliername = $input->param('suppliername');
40
41 # open template first (security & userenv set here)
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user({template_name => 'serials/claims.tt',
44             query => $input,
45             type => 'intranet',
46             authnotrequired => 0,
47             flagsrequired => {serials => 'claim_serials'},
48             debug => 1,
49             });
50
51 # supplierlist is returned in name order
52 my $supplierlist = GetSuppliersWithLateIssues();
53 for my $s (@{$supplierlist} ) {
54     $s->{count} = scalar  GetLateOrMissingIssues($s->{id});
55     if ($supplierid && $s->{id} == $supplierid) {
56         $s->{selected} = 1;
57     }
58 }
59
60 my $branchloop = GetBranchesLoop();
61
62 my @serialnums=$input->param('serialid');
63 if (@serialnums) { # i.e. they have been flagged to generate claims
64     my $err;
65     eval {
66         $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
67         if ( not ref $err or not exists $err->{error} ) {
68            UpdateClaimdateIssues(\@serialnums);
69         }
70     };
71     if ( $@ ) {
72         $template->param(error_claim => $@);
73     } elsif ( ref $err and exists $err->{error} ) {
74         if ( $err->{error} eq "no_email" ) {
75             $template->param( error_claim => 'no_vendor_email' );
76         } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
77             $template->param( error_claim => 'no_loggedin_user_email' );
78         }
79     } else {
80         $template->param( info_claim => 1 );
81     }
82 }
83
84 my $letters = GetLetters({ module => 'claimissues' });
85
86 my @missingissues;
87 my @supplierinfo;
88 if ($supplierid) {
89     @missingissues = GetLateOrMissingIssues($supplierid);
90     @supplierinfo=GetBookSeller($supplierid);
91 }
92
93 $template->param(
94         suploop => $supplierlist,
95         phone => $supplierinfo[0]->{phone},
96         booksellerfax => $supplierinfo[0]->{booksellerfax},
97         bookselleremail => $supplierinfo[0]->{bookselleremail},
98         missingissues => \@missingissues,
99         supplierid => $supplierid,
100         claimletter => $claimletter,
101         supplierloop => \@supplierinfo,
102         branchloop   => $branchloop,
103         csv_profiles => C4::Csv::GetCsvProfiles( "sql" ),
104         letters => $letters,
105         (uc(C4::Context->preference("marcflavour"))) => 1
106         );
107 output_html_with_http_headers $input, $cookie, $template->output;