Merge commit 'pianohacker-koha/prefs-submit' into master
[wip/koha-chris_n.git] / acqui / parcels.pl
1 #!/usr/bin/perl
2
3
4 #script to show display basket of orders
5
6
7 # Copyright 2000-2002 Katipo Communications
8 # Copyright 2008-2009 BibLibre SARL
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::Dates qw/format_date/;
69 use C4::Acquisition;
70 use C4::Bookseller;
71
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');
80
81
82 my ($template, $loggedinuser, $cookie)
83     = get_template_and_user({template_name => "acqui/parcels.tmpl",
84                  query => $input,
85                  type => "intranet",
86                  authnotrequired => 0,
87                  flagsrequired => {acquisition => 'order_receive'},
88                  debug => 1,
89 });
90
91
92 my $bookseller=GetBookSellerFromId($supplierid);
93 $resultsperpage = 20 unless ($resultsperpage);
94 my @results =GetParcels($supplierid, $order, $code,$datefrom,$dateto);
95 my $count = scalar @results;
96
97 # multi page display gestion
98 $startfrom=0 unless ($startfrom);
99 if ($count>$resultsperpage){
100     my $displaynext=0;
101     my $displayprev=$startfrom;
102     if(($count - ($startfrom+$resultsperpage)) > 0 ) {
103         $displaynext = 1;
104     }
105
106     my @numbers = ();
107     if ($count>$resultsperpage) {
108         for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
109             if ($i<16) {
110                 my $highlight=0;
111                 ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
112                 push @numbers, { number => $i,
113                     highlight => $highlight ,
114 #                   searchdata=> "test",
115                     startfrom => ($i-1)*$resultsperpage};
116             }
117         }
118     }
119
120     my $from = $startfrom*$resultsperpage+1;
121     my $to;
122     if($count < (($startfrom+1)*$resultsperpage)){
123         $to = $count;
124     } else {
125         $to = (($startfrom+1)*$resultsperpage);
126     }
127     $template->param(numbers=>\@numbers, 
128                      displaynext=>$displaynext,
129                      displayprev=>$displayprev,
130                      nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
131                      prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
132                     );
133 }
134 my @loopres;
135
136 for (my $i=$startfrom;$i<=($startfrom+$resultsperpage-1<$count-1?$startfrom+$resultsperpage-1:$count-1);$i++){
137
138     my %cell;
139     $cell{number}=$i+1;
140     $cell{code}=$results[$i]->{booksellerinvoicenumber};
141     $cell{nullcode}=$results[$i]->{booksellerinvoicenumber} eq "NULL";
142     $cell{emptycode}=$results[$i]->{booksellerinvoicenumber} eq '';
143     $cell{raw_datereceived}=$results[$i]->{datereceived};
144     $cell{datereceived}=format_date($results[$i]->{datereceived});
145     $cell{bibcount}=$results[$i]->{biblio};
146     $cell{reccount}=$results[$i]->{itemsreceived};
147     $cell{itemcount}=$results[$i]->{itemsexpected};
148     push @loopres, \%cell;
149 }
150 $template->param(searchresults=>\@loopres, count=>$count) if ($count);
151 $template->param(orderby=>$order, filter=>$code, datefrom=>$datefrom,dateto=>$dateto, resultsperpage=>$resultsperpage);
152 $template->param(
153         name => $bookseller->{'name'},
154         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
155                 datereceived_today => C4::Dates->new()->output(),
156                 supplierid => $supplierid,
157             GST => C4::Context->preference("gist"),
158         );
159
160 output_html_with_http_headers $input, $cookie, $template->output;