3 #script to recieve orders
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 This script shows all orders receipt or pending for a given supplier.
31 It allows to write an order as 'received' when he arrives.
39 To know the supplier this script has to show orders.
43 is the bookseller invoice number.
51 To filter the results list on this given date.
67 use C4::Dates qw/format_date format_date_in_iso/;
69 use C4::Reserves qw/GetReservesFromBiblionumber/;
71 use Koha::Acquisition::Bookseller;
76 my $sticky_filters = $input->param('sticky_filters') || 0;
78 my ($template, $loggedinuser, $cookie)
79 = get_template_and_user({template_name => "acqui/parcel.tt",
83 flagsrequired => {acquisition => 'order_receive'},
87 my $op = $input->param('op') // '';
89 # process cancellation first so that list of
90 # orders to display is calculated after
91 if ($op eq 'cancelreceipt') {
92 my $ordernumber = $input->param('ordernumber');
93 my $parent_ordernumber = CancelReceipt($ordernumber);
94 unless($parent_ordernumber) {
95 $template->param(error_cancelling_receipt => 1);
99 my $invoiceid = $input->param('invoiceid');
101 $invoice = GetInvoiceDetails($invoiceid) if $invoiceid;
103 unless( $invoiceid and $invoice->{invoiceid} ) {
105 error_invoice_not_known => 1,
106 no_orders_to_display => 1
108 output_html_with_http_headers $input, $cookie, $template->output;
112 my $booksellerid = $invoice->{booksellerid};
113 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
114 my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
115 my $datereceived = C4::Dates->new();
117 my @orders = @{ $invoice->{orders} };
118 my $countlines = scalar @orders;
119 my @loop_received = ();
125 for my $order ( @orders ) {
126 $order = C4::Acquisition::populate_order_with_prices({ order => $order, booksellerid => $bookseller->{id}, receiving => 1, ordering => 1 });
127 $order->{'unitprice'} += 0;
129 if ( $bookseller->{listincgst} and not $bookseller->{invoiceincgst} ) {
130 $order->{ecost} = $order->{ecostgste};
131 $order->{unitprice} = $order->{unitpricegste};
133 elsif ( not $bookseller->{listinct} and $bookseller->{invoiceincgst} ) {
134 $order->{ecost} = $order->{ecostgsti};
135 $order->{unitprice} = $order->{unitpricegsti};
137 $order->{total} = $order->{ecost} * $order->{quantity};
139 my %line = %{ $order };
140 $line{invoice} = $invoice->{invoicenumber};
142 my @itemnumbers = GetItemnumbersFromOrder( $order->{ordernumber} );
143 for my $itemnumber ( @itemnumbers ) {
144 my $holds = GetReservesFromBiblionumber({ biblionumber => $line{biblionumber}, itemnumber => $itemnumber });
145 $line{holds} += scalar( @$holds );
147 $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
148 $foot{$line{gstrate}}{gstrate} = $line{gstrate};
149 $foot{$line{gstrate}}{gstvalue} += $line{gstvalue};
150 $total_gste += $line{totalgste};
151 $total_gsti += $line{totalgsti};
153 my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
154 $line{suggestionid} = $suggestion->{suggestionid};
155 $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby};
156 $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
158 if ( $line{parent_ordernumber} != $line{ordernumber} ) {
159 if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
163 $line{cannot_cancel} = 1;
167 my $budget = GetBudget( $line{budget_id} );
168 $line{budget_name} = $budget->{'budget_name'};
170 push @loop_received, \%line;
172 push @book_foot_loop, map { $_ } values %foot;
174 my @loop_orders = ();
175 unless( defined $invoice->{closedate} ) {
177 if ( $op eq "search" or $sticky_filters ) {
178 my ( $search, $ean, $basketname, $orderno, $basketgroupname );
179 if ( $sticky_filters ) {
180 $search = $input->cookie("filter_parcel_summary");
181 $ean = $input->cookie("filter_parcel_ean");
182 $basketname = $input->cookie("filter_parcel_basketname");
183 $orderno = $input->cookie("filter_parcel_orderno");
184 $basketgroupname = $input->cookie("filter_parcel_basketgroupname");
186 $search = $input->param('summaryfilter') || '';
187 $ean = $input->param('eanfilter') || '';
188 $basketname = $input->param('basketfilter') || '';
189 $orderno = $input->param('orderfilter') || '';
190 $basketgroupname = $input->param('basketgroupnamefilter') || '';
192 $pendingorders = SearchOrders({
193 booksellerid => $booksellerid,
194 basketname => $basketname,
195 ordernumber => $orderno,
198 basketgroupname => $basketgroupname,
203 summaryfilter => $search,
205 basketfilter => $basketname,
206 orderfilter => $orderno,
207 basketgroupnamefilter => $basketgroupname,
210 $pendingorders = SearchOrders({
211 booksellerid => $booksellerid,
215 my $countpendings = scalar @$pendingorders;
217 for (my $i = 0 ; $i < $countpendings ; $i++) {
218 my $order = $pendingorders->[$i];
219 $order = C4::Acquisition::populate_order_with_prices({ order => $order, booksellerid => $bookseller->{id}, receiving => 1, ordering => 1 });
221 if ( $bookseller->{listincgst} and not $bookseller->{invoiceincgst} ) {
222 $order->{ecost} = $order->{ecostgste};
223 } elsif ( not $bookseller->{listinct} and $bookseller->{invoiceincgst} ) {
224 $order->{ecost} = $order->{ecostgsti};
226 $order->{total} = $order->{ecost} * $order->{quantity};
230 $line{invoice} = $invoice;
231 $line{booksellerid} = $booksellerid;
233 my $biblionumber = $line{'biblionumber'};
234 my $countbiblio = CountBiblioInOrders($biblionumber);
235 my $ordernumber = $line{'ordernumber'};
236 my @subscriptions = GetSubscriptionsId ($biblionumber);
237 my $itemcount = GetItemsCount($biblionumber);
238 my $holds = GetHolds ($biblionumber);
239 my @items = GetItemnumbersFromOrder( $ordernumber );
241 foreach my $item (@items){
242 my $nb = GetItemHolds($biblionumber, $item);
248 my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
249 $line{suggestionid} = $suggestion->{suggestionid};
250 $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby};
251 $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
253 # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
254 $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
255 $line{items} = ($itemcount) - (scalar @items);
256 $line{left_item} = 1 if $line{items} >= 1;
257 $line{left_biblio} = 1 if $countbiblio > 1;
258 $line{biblios} = $countbiblio - 1;
259 $line{left_subscription} = 1 if scalar @subscriptions >= 1;
260 $line{subscriptions} = scalar @subscriptions;
261 $line{left_holds} = ($holds >= 1) ? 1 : 0;
262 $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
263 $line{holds} = $holds;
264 $line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order};
266 my $budget = GetBudget( $line{budget_id} );
267 $line{budget_name} = $budget->{'budget_name'};
269 push @loop_orders, \%line;
273 loop_orders => \@loop_orders,
278 invoiceid => $invoice->{invoiceid},
279 invoice => $invoice->{invoicenumber},
280 invoiceclosedate => $invoice->{closedate},
281 datereceived => $datereceived->output('iso'),
282 invoicedatereceived => $datereceived->output('iso'),
283 formatteddatereceived => $datereceived->output(),
284 name => $bookseller->{'name'},
285 booksellerid => $bookseller->{id},
286 loop_received => \@loop_received,
287 loop_orders => \@loop_orders,
288 book_foot_loop => \@book_foot_loop,
289 (uc(C4::Context->preference("marcflavour"))) => 1,
290 total_gste => $total_gste,
291 total_gsti => $total_gsti,
292 sticky_filters => $sticky_filters,
294 output_html_with_http_headers $input, $cookie, $template->output;