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>
29 use C4
::Bookseller qw
/GetBookSellerFromId GetBookSeller/;
31 use C4
::Dates qw
/format_date_in_iso/;
32 use Date
::Calc qw
/Today/;
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
36 { template_name
=> "acqui/transferorder.tmpl",
39 flagsrequired
=> { acquisition
=> 'order_manage' },
43 my $dbh = C4
::Context
->dbh;
45 my $bookselleridfrom = $input->param('bookselleridfrom');
46 my $ordernumber = $input->param('ordernumber');
47 my $bookselleridto = $input->param('bookselleridto');
48 my $basketno = $input->param('basketno');
49 my $op = $input->param('op');
50 my $query = $input->param('query');
52 my $order = GetOrder
($ordernumber);
54 my $basket = GetBasket
($order->{basketno
});
55 $bookselleridfrom = $basket->{booksellerid
} if $basket;
58 my $booksellerfrom = GetBookSellerFromId
($bookselleridfrom);
59 my $booksellerfromname;
61 $booksellerfromname = $booksellerfrom->{name
};
63 my $booksellerto = GetBookSellerFromId
($bookselleridto);
66 $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 = GetBookSellerFromId
($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 = GetBookSellerFromId
( $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 = GetBookSeller
($query);
124 booksellersloop
=> \
@booksellers,
130 bookselleridfrom
=> $bookselleridfrom,
131 booksellerfromname
=> $booksellerfromname,
132 bookselleridto
=> $bookselleridto,
133 booksellertoname
=> $booksellertoname,
134 ordernumber
=> $ordernumber,
135 basketno
=> $basketno,
138 output_html_with_http_headers
$input, $cookie, $template->output;