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 C4
::Dates qw
/format_date_in_iso/;
31 use Date
::Calc qw
/Today/;
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
35 { template_name
=> "acqui/transferorder.tt",
38 flagsrequired
=> { acquisition
=> 'order_manage' },
42 my $dbh = C4
::Context
->dbh;
44 my $bookselleridfrom = $input->param('bookselleridfrom');
45 my $ordernumber = $input->param('ordernumber');
46 my $bookselleridto = $input->param('bookselleridto');
47 my $basketno = $input->param('basketno');
48 my $op = $input->param('op');
49 my $query = $input->param('query');
51 my $order = GetOrder
($ordernumber);
53 my $basket = GetBasket
($order->{basketno
});
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
};
68 if( $basketno && $ordernumber) {
69 # Transfer order and exit
70 my $order = GetOrder
( $ordernumber );
71 my $basket = GetBasket
($order->{basketno
});
72 my $booksellerfrom = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $basket->{booksellerid
} });
73 my $bookselleridfrom = $booksellerfrom->{id
};
75 TransferOrder
($ordernumber, $basketno);
77 $template->param(transferred
=> 1)
78 } elsif ( $bookselleridto && $ordernumber) {
79 # Show open baskets for this bookseller
80 my $order = GetOrder
( $ordernumber );
81 my $basketfrom = GetBasket
( $order->{basketno
} );
82 my $booksellerfrom = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $basketfrom->{booksellerid
} });
83 $booksellerfromname = $booksellerfrom->{name
};
84 my $baskets = GetBasketsByBookseller
( $bookselleridto );
85 my $basketscount = scalar @
$baskets;
87 for( my $i = 0 ; $i < $basketscount ; $i++ ){
89 %line = %{ $baskets->[$i] };
90 my $createdby = GetMember
(borrowernumber
=> $line{authorisedby
});
91 $line{createdby
} = "$createdby->{surname}, $createdby->{firstname}";
92 push @basketsloop, \
%line unless $line{closedate
};
96 basketsloop
=> \
@basketsloop,
97 basketfromname
=> $basketfrom->{basketname
},
99 } elsif ( $bookselleridfrom && !defined $ordernumber) {
100 # Show pending orders
101 my $pendingorders = SearchOrders
({
102 booksellerid
=> $bookselleridfrom,
105 my $orderscount = scalar @
$pendingorders;
107 for( my $i = 0 ; $i < $orderscount ; $i++ ){
109 %line = %{ $pendingorders->[$i] };
110 push @ordersloop, \
%line;
113 ordersloop
=> \
@ordersloop,
116 # Search for booksellers to transfer from/to
118 if( $op eq "do_search" ) {
119 my @booksellers = Koha
::Acquisition
::Bookseller
->search({ name
=> $query });
123 booksellersloop
=> \
@booksellers,
129 bookselleridfrom
=> $bookselleridfrom,
130 booksellerfromname
=> $booksellerfromname,
131 bookselleridto
=> $bookselleridto,
132 booksellertoname
=> $booksellertoname,
133 ordernumber
=> $ordernumber,
134 basketno
=> $basketno,
137 output_html_with_http_headers
$input, $cookie, $template->output;