Bug 26145: (follow-up 2) DBIC schema changes
[koha.git] / acqui / uncertainprice.pl
blob93f7975381245e80b3e30026f80b9f478f90ba85
1 #!/usr/bin/perl
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
7 # Copyright 2008-2009 BibLibre SARL
9 # This file is part of Koha.
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.
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.
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>.
25 =head1 NAME
27 uncertainprice.pl
29 =head1 DESCRIPTION
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
33 =head1 CGI PARAMETERS
35 =over 4
37 =item $booksellerid
39 The bookseller who we want to display the orders of.
41 =back
43 =cut
46 use Modern::Perl;
48 use C4::Auth;
49 use C4::Output;
50 use CGI qw ( -utf8 );
52 use C4::Acquisition qw/SearchOrders GetOrder ModOrder/;
53 use C4::Biblio qw/GetBiblioData/;
55 use Koha::Acquisition::Booksellers;
56 use Koha::Acquisition::Baskets;
58 my $input=new CGI;
60 my ($template, $loggedinuser, $cookie)
61 = get_template_and_user({template_name => "acqui/uncertainprice.tt",
62 query => $input,
63 type => "intranet",
64 flagsrequired => { acquisition => 'order_manage' },
65 debug => 1,
66 });
68 my $booksellerid = $input->param('booksellerid');
69 my $basketno = $input->param('basketno');
70 my $op = $input->param('op');
71 my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders
72 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
74 $template->param( basket => Koha::Acquisition::Baskets->find($basketno) );
76 #show all orders that have uncertain price for the bookseller
77 my $pendingorders = SearchOrders({
78 booksellerid => $booksellerid,
79 owner => $owner,
80 basketno => $basketno,
81 pending => 1,
82 });
83 my @orders = grep { $_->{'uncertainprice'} } @$pendingorders;
85 if ( $op eq 'validate' ) {
86 $template->param( validate => 1);
87 my $count = scalar(@orders);
88 for (my $i=0; $i < $count; $i++) {
89 my $order = pop(@orders);
90 my $ordernumber = $order->{ordernumber};
91 my $order_as_from_db=GetOrder($order->{ordernumber});
92 $order->{'listprice'} = $input->param('price'.$ordernumber);
93 $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->discount);
94 $order->{'rrp'} = $input->param('price'.$ordernumber);
95 $order->{'quantity'}=$input->param('qty'.$ordernumber);
96 $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber);
97 ModOrder($order);
101 $template->param( uncertainpriceorders => \@orders,
102 booksellername => "".$bookseller->name,
103 booksellerid => $bookseller->id,
104 booksellerpostal =>$bookseller->postal,
105 bookselleraddress1 => $bookseller->address1,
106 bookselleraddress2 => $bookseller->address2,
107 bookselleraddress3 => $bookseller->address3,
108 bookselleraddress4 => $bookseller->address4,
109 booksellerphone =>$bookseller->phone,
110 booksellernotes => $bookseller->notes,
111 basketcount => $bookseller->baskets->count,
112 subscriptioncount => $bookseller->subscriptions->count,
113 active => $bookseller->active,
114 owner => $owner,
115 scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl");
116 $template->{'VARS'}->{'contacts'} = $bookseller->contacts;
117 output_html_with_http_headers $input, $cookie, $template->output;