this file replaces recieveorder.pl
[koha.git] / acqui / order.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 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Auth;
27 use C4::Biblio;
28 use C4::Output;
29 use CGI;
30 use C4::Interface::CGI::Output;
31 use C4::Database;
32 use HTML::Template;
33 use C4::Acquisition;
34 use C4::Date;
35
36 my $query = new CGI;
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38     {
39         template_name   => "acqui/order.tmpl",
40         query           => $query,
41         type            => "intranet",
42         authnotrequired => 0,
43         flagsrequired   => { acquisition => 1 },
44         debug           => 1,
45     }
46 );
47
48 my $supplier = $query->param('supplier');
49 my ( $count, @suppliers ) = bookseller($supplier);
50
51 # check if we have to "close" a basket before building page
52 my $op     = $query->param('op');
53 my $basket = $query->param('basket');
54 if ( $op eq 'close' ) {
55     closebasket($basket);
56 }
57
58 #build result page
59 my $toggle = 0;
60 my @loop_suppliers;
61 for ( my $i = 0 ; $i < $count ; $i++ ) {
62     my ( $ordcount, $orders ) = getorders( $suppliers[$i]->{'id'} );
63     my %line;
64     if ( $toggle == 0 ) {
65         $line{even} = 1;
66         $toggle = 1;
67     }
68     else {
69         $line{even} = 0;
70         $toggle = 0;
71     }
72     $line{supplierid} = $suppliers[$i]->{'id'};
73     $line{name}       = $suppliers[$i]->{'name'};
74     $line{active}     = $suppliers[$i]->{'active'};
75     my @loop_basket;
76     for ( my $i2 = 0 ; $i2 < $ordcount ; $i2++ ) {
77         my %inner_line;
78         $inner_line{basketno}     = $orders->[$i2]->{'basketno'};
79         $inner_line{total}        = $orders->[$i2]->{'count(*)'};
80         $inner_line{authorisedby} = $orders->[$i2]->{'authorisedby'};
81         $inner_line{surname}      = $orders->[$i2]->{'firstname'};
82         $inner_line{firstname}    = $orders->[$i2]->{'surname'};
83         $inner_line{creationdate} =
84           format_date( $orders->[$i2]->{'creationdate'} );
85         $inner_line{closedate} = format_date( $orders->[$i2]->{'closedate'} );
86         push @loop_basket, \%inner_line;
87     }
88     $line{loop_basket} = \@loop_basket;
89     push @loop_suppliers, \%line;
90 }
91 $template->param(
92     loop_suppliers          => \@loop_suppliers,
93     supplier                => $supplier,
94     count                   => $count,
95     intranetcolorstylesheet =>
96       C4::Context->preference("intranetcolorstylesheet"),
97     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
98     IntranetNav        => C4::Context->preference("IntranetNav"),
99 );
100
101 output_html_with_http_headers $query, $cookie, $template->output;