Head & rel_2_2 merged
[wip/koha-chris_n.git] / acqui / recieveorder.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to show display basket of orders
6 #written by chris@katipo.co.nz 24/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 use strict;
26 use CGI;
27 use C4::Auth;
28 use C4::Output;
29 use C4::Interface::CGI::Output;
30 use C4::Database;
31 use C4::Date;
32 use HTML::Template;
33 use C4::Acquisition;
34
35 my $input=new CGI;
36 my $supplierid=$input->param('supplierid');
37 my $order=$input->param('orderby') || "datereceived desc";
38 my $startfrom=$input->param('startfrom');
39 my $code=$input->param('filter');
40 my $datefrom=$input->param('datefrom');
41 my $dateto=$input->param('dateto');
42 my $resultsperpage = $input->param('resultsperpage');
43
44 my ($count,@booksellers)=bookseller($supplierid);
45
46 my ($template, $loggedinuser, $cookie)
47     = get_template_and_user({template_name => "acqui/recieveorder.tmpl",
48                              query => $input,
49                              type => "intranet",
50                              authnotrequired => 0,
51                              flagsrequired => {acquisition => 1},
52                              debug => 1,
53                              });
54
55
56 $resultsperpage = 20 unless ($resultsperpage);
57 my ($count,@results)=getparcels($supplierid, $order, $code,$datefrom,$dateto);
58
59 # multi page display gestion
60 $startfrom=0 unless ($startfrom);
61 if ($count>$resultsperpage){
62         my $displaynext=0;
63         my $displayprev=$startfrom;
64         if(($count - ($startfrom+$resultsperpage)) > 0 ) {
65                 $displaynext = 1;
66         }
67         
68         my @numbers = ();
69         if ($count>$resultsperpage) {
70                 for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
71                         if ($i<16) {
72                                 my $highlight=0;
73                                 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
74                                 push @numbers, { number => $i,
75                                         highlight => $highlight ,
76 #                                       searchdata=> "test",
77                                         startfrom => ($i-1)*$resultsperpage};
78                         }
79                 }
80         }
81         
82         my $from = $startfrom*$resultsperpage+1;
83         my $to;
84         
85         if($count < (($startfrom+1)*$resultsperpage))
86         {
87                 $to = $count;
88         } else {
89                 $to = (($startfrom+1)*$resultsperpage);
90         }
91         $template->param(numbers=>\@numbers, 
92                                          displaynext=>$displaynext,
93                                          displayprev=>$displayprev,
94                                          nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
95                                          prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
96                                         );
97 }
98 my @loopres;
99
100 my $hilighted=0;
101 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
102 ### startfrom: $startfrom
103 ### resultsperpage: $resultsperpage
104 ### count: $count
105 ### code: $results[$i]->{booksellerinvoicenumber}
106 ### datereceived: $results[$i]->{datereceived}
107
108         my %cell;
109         $cell{number}=$i+1;
110         $cell{code}=$results[$i]->{booksellerinvoicenumber};
111         $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
112         $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
113         $cell{raw_datereceived}=$results[$i]->{datereceived};
114         $cell{datereceived}=format_date($results[$i]->{datereceived});
115         $cell{bibcount}=$results[$i]->{biblio};
116         $cell{reccount}=$results[$i]->{itemsreceived};
117         $cell{itemcount}=$results[$i]->{itemsexpected};
118         $cell{hilighted} = $hilighted%2;
119         $hilighted++;
120         push @loopres, \%cell;
121 }
122 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
123 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
124 $template->param(
125                 name => $booksellers[0]->{'name'},
126                 supplierid => $supplierid,
127                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
128                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
129                 IntranetNav => C4::Context->preference("IntranetNav"),
130                 );
131
132 output_html_with_http_headers $input, $cookie, $template->output;