synch'ing head and rel_2_2 (from 2.2.5, including npl templates)
[wip/koha-chris_n.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::Output;
8 use C4::Interface::CGI::Output;
9 use C4::Context;
10 use HTML::Template;
11
12 my $query = new CGI;
13 my ($template, $loggedinuser, $cookie)
14 = get_template_and_user({template_name => "acqui/lateorders.tmpl",
15                                 query => $query,
16                                 type => "intranet",
17                                 authnotrequired => 0,
18                                 flagsrequired => {acquisition => 1},
19                                 debug => 1,
20                                 });
21 # my $title = $query->param('title');
22 # my $ISSN = $query->param('ISSN');
23 # my @subscriptions = getsubscriptions($title,$ISSN);
24
25 my $supplierid = $query->param('supplierid');
26 my $delay = $query->param('delay');
27 my $branch = $query->param('branch');
28
29 $delay =($delay?$delay:30);
30
31 my %supplierlist = getsupplierlistwithlateorders($delay,$branch);
32 my @select_supplier;
33 push @select_supplier,"";
34 foreach my $supplierid (keys %supplierlist){
35         push @select_supplier, $supplierid;
36 }
37 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
38                         -values   => \@select_supplier,
39                         -default  => $supplierid,
40                         -labels   => \%supplierlist,
41                         -size     => 1,
42                         -multiple => 0 );
43
44 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
45
46 my @select_branches;
47 my %select_branches;
48 push @select_branches,"";
49 $select_branches{""}="";
50 my ($count, @branches) = branches(); 
51 #branches is IndependantBranches aware
52 foreach my $branch (@branches){
53         push @select_branches, $branch->{branchcode};
54         $select_branches{$branch->{branchcode}}=$branch->{branchname};
55 }
56 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
57                                 -values   => \@select_branches,
58                                 -labels   => \%select_branches,
59                                 -size     => 1,
60                                 -multiple => 0 );
61
62 my ($count, @lateorders) = getlateorders($delay,$supplierid,$branch);
63 my $total;
64 foreach my $lateorder (@lateorders){
65         $total+=$lateorder->{subtotal};
66 }
67 $template->param(delay=>$delay) if ($delay);
68 $template->param(
69         CGIbranch => $CGIbranch,
70         CGIsupplier => $CGIsupplier,
71         lateorders => \@lateorders,
72         total=>$total,
73         );
74 output_html_with_http_headers $query, $cookie, $template->output;