Bug 10317: improve display when order receiving page is given an invalid invoiceid
[koha.git] / acqui / parcel.pl
index 0e0f41b..ee96e3f 100755 (executable)
@@ -118,6 +118,18 @@ my ($template, $loggedinuser, $cookie)
 });
 
 my $invoiceid = $input->param('invoiceid');
+my $invoice;
+$invoice = GetInvoiceDetails($invoiceid) if $invoiceid;
+
+unless( $invoiceid and $invoice->{invoiceid} ) {
+    $template->param(
+        error_invoice_not_known => 1,
+        no_orders_to_display    => 1
+    );
+    output_html_with_http_headers $input, $cookie, $template->output;
+    exit;
+}
+
 my $op = $input->param('op') // '';
 
 if ($op eq 'cancelreceipt') {
@@ -128,33 +140,10 @@ if ($op eq 'cancelreceipt') {
     }
 }
 
-my $invoice = GetInvoiceDetails($invoiceid);
 my $booksellerid = $invoice->{booksellerid};
 my $bookseller = GetBookSellerFromId($booksellerid);
 my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
 my $datereceived = C4::Dates->new();
-my $code            = $input->param('code');
-my @rcv_err         = $input->param('error');
-my @rcv_err_barcode = $input->param('error_bc');
-my $startfrom=$input->param('startfrom');
-my $resultsperpage = $input->param('resultsperpage');
-$resultsperpage = 20 unless ($resultsperpage);
-$startfrom=0 unless ($startfrom);
-
-
-
-# If receiving error, report the error (coming from finishrecieve.pl(sic)).
-if( scalar(@rcv_err) ) {
-       my $cnt=0;
-       my $error_loop;
-       for my $err (@rcv_err) {
-               push @$error_loop, { "error_$err" => 1 , barcode => $rcv_err_barcode[$cnt] };
-               $cnt++;
-       }
-       $template->param( receive_error => 1 ,
-                                               error_loop => $error_loop,
-                                       );
-}
 
 my $cfstr         = "%.2f";                                                           # currency format string -- could get this from currency table.
 my @parcelitems   = @{ $invoice->{orders} };
@@ -281,40 +270,7 @@ if(!defined $invoice->{closedate}) {
         my $budget = GetBudget( $line{budget_id} );
         $line{budget_name} = $budget->{'budget_name'};
 
-        push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage);
-    }
-
-    my $count = $countpendings;
-
-    if ($count>$resultsperpage){
-        my $displaynext=0;
-        my $displayprev=$startfrom;
-        if(($count - ($startfrom+$resultsperpage)) > 0 ) {
-            $displaynext = 1;
-        }
-
-        my @numbers = ();
-        for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
-                my $highlight=0;
-                ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
-                push @numbers, { number => $i,
-                    highlight => $highlight ,
-                    startfrom => ($i-1)*$resultsperpage};
-        }
-
-        my $from = $startfrom*$resultsperpage+1;
-        my $to;
-        if($count < (($startfrom+1)*$resultsperpage)){
-            $to = $count;
-        } else {
-            $to = (($startfrom+1)*$resultsperpage);
-        }
-        $template->param(numbers=>\@numbers,
-                         displaynext=>$displaynext,
-                         displayprev=>$displayprev,
-                         nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
-                         prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
-                        );
+        push @loop_orders, \%line;
     }
 
     $template->param(
@@ -333,12 +289,10 @@ $template->param(
     booksellerid          => $bookseller->{id},
     countreceived         => $countlines,
     loop_received         => \@loop_received,
-    booksellerid          => $booksellerid,
     loop_orders           => \@loop_orders,
     book_foot_loop        => \@book_foot_loop,
     totalprice            => sprintf($cfstr, $totalprice),
     totalquantity         => $totalquantity,
-    resultsperpage        => $resultsperpage,
     (uc(C4::Context->preference("marcflavour"))) => 1,
     total_quantity       => $total_quantity,
     total_gste           => sprintf( "%.2f", $total_gste ),