Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Script to move an order from a bookseller to another |
4 |
|
5 |
# Copyright 2011 BibLibre SARL |
6 |
# |
7 |
# This file is part of Koha. |
8 |
# |
9 |
# Koha is free software; you can redistribute it and/or modify it under the |
10 |
# terms of the GNU General Public License as published by the Free Software |
11 |
# Foundation; either version 2 of the License, or (at your option) any later |
12 |
# version. |
13 |
# |
14 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
15 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
17 |
# |
18 |
# You should have received a copy of the GNU General Public License along |
19 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 |
|
22 |
use Modern::Perl; |
23 |
use CGI; |
24 |
|
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/; |
33 |
|
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, |
42 |
} |
43 |
); |
44 |
|
45 |
my $dbh = C4::Context->dbh; |
46 |
|
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'); |
53 |
|
54 |
my $order = GetOrder($ordernumber); |
55 |
if($order) { |
56 |
my $basket = GetBasket($order->{basketno}); |
57 |
$bookselleridfrom = $basket->{booksellerid} if $basket; |
58 |
} |
59 |
|
60 |
my $booksellerfrom = GetBookSellerFromId($bookselleridfrom); |
61 |
my $booksellerfromname; |
62 |
if($booksellerfrom){ |
63 |
$booksellerfromname = $booksellerfrom->{name}; |
64 |
} |
65 |
my $booksellerto = GetBookSellerFromId($bookselleridto); |
66 |
my $booksellertoname; |
67 |
if($booksellerto){ |
68 |
$booksellertoname = $booksellerto->{name}; |
69 |
} |
70 |
|
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}; |
77 |
|
78 |
TransferOrder($ordernumber, $basketno); |
79 |
|
80 |
my $referrer = $input->param('referrer'); |
81 |
print $input->redirect($referrer); |
82 |
exit; |
83 |
} elsif ( $bookselleridto && $ordernumber) { |
84 |
# Show open baskets for this bookseller |
85 |
my $order = GetOrder( $ordernumber ); |
86 |
my $basketfrom = GetBasket( $order->{basketno} ); |
87 |
my $booksellerfrom = GetBookSellerFromId( $basketfrom->{booksellerid} ); |
88 |
$booksellerfromname = $booksellerfrom->{name}; |
89 |
my $baskets = GetBasketsByBookseller( $bookselleridto ); |
90 |
my $basketscount = scalar @$baskets; |
91 |
my @basketsloop = (); |
92 |
for( my $i = 0 ; $i < $basketscount ; $i++ ){ |
93 |
my %line; |
94 |
%line = %{ $baskets->[$i] }; |
95 |
my $createdby = GetMember(borrowernumber => $line{authorisedby}); |
96 |
$line{createdby} = "$createdby->{surname}, $createdby->{firstname}"; |
97 |
push @basketsloop, \%line unless $line{closedate}; |
98 |
} |
99 |
$template->param( |
100 |
show_baskets => 1, |
101 |
basketsloop => \@basketsloop, |
102 |
basketfromname => $basketfrom->{basketname}, |
103 |
); |
104 |
} elsif ( $bookselleridfrom && !defined $ordernumber) { |
105 |
# Show pending orders |
106 |
my $pendingorders = GetPendingOrders($bookselleridfrom); |
107 |
my $orderscount = scalar @$pendingorders; |
108 |
my @ordersloop = (); |
109 |
for( my $i = 0 ; $i < $orderscount ; $i++ ){ |
110 |
my %line; |
111 |
%line = %{ $pendingorders->[$i] }; |
112 |
push @ordersloop, \%line; |
113 |
} |
114 |
$template->param( |
115 |
ordersloop => \@ordersloop, |
116 |
); |
117 |
} else { |
118 |
# Search for booksellers to transfer from/to |
119 |
$op = '' unless $op; |
120 |
if( $op eq "do_search" ) { |
121 |
my @booksellers = GetBookSeller($query); |
122 |
$template->param( |
123 |
query => $query, |
124 |
do_search => 1, |
125 |
booksellersloop => \@booksellers, |
126 |
); |
127 |
} else { |
128 |
$template->param( |
129 |
search_form => 1, |
130 |
); |
131 |
} |
132 |
} |
133 |
|
134 |
$template->param( |
135 |
bookselleridfrom => $bookselleridfrom, |
136 |
booksellerfromname => $booksellerfromname, |
137 |
bookselleridto => $bookselleridto, |
138 |
booksellertoname => $booksellertoname, |
139 |
ordernumber => $ordernumber, |
140 |
basketno => $basketno, |
141 |
referrer => $input->param('referrer') |
142 |
); |
143 |
|
144 |
output_html_with_http_headers $input, $cookie, $template->output; |
145 |
|