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