Bug 2720 - Overdues which debar automatically should undebar automatically when returned
[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 my $order = $input->param('order');
41
42 # open template first (security & userenv set here)
43 my ($template, $loggedinuser, $cookie)
44 = get_template_and_user({template_name => 'serials/claims.tmpl',
45             query => $input,
46             type => 'intranet',
47             authnotrequired => 0,
48             flagsrequired => {serials => 'claim_serials'},
49             debug => 1,
50             });
51
52 # supplierlist is returned in name order
53 my $supplierlist = GetSuppliersWithLateIssues();
54 for my $s (@{$supplierlist} ) {
55     $s->{count} = scalar  GetLateOrMissingIssues($s->{id}, q{}, $order);
56     if ($supplierid && $s->{id} == $supplierid) {
57         $s->{selected} = 1;
58     }
59 }
60
61 my $letters = GetLetters('claimissues');
62 my @letters;
63 foreach (keys %{$letters}){
64     push @letters ,{code=>$_,name=> $letters->{$_}};
65 }
66
67 my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code}));
68 my  @missingissues;
69 my @supplierinfo;
70 if ($supplierid) {
71     @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order);
72     @supplierinfo=GetBookSeller($supplierid);
73 }
74
75 my $branchloop = GetBranchesLoop();
76 unshift @$branchloop, {value=> 'all',name=>''};
77
78 my $preview=0;
79 if($op && $op eq 'preview'){
80     $preview = 1;
81 } else {
82     my @serialnums=$input->param('serialid');
83     if (@serialnums) { # i.e. they have been flagged to generate claims
84         SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
85         my $cntupdate=UpdateClaimdateIssues(\@serialnums);
86         ### $cntupdate SHOULD be equal to scalar(@$serialnums)
87     }
88 }
89 $template->param('letters'=>\@letters,'letter'=>$letter);
90 $template->param(
91         order =>$order,
92         suploop => $supplierlist,
93         phone => $supplierinfo[0]->{phone},
94         booksellerfax => $supplierinfo[0]->{booksellerfax},
95         bookselleremail => $supplierinfo[0]->{bookselleremail},
96         preview => $preview,
97         missingissues => \@missingissues,
98         supplierid => $supplierid,
99         claimletter => $claimletter,
100         supplierloop => \@supplierinfo,
101         branchloop   => $branchloop,
102         csv_profiles => C4::Csv::GetCsvProfiles( "sql" ),
103         (uc(C4::Context->preference("marcflavour"))) => 1
104         );
105 output_html_with_http_headers $input, $cookie, $template->output;