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>.
26 this script shows late orders for a specific supplier, branch and delay
34 To know on which supplier this script have to display late order.
37 To know the time boundary. Default value is 30 days.
40 To know on which branch this script have to display late order.
55 use Koha::Acquisition::Orders;
56 use Koha::CsvProfiles;
59 my ($template, $loggedinuser, $cookie) = get_template_and_user(
61 template_name => "acqui/lateorders.tt",
64 flagsrequired => { acquisition => 'order_receive' },
68 my $booksellerid = $input->param('booksellerid');
69 my $delay = $input->param('delay') // 0;
71 # Get the "date from" param if !defined is today
72 my $estimateddeliverydatefrom = $input->param('estimateddeliverydatefrom');
73 my $estimateddeliverydateto = $input->param('estimateddeliverydateto');
75 my $estimateddeliverydatefrom_dt =
76 $estimateddeliverydatefrom
77 ? dt_from_string($estimateddeliverydatefrom)
80 # Get the "date to" param. If it is not defined and $delay is not defined too, it is the today's date.
81 my $estimateddeliverydateto_dt = $estimateddeliverydateto
82 ? dt_from_string($estimateddeliverydateto)
83 : ( not defined $delay and not defined $estimateddeliverydatefrom)
87 # Format the output of "date from" and "date to"
88 if ($estimateddeliverydatefrom_dt) {
89 $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1});
91 if ($estimateddeliverydateto_dt) {
92 $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1});
95 my $branch = $input->param('branch');
96 my $op = $input->param('op');
99 if ( $delay and not $delay =~ /^\d{1,3}$/ ) {
100 push @errors, {delay_digits => 1, bad_delay => $delay};
103 if ($op and $op eq "send_alert"){
104 my @ordernums = $input->multi_param("ordernumber");
107 $err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") );
108 if ( not ref $err or not exists $err->{error} ) {
109 Koha::Acquisition::Orders->find($_)->claim() for @ordernums;
113 if ( ref $err and exists $err->{error} and $err->{error} eq "no_email" ) {
114 $template->{VARS}->{'error_claim'} = "no_email";
115 } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_order_selected"){
116 $template->{VARS}->{'error_claim'} = "no_order_selected";
117 } elsif ( $@ or ref $err and exists $err->{error} ) {
118 $template->param(error_claim => $@ || $err->{error});
120 $template->{VARS}->{'info_claim'} = 1;
124 my @lateorders = Koha::Acquisition::Orders->filter_by_lates(
128 $estimateddeliverydatefrom_dt
129 ? ( estimated_from => $estimateddeliverydatefrom_dt )
133 $estimateddeliverydateto_dt
134 ? ( estimated_to => $estimateddeliverydateto_dt )
140 my $booksellers = Koha::Acquisition::Booksellers->search(
143 -in => [ map { $_->basket->booksellerid } @lateorders ]
148 @lateorders = grep { $_->basket->booksellerid eq $booksellerid } @lateorders if $booksellerid;
150 my $letters = GetLetters({ module => "claimacquisition" });
152 $template->param(ERROR_LOOP => \@errors) if (@errors);
154 lateorders => \@lateorders,
155 booksellers => $booksellers,
156 bookseller_filter => ( $booksellerid ? $booksellers->find($booksellerid) : undef),
159 estimateddeliverydatefrom => $estimateddeliverydatefrom,
160 estimateddeliverydateto => $estimateddeliverydateto,
161 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
162 csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql', used_for => 'late_orders' }) ],
164 output_html_with_http_headers $input, $cookie, $template->output;