3 # Script to move an order from a bookseller to another
5 # Copyright 2011 BibLibre SARL
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 { template_name => "acqui/transferorder.tt",
36 flagsrequired => { acquisition => 'order_manage' },
40 my $dbh = C4::Context->dbh;
42 my $bookselleridfrom = $input->param('bookselleridfrom');
43 my $ordernumber = $input->param('ordernumber');
44 my $bookselleridto = $input->param('bookselleridto');
45 my $basketno = $input->param('basketno');
46 my $op = $input->param('op');
47 my $query = $input->param('query');
49 my $order = GetOrder($ordernumber);
50 my $basketfromname = '';
52 my $basket = GetBasket($order->{basketno});
53 $basketfromname = $basket->{basketname};
54 $bookselleridfrom = $basket->{booksellerid} if $basket;
57 my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridfrom });
58 my $booksellerfromname;
60 $booksellerfromname = $booksellerfrom->{name};
62 my $booksellerto = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridto });
65 $booksellertoname = $booksellerto->{name};
69 if( $basketno && $ordernumber) {
70 # Transfer order and exit
71 my $order = GetOrder( $ordernumber );
72 my $basket = GetBasket($order->{basketno});
73 my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
74 my $bookselleridfrom = $booksellerfrom->{id};
76 TransferOrder($ordernumber, $basketno);
78 $template->param(transferred => 1)
79 } elsif ( $bookselleridto && $ordernumber) {
80 # Show open baskets for this bookseller
81 my $order = GetOrder( $ordernumber );
82 my $basketfrom = GetBasket( $order->{basketno} );
83 my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basketfrom->{booksellerid} });
84 $booksellerfromname = $booksellerfrom->{name};
85 my $baskets = GetBasketsByBookseller( $bookselleridto );
86 my $basketscount = scalar @$baskets;
88 for( my $i = 0 ; $i < $basketscount ; $i++ ){
90 %line = %{ $baskets->[$i] };
91 my $createdby = GetMember(borrowernumber => $line{authorisedby});
92 $line{createdby} = "$createdby->{surname}, $createdby->{firstname}";
93 push @basketsloop, \%line unless $line{closedate};
97 basketsloop => \@basketsloop,
98 basketfromname => $basketfrom->{basketname},
100 } elsif ( $bookselleridfrom && !defined $ordernumber) {
101 # Show pending orders
102 my $pendingorders = SearchOrders({
103 booksellerid => $bookselleridfrom,
106 my $orderscount = scalar @$pendingorders;
108 for( my $i = 0 ; $i < $orderscount ; $i++ ){
110 %line = %{ $pendingorders->[$i] };
111 push @ordersloop, \%line;
114 ordersloop => \@ordersloop,
117 # Search for booksellers to transfer from/to
119 if( $op eq "do_search" ) {
120 my @booksellers = Koha::Acquisition::Bookseller->search({ name => $query });
124 booksellersloop => \@booksellers,
130 bookselleridfrom => $bookselleridfrom,
131 booksellerfromname => $booksellerfromname,
132 bookselleridto => $bookselleridto,
133 booksellertoname => $booksellertoname,
134 ordernumber => $ordernumber,
135 basketno => $basketno,
136 basketfromname => $basketfromname,
139 output_html_with_http_headers $input, $cookie, $template->output;