3 #script to receive 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
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 This script shows all orders receipt or pending for a given supplier.
31 It allows to write an order as 'received' when it 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.
68 use Koha::Acquisition::Baskets;
69 use Koha::Acquisition::Bookseller;
70 use Koha::Acquisition::Orders;
79 my ($template, $loggedinuser, $cookie)
80 = 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 $sticky_filters = $input->param('sticky_filters') || 0;
114 if ($sticky_filters) {
115 my $search = $input->cookie("filter_parcel_summary");
116 my $ean = $input->cookie("filter_parcel_ean");
117 my $basketname = $input->cookie("filter_parcel_basketname");
118 my $orderno = $input->cookie("filter_parcel_orderno");
119 my $basketgroupname = $input->cookie("filter_parcel_basketgroupname");
122 summaryfilter => $search,
124 basketfilter => $basketname,
125 orderfilter => $orderno,
126 basketgroupnamefilter => $basketgroupname,
131 my $booksellerid = $invoice->{booksellerid};
132 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
134 my @orders = @{ $invoice->{orders} };
135 my $countlines = scalar @orders;
136 my @loop_received = ();
139 my $total_tax_excluded = 0;
140 my $total_tax_included = 0;
142 my $subtotal_for_funds;
143 for my $order ( @orders ) {
144 $order->{'unitprice'} += 0;
146 my $order_object = Koha::Acquisition::Orders->find($order->{ordernumber});
147 if ( $bookseller->invoiceincgst ) {
148 $order->{ecost} = $order->{ecost_tax_included};
149 $order->{unitprice} = $order->{unitprice_tax_included};
152 $order->{ecost} = $order->{ecost_tax_excluded};
153 $order->{unitprice} = $order->{unitprice_tax_excluded};
156 $order->{total} = get_rounded_price($order->{unitprice}) * $order->{quantity};
158 my %line = %{ $order };
159 $line{invoice} = $invoice->{invoicenumber};
160 my @itemnumbers = $order_object->items->get_column('itemnumber');
161 my $biblio = Koha::Biblios->find( $line{biblionumber} );
162 $line{total_holds} = $biblio ? $biblio->holds->count : 0;
163 $line{item_holds} = $biblio ? $biblio->current_holds->search(
165 itemnumber => { -in => \@itemnumbers },
168 $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
170 $line{tax_value} = $line{tax_value_on_receiving};
171 $line{tax_rate} = $line{tax_rate_on_receiving};
172 $foot{$line{tax_rate}}{tax_rate} = $line{tax_rate};
173 $foot{$line{tax_rate}}{tax_value} += $line{tax_value};
174 $total_tax_excluded += get_rounded_price($line{unitprice_tax_excluded}) * $line{quantity};
175 $total_tax_included += get_rounded_price($line{unitprice_tax_included}) * $line{quantity};
177 my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
178 $line{suggestionid} = $suggestion->{suggestionid};
179 $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby};
180 $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
182 if ( $line{parent_ordernumber} != $line{ordernumber} ) {
183 if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
187 $line{cannot_cancel} = 1;
191 my $budget_name = GetBudgetName( $line{budget_id} );
192 $line{budget_name} = $budget_name;
194 $subtotal_for_funds->{ $line{budget_name} }{ecost} += get_rounded_price($order->{ecost}) * $order->{quantity};
195 $subtotal_for_funds->{ $line{budget_name} }{unitprice} += $order->{total};
197 push @loop_received, \%line;
199 push @book_foot_loop, map { $_ } values %foot;
202 invoiceid => $invoice->{invoiceid},
203 invoice => $invoice->{invoicenumber},
204 invoiceclosedate => $invoice->{closedate},
205 shipmentdate => $invoice->{shipmentdate},
206 name => $bookseller->name,
207 booksellerid => $bookseller->id,
208 loop_received => \@loop_received,
209 book_foot_loop => \@book_foot_loop,
210 (uc(C4::Context->preference("marcflavour"))) => 1,
211 total_tax_excluded => $total_tax_excluded,
212 total_tax_included => $total_tax_included,
213 subtotal_for_funds => $subtotal_for_funds,
214 sticky_filters => $sticky_filters,
216 output_html_with_http_headers $input, $cookie, $template->output;