Code cleaned. POD added. Some sub renamed & API changed.
[koha.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 # $Id$
19
20 =head1 NAME
21
22 lateorders.pl
23
24 =head1 DESCRIPTION
25
26 this script shows late orders for a specific supplier, branch and delay
27 given on input arg.
28
29 =head1 CGI PARAMETERS
30
31 =over 4
32
33 =item supplierid
34 To know on which supplier this script have to display late order.
35
36 =item delay
37 To know the time boundary. Default value is 30 days.
38
39 =item branch
40 To know on which branch this script have to display late order.
41
42 =back
43
44 =cut
45
46 use strict;
47 use CGI;
48 use C4::Bookseller;
49 use C4::Auth;
50 use C4::Koha;
51 use C4::Output;
52 use C4::Interface::CGI::Output;
53 use C4::Context;
54 use HTML::Template;
55 use C4::Acquisition;
56
57 my $query = new CGI;
58 my ($template, $loggedinuser, $cookie)
59 = get_template_and_user(
60                 {template_name => "acqui/lateorders.tmpl",
61                                 query => $query,
62                                 type => "intranet",
63                                 authnotrequired => 0,
64                                 flagsrequired => {acquisition => 1},
65                                 debug => 1,
66                                 });
67
68 my $supplierid = $query->param('supplierid');
69 my $delay = $query->param('delay');
70 my $branch = $query->param('branch');
71
72 #default value for delay
73 $delay = 30 unless $delay;
74
75 my %supplierlist = GetBooksellersWithLateOrders($delay,$branch);
76 my @select_supplier;
77 push @select_supplier,"";
78 foreach my $supplierid (keys %supplierlist){
79         push @select_supplier, $supplierid;
80 }
81
82 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
83                         -values   => \@select_supplier,
84                         -default  => $supplierid,
85                         -labels   => \%supplierlist,
86                         -size     => 1,
87                         -tabindex=>'',
88                         -multiple => 0 );
89
90 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
91
92 my $branches = GetBranches;
93
94 my @branchloop;
95 foreach my $thisbranch (sort keys %$branches) {
96         my %row =(value => $thisbranch,
97                                 branchname => $branches->{$thisbranch}->{'branchname'},
98                         );
99         push @branchloop, \%row;
100 }
101 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
102                                 -values   => \@branchloop,
103                                 -labels   => $branches,
104                                 -size     => 1,
105                                 -tabindex=>'',
106                                 -multiple => 0 );
107
108 my @lateorders = GetLateOrders($delay,$supplierid,$branch);
109 my $count = scalar @lateorders;
110
111 my $total;
112 foreach my $lateorder (@lateorders){
113         $total+=$lateorder->{subtotal};
114 }
115 $template->param(delay=>$delay) if ($delay);
116 $template->param(
117         branchloop => \@branchloop,
118         CGIsupplier => $CGIsupplier,
119         lateorders => \@lateorders,
120         total=>$total,
121         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
122         );
123 output_html_with_http_headers $query, $cookie, $template->output;