Bug 14187 - DBRev 16.12.00.002
[koha.git] / acqui / transferorder.pl
blob6cd1d2ebabb54f3faa816a77a32051a0be1eba1e
1 #!/usr/bin/perl
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>
22 use Modern::Perl;
23 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Output;
27 use C4::Context;
28 use C4::Acquisition;
29 use C4::Members;
30 use Koha::Acquisition::Booksellers;
32 my $input = new CGI;
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 { template_name => "acqui/transferorder.tt",
35 query => $input,
36 type => "intranet",
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 = '';
52 if($order) {
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;
60 if($booksellerfrom){
61 $booksellerfromname = $booksellerfrom->name;
63 my $booksellerto = Koha::Acquisition::Booksellers->finf( $bookselleridto );
64 my $booksellertoname;
65 if($booksellerto){
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;
88 my @basketsloop = ();
89 for( my $i = 0 ; $i < $basketscount ; $i++ ){
90 my %line;
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};
96 $template->param(
97 show_baskets => 1,
98 basketsloop => \@basketsloop,
99 basketfromname => $basketfrom->{basketname},
101 } elsif ( $bookselleridfrom && !defined $ordernumber) {
102 # Show pending orders
103 my $pendingorders = SearchOrders({
104 booksellerid => $bookselleridfrom,
105 pending => 1,
107 my $orderscount = scalar @$pendingorders;
108 my @ordersloop = ();
109 for( my $i = 0 ; $i < $orderscount ; $i++ ){
110 my %line;
111 %line = %{ $pendingorders->[$i] };
112 push @ordersloop, \%line;
114 $template->param(
115 ordersloop => \@ordersloop,
117 } else {
118 # Search for booksellers to transfer from/to
119 $op = '' unless $op;
120 if( $op eq "do_search" ) {
121 my @booksellers = Koha::Acquisition::Booksellers->search({ name => $query });
122 $template->param(
123 query => $query,
124 do_search => 1,
125 booksellersloop => \@booksellers,
130 $template->param(
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;