Finalized XML version for intranet
[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 C4::Acquisition;
55
56 my $query = new CGI;
57 my ($template, $loggedinuser, $cookie)
58 = get_template_and_user(
59                 {template_name => "acqui/lateorders.tmpl",
60                                 query => $query,
61                                 type => "intranet",
62                                 authnotrequired => 0,
63                                 flagsrequired => {acquisition => 1},
64                                 debug => 1,
65                                 });
66
67 my $supplierid = $query->param('supplierid');
68 my $delay = $query->param('delay');
69 my $branch = $query->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                         -labels   => \%supplierlist,
85                         -size     => 1,
86                         -tabindex=>'',
87                         -multiple => 0 );
88
89 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
90
91 my $branches = GetBranches;
92
93 my @branchloop;
94 foreach my $thisbranch (sort keys %$branches) {
95         my %row =(value => $thisbranch,
96                                 branchname => $branches->{$thisbranch}->{'branchname'},
97                         );
98         push @branchloop, \%row;
99 }
100 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
101                                 -values   => \@branchloop,
102                                 -labels   => $branches,
103                                 -size     => 1,
104                                 -tabindex=>'',
105                                 -multiple => 0 );
106
107 my @lateorders = GetLateOrders($delay,$supplierid,$branch);
108 my $count = scalar @lateorders;
109
110 my $total;
111 foreach my $lateorder (@lateorders){
112         $total+=$lateorder->{subtotal};
113 }
114 $template->param(delay=>$delay) if ($delay);
115 $template->param(
116         branchloop => \@branchloop,
117         CGIsupplier => $CGIsupplier,
118         lateorders => \@lateorders,
119         total=>$total,
120         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
121         );
122 output_html_with_http_headers $query, $cookie, $template->output;