rel_3_0 moved to HEAD
[wip/koha-chris_n.git] / acqui / lateorders.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 # $Id$
19
20 =head1 NAME
21
22 lateorders.pl
23
24 =head1 DESCRIPTION
25
26 this script shows late orders for a specific supplier, branch and delay
27 given on input arg.
28
29 =head1 CGI PARAMETERS
30
31 =over 4
32
33 =item supplierid
34 To know on which supplier this script have to display late order.
35
36 =item delay
37 To know the time boundary. Default value is 30 days.
38
39 =item branch
40 To know on which branch this script have to display late order.
41
42 =back
43
44 =cut
45
46 use strict;
47 use CGI;
48 use C4::Bookseller;
49 use C4::Auth;
50 use C4::Koha;
51 use C4::Output;
52 use C4::Interface::CGI::Output;
53 use C4::Context;
54 use C4::Acquisition;
55 use C4::Letters;
56 use C4::Branch; # GetBranches
57
58 my $input = new CGI;
59 my ($template, $loggedinuser, $cookie)
60 = get_template_and_user(
61                 {template_name => "acqui/lateorders.tmpl",
62                                 query => $input,
63                                 type => "intranet",
64                                 authnotrequired => 0,
65                                 flagsrequired => {acquisition => 1},
66                                 debug => 1,
67                                 });
68
69 my $supplierid = $input->param('supplierid');
70 my $delay = $input->param('delay');
71 my $branch = $input->param('branch');
72
73 #default value for delay
74 $delay = 30 unless $delay;
75
76 my %supplierlist = GetBooksellersWithLateOrders($delay,$branch);
77 my @select_supplier;
78 push @select_supplier,"";
79 foreach my $supplierid (keys %supplierlist){
80         push @select_supplier, $supplierid;
81 }
82
83 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
84                         -values   => \@select_supplier,
85                         -default  => $supplierid,
86                         -labels   => \%supplierlist,
87                         -size     => 1,
88                         -tabindex=>'',
89                         -multiple => 0 );
90
91 $template->param(Supplier=>$supplierlist{$supplierid}) if ($supplierid);
92
93 my @lateorders = GetLateOrders($delay,$supplierid,$branch);
94 my $count = scalar @lateorders;
95
96 my $total;
97 foreach my $lateorder (@lateorders){
98         $total+=$lateorder->{subtotal};
99 }
100
101 my @letters;
102 my $letters=GetLetters("claimacquisition");
103 foreach (keys %$letters){
104  push @letters ,{code=>$_,name=>$letters->{$_}};
105 }
106
107 $template->param(letters=>\@letters) if (@letters);
108 my $op=$input->param("op");
109 if ($op eq "send_alert"){
110   my @ordernums=$input->param("claim_for");
111   SendAlerts('claimacquisition',\@ordernums,$input->param("letter_code"));
112 }
113
114 $template->param(delay=>$delay) if ($delay);
115 $template->param(
116         CGIsupplier => $CGIsupplier,
117         lateorders => \@lateorders,
118         total=>$total,
119         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
120         );
121 output_html_with_http_headers $input, $cookie, $template->output;