"Fossies" - the Fresh Open Source Software Archive 
Member "koha-19.11.15/acqui/finishreceive.pl" (23 Feb 2021, 7470 Bytes) of package /linux/misc/koha-19.11.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "finishreceive.pl" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
20.05.06_vs_20.11.00.
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
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.
14 #
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.
19 #
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>.
22
23 use Modern::Perl;
24 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Output;
27 use C4::Context;
28 use C4::Acquisition;
29 use C4::Biblio;
30 use C4::Items;
31 use C4::Search;
32
33 use Koha::Number::Price;
34 use Koha::Acquisition::Booksellers;
35 use Koha::Acquisition::Orders;
36
37 use List::MoreUtils qw/any/;
38
39 my $input=new CGI;
40 my $flagsrequired = {acquisition => 'order_receive'};
41
42 checkauth($input, 0, $flagsrequired, 'intranet');
43
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('unitprice');
51 my $replacementprice = $input->param('replacementprice');
52 my $datereceived = $input->param('datereceived'),
53 my $invoiceid = $input->param('invoiceid');
54 my $invoice = GetInvoice($invoiceid);
55 my $invoiceno = $invoice->{invoicenumber};
56 my $booksellerid = $input->param('booksellerid');
57 my $cnt = 0;
58 my $bookfund = $input->param("bookfund");
59 my $order = GetOrder($ordernumber);
60 my $new_ordernumber = $ordernumber;
61
62 #bug18723 regression fix
63 if (C4::Context->preference("CurrencyFormat") eq 'FR') {
64 if (rindex($unitprice, '.') ge 0) {
65 substr($unitprice, rindex($unitprice, '.'), 1, ',');
66 }
67 if (rindex($replacementprice,'.') ge 0) {
68 substr($replacementprice, rindex($replacementprice, '.'), 1, ',');
69 }
70 }
71
72 $unitprice = Koha::Number::Price->new( $unitprice )->unformat();
73 $replacementprice = Koha::Number::Price->new( $replacementprice )->unformat();
74 my $order_obj = Koha::Acquisition::Orders->find( $ordernumber );
75 my $basket = $order_obj->basket;
76
77 #need old receivedate if we update the order, parcel.pl only shows the right parcel this way FIXME
78 if ($quantityrec > $origquantityrec ) {
79 my @received_items = ();
80 if ($basket->effective_create_items eq 'ordering') {
81 @received_items = $input->param('items_to_receive');
82 my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceived");
83 if ( @affects ) {
84 my $frameworkcode = GetFrameworkCode($biblionumber);
85 my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber' );
86 for my $in ( @received_items ) {
87 my $item = C4::Items::GetMarcItem( $biblionumber, $in );
88 for my $affect ( @affects ) {
89 my ( $sf, $v ) = split q{=}, $affect, 2;
90 foreach ( $item->field($itemfield) ) {
91 $_->update( $sf => $v );
92 }
93 }
94 C4::Items::ModItemFromMarc( $item, $biblionumber, $in );
95 }
96 }
97 }
98
99 $order->{order_internalnote} = $input->param("order_internalnote");
100 $order->{tax_rate_on_receiving} = $input->param("tax_rate");
101 $order->{replacementprice} = $replacementprice;
102 $order->{unitprice} = $unitprice;
103
104 $order = C4::Acquisition::populate_order_with_prices(
105 {
106 order => $order,
107 booksellerid => $booksellerid,
108 receiving => 1
109 }
110 );
111
112 # save the quantity received.
113 if ( $quantityrec > 0 ) {
114 if ( $order_obj->subscriptionid ) {
115 # Quantity can only be modified if linked to a subscription
116 $order->{quantity} = $quantity; # quantityrec will be deduced from this value in ModReceiveOrder
117 }
118 ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
119 {
120 biblionumber => $biblionumber,
121 order => $order,
122 quantityreceived => $quantityrec,
123 user => $user,
124 invoice => $invoice,
125 budget_id => $bookfund,
126 datereceived => $datereceived,
127 received_items => \@received_items,
128 }
129 );
130 }
131
132 # now, add items if applicable
133 if ($basket->effective_create_items eq 'receiving') {
134
135 my @tags = $input->multi_param('tag');
136 my @subfields = $input->multi_param('subfield');
137 my @field_values = $input->multi_param('field_value');
138 my @serials = $input->multi_param('serial');
139 my @itemid = $input->multi_param('itemid');
140 my @ind_tag = $input->multi_param('ind_tag');
141 my @indicator = $input->multi_param('indicator');
142 #Rebuilding ALL the data for items into a hash
143 # parting them on $itemid.
144 my %itemhash;
145 my $countdistinct;
146 my $range=scalar(@itemid);
147 for (my $i=0; $i<$range; $i++){
148 unless ($itemhash{$itemid[$i]}){
149 $countdistinct++;
150 }
151 push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
152 push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
153 push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
154 push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
155 push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
156 }
157 my $new_order = Koha::Acquisition::Orders->find( $new_ordernumber );
158 foreach my $item (keys %itemhash){
159 my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
160 $itemhash{$item}->{'subfields'},
161 $itemhash{$item}->{'field_values'},
162 $itemhash{$item}->{'indicator'},
163 $itemhash{$item}->{'ind_tag'},
164 'ITEM' );
165 my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
166 my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
167 $new_order->add_item( $itemnumber );
168 }
169 }
170 }
171
172 my $new_order_object = Koha::Acquisition::Orders->find( $new_ordernumber ); # FIXME we should not need to refetch it
173 my $items = $new_order_object->items;
174 while ( my $item = $items->next ) {
175 ModItem(
176 {
177 booksellerid => $booksellerid,
178 dateaccessioned => $datereceived,
179 datelastseen => $datereceived,
180 price => $unitprice,
181 replacementprice => $replacementprice,
182 replacementpricedate => $datereceived,
183 },
184 $biblionumber,
185 $item->itemnumber,
186 );
187 }
188
189 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");