Bug 9978: Replace license header with the correct license (GPLv3+)
[koha.git] / acqui / uncertainprice.pl
1 #!/usr/bin/perl
2
3 #script to show a list of orders with uncertain prices for a bookseller
4 #the script also allows to edit the prices and uncheck the uncertainprice property of them
5 #written by john.soros@biblibre.com 01/10/2008
6
7 # Copyright 2008-2009 BibLibre SARL
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23
24
25 =head1 NAME
26
27 uncertainprice.pl
28
29 =head1 DESCRIPTION
30
31  This script displays all the orders with uncertain prices for a given bookseller, it also lets the user modify the unitprice and uncertainprice properties of the order
32
33 =head1 CGI PARAMETERS
34
35 =over 4
36
37 =item $booksellerid
38
39 The bookseller who we want to display the orders of.
40
41 =back
42
43 =cut
44
45
46 use strict;
47 use warnings;
48
49 use C4::Input;
50 use C4::Auth;
51 use C4::Output;
52 use CGI qw ( -utf8 );
53
54 use C4::Bookseller::Contact;
55 use C4::Acquisition qw/SearchOrders GetOrder ModOrder/;
56 use C4::Biblio qw/GetBiblioData/;
57
58 use Koha::Acquisition::Bookseller;
59
60 my $input=new CGI;
61
62 my ($template, $loggedinuser, $cookie)
63     = get_template_and_user({template_name => "acqui/uncertainprice.tt",
64                              query => $input,
65                              type => "intranet",
66                              authnotrequired => 0,
67                              flagsrequired   => { acquisition => 'order_manage' },
68                              debug => 1,
69                 });
70
71 my $booksellerid = $input->param('booksellerid');
72 my $basketno     = $input->param('basketno');
73 my $op = $input->param('op');
74 my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders
75 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
76
77 #show all orders that have uncertain price for the bookseller
78 my $pendingorders = SearchOrders({
79     booksellerid => $booksellerid,
80     owner => $owner,
81     basketno => $basketno,
82     pending => 1,
83 });
84 my @orders;
85
86 foreach my $order (@{$pendingorders}) {
87     if ( $order->{'uncertainprice'} ) {
88         my $bibdata = &GetBiblioData($order->{'biblionumber'});
89         $order->{'bibisbn'} = $bibdata->{'isbn'};
90         $order->{'bibpublishercode'} = $bibdata->{'publishercode'};
91         $order->{'bibpublicationyear'} = $bibdata->{'publicationyear'};
92         $order->{'bibtitle'} = $bibdata->{'title'};
93         $order->{'bibauthor'} = $bibdata->{'author'};
94         $order->{'surname'} = $order->{'surname'};
95         $order->{'firstname'} = $order->{'firstname'};
96         my $order_as_from_db=GetOrder($order->{ordernumber});
97         $order->{'quantity'} = $order_as_from_db->{'quantity'};
98         $order->{'listprice'} = $order_as_from_db->{'listprice'};
99         push(@orders, $order);
100     }
101 }
102 if ( $op eq 'validate' ) {
103     $template->param( validate => 1);
104     my $count = scalar(@orders);
105     for (my $i=0; $i < $count; $i++) {
106         my $order = pop(@orders);
107         my $ordernumber = $order->{ordernumber};
108         my $order_as_from_db=GetOrder($order->{ordernumber});
109         $order->{'listprice'} = $input->param('price'.$ordernumber);
110         $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->{'discount'});
111         $order->{'rrp'} = $input->param('price'.$ordernumber);
112         $order->{'quantity'}=$input->param('qty'.$ordernumber);
113         $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber);
114         ModOrder($order);
115     }
116 }
117
118 $template->param( uncertainpriceorders => \@orders,
119                                    booksellername => "".$bookseller->{'name'},
120                                    booksellerid => $bookseller->{'id'},
121                                    booksellerpostal =>$bookseller->{'postal'},
122                                    bookselleraddress1 => $bookseller->{'address1'},
123                                    bookselleraddress2 => $bookseller->{'address2'},
124                                    bookselleraddress3 => $bookseller->{'address3'},
125                                    bookselleraddress4 => $bookseller->{'address4'},
126                                    booksellerphone =>$bookseller->{'phone'},
127                                    booksellerfax => $bookseller->{'fax'},
128                                    booksellerurl => $bookseller->{'url'},
129                                    booksellernotes => $bookseller->{'notes'},
130                                    basketcount   => $bookseller->{'basketcount'},
131                                    subscriptioncount   => $bookseller->{'subscriptioncount'},
132                                    owner => $owner,
133                                    scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl");
134 $template->{'VARS'}->{'contacts'} = $bookseller->{'contacts'};
135 output_html_with_http_headers $input, $cookie, $template->output;