+
+sub get_order_infos {
+ my $order = shift;
+ my $bookseller = shift;
+ my $qty = $order->{'quantity'} || 0;
+ if ( !defined $order->{quantityreceived} ) {
+ $order->{quantityreceived} = 0;
+ }
+ my $budget = GetBudget($order->{budget_id});
+ my $basket = GetBasket($order->{basketno});
+
+ my %line = %{ $order };
+ # Don't show unreceived standing orders as received
+ $line{order_received} = ( $qty == $order->{'quantityreceived'} && ( $basket->{is_standing} ? $qty : 1 ) );
+ $line{basketno} = $basketno;
+ $line{budget_name} = $budget->{budget_name};
+
+ $line{total_tax_included} = $line{ecost_tax_included} * $line{quantity};
+ $line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity};
+ $line{tax_value} = $line{tax_value_on_ordering};
+ $line{tax_rate} = $line{tax_rate_on_ordering};
+
+ if ( $line{uncertainprice} ) {
+ $line{rrp_tax_excluded} .= ' (Uncertain)';
+ }
+ if ( $line{'title'} ) {
+ my $volume = $order->{'volume'};
+ my $seriestitle = $order->{'seriestitle'};
+ $line{'title'} .= " / $seriestitle" if $seriestitle;
+ $line{'title'} .= " / $volume" if $volume;
+ }
+
+ my $biblionumber = $order->{'biblionumber'};
+ if ( $biblionumber ) { # The biblio still exists
+ my $biblio = Koha::Biblios->find( $biblionumber );
+ my $countbiblio = CountBiblioInOrders($biblionumber);
+ my $ordernumber = $order->{'ordernumber'};
+ my $cnt_subscriptions = $biblio->subscriptions->count;
+ my $itemcount = $biblio->items->count;
+ my $holds_count = $biblio->holds->count;
+ my $order = Koha::Acquisition::Orders->find($ordernumber); # FIXME We should certainly do that at the beginning of this sub
+ my $items = $order->items;
+ my $itemholds = $biblio->holds->search({ itemnumber => { -in => [ $items->get_column('itemnumber') ] } })->count;
+
+ # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
+ $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == $items->count && !($cnt_subscriptions) && !($holds_count);
+ $line{items} = $itemcount - $items->count;
+ $line{left_item} = 1 if $line{items} >= 1;
+ $line{left_biblio} = 1 if $countbiblio > 1;
+ $line{biblios} = $countbiblio - 1;
+ $line{left_subscription} = 1 if $cnt_subscriptions;
+ $line{subscriptions} = $cnt_subscriptions;
+ ($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0;
+ $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
+ $line{holds} = $holds_count;
+ $line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order};
+ }
+
+
+ my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
+ $line{suggestionid} = $$suggestion{suggestionid};
+ $line{surnamesuggestedby} = $$suggestion{surnamesuggestedby};
+ $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby};
+
+ foreach my $key (qw(transferred_from transferred_to)) {
+ if ($line{$key}) {
+ my $order = GetOrder($line{$key});
+ my $basket = GetBasket($order->{basketno});
+ my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
+ $line{$key} = {
+ order => $order,
+ basket => $basket,
+ bookseller => $bookseller,
+ timestamp => $line{$key . '_timestamp'},
+ };
+ }
+ }
+
+ return \%line;
+}
+
+sub edi_close_and_order {
+ my $confirm = $query->param('confirm') || $confirm_pref eq '2';
+ if ($confirm) {
+ my $edi_params = {
+ basketno => $basketno,
+ ean => $ean,
+ };
+ if ( $basket->{branch} ) {
+ $edi_params->{branchcode} = $basket->{branch};
+ }
+ if ( create_edi_order($edi_params) ) {
+ #$template->param( edifile => 1 );
+ }
+ CloseBasket($basketno);
+
+ # if requested, create basket group, close it and attach the basket
+ if ( $query->param('createbasketgroup') ) {
+ my $branchcode;
+ if ( C4::Context->userenv
+ and C4::Context->userenv->{'branch'}
+ and C4::Context->userenv->{'branch'} ne "NO_LIBRARY_SET" )
+ {
+ $branchcode = C4::Context->userenv->{'branch'};
+ }
+ my $basketgroupid = NewBasketgroup(
+ {
+ name => $basket->{basketname},
+ booksellerid => $booksellerid,
+ deliveryplace => $branchcode,
+ billingplace => $branchcode,
+ closed => 1,
+ }
+ );
+ ModBasket(
+ {
+ basketno => $basketno,
+ basketgroupid => $basketgroupid
+ }
+ );
+ print $query->redirect(
+"/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=$booksellerid&closed=1"
+ );
+ }
+ else {
+ print $query->redirect(
+ "/cgi-bin/koha/acqui/booksellers.pl?booksellerid=$booksellerid"
+ );
+ }
+ exit;
+ }
+ else {
+ $template->param(
+ edi_confirm => 1,
+ booksellerid => $booksellerid,
+ basketno => $basket->{basketno},
+ basketname => $basket->{basketname},
+ basketgroupname => $basket->{basketname},
+ );
+ if ($ean) {
+ $template->param( ean => $ean );
+ }
+
+ }
+ return;
+}