Bug 10951 - Tweaked opac-auth.tt sentence.
[koha.git] / acqui / transferorder.pl
blobfe4968afc77279eeb53e28eb73039282c553105e
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.tmpl",
37 query => $input,
38 type => "intranet",
39 authnotrequired => 1,
40 flagsrequired => { acquisition => 'order_manage' },
41 debug => 1,
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);
55 if($order) {
56 my $basket = GetBasket($order->{basketno});
57 $bookselleridfrom = $basket->{booksellerid} if $basket;
60 my $booksellerfrom = GetBookSellerFromId($bookselleridfrom);
61 my $booksellerfromname;
62 if($booksellerfrom){
63 $booksellerfromname = $booksellerfrom->{name};
65 my $booksellerto = GetBookSellerFromId($bookselleridto);
66 my $booksellertoname;
67 if($booksellerto){
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;
89 my @basketsloop = ();
90 for( my $i = 0 ; $i < $basketscount ; $i++ ){
91 my %line;
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};
97 $template->param(
98 show_baskets => 1,
99 basketsloop => \@basketsloop,
100 basketfromname => $basketfrom->{basketname},
102 } elsif ( $bookselleridfrom && !defined $ordernumber) {
103 # Show pending orders
104 my $pendingorders = SearchOrders({
105 booksellerid => $bookselleridfrom,
106 pending => 1,
108 my $orderscount = scalar @$pendingorders;
109 my @ordersloop = ();
110 for( my $i = 0 ; $i < $orderscount ; $i++ ){
111 my %line;
112 %line = %{ $pendingorders->[$i] };
113 push @ordersloop, \%line;
115 $template->param(
116 ordersloop => \@ordersloop,
118 } else {
119 # Search for booksellers to transfer from/to
120 $op = '' unless $op;
121 if( $op eq "do_search" ) {
122 my @booksellers = GetBookSeller($query);
123 $template->param(
124 query => $query,
125 do_search => 1,
126 booksellersloop => \@booksellers,
131 $template->param(
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;