Changing to two-column layout
[koha.git] / acqui / parcels.pl
1 #!/usr/bin/perl
2
3
4 #script to show display basket of orders
5 #written by chris@katipo.co.nz 24/2/2000
6
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 =head1 NAME
26
27 parcels.pl
28
29 =head1 DESCRIPTION
30 This script shows all orders/parcels receipt or pending for a given supplier.
31 It allows to write an order/parcels as 'received' when he arrives.
32
33 =head1 CGI PARAMETERS
34
35 =over 4
36
37 =item supplierid
38 To know the supplier this script has to show orders.
39
40 =item orderby
41 sort list of order by 'orderby'.
42 Orderby can be equals to
43     * datereceived desc (default value)
44     * aqorders.booksellerinvoicenumber
45     * datereceived
46     * aqorders.booksellerinvoicenumber desc
47
48 =item filter
49
50 =item datefrom
51 To filter on date
52
53 =item dateto
54 To filter on date
55
56 =item resultsperpage
57 To know how many results have to be display / page.
58
59 =back
60
61 =cut
62
63 use strict;
64 use CGI;
65 use C4::Auth;
66 use C4::Output;
67
68 use C4::Date;
69
70 use C4::Acquisition;
71 use C4::Bookseller;
72
73 my $input=new CGI;
74 my $supplierid=$input->param('supplierid');
75 my $order=$input->param('orderby') || "datereceived desc";
76 my $startfrom=$input->param('startfrom');
77 my $code=$input->param('filter');
78 my $datefrom=$input->param('datefrom');
79 my $dateto=$input->param('dateto');
80 my $resultsperpage = $input->param('resultsperpage');
81
82 my @booksellers=GetBookSeller($supplierid);
83 my $count = scalar @booksellers;
84
85 my ($template, $loggedinuser, $cookie)
86     = get_template_and_user({template_name => "acqui/parcels.tmpl",
87                  query => $input,
88                  type => "intranet",
89                  authnotrequired => 0,
90                  flagsrequired => {acquisition => 1},
91                  debug => 1,
92 });
93
94
95 $resultsperpage = 20 unless ($resultsperpage);
96 my @results =GetParcels($supplierid, $order, $code,$datefrom,$dateto);
97 $count = scalar @results;
98
99 # multi page display gestion
100 $startfrom=0 unless ($startfrom);
101 if ($count>$resultsperpage){
102     my $displaynext=0;
103     my $displayprev=$startfrom;
104     if(($count - ($startfrom+$resultsperpage)) > 0 ) {
105         $displaynext = 1;
106     }
107
108     my @numbers = ();
109     if ($count>$resultsperpage) {
110         for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
111             if ($i<16) {
112                 my $highlight=0;
113                 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
114                 push @numbers, { number => $i,
115                     highlight => $highlight ,
116 #                   searchdata=> "test",
117                     startfrom => ($i-1)*$resultsperpage};
118             }
119         }
120     }
121
122     my $from = $startfrom*$resultsperpage+1;
123     my $to;
124     if($count < (($startfrom+1)*$resultsperpage)){
125         $to = $count;
126     } else {
127         $to = (($startfrom+1)*$resultsperpage);
128     }
129     $template->param(numbers=>\@numbers, 
130                      displaynext=>$displaynext,
131                      displayprev=>$displayprev,
132                      nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
133                      prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
134                     );
135 }
136 my @loopres;
137
138 my $hilighted=0;
139 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
140 ### startfrom: $startfrom
141 ### resultsperpage: $resultsperpage
142 ### count: $count
143 ### code: $results[$i]->{booksellerinvoicenumber}
144 ### datereceived: $results[$i]->{datereceived}
145
146     my %cell;
147     $cell{number}=$i+1;
148     $cell{code}=$results[$i]->{booksellerinvoicenumber};
149     $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
150     $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
151     $cell{raw_datereceived}=$results[$i]->{datereceived};
152     $cell{datereceived}=format_date($results[$i]->{datereceived});
153     $cell{bibcount}=$results[$i]->{biblio};
154     $cell{reccount}=$results[$i]->{itemsreceived};
155     $cell{itemcount}=$results[$i]->{itemsexpected};
156     $cell{hilighted} = $hilighted%2;
157     $hilighted++;
158     push @loopres, \%cell;
159 }
160 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
161 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
162 $template->param(
163         name => $booksellers[0]->{'name'},
164         supplierid => $supplierid,
165         );
166
167 output_html_with_http_headers $input, $cookie, $template->output;