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>.
34 use Koha
::Acquisition
::Booksellers
;
36 use List
::MoreUtils qw
/any/;
39 my $flagsrequired = {acquisition
=> 'order_receive'};
41 checkauth
($input, 0, $flagsrequired, 'intranet');
43 my $user = $input->remote_user;
44 my $biblionumber = $input->param('biblionumber');
45 my $ordernumber = $input->param('ordernumber');
46 my $origquantityrec = $input->param('origquantityrec');
47 my $quantityrec = $input->param('quantityrec');
48 my $quantity = $input->param('quantity');
49 my $unitprice = $input->param('unitprice');
50 my $datereceived = $input->param('datereceived'),
51 my $invoiceid = $input->param('invoiceid');
52 my $invoice = GetInvoice
($invoiceid);
53 my $invoiceno = $invoice->{invoicenumber
};
54 my $booksellerid = $input->param('booksellerid');
56 my $bookfund = $input->param("bookfund");
57 my $order = GetOrder
($ordernumber);
58 my $new_ordernumber = $ordernumber;
60 #need old receivedate if we update the order, parcel.pl only shows the right parcel this way FIXME
61 if ($quantityrec > $origquantityrec ) {
62 my @received_items = ();
63 if(C4
::Context
->preference('AcqCreateItem') eq 'ordering') {
64 @received_items = $input->multi_param('items_to_receive');
65 my @affects = split q{\|}, C4
::Context
->preference("AcqItemSetSubfieldsWhenReceived");
67 my $frameworkcode = GetFrameworkCode
($biblionumber);
68 my ( $itemfield ) = GetMarcFromKohaField
( 'items.itemnumber', $frameworkcode );
69 for my $in ( @received_items ) {
70 my $item = C4
::Items
::GetMarcItem
( $biblionumber, $in );
71 for my $affect ( @affects ) {
72 my ( $sf, $v ) = split q{=}, $affect, 2;
73 foreach ( $item->field($itemfield) ) {
74 $_->update( $sf => $v );
77 C4
::Items
::ModItemFromMarc
( $item, $biblionumber, $in );
82 $order->{order_internalnote
} = $input->param("order_internalnote");
83 $order->{tax_rate_on_receiving
} = $input->param("tax_rate");
84 $order->{unitprice
} = $unitprice;
86 $order = C4
::Acquisition
::populate_order_with_prices
(
89 booksellerid
=> $booksellerid,
94 # save the quantity received.
95 if ( $quantityrec > 0 ) {
96 ( $datereceived, $new_ordernumber ) = ModReceiveOrder
(
98 biblionumber
=> $biblionumber,
100 quantityreceived
=> $quantityrec,
103 budget_id
=> $bookfund,
104 received_items
=> \
@received_items,
109 # now, add items if applicable
110 if (C4
::Context
->preference('AcqCreateItem') eq 'receiving') {
112 my @tags = $input->multi_param('tag');
113 my @subfields = $input->multi_param('subfield');
114 my @field_values = $input->multi_param('field_value');
115 my @serials = $input->multi_param('serial');
116 my @itemid = $input->multi_param('itemid');
117 my @ind_tag = $input->multi_param('ind_tag');
118 my @indicator = $input->multi_param('indicator');
119 #Rebuilding ALL the data for items into a hash
120 # parting them on $itemid.
123 my $range=scalar(@itemid);
124 for (my $i=0; $i<$range; $i++){
125 unless ($itemhash{$itemid[$i]}){
128 push @
{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
129 push @
{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
130 push @
{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
131 push @
{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
132 push @
{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
134 my $order = Koha
::Acquisition
::Order
->fetch({ ordernumber
=> $new_ordernumber });
135 foreach my $item (keys %itemhash){
136 my $xml = TransformHtmlToXml
( $itemhash{$item}->{'tags'},
137 $itemhash{$item}->{'subfields'},
138 $itemhash{$item}->{'field_values'},
139 $itemhash{$item}->{'indicator'},
140 $itemhash{$item}->{'ind_tag'},
142 my $record=MARC
::Record
::new_from_xml
($xml, 'UTF-8');
143 my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc
($record,$biblionumber);
144 $order->add_item( $itemnumber );
151 booksellerid
=> $booksellerid,
152 dateaccessioned
=> $datereceived,
154 replacementprice
=> $order->{rrp
},
155 replacementpricedate
=> $datereceived,
159 ) foreach GetItemnumbersFromOrder
($new_ordernumber);
161 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");