more items work; handle unlinked subfields (DB rev => 048)
[koha.git] / acqui / parcels.pl
blob213ba23f37339f44d41f18e63cf6d4490aa20868
1 #!/usr/bin/perl
4 #script to show display basket of orders
5 #written by chris@katipo.co.nz 24/2/2000
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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.
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.
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
25 =head1 NAME
27 parcels.pl
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.
33 =head1 CGI PARAMETERS
35 =over 4
37 =item supplierid
38 To know the supplier this script has to show orders.
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
48 =item filter
50 =item datefrom
51 To filter on date
53 =item dateto
54 To filter on date
56 =item resultsperpage
57 To know how many results have to be display / page.
59 =back
61 =cut
63 use strict;
64 use CGI;
65 use C4::Auth;
66 use C4::Output;
68 use C4::Dates qw/format_date/;
69 use C4::Acquisition;
70 use C4::Bookseller;
72 my $input=new CGI;
73 my $supplierid=$input->param('supplierid');
74 my $order=$input->param('orderby') || "datereceived desc";
75 my $startfrom=$input->param('startfrom');
76 my $code=$input->param('filter');
77 my $datefrom=$input->param('datefrom');
78 my $dateto=$input->param('dateto');
79 my $resultsperpage = $input->param('resultsperpage');
81 my @booksellers=GetBookSeller($supplierid);
82 my $count = scalar @booksellers;
84 my ($template, $loggedinuser, $cookie)
85 = get_template_and_user({template_name => "acqui/parcels.tmpl",
86 query => $input,
87 type => "intranet",
88 authnotrequired => 0,
89 flagsrequired => {acquisition => 1},
90 debug => 1,
91 });
94 $resultsperpage = 20 unless ($resultsperpage);
95 my @results =GetParcels($supplierid, $order, $code,$datefrom,$dateto);
96 $count = scalar @results;
98 # multi page display gestion
99 $startfrom=0 unless ($startfrom);
100 if ($count>$resultsperpage){
101 my $displaynext=0;
102 my $displayprev=$startfrom;
103 if(($count - ($startfrom+$resultsperpage)) > 0 ) {
104 $displaynext = 1;
107 my @numbers = ();
108 if ($count>$resultsperpage) {
109 for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
110 if ($i<16) {
111 my $highlight=0;
112 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
113 push @numbers, { number => $i,
114 highlight => $highlight ,
115 # searchdata=> "test",
116 startfrom => ($i-1)*$resultsperpage};
121 my $from = $startfrom*$resultsperpage+1;
122 my $to;
123 if($count < (($startfrom+1)*$resultsperpage)){
124 $to = $count;
125 } else {
126 $to = (($startfrom+1)*$resultsperpage);
128 $template->param(numbers=>\@numbers,
129 displaynext=>$displaynext,
130 displayprev=>$displayprev,
131 nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
132 prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
135 my @loopres;
137 my $hilighted=0;
138 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
139 ### startfrom: $startfrom
140 ### resultsperpage: $resultsperpage
141 ### count: $count
142 ### code: $results[$i]->{booksellerinvoicenumber}
143 ### datereceived: $results[$i]->{datereceived}
145 my %cell;
146 $cell{number}=$i+1;
147 $cell{code}=$results[$i]->{booksellerinvoicenumber};
148 $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
149 $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
150 $cell{raw_datereceived}=$results[$i]->{datereceived};
151 $cell{datereceived}=format_date($results[$i]->{datereceived});
152 $cell{bibcount}=$results[$i]->{biblio};
153 $cell{reccount}=$results[$i]->{itemsreceived};
154 $cell{itemcount}=$results[$i]->{itemsexpected};
155 $cell{hilighted} = $hilighted%2;
156 $hilighted++;
157 push @loopres, \%cell;
159 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
160 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
161 $template->param(
162 name => $booksellers[0]->{'name'},
163 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
164 supplierid => $supplierid,
165 GST => C4::Context->preference("gist"),
168 output_html_with_http_headers $input, $cookie, $template->output;