Bug 8378 - followup - update notices to use <<items.fine>>
[koha.git] / acqui / finishreceive.pl
blob0ea16ca899d082bbe695d2dbdce61fa76bb1758e
1 #!/usr/bin/perl
3 #script to add a new item and to mark orders as received
4 #written 1/3/00 by chris@katipo.co.nz
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
13 # version.
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
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
25 use CGI;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Context;
29 use C4::Acquisition;
30 use C4::Biblio;
31 use C4::Bookseller;
32 use C4::Items;
33 use C4::Search;
34 use List::MoreUtils qw/any/;
36 my $input=new CGI;
37 my $flagsrequired = {acquisition => 'order_receive'};
39 checkauth($input, 0, $flagsrequired, 'intranet');
41 my $user = $input->remote_user;
42 my $biblionumber = $input->param('biblionumber');
43 my $biblioitemnumber = $input->param('biblioitemnumber');
44 my $ordernumber = $input->param('ordernumber');
45 my $origquantityrec = $input->param('origquantityrec');
46 my $quantityrec = $input->param('quantityrec');
47 my $quantity = $input->param('quantity');
48 my $unitprice = $input->param('cost');
49 my $invoiceid = $input->param('invoiceid');
50 my $invoice = GetInvoice($invoiceid);
51 my $invoiceno = $invoice->{invoicenumber};
52 my $datereceived = $invoice->{shipmentdate};
53 my $booksellerid = $input->param('booksellerid');
54 my $cnt = 0;
55 my $error_url_str;
56 my $ecost = $input->param('ecost');
57 my $rrp = $input->param('rrp');
58 my $note = $input->param("note");
59 my $order = GetOrder($ordernumber);
61 #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME
62 if ($quantityrec > $origquantityrec ) {
63 my @received_items = ();
64 if(C4::Context->preference('AcqCreateItem') eq 'ordering') {
65 @received_items = $input->param('items_to_receive');
68 $order->{rrp} = $rrp;
69 $order->{ecost} = $ecost;
70 $order->{unitprice} = $unitprice;
71 my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
72 if ( $bookseller->{listincgst} ) {
73 if ( not $bookseller->{invoiceincgst} ) {
74 $order->{rrp} = $order->{rrp} * ( 1 + $order->{gstrate} );
75 $order->{ecost} = $order->{ecost} * ( 1 + $order->{gstrate} );
76 $order->{unitprice} = $order->{unitprice} * ( 1 + $order->{gstrate} );
78 } else {
79 if ( $bookseller->{invoiceincgst} ) {
80 $order->{rrp} = $order->{rrp} / ( 1 + $order->{gstrate} );
81 $order->{ecost} = $order->{ecost} / ( 1 + $order->{gstrate} );
82 $order->{unitprice} = $order->{unitprice} / ( 1 + $order->{gstrate} );
86 my $new_ordernumber = $ordernumber;
87 # save the quantity received.
88 if ( $quantityrec > 0 ) {
89 ($datereceived, $new_ordernumber) = ModReceiveOrder(
90 $biblionumber,
91 $ordernumber,
92 $quantityrec,
93 $user,
94 $order->{unitprice},
95 $order->{ecost},
96 $invoiceid,
97 $order->{rrp},
98 undef,
99 $datereceived,
100 \@received_items,
104 # now, add items if applicable
105 if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
107 my @tags = $input->param('tag');
108 my @subfields = $input->param('subfield');
109 my @field_values = $input->param('field_value');
110 my @serials = $input->param('serial');
111 my @itemid = $input->param('itemid');
112 my @ind_tag = $input->param('ind_tag');
113 my @indicator = $input->param('indicator');
114 #Rebuilding ALL the data for items into a hash
115 # parting them on $itemid.
116 my %itemhash;
117 my $countdistinct;
118 my $range=scalar(@itemid);
119 for (my $i=0; $i<$range; $i++){
120 unless ($itemhash{$itemid[$i]}){
121 $countdistinct++;
123 push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
124 push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
125 push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
126 push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
127 push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
129 foreach my $item (keys %itemhash){
130 my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
131 $itemhash{$item}->{'subfields'},
132 $itemhash{$item}->{'field_values'},
133 $itemhash{$item}->{'ind_tag'},
134 $itemhash{$item}->{'indicator'},'ITEM');
135 my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
136 my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
137 NewOrderItem($itemnumber, $new_ordernumber);
143 update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber );
145 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid");
147 ################################ End of script ################################
149 sub update_item {
150 my ( $itemnumber ) = @_;
152 ModItem( {
153 booksellerid => $booksellerid,
154 dateaccessioned => $datereceived,
155 price => $unitprice,
156 replacementprice => $rrp,
157 replacementpricedate => $datereceived,
158 }, $biblionumber, $itemnumber );