Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / acqui / lateorders.pl
blob2b2ed17b0cc4fcb8e3861b35e575bb79df7b20ca
1 #!/usr/bin/perl
4 # Copyright 2005 Biblibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 =head1 NAME
22 lateorders.pl
24 =head1 DESCRIPTION
26 this script shows late orders for a specific supplier, branch and delay
27 given on input arg.
29 =head1 CGI PARAMETERS
31 =over 4
33 =item booksellerid
34 To know on which supplier this script have to display late order.
36 =item delay
37 To know the time boundary. Default value is 30 days.
39 =item branch
40 To know on which branch this script have to display late order.
42 =back
44 =cut
46 use Modern::Perl;
47 use CGI qw ( -utf8 );
48 use C4::Bookseller qw( GetBooksellersWithLateOrders );
49 use C4::Auth;
50 use C4::Koha;
51 use C4::Output;
52 use C4::Context;
53 use C4::Acquisition;
54 use C4::Letters;
55 use Koha::DateUtils;
57 my $input = new CGI;
58 my ($template, $loggedinuser, $cookie) = get_template_and_user(
60 template_name => "acqui/lateorders.tt",
61 query => $input,
62 type => "intranet",
63 authnotrequired => 0,
64 flagsrequired => { acquisition => 'order_receive' },
65 debug => 1,
69 my $booksellerid = $input->param('booksellerid') || undef; # we don't want "" or 0
70 my $delay = $input->param('delay') // 0;
72 # Get the "date from" param if !defined is today
73 my $estimateddeliverydatefrom = $input->param('estimateddeliverydatefrom');
74 my $estimateddeliverydateto = $input->param('estimateddeliverydateto');
76 my $estimateddeliverydatefrom_dt =
77 $estimateddeliverydatefrom
78 ? dt_from_string($estimateddeliverydatefrom)
79 : undef;
81 # Get the "date to" param. If it is not defined and $delay is not defined too, it is the today's date.
82 my $estimateddeliverydateto_dt = $estimateddeliverydateto
83 ? dt_from_string($estimateddeliverydateto)
84 : ( not defined $delay and not defined $estimateddeliverydatefrom)
85 ? dt_from_string()
86 : undef;
88 # Format the output of "date from" and "date to"
89 if ($estimateddeliverydatefrom_dt) {
90 $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1});
92 if ($estimateddeliverydateto_dt) {
93 $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1});
96 my $branch = $input->param('branch');
97 my $op = $input->param('op');
99 my @errors = ();
100 if ( $delay and not $delay =~ /^\d{1,3}$/ ) {
101 push @errors, {delay_digits => 1, bad_delay => $delay};
104 if ($op and $op eq "send_alert"){
105 my @ordernums = $input->multi_param("ordernumber");# FIXME: Fallback values?
106 my $err;
107 eval {
108 $err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") ); # FIXME: Fallback value?
109 if ( not ref $err or not exists $err->{error} ) {
110 AddClaim ( $_ ) for @ordernums;
114 if ( $@ ) {
115 $template->param(error_claim => $@);
116 } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_email" ) {
117 $template->{VARS}->{'error_claim'} = "no_email";
118 } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_order_seleted"){
119 $template->{VARS}->{'error_claim'} = "no_order_seleted";
120 } else {
121 $template->{VARS}->{'info_claim'} = 1;
125 my @parameters = ( $delay );
126 push @parameters, $estimateddeliverydatefrom_dt
127 ? $estimateddeliverydatefrom_dt->ymd()
128 : undef;
130 push @parameters, $estimateddeliverydateto_dt
131 ? $estimateddeliverydateto_dt->ymd()
132 : undef;
134 my %supplierlist = GetBooksellersWithLateOrders(@parameters);
136 my (@sloopy); # supplier loop
137 foreach (keys %supplierlist){
138 push @sloopy, (($booksellerid and $booksellerid eq $_ ) ?
139 {id=>$_, name=>$supplierlist{$_}, selected=>1} :
140 {id=>$_, name=>$supplierlist{$_}} ) ;
142 $template->param(SUPPLIER_LOOP => \@sloopy);
144 $template->param(Supplier=>$supplierlist{$booksellerid}) if ($booksellerid);
145 $template->param(booksellerid=>$booksellerid) if ($booksellerid);
147 @parameters =
148 ( $delay, $booksellerid, $branch );
149 if ($estimateddeliverydatefrom_dt) {
150 push @parameters, $estimateddeliverydatefrom_dt->ymd();
152 else {
153 push @parameters, undef;
155 if ($estimateddeliverydateto_dt) {
156 push @parameters, $estimateddeliverydateto_dt->ymd();
158 my @lateorders = GetLateOrders( @parameters );
160 my $total;
161 foreach (@lateorders){
162 $total += $_->{subtotal};
165 my $letters = GetLetters({ module => "claimacquisition" });
167 $template->param(ERROR_LOOP => \@errors) if (@errors);
168 $template->param(
169 lateorders => \@lateorders,
170 delay => $delay,
171 letters => $letters,
172 estimateddeliverydatefrom => $estimateddeliverydatefrom,
173 estimateddeliverydateto => $estimateddeliverydateto,
174 total => $total,
175 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
177 output_html_with_http_headers $input, $cookie, $template->output;