rel_3_0 moved to HEAD
[koha.git] / acqui / select-late.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to show suppliers and orders
6 #written by chris@katipo.co.nz 23/2/2000
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27 use C4::Auth;
28 use C4::Biblio;
29 use CGI;
30 use C4::Interface::CGI::Output;
31 use C4::Context;
32 use C4::Date;
33 use C4::Acquisition;
34
35 my $query=new CGI;
36 my $dbh = C4::Context->dbh;
37 my ($template, $loggedinuser, $cookie)
38     = get_template_and_user({template_name => "acqui/select-late.tmpl",
39                              query => $query,
40                              type => "intranet",
41                              authnotrequired => 0,
42                              flagsrequired => {acquisition => 1},
43                              debug => 1,
44                              });
45
46 my $supplier=$query->param('id');
47 my @suppliers=GetBookSeller($supplier);
48 my $count = scalar @suppliers;
49
50 my $sth = $dbh->prepare("select s.serialseq from serial s, subscription u where s.subscriptionid = u.subscriptionid and u.aqbooksellerid = ? and s.status = 2");
51
52 $sth->execute($supplier);
53 my  @final;
54 while (my $sol = $sth->fetchrow_hashref)
55 {
56     push @final, $sol;
57 }
58
59 $template->param(@loop_sol => \@final);
60
61 my $colour='#EEEEEE';
62 my $toggle=0;
63 my @loop_suppliers;
64 for (my $i=0; $i<$count; $i++) {
65         my $orders = GetPendingOrders($suppliers[$i]->{'id'});
66     my $ordcount = scalar @$orders;
67     
68         my %line;
69         if ($toggle==0){
70                 $line{color}='#EEEEEE';
71                 $toggle=1;
72         } else {
73                 $line{color}='white';
74                 $toggle=0;
75         }
76         $line{id} =$suppliers[$i]->{'id'};
77         $line{name} = $suppliers[$i]->{'name'};
78         $line{active} = $suppliers[$i]->{'active'};
79         $line{total} = $orders->[0]->{'count(*)'};
80         $line{authorisedby} = $orders->[0]->{'authorisedby'};
81         $line{entrydate} = $orders->[0]->{'entrydate'};
82         my @loop_basket;
83         for (my $i2=0;$i2<$ordcount;$i2++){
84                 my %inner_line;
85                 $inner_line{basketno} =$orders->[$i2]->{'basketno'};
86                 $inner_line{total} =$orders->[$i2]->{'count(*)'};
87                 $inner_line{authorisedby} = $orders->[$i2]->{'authorisedby'};
88                 $inner_line{entrydate} = format_date($orders->[$i2]->{'entrydate'});
89                 push @loop_basket, \%inner_line;
90         }
91         $line{loop_basket} = \@loop_basket;
92         push @loop_suppliers, \%line;
93 }
94 $template->param(loop_suppliers => \@loop_suppliers,
95                                                 supplier => $supplier,
96                                                 count => $count,
97                                                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
98                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
99                 IntranetNav => C4::Context->preference("IntranetNav"),
100                                                 );
101
102 output_html_with_http_headers $query, $cookie, $template->output;