Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / acqui / transferorder.pl
blob5ce3890a2781d80b82ffed1617a2a8f05f407bb0
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;
31 my $input = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 { template_name => "acqui/transferorder.tt",
34 query => $input,
35 type => "intranet",
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 = '';
51 if($order) {
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;
59 if($booksellerfrom){
60 $booksellerfromname = $booksellerfrom->{name};
62 my $booksellerto = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridto });
63 my $booksellertoname;
64 if($booksellerto){
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;
87 my @basketsloop = ();
88 for( my $i = 0 ; $i < $basketscount ; $i++ ){
89 my %line;
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};
95 $template->param(
96 show_baskets => 1,
97 basketsloop => \@basketsloop,
98 basketfromname => $basketfrom->{basketname},
100 } elsif ( $bookselleridfrom && !defined $ordernumber) {
101 # Show pending orders
102 my $pendingorders = SearchOrders({
103 booksellerid => $bookselleridfrom,
104 pending => 1,
106 my $orderscount = scalar @$pendingorders;
107 my @ordersloop = ();
108 for( my $i = 0 ; $i < $orderscount ; $i++ ){
109 my %line;
110 %line = %{ $pendingorders->[$i] };
111 push @ordersloop, \%line;
113 $template->param(
114 ordersloop => \@ordersloop,
116 } else {
117 # Search for booksellers to transfer from/to
118 $op = '' unless $op;
119 if( $op eq "do_search" ) {
120 my @booksellers = Koha::Acquisition::Bookseller->search({ name => $query });
121 $template->param(
122 query => $query,
123 do_search => 1,
124 booksellersloop => \@booksellers,
129 $template->param(
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;