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>
30 use Koha::Acquisition::Booksellers;
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 { template_name => "acqui/transferorder.tt",
37 flagsrequired => { acquisition => 'order_manage' },
41 my $dbh = C4::Context->dbh;
43 my $bookselleridfrom = $input->param('bookselleridfrom');
44 my $ordernumber = $input->param('ordernumber');
45 my $bookselleridto = $input->param('bookselleridto');
46 my $basketno = $input->param('basketno');
47 my $op = $input->param('op');
48 my $query = $input->param('query');
50 my $order = GetOrder($ordernumber);
51 my $basketfromname = '';
53 my $basket = GetBasket($order->{basketno});
54 $basketfromname = $basket->{basketname};
55 $bookselleridfrom = $basket->{booksellerid} if $basket;
58 my $booksellerfrom = Koha::Acquisition::Booksellers->find( $bookselleridfrom );
59 my $booksellerfromname;
61 $booksellerfromname = $booksellerfrom->name;
63 my $booksellerto = Koha::Acquisition::Booksellers->find( $bookselleridto );
66 $booksellertoname = $booksellerto->name;
70 if( $basketno && $ordernumber) {
71 # Transfer order and exit
72 my $order = GetOrder( $ordernumber );
73 my $basket = GetBasket($order->{basketno});
74 my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
75 my $bookselleridfrom = $booksellerfrom->id;
77 TransferOrder($ordernumber, $basketno);
79 $template->param(transferred => 1)
80 } elsif ( $bookselleridto && $ordernumber) {
81 # Show open baskets for this bookseller
82 my $order = GetOrder( $ordernumber );
83 my $basketfrom = GetBasket( $order->{basketno} );
84 my $booksellerfrom = Koha::Acquisition::Booksellers->find( $basketfrom->{booksellerid} );
85 $booksellerfromname = $booksellerfrom->name;
86 my $baskets = GetBasketsByBookseller( $bookselleridto );
87 my $basketscount = scalar @$baskets;
89 for( my $i = 0 ; $i < $basketscount ; $i++ ){
91 %line = %{ $baskets->[$i] };
92 my $createdby = GetMember(borrowernumber => $line{authorisedby});
93 $line{createdby} = "$createdby->{surname}, $createdby->{firstname}";
94 push @basketsloop, \%line unless $line{closedate};
98 basketsloop => \@basketsloop,
99 basketfromname => $basketfrom->{basketname},
101 } elsif ( $bookselleridfrom && !defined $ordernumber) {
102 # Show pending orders
103 my $pendingorders = SearchOrders({
104 booksellerid => $bookselleridfrom,
107 my $orderscount = scalar @$pendingorders;
109 for( my $i = 0 ; $i < $orderscount ; $i++ ){
111 %line = %{ $pendingorders->[$i] };
112 push @ordersloop, \%line;
115 ordersloop => \@ordersloop,
118 # Search for booksellers to transfer from/to
120 if( $op eq "do_search" ) {
121 my @booksellers = Koha::Acquisition::Booksellers->search({ name => $query });
125 booksellersloop => \@booksellers,
131 bookselleridfrom => $bookselleridfrom,
132 booksellerfromname => $booksellerfromname,
133 bookselleridto => $bookselleridto,
134 booksellertoname => $booksellertoname,
135 ordernumber => $ordernumber,
136 basketno => $basketno,
137 basketfromname => $basketfromname,
140 output_html_with_http_headers $input, $cookie, $template->output;