Bug 12868: Improving t/db_dependent/Member.t
[koha.git] / serials / claims.pl
blob7120515eb572b32ec239648ef2c476f44b146b1e
1 #!/usr/bin/perl
3 # Parts Copyright 2010 Biblibre
5 # This file is part of Koha.
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.
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.
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.
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::Context;
28 use C4::Letters;
29 use C4::Branch; # GetBranches GetBranchesLoop
30 use C4::Csv qw( GetCsvProfiles );
32 my $input = CGI->new;
34 my $serialid = $input->param('serialid');
35 my $op = $input->param('op');
36 my $claimletter = $input->param('claimletter');
37 my $supplierid = $input->param('supplierid');
38 my $suppliername = $input->param('suppliername');
40 # open template first (security & userenv set here)
41 my ($template, $loggedinuser, $cookie)
42 = get_template_and_user({template_name => 'serials/claims.tt',
43 query => $input,
44 type => 'intranet',
45 authnotrequired => 0,
46 flagsrequired => {serials => 'claim_serials'},
47 debug => 1,
48 });
50 # supplierlist is returned in name order
51 my $supplierlist = GetSuppliersWithLateIssues();
52 for my $s (@{$supplierlist} ) {
53 $s->{count} = scalar GetLateOrMissingIssues($s->{id});
54 if ($supplierid && $s->{id} == $supplierid) {
55 $s->{selected} = 1;
59 my $branchloop = GetBranchesLoop();
61 my @serialnums=$input->param('serialid');
62 if (@serialnums) { # i.e. they have been flagged to generate claims
63 my $err;
64 eval {
65 $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
66 if ( not ref $err or not exists $err->{error} ) {
67 UpdateClaimdateIssues(\@serialnums);
70 if ( $@ ) {
71 $template->param(error_claim => $@);
72 } elsif ( ref $err and exists $err->{error} ) {
73 if ( $err->{error} eq "no_email" ) {
74 $template->param( error_claim => 'no_vendor_email' );
75 } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
76 $template->param( error_claim => 'no_loggedin_user_email' );
78 } else {
79 $template->param( info_claim => 1 );
83 my $letters = GetLetters({ module => 'claimissues' });
85 my @missingissues;
86 if ($supplierid) {
87 @missingissues = GetLateOrMissingIssues($supplierid);
90 $template->param(
91 suploop => $supplierlist,
92 missingissues => \@missingissues,
93 supplierid => $supplierid,
94 claimletter => $claimletter,
95 branchloop => $branchloop,
96 csv_profiles => C4::Csv::GetCsvProfiles( "sql" ),
97 letters => $letters,
98 (uc(C4::Context->preference("marcflavour"))) => 1
100 output_html_with_http_headers $input, $cookie, $template->output;