Head & rel_2_2 merged
[koha.git] / acqui / lateorders.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Acquisition;
6 use C4::Auth;
7 use C4::Koha;
8 use C4::Output;
9 use C4::Interface::CGI::Output;
10 use C4::Context;
11 use HTML::Template;
12
13 my $query = new CGI;
14 my ($template, $loggedinuser, $cookie)
15 = get_template_and_user({template_name => "acqui/lateorders.tmpl",
16                                 query => $query,
17                                 type => "intranet",
18                                 authnotrequired => 0,
19                                 flagsrequired => {acquisition => 1},
20                                 debug => 1,
21                                 });
22 # my $title = $query->param('title');
23 # my $ISSN = $query->param('ISSN');
24 # my @subscriptions = getsubscriptions($title,$ISSN);
25
26 my $supplierid = $query->param('supplierid');
27 my $delay = $query->param('delay');
28 my $branch = $query->param('branch');
29
30 $delay =($delay?$delay:30);
31
32 my %supplierlist = getsupplierlistwithlateorders($delay,$branch);
33 my @select_supplier;
34 push @select_supplier,"";
35 foreach my $supplierid (keys %supplierlist){
36         push @select_supplier, $supplierid;
37 }
38 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
39                         -values   => \@select_supplier,
40                         -default  => $supplierid,
41                         -labels   => \%supplierlist,
42                         -size     => 1,
43                         -tabindex=>'',
44                         -multiple => 0 );
45
46 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
47
48 my $branches = getbranches;
49 my @branchloop;
50 foreach my $thisbranch (sort keys %$branches) {
51         my %row =(value => $thisbranch,
52                                 branchname => $branches->{$thisbranch}->{'branchname'},
53                         );
54         push @branchloop, \%row;
55 }
56 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
57                                 -values   => \@select_branches,
58                                 -labels   => \%select_branches,
59                                 -size     => 1,
60                                 -tabindex=>'',
61                                 -multiple => 0 );
62
63 my ($count, @lateorders) = getlateorders($delay,$supplierid,$branch);
64 my $total;
65 foreach my $lateorder (@lateorders){
66         $total+=$lateorder->{subtotal};
67 }
68 $template->param(delay=>$delay) if ($delay);
69 $template->param(
70         branchloop => \@branchloop,
71         CGIsupplier => $CGIsupplier,
72         lateorders => \@lateorders,
73         total=>$total,
74         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
75         );
76 output_html_with_http_headers $query, $cookie, $template->output;