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.
48 use C4::Bookseller qw( GetBooksellersWithLateOrders );
56 use Koha::Acquisition::Orders;
59 my ($template, $loggedinuser, $cookie) = get_template_and_user(
61 template_name => "acqui/lateorders.tt",
65 flagsrequired => { acquisition => 'order_receive' },
70 my $booksellerid = $input->param('booksellerid') || undef; # we don't want "" or 0
71 my $delay = $input->param('delay') // 0;
73 # Get the "date from" param if !defined is today
74 my $estimateddeliverydatefrom = $input->param('estimateddeliverydatefrom');
75 my $estimateddeliverydateto = $input->param('estimateddeliverydateto');
77 my $estimateddeliverydatefrom_dt =
78 $estimateddeliverydatefrom
79 ? dt_from_string($estimateddeliverydatefrom)
82 # Get the "date to" param. If it is not defined and $delay is not defined too, it is the today's date.
83 my $estimateddeliverydateto_dt = $estimateddeliverydateto
84 ? dt_from_string($estimateddeliverydateto)
85 : ( not defined $delay and not defined $estimateddeliverydatefrom)
89 # Format the output of "date from" and "date to"
90 if ($estimateddeliverydatefrom_dt) {
91 $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1});
93 if ($estimateddeliverydateto_dt) {
94 $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1});
97 my $branch = $input->param('branch');
98 my $op = $input->param('op');
101 if ( $delay and not $delay =~ /^\d{1,3}$/ ) {
102 push @errors, {delay_digits => 1, bad_delay => $delay};
105 if ($op and $op eq "send_alert"){
106 my @ordernums = $input->multi_param("ordernumber");
109 $err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") );
110 if ( not ref $err or not exists $err->{error} ) {
111 AddClaim ( $_ ) for @ordernums;
116 $template->param(error_claim => $@);
117 } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_email" ) {
118 $template->{VARS}->{'error_claim'} = "no_email";
119 } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_order_selected"){
120 $template->{VARS}->{'error_claim'} = "no_order_selected";
122 $template->{VARS}->{'info_claim'} = 1;
126 if ($op && $op eq "save"){
128 my @orders = $input->param;
130 foreach my $order (@orders){
131 if ( $order ne "op"){
132 my @split = split (/_/,$order);
133 $listorders->{$split[0]}->{$split[1]} = $input->param($order);
137 my $orders_rs = Koha::Acquisition::Orders->search({ ordernumber => [ keys %$listorders ] });
138 while ( my $order = $orders_rs->next ) {
139 my $internalnote = $listorders->{$order->ordernumber}->{i};
140 my $vendornote = $listorders->{$order->ordernumber}->{v};
142 $order->order_internalnote($internalnote) if defined $internalnote;
143 $order->order_vendornote($vendornote) if defined $vendornote;
148 my @parameters = ( $delay );
149 push @parameters, $estimateddeliverydatefrom_dt
150 ? $estimateddeliverydatefrom_dt->ymd()
153 push @parameters, $estimateddeliverydateto_dt
154 ? $estimateddeliverydateto_dt->ymd()
157 my %supplierlist = GetBooksellersWithLateOrders(@parameters);
159 my (@sloopy); # supplier loop
160 foreach( sort { $supplierlist{$a} cmp $supplierlist{$b} } keys %supplierlist ) {
161 push @sloopy, (($booksellerid and $booksellerid eq $_ ) ?
162 {id=>$_, name=>$supplierlist{$_}, selected=>1} :
163 {id=>$_, name=>$supplierlist{$_}} ) ;
165 $template->param(SUPPLIER_LOOP => \@sloopy);
167 $template->param(Supplier=>$supplierlist{$booksellerid}) if ($booksellerid);
168 $template->param(booksellerid=>$booksellerid) if ($booksellerid);
171 ( $delay, $booksellerid, $branch );
172 if ($estimateddeliverydatefrom_dt) {
173 push @parameters, $estimateddeliverydatefrom_dt->ymd();
176 push @parameters, undef;
178 if ($estimateddeliverydateto_dt) {
179 push @parameters, $estimateddeliverydateto_dt->ymd();
181 my @lateorders = GetLateOrders( @parameters );
184 foreach (@lateorders){
185 $total += $_->{subtotal};
188 my $letters = GetLetters({ module => "claimacquisition" });
190 $template->param(ERROR_LOOP => \@errors) if (@errors);
192 lateorders => \@lateorders,
195 estimateddeliverydatefrom => $estimateddeliverydatefrom,
196 estimateddeliverydateto => $estimateddeliverydateto,
198 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
200 output_html_with_http_headers $input, $cookie, $template->output;