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
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
35 use Koha
::Acquisition
::Bookseller
;
37 use List
::MoreUtils qw
/any/;
40 my $flagsrequired = {acquisition
=> 'order_receive'};
42 checkauth
($input, 0, $flagsrequired, 'intranet');
44 my $user = $input->remote_user;
45 my $biblionumber = $input->param('biblionumber');
46 my $ordernumber = $input->param('ordernumber');
47 my $origquantityrec = $input->param('origquantityrec');
48 my $quantityrec = $input->param('quantityrec');
49 my $quantity = $input->param('quantity');
50 my $unitprice = $input->param('cost');
51 my $datereceived = $input->param('datereceived'),
52 my $invoiceid = $input->param('invoiceid');
53 my $invoice = GetInvoice
($invoiceid);
54 my $invoiceno = $invoice->{invoicenumber
};
55 my $booksellerid = $input->param('booksellerid');
57 my $ecost = $input->param('ecost');
58 my $rrp = $input->param('rrp');
59 my $order_internalnote = $input->param("order_internalnote");
60 my $bookfund = $input->param("bookfund");
61 my $order = GetOrder
($ordernumber);
62 my $new_ordernumber = $ordernumber;
64 #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME
65 if ($quantityrec > $origquantityrec ) {
66 my @received_items = ();
67 if(C4
::Context
->preference('AcqCreateItem') eq 'ordering') {
68 @received_items = $input->multi_param('items_to_receive');
69 my @affects = split q{\|}, C4
::Context
->preference("AcqItemSetSubfieldsWhenReceived");
71 my $frameworkcode = GetFrameworkCode
($biblionumber);
72 my ( $itemfield ) = GetMarcFromKohaField
( 'items.itemnumber', $frameworkcode );
73 for my $in ( @received_items ) {
74 my $item = C4
::Items
::GetMarcItem
( $biblionumber, $in );
75 for my $affect ( @affects ) {
76 my ( $sf, $v ) = split q{=}, $affect, 2;
77 foreach ( $item->field($itemfield) ) {
78 $_->update( $sf => $v );
81 C4
::Items
::ModItemFromMarc
( $item, $biblionumber, $in );
87 $order->{ecost
} = $ecost;
88 $order->{unitprice
} = $unitprice;
89 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
90 if ( $bookseller->{listincgst
} ) {
91 if ( not $bookseller->{invoiceincgst
} ) {
92 $order->{rrp
} = $order->{rrp
} * ( 1 + $order->{gstrate
} );
93 $order->{ecost
} = $order->{ecost
} * ( 1 + $order->{gstrate
} );
94 $order->{unitprice
} = $order->{unitprice
} * ( 1 + $order->{gstrate
} );
97 if ( $bookseller->{invoiceincgst
} ) {
98 $order->{rrp
} = $order->{rrp
} / ( 1 + $order->{gstrate
} );
99 $order->{ecost
} = $order->{ecost
} / ( 1 + $order->{gstrate
} );
100 $order->{unitprice
} = $order->{unitprice
} / ( 1 + $order->{gstrate
} );
104 # save the quantity received.
105 if ( $quantityrec > 0 ) {
106 ($datereceived, $new_ordernumber) = ModReceiveOrder
({
107 biblionumber
=> $biblionumber,
108 ordernumber
=> $ordernumber,
109 quantityreceived
=> $quantityrec,
111 cost
=> $order->{unitprice
},
112 ecost
=> $order->{ecost
},
113 invoiceid
=> $invoiceid,
114 rrp
=> $order->{rrp
},
115 budget_id
=> $bookfund,
116 datereceived
=> $datereceived,
117 received_items
=> \
@received_items,
118 order_internalnote
=> $order_internalnote,
122 # now, add items if applicable
123 if (C4
::Context
->preference('AcqCreateItem') eq 'receiving') {
125 my @tags = $input->multi_param('tag');
126 my @subfields = $input->multi_param('subfield');
127 my @field_values = $input->multi_param('field_value');
128 my @serials = $input->multi_param('serial');
129 my @itemid = $input->multi_param('itemid');
130 my @ind_tag = $input->multi_param('ind_tag');
131 my @indicator = $input->multi_param('indicator');
132 #Rebuilding ALL the data for items into a hash
133 # parting them on $itemid.
136 my $range=scalar(@itemid);
137 for (my $i=0; $i<$range; $i++){
138 unless ($itemhash{$itemid[$i]}){
141 push @
{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
142 push @
{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
143 push @
{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
144 push @
{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
145 push @
{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
147 my $order = Koha
::Acquisition
::Order
->fetch({ ordernumber
=> $new_ordernumber });
148 foreach my $item (keys %itemhash){
149 my $xml = TransformHtmlToXml
( $itemhash{$item}->{'tags'},
150 $itemhash{$item}->{'subfields'},
151 $itemhash{$item}->{'field_values'},
152 $itemhash{$item}->{'indicator'},
153 $itemhash{$item}->{'ind_tag'},
155 my $record=MARC
::Record
::new_from_xml
($xml, 'UTF-8');
156 my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc
($record,$biblionumber);
157 $order->add_item( $itemnumber );
164 booksellerid
=> $booksellerid,
165 dateaccessioned
=> $datereceived,
167 replacementprice
=> $rrp,
168 replacementpricedate
=> $datereceived,
172 ) foreach GetItemnumbersFromOrder
($new_ordernumber);
174 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");