fix bad link.
[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 use C4::Interface::CGI::Output;
69 use C4::Database;
70 use C4::Date;
71 use HTML::Template;
72 use C4::Acquisition;
73 use C4::Bookseller;
74
75 my $input=new CGI;
76 my $supplierid=$input->param('supplierid');
77 my $order=$input->param('orderby') || "datereceived desc";
78 my $startfrom=$input->param('startfrom');
79 my $code=$input->param('filter');
80 my $datefrom=$input->param('datefrom');
81 my $dateto=$input->param('dateto');
82 my $resultsperpage = $input->param('resultsperpage');
83
84 my @booksellers=GetBookSeller($supplierid);
85 my $count = scalar @booksellers;
86
87 my ($template, $loggedinuser, $cookie)
88     = get_template_and_user({template_name => "acqui/parcels.tmpl",
89                  query => $input,
90                  type => "intranet",
91                  authnotrequired => 0,
92                  flagsrequired => {acquisition => 1},
93                  debug => 1,
94 });
95
96
97 $resultsperpage = 20 unless ($resultsperpage);
98 my @results =GetParcels($supplierid, $order, $code,$datefrom,$dateto);
99 my $count = scalar @results;
100
101 # multi page display gestion
102 $startfrom=0 unless ($startfrom);
103 if ($count>$resultsperpage){
104     my $displaynext=0;
105     my $displayprev=$startfrom;
106     if(($count - ($startfrom+$resultsperpage)) > 0 ) {
107         $displaynext = 1;
108     }
109
110     my @numbers = ();
111     if ($count>$resultsperpage) {
112         for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
113             if ($i<16) {
114                 my $highlight=0;
115                 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
116                 push @numbers, { number => $i,
117                     highlight => $highlight ,
118 #                   searchdata=> "test",
119                     startfrom => ($i-1)*$resultsperpage};
120             }
121         }
122     }
123
124     my $from = $startfrom*$resultsperpage+1;
125     my $to;
126     if($count < (($startfrom+1)*$resultsperpage)){
127         $to = $count;
128     } else {
129         $to = (($startfrom+1)*$resultsperpage);
130     }
131     $template->param(numbers=>\@numbers, 
132                      displaynext=>$displaynext,
133                      displayprev=>$displayprev,
134                      nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
135                      prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
136                     );
137 }
138 my @loopres;
139
140 my $hilighted=0;
141 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
142 ### startfrom: $startfrom
143 ### resultsperpage: $resultsperpage
144 ### count: $count
145 ### code: $results[$i]->{booksellerinvoicenumber}
146 ### datereceived: $results[$i]->{datereceived}
147
148     my %cell;
149     $cell{number}=$i+1;
150     $cell{code}=$results[$i]->{booksellerinvoicenumber};
151     $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
152     $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
153     $cell{raw_datereceived}=$results[$i]->{datereceived};
154     $cell{datereceived}=format_date($results[$i]->{datereceived});
155     $cell{bibcount}=$results[$i]->{biblio};
156     $cell{reccount}=$results[$i]->{itemsreceived};
157     $cell{itemcount}=$results[$i]->{itemsexpected};
158     $cell{hilighted} = $hilighted%2;
159     $hilighted++;
160     push @loopres, \%cell;
161 }
162 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
163 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
164 $template->param(
165         name => $booksellers[0]->{'name'},
166         supplierid => $supplierid,
167         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
168         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
169         IntranetNav => C4::Context->preference("IntranetNav"),
170         );
171
172 output_html_with_http_headers $input, $cookie, $template->output;