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",
40 flagsrequired
=> { acquisition
=> 'order_manage' },
45 my $dbh = C4
::Context
->dbh;
47 my $bookselleridfrom = $input->param('bookselleridfrom');
48 my $ordernumber = $input->param('ordernumber');
49 my $bookselleridto = $input->param('bookselleridto');
50 my $basketno = $input->param('basketno');
51 my $op = $input->param('op');
52 my $query = $input->param('query');
54 my $order = GetOrder
($ordernumber);
56 my $basket = GetBasket
($order->{basketno
});
57 $bookselleridfrom = $basket->{booksellerid
} if $basket;
60 my $booksellerfrom = GetBookSellerFromId
($bookselleridfrom);
61 my $booksellerfromname;
63 $booksellerfromname = $booksellerfrom->{name
};
65 my $booksellerto = GetBookSellerFromId
($bookselleridto);
68 $booksellertoname = $booksellerto->{name
};
71 if( $basketno && $ordernumber) {
72 # Transfer order and exit
73 my $order = GetOrder
( $ordernumber );
74 my $basket = GetBasket
($order->{basketno
});
75 my $booksellerfrom = GetBookSellerFromId
($basket->{booksellerid
});
76 my $bookselleridfrom = $booksellerfrom->{id
};
78 TransferOrder
($ordernumber, $basketno);
80 $template->param(transferred
=> 1)
81 } elsif ( $bookselleridto && $ordernumber) {
82 # Show open baskets for this bookseller
83 my $order = GetOrder
( $ordernumber );
84 my $basketfrom = GetBasket
( $order->{basketno
} );
85 my $booksellerfrom = GetBookSellerFromId
( $basketfrom->{booksellerid
} );
86 $booksellerfromname = $booksellerfrom->{name
};
87 my $baskets = GetBasketsByBookseller
( $bookselleridto );
88 my $basketscount = scalar @
$baskets;
90 for( my $i = 0 ; $i < $basketscount ; $i++ ){
92 %line = %{ $baskets->[$i] };
93 my $createdby = GetMember
(borrowernumber
=> $line{authorisedby
});
94 $line{createdby
} = "$createdby->{surname}, $createdby->{firstname}";
95 push @basketsloop, \
%line unless $line{closedate
};
99 basketsloop
=> \
@basketsloop,
100 basketfromname
=> $basketfrom->{basketname
},
102 } elsif ( $bookselleridfrom && !defined $ordernumber) {
103 # Show pending orders
104 my $pendingorders = SearchOrders
({
105 booksellerid
=> $bookselleridfrom,
108 my $orderscount = scalar @
$pendingorders;
110 for( my $i = 0 ; $i < $orderscount ; $i++ ){
112 %line = %{ $pendingorders->[$i] };
113 push @ordersloop, \
%line;
116 ordersloop
=> \
@ordersloop,
119 # Search for booksellers to transfer from/to
121 if( $op eq "do_search" ) {
122 my @booksellers = GetBookSeller
($query);
126 booksellersloop
=> \
@booksellers,
132 bookselleridfrom
=> $bookselleridfrom,
133 booksellerfromname
=> $booksellerfromname,
134 bookselleridto
=> $bookselleridto,
135 booksellertoname
=> $booksellertoname,
136 ordernumber
=> $ordernumber,
137 basketno
=> $basketno,
140 output_html_with_http_headers
$input, $cookie, $template->output;