this file replaces acquire.pl
[koha.git] / acqui / parcels.pl
1  
2 #!/usr/bin/perl
3
4 # $Id$
5
6 #script to show display basket of orders
7 #written by chris@katipo.co.nz 24/2/2000
8
9
10 # Copyright 2000-2002 Katipo Communications
11 #
12 # This file is part of Koha.
13 #
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
17 # version.
18 #
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA  02111-1307 USA
26 use strict;
27 use CGI;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Interface::CGI::Output;
31 use C4::Database;
32 use C4::Date;
33 use HTML::Template;
34 use C4::Acquisition;
35
36 my $input=new CGI;
37 my $supplierid=$input->param('supplierid');
38 my $order=$input->param('orderby') || "datereceived desc";
39 my $startfrom=$input->param('startfrom');
40 my $code=$input->param('filter');
41 my $datefrom=$input->param('datefrom');
42 my $dateto=$input->param('dateto');
43 my $resultsperpage = $input->param('resultsperpage');
44
45 my ($count,@booksellers)=bookseller($supplierid);
46
47 my ($template, $loggedinuser, $cookie)
48     = get_template_and_user({template_name => "acqui/parcels.tmpl",
49                  query => $input,
50                  type => "intranet",
51                  authnotrequired => 0,
52                  flagsrequired => {acquisition => 1},
53                  debug => 1,
54 });
55
56
57 $resultsperpage = 20 unless ($resultsperpage);
58 my ($count,@results)=getparcels($supplierid, $order, $code,$datefrom,$dateto);
59
60 # multi page display gestion
61 $startfrom=0 unless ($startfrom);
62 if ($count>$resultsperpage){
63     my $displaynext=0;
64     my $displayprev=$startfrom;
65     if(($count - ($startfrom+$resultsperpage)) > 0 ) {
66         $displaynext = 1;
67 }
68     
69     my @numbers = ();
70     if ($count>$resultsperpage) {
71         for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
72             if ($i<16) {
73                 my $highlight=0;
74                 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
75                 push @numbers, { number => $i,
76                     highlight => $highlight ,
77 #                   searchdata=> "test",
78                     startfrom => ($i-1)*$resultsperpage};
79 }
80 }
81 }
82     
83     my $from = $startfrom*$resultsperpage+1;
84     my $to;
85     
86     if($count < (($startfrom+1)*$resultsperpage))
87 {
88         $to = $count;
89 } else {
90         $to = (($startfrom+1)*$resultsperpage);
91 }
92     $template->param(numbers=>\@numbers, 
93                      displaynext=>$displaynext,
94                      displayprev=>$displayprev,
95                      nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
96                      prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
97                     );
98 }
99 my @loopres;
100
101 my $hilighted=0;
102 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
103 ### startfrom: $startfrom
104 ### resultsperpage: $resultsperpage
105 ### count: $count
106 ### code: $results[$i]->{booksellerinvoicenumber}
107 ### datereceived: $results[$i]->{datereceived}
108
109     my %cell;
110     $cell{number}=$i+1;
111     $cell{code}=$results[$i]->{booksellerinvoicenumber};
112     $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
113     $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
114     $cell{raw_datereceived}=$results[$i]->{datereceived};
115     $cell{datereceived}=format_date($results[$i]->{datereceived});
116     $cell{bibcount}=$results[$i]->{biblio};
117     $cell{reccount}=$results[$i]->{itemsreceived};
118     $cell{itemcount}=$results[$i]->{itemsexpected};
119     $cell{hilighted} = $hilighted%2;
120     $hilighted++;
121     push @loopres, \%cell;
122 }
123 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
124 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
125 $template->param(
126         name => $booksellers[0]->{'name'},
127         supplierid => $supplierid,
128         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
129         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
130         IntranetNav => C4::Context->preference("IntranetNav"),
131         );
132
133 output_html_with_http_headers $input, $cookie, $template->output;