Fix for Bug 2086, Filter Button Misleading. This moves the filter form into the left...
[wip/koha-chris_n.git] / acqui / lateorders.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 with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18
19 =head1 NAME
20
21 lateorders.pl
22
23 =head1 DESCRIPTION
24
25 this script shows late orders for a specific supplier, branch and delay
26 given on input arg.
27
28 =head1 CGI PARAMETERS
29
30 =over 4
31
32 =item supplierid
33 To know on which supplier this script have to display late order.
34
35 =item delay
36 To know the time boundary. Default value is 30 days.
37
38 =item branch
39 To know on which branch this script have to display late order.
40
41 =back
42
43 =cut
44
45 use strict;
46 use CGI;
47 use C4::Bookseller;
48 use C4::Auth;
49 use C4::Koha;
50 use C4::Output;
51 use C4::Context;
52 use C4::Acquisition;
53 use C4::Letters;
54 use C4::Branch; # GetBranches
55
56 my $input = new CGI;
57 my ($template, $loggedinuser, $cookie)
58 = get_template_and_user(
59                 {template_name => "acqui/lateorders.tmpl",
60                                 query => $input,
61                                 type => "intranet",
62                                 authnotrequired => 0,
63                                 flagsrequired => {acquisition => 1},
64                                 debug => 1,
65                                 });
66
67 my $supplierid = $input->param('supplierid');
68 my $delay = $input->param('delay');
69 my $branch = $input->param('branch');
70
71 #default value for delay
72 $delay = 30 unless $delay;
73
74 my %supplierlist = GetBooksellersWithLateOrders($delay,$branch);
75 my @select_supplier;
76 push @select_supplier,"";
77 foreach my $supplierid (keys %supplierlist){
78         push @select_supplier, $supplierid;
79 }
80
81 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
82                         -values   => \@select_supplier,
83                         -default  => $supplierid,
84                         -id        => 'supplierid',
85                         -labels   => \%supplierlist,
86                         -size     => 1,
87                         -tabindex=>'',
88                         -multiple => 0 );
89
90 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
91
92 my @lateorders = GetLateOrders($delay,$supplierid,$branch);
93 my $count = scalar @lateorders;
94
95 my $total;
96 foreach my $lateorder (@lateorders){
97         $total+=$lateorder->{subtotal};
98 }
99
100 my @letters;
101 my $letters=GetLetters("claimacquisition");
102 foreach (keys %$letters){
103  push @letters ,{code=>$_,name=>$letters->{$_}};
104 }
105
106 $template->param(letters=>\@letters) if (@letters);
107 my $op=$input->param("op");
108 if ($op eq "send_alert"){
109   my @ordernums=$input->param("claim_for");
110   SendAlerts('claimacquisition',\@ordernums,$input->param("letter_code"));
111 }
112
113 $template->param(delay=>$delay) if ($delay);
114 $template->param(
115         CGIsupplier => $CGIsupplier,
116         lateorders => \@lateorders,
117         total=>$total,
118         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
119         );
120 output_html_with_http_headers $input, $cookie, $template->output;