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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use C4::Auth qw( get_template_and_user );
23 use C4::Serials qw( GetSuppliersWithLateIssues GetLateOrMissingIssues updateClaim can_claim_subscription );
24 use C4::Output qw( output_html_with_http_headers );
26 use C4::Letters qw( GetLetters SendAlerts );
28 use Koha::AdditionalFields;
29 use Koha::CsvProfiles;
33 my $serialid = $input->param('serialid');
34 my $op = $input->param('op');
35 my $claimletter = $input->param('claimletter');
36 my $supplierid = $input->param('supplierid');
37 my $suppliername = $input->param('suppliername');
39 # open template first (security & userenv set here)
40 my ($template, $loggedinuser, $cookie)
41 = get_template_and_user({template_name => 'serials/claims.tt',
44 flagsrequired => {serials => 'claim_serials'},
47 # supplierlist is returned in name order
48 my $supplierlist = GetSuppliersWithLateIssues();
49 for my $s (@{$supplierlist} ) {
50 $s->{count} = scalar GetLateOrMissingIssues($s->{id});
51 if ($supplierid && $s->{id} == $supplierid) {
56 my $additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription', searchable => 1 } );
58 my @serialnums=$input->multi_param('serialid');
59 if (@serialnums) { # i.e. they have been flagged to generate claims
62 $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
63 if ( not ref $err or not exists $err->{error} ) {
64 C4::Serials::updateClaim( \@serialnums );
68 $template->param(error_claim => $@);
69 } elsif ( ref $err and exists $err->{error} ) {
70 if ( $err->{error} eq "no_email" ) {
71 $template->param( error_claim => 'no_vendor_email' );
72 } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
73 $template->param( error_claim => 'bad_or_missing_sender' );
76 $template->param( info_claim => 1 );
80 my $letters = GetLetters({ module => 'claimissues' });
84 my $supplier = Koha::Acquisition::Booksellers->find( $supplierid );
85 @missingissues = GetLateOrMissingIssues($supplierid);
86 foreach my $issue (@missingissues) {
87 $issue->{cannot_claim} = 1
88 unless C4::Serials::can_claim_subscription($issue);
90 $template->param( suppliername => $supplier->name );
94 suploop => $supplierlist,
95 missingissues => \@missingissues,
96 supplierid => $supplierid,
97 claimletter => $claimletter,
98 additional_fields_for_subscription => $additional_fields,
99 csv_profiles => Koha::CsvProfiles->search({ type => 'sql', used_for => 'late_issues' }),
101 (uc(C4::Context->preference("marcflavour"))) => 1
103 output_html_with_http_headers $input, $cookie, $template->output;