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