A new acquisition to handle different tax values to each item, receiving multiple...
[koha.git] / acqui / finishreceive.pl
1 #!/usr/bin/perl
2
3 #script to add a new item and to mark orders as received
4 #written 1/3/00 by chris@katipo.co.nz
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 # this script makes the items, addorder.pl has already made the biblio and biblioitem records: MASON
24
25
26 =head1 NAME
27
28 finishreceive.pl
29
30 =head1 DESCRIPTION
31 TODO
32
33 =head1 CGI PARAMETERS
34
35 =over 4
36
37 TODO
38
39 =back
40
41 =cut
42
43 use strict;
44 use C4::Acquisition;
45 use CGI;
46 use C4::Interface::CGI::Output;
47 use C4::Auth;
48 use C4::Bookseller;
49
50 my $input = new CGI;
51
52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
53     {
54         template_name   => "acqui/finishreceive.tmpl",
55         query           => $input,
56         type            => "intranet",
57         authnotrequired => 0,
58         flagsrequired   => { editcatalogue => 1 },
59         debug           => 1,
60     }
61 );
62
63 my @biblionumber     = $input->param('biblionumber');
64 my @ordnum           = $input->param('ordernumber');
65 my $cost             = $input->param('invoicetotal');
66 my $locacost             = $input->param('localtotal');
67 my $invoiceno        = $input->param('invoice');
68 my @replacement    = $input->param('actual');
69 my @gst            = $input->param('gstrate');
70 my $freight        = $input->param('actualfreight');
71 my @freightperitem = $input->param('freight');
72 my $supplierid     = $input->param('supplierid');
73 my @title         = $input->param('title');
74 my $currencyrate=$input->param('currencyrate');
75 my @bookfund      = $input->param('bookfund');
76 my @discount     = $input->param('discount');
77 my @quantrec      = $input->param('received');
78 my $totalreceived=$input->param('totalreceived');
79 my $incgst=$input->param('incgst');
80 my $ecost;
81 my $unitprice;
82 my $listprice;
83
84 my @supplier=GetBookSeller($supplierid);
85 my $count=scalar @quantrec;
86 my @additems;
87
88  for (my $i=0; $i<$count;$i++){
89  $freightperitem[$i]=$freight/$totalreceived unless  $freightperitem[$i];
90 $listprice=$replacement[$i];
91   $replacement[$i]= $replacement[$i]*$currencyrate;
92         if ($incgst){
93         $ecost= ($replacement[$i]*100/($gst[$i]+100))*(100 - $discount[$i])/100;
94         }else{
95         $ecost= $replacement[$i]*(100 - $discount[$i])/100;
96         }
97 $unitprice=$ecost + $ecost*$gst[$i]/100;
98         if ( $quantrec[$i] != 0 ) {
99          # save the quantity recieved.
100                 ModReceiveOrder( $biblionumber[$i], $ordnum[$i], $quantrec[$i], $unitprice,
101             $invoiceno, $freightperitem[$i], $replacement[$i] ,$listprice,$input );   
102         push @additems,{biblionumber=>$biblionumber[$i],itemcount=>$quantrec[$i], title=>$title[$i],supplier=>$supplier[0]->{name},rrp=>$replacement[$i],};
103
104         }
105 }
106 $template->param(loopbiblios => \@additems,);
107                       
108  output_html_with_http_headers $input, $cookie, $template->output;