3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
29 use C4::Interface::CGI::Output;
41 This script display all informations about basket for the supplier given
42 on input arg. Moreover, it allow to add a new order for this supplier from
43 an existing record, a suggestion or from a new record.
51 this parameter seems to be unused.
55 the supplier this script have to display the basket.
66 my $basketno = $query->param('basketno');
67 my $booksellerid = $query->param('supplierid');
68 my $order = $query->param('order');
69 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
71 template_name => "acqui/basket.tmpl",
75 flagsrequired => { acquisition => 1 },
80 my $basket = GetBasket($basketno);
81 $basket->{authorisedbyname};
82 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
83 # if no booksellerid in parameter, get it from basket
84 $booksellerid = $basket->{booksellerid} unless $booksellerid;
85 my @booksellers = GetBookSeller($booksellerid);
86 my $count2 = scalar @booksellers;
88 # get librarian branch...
89 if ( C4::Context->preference("IndependantBranches") ) {
90 my $userenv = C4::Context->userenv;
91 unless ( $userenv->{flags} == 1 ) {
92 my $validtest = ( $basket->{creationdate} eq '' )
93 || ( $basket->{branch} eq '' )
94 || ( $userenv->{branch} eq $basket->{branch} )
95 || ( $userenv->{branch} eq '' )
96 || ( $basket->{branch} eq '' );
98 print $query->redirect("../mainpage.pl");
104 # if new basket, pre-fill infos
105 $basket->{creationdate} = "" unless ( $basket->{creationdate} );
106 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
108 my ( $count, @results );
109 @results = GetOrders( $basketno, $order );
110 $count = scalar @results;
111 my $line_total; # total of each line
112 my $gist =C4::Context->preference('gist'); # GST
115 # my $line_total_est; # total of each line
116 my $sub_total_est; # total of line totals
118 my $grand_total_est; # $subttotal + $gist_est - $disc_est
123 for ( my $i = 0 ; $i < $count ; $i++ ) {
124 $line_total = $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
125 $sub_total_est += $line_total ;
126 $disc_est +=$line_total *$results[$i]->{'discount'}/100;
127 $gist_est +=($line_total - ($line_total *$results[$i]->{'discount'}/100))*$results[$i]->{'gst'}/100;
130 $qty_total += $results[$i]->{'quantity'};
132 if ( $toggle == 0 ) {
133 $line{color} = '#EEEEEE';
137 $line{color} = 'white';
140 $line{ordernumber} = $results[$i]->{'ordernumber'};
141 $line{publishercode} = $results[$i]->{'publishercode'};
142 $line{isbn} = $results[$i]->{'isbn'};
143 $line{booksellerid} = $booksellers[0]->{'id'};
144 $line{basketno} = $basketno;
145 $line{title} = $results[$i]->{'title'};
146 $line{notes} = $results[$i]->{'notes'};
147 $line{author} = $results[$i]->{'author'};
149 $line{rrp} = sprintf( "%.2f", $results[$i]->{'rrp'} );
150 $line{ecost} = sprintf( "%.2f", $results[$i]->{'ecost'} );
151 $line{discount} = sprintf( "%.2f", $results[$i]->{'discount'} );
152 $line{quantity} = $results[$i]->{'quantity'};
153 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
154 $line{line_total} = sprintf( "%.2f", $line_total );
155 $line{biblionumber} = $results[$i]->{'biblionumber'};
156 $line{bookfundid} = $results[$i]->{'bookfundid'};
158 if ($line{quantityrecieved}>0){$line{donotdelete}=1;}
159 push @books_loop, \%line;
160 $template->param(purchaseordernumber => $results[0]->{'purchaseordernumber'},
161 booksellerinvoicenumber=>$results[0]->{booksellerinvoicenumber},);
163 $grand_total_est = sprintf( "%.2f", $sub_total_est - $disc_est+$gist_est );
166 basketno => $basketno,
167 creationdate => format_date( $basket->{creationdate} ),
168 authorisedby => $basket->{authorisedby},
169 authorisedbyname => $basket->{authorisedbyname},
170 closedate => format_date( $basket->{closedate} ),
171 active => $booksellers[0]->{'active'},
172 booksellerid => $booksellers[0]->{'id'},
173 name => $booksellers[0]->{'name'},
174 address1 => $booksellers[0]->{'address1'},
175 address2 => $booksellers[0]->{'address2'},
176 address3 => $booksellers[0]->{'address3'},
177 address4 => $booksellers[0]->{'address4'},
178 entrydate => format_date( $results[0]->{'entrydate'} ),
179 books_loop => \@books_loop,
182 sub_total_est => sprintf( "%.2f",$sub_total_est),
183 gist_est => sprintf( "%.2f",$gist_est),
184 disc_est => sprintf( "%.2f",$disc_est),
185 grand_total_est => $grand_total_est,
186 currency => $booksellers[0]->{'listprice'},
187 qty_total => $qty_total,
189 output_html_with_http_headers $query, $cookie, $template->output;