Bug 14585: Fixing up online help on main page
[koha.git] / acqui / transferorder.pl
blobd82ce20738b9d1fe4f9580fab504ce0b3c84b670
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;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Context;
28 use C4::Acquisition;
29 use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
30 use C4::Members;
31 use C4::Dates qw/format_date_in_iso/;
32 use Date::Calc qw/Today/;
34 my $input = new CGI;
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36 { template_name => "acqui/transferorder.tt",
37 query => $input,
38 type => "intranet",
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);
53 if($order) {
54 my $basket = GetBasket($order->{basketno});
55 $bookselleridfrom = $basket->{booksellerid} if $basket;
58 my $booksellerfrom = GetBookSellerFromId($bookselleridfrom);
59 my $booksellerfromname;
60 if($booksellerfrom){
61 $booksellerfromname = $booksellerfrom->{name};
63 my $booksellerto = GetBookSellerFromId($bookselleridto);
64 my $booksellertoname;
65 if($booksellerto){
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;
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 = GetBookSeller($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,
138 output_html_with_http_headers $input, $cookie, $template->output;