uncertainprices
[wip/koha-chris_n.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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
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;
53
54 use C4::Bookseller qw/GetBookSellerFromId/;
55 use C4::Acquisition qw/GetPendingOrders GetOrder ModOrder/;
56 use C4::Biblio qw/GetBiblioData/;
57
58 my $input=new CGI;
59
60 my ($template, $loggedinuser, $cookie)
61     = get_template_and_user({template_name => "acqui/uncertainprice.tmpl",
62                              query => $input,
63                              type => "intranet",
64                              authnotrequired => 0,
65                              flagsrequired   => { acquisition => 'order_manage' },
66                              debug => 1,
67                 });
68
69 my $booksellerid = $input->param('booksellerid');
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 = &GetBookSellerFromId($booksellerid);
73
74 #show all orders that have uncertain price for the bookseller
75 my $pendingorders = &GetPendingOrders($booksellerid,0,$owner);
76 my @orders;
77
78 foreach my $order (@{$pendingorders}) {
79     if ( $order->{'uncertainprice'} ) {
80         my $bibdata = &GetBiblioData($order->{'biblionumber'});
81         $order->{'bibisbn'} = $bibdata->{'isbn'};
82         $order->{'bibpublishercode'} = $bibdata->{'publishercode'};
83         $order->{'bibpublicationyear'} = $bibdata->{'publicationyear'};
84         $order->{'bibtitle'} = $bibdata->{'title'};
85         $order->{'bibauthor'} = $bibdata->{'author'};
86         my $order_as_from_db=GetOrder($order->{ordernumber});
87         $order->{'quantity'} = $order_as_from_db->{'quantity'};
88         $order->{'listprice'} = $order_as_from_db->{'listprice'};
89         push(@orders, $order);
90     }
91 }
92 if ( $op eq 'validate' ) {
93     $template->param( validate => 1);
94     my $count = scalar(@orders);
95     for (my $i=0; $i < $count; $i++) {
96         my $order = pop(@orders);
97         my $ordernumber = $order->{ordernumber};
98         my $order_as_from_db=GetOrder($order->{ordernumber});
99         $order->{'listprice'} = $input->param('price'.$ordernumber);
100         $order->{'ecost'}= $input->param('price'.$ordernumber) - (($input->param('price'.$ordernumber) /100) * $bookseller->{'discount'});
101         $order->{'rrp'} = $input->param('price'.$ordernumber);
102         $order->{'quantity'}=$input->param('qty'.$ordernumber);
103         $order->{'uncertainprice'}=$input->param('uncertainprice'.$ordernumber);
104         ModOrder($order);
105     }
106 }
107
108 $template->param( uncertainpriceorders => \@orders,
109                                    booksellername => "".$bookseller->{'name'},
110                                    booksellerid => $bookseller->{'id'},
111                                    booksellerpostal =>$bookseller->{'postal'},
112                                    bookselleraddress1 => $bookseller->{'address1'},
113                                    bookselleraddress2 => $bookseller->{'address2'},
114                                    bookselleraddress3 => $bookseller->{'address3'},
115                                    bookselleraddress4 => $bookseller->{'address4'},
116                                    booksellerphone =>$bookseller->{'phone'},
117                                    booksellerfax => $bookseller->{'fax'},
118                                    booksellerurl => $bookseller->{'url'},
119                                    booksellercontact => $bookseller->{'contact'},
120                                    booksellercontpos => $bookseller->{'contpos'},
121                                    booksellercontphone => $bookseller->{'contphone'},
122                                    booksellercontaltphone => $bookseller->{'contaltphone'},
123                                    booksellercontfax => $bookseller->{'contfax'},
124                                    booksellercontemail => $bookseller->{'contemail'},
125                                    booksellercontnotes => $bookseller->{'contnotes'},
126                                    booksellernotes => $bookseller->{'notes'},
127                                    owner => $owner,
128                                    scriptname => "/cgi-bin/koha/acqui/uncertainprice.pl");
129 output_html_with_http_headers $input, $cookie, $template->output;