A new acquisition to handle different tax values to each item, receiving multiple...
[koha.git] / acqui / basket.pl
1 #!/usr/bin/perl
2
3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
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
13 # version.
14 #
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.
18 #
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
22
23 # $Id$
24
25 use strict;
26 use C4::Auth;
27 use C4::Koha;
28 use CGI;
29 use C4::Interface::CGI::Output;
30 use C4::Acquisition;
31 use C4::Bookfund;
32 use C4::Bookseller;
33 use C4::Date;
34
35 =head1 NAME
36
37 basket.pl
38
39 =head1 DESCRIPTION
40
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.
44
45 =head1 CGI PARAMETERS
46
47 =over 4
48
49 =item $basketno
50
51 this parameter seems to be unused.
52
53 =item supplierid
54
55 the supplier this script have to display the basket.
56
57 =item order
58
59
60
61 =back
62
63 =cut
64
65 my $query        = new CGI;
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(
70     {
71         template_name   => "acqui/basket.tmpl",
72         query           => $query,
73         type            => "intranet",
74         authnotrequired => 0,
75         flagsrequired   => { acquisition => 1 },
76         debug           => 1,
77     }
78 );
79
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;
87
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 '' );
97         unless ($validtest) {
98             print $query->redirect("../mainpage.pl");
99             exit 1;
100         }
101     }
102 }
103
104 # if new basket, pre-fill infos
105 $basket->{creationdate} = ""            unless ( $basket->{creationdate} );
106 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
107
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 
113 my $toggle = 0;
114
115 # my $line_total_est; # total of each line
116 my $sub_total_est;      # total of line totals
117 my $gist_est;           # GST
118 my $grand_total_est;    # $subttotal + $gist_est - $disc_est
119 my $disc_est;
120 my $qty_total;
121
122 my @books_loop;
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;
128    
129    
130     $qty_total += $results[$i]->{'quantity'};
131     my %line;
132    if ( $toggle == 0 ) {
133         $line{color} = '#EEEEEE';
134         $toggle = 1;
135     }
136     else {
137         $line{color} = 'white';
138         $toggle = 0;
139     }
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'};
148     $line{i}                = $i;
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'};
157     $line{odd}              = $i % 2;
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},);
162 }
163 $grand_total_est =  sprintf( "%.2f", $sub_total_est - $disc_est+$gist_est );
164
165 $template->param(
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,
180     count            => $count,
181     gist             => $gist,
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,
188 );
189 output_html_with_http_headers $query, $cookie, $template->output;