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 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.
68 use C4
::Reserves qw
/GetReservesFromBiblionumber/;
70 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 });
115 my @orders = @
{ $invoice->{orders
} };
116 my $countlines = scalar @orders;
117 my @loop_received = ();
120 my $total_tax_excluded = 0;
121 my $total_tax_included = 0;
123 my $subtotal_for_funds;
124 for my $order ( @orders ) {
125 $order->{'unitprice'} += 0;
127 if ( $bookseller->{invoiceincgst
} ) {
128 $order->{ecost
} = $order->{ecost_tax_included
};
129 $order->{unitprice
} = $order->{unitprice_tax_included
};
132 $order->{ecost
} = $order->{ecost_tax_excluded
};
133 $order->{unitprice
} = $order->{unitprice_tax_excluded
};
136 $order->{total
} = $order->{unitprice
} * $order->{quantity
};
138 my %line = %{ $order };
139 $line{invoice
} = $invoice->{invoicenumber
};
141 my @itemnumbers = GetItemnumbersFromOrder
( $order->{ordernumber
} );
142 for my $itemnumber ( @itemnumbers ) {
143 my $holds = GetReservesFromBiblionumber
({ biblionumber
=> $line{biblionumber
}, itemnumber
=> $itemnumber });
144 $line{holds
} += scalar( @
$holds );
146 $line{budget
} = GetBudgetByOrderNumber
( $line{ordernumber
} );
148 $line{tax_value
} = $line{tax_value_on_receiving
};
149 $line{tax_rate
} = $line{tax_rate_on_receiving
};
150 $foot{$line{tax_rate
}}{tax_rate
} = $line{tax_rate
};
151 $foot{$line{tax_rate
}}{tax_value
} += $line{tax_value
};
152 $total_tax_excluded += $line{unitprice_tax_excluded
} * $line{quantity
};
153 $total_tax_included += $line{unitprice_tax_included
} * $line{quantity
};
155 my $suggestion = GetSuggestionInfoFromBiblionumber
($line{biblionumber
});
156 $line{suggestionid
} = $suggestion->{suggestionid
};
157 $line{surnamesuggestedby
} = $suggestion->{surnamesuggestedby
};
158 $line{firstnamesuggestedby
} = $suggestion->{firstnamesuggestedby
};
160 if ( $line{parent_ordernumber
} != $line{ordernumber
} ) {
161 if ( grep { $_->{ordernumber
} == $line{parent_ordernumber
} }
165 $line{cannot_cancel
} = 1;
169 my $budget_name = GetBudgetName
( $line{budget_id
} );
170 $line{budget_name
} = $budget_name;
172 $subtotal_for_funds->{ $line{budget_name
} }{ecost
} += $order->{ecost
} * $order->{quantity
};
173 $subtotal_for_funds->{ $line{budget_name
} }{unitprice
} += $order->{total
};
175 push @loop_received, \
%line;
177 push @book_foot_loop, map { $_ } values %foot;
179 my @loop_orders = ();
180 unless( defined $invoice->{closedate
} ) {
182 if ( $op eq "search" or $sticky_filters ) {
183 my ( $search, $ean, $basketname, $orderno, $basketgroupname );
184 if ( $sticky_filters ) {
185 $search = $input->cookie("filter_parcel_summary");
186 $ean = $input->cookie("filter_parcel_ean");
187 $basketname = $input->cookie("filter_parcel_basketname");
188 $orderno = $input->cookie("filter_parcel_orderno");
189 $basketgroupname = $input->cookie("filter_parcel_basketgroupname");
191 $search = $input->param('summaryfilter') || '';
192 $ean = $input->param('eanfilter') || '';
193 $basketname = $input->param('basketfilter') || '';
194 $orderno = $input->param('orderfilter') || '';
195 $basketgroupname = $input->param('basketgroupnamefilter') || '';
197 $pendingorders = SearchOrders
({
198 booksellerid
=> $booksellerid,
199 basketname
=> $basketname,
200 ordernumber
=> $orderno,
203 basketgroupname
=> $basketgroupname,
208 summaryfilter
=> $search,
210 basketfilter
=> $basketname,
211 orderfilter
=> $orderno,
212 basketgroupnamefilter
=> $basketgroupname,
215 $pendingorders = SearchOrders
({
216 booksellerid
=> $booksellerid,
220 my $countpendings = scalar @
$pendingorders;
222 for (my $i = 0 ; $i < $countpendings ; $i++) {
223 my $order = $pendingorders->[$i];
225 if ( $bookseller->{invoiceincgst
} ) {
226 $order->{ecost
} = $order->{ecost_tax_included
};
228 $order->{ecost
} = $order->{ecost_tax_excluded
};
230 $order->{total
} = $order->{ecost
} * $order->{quantity
};
234 $line{invoice
} = $invoice;
235 $line{booksellerid
} = $booksellerid;
237 my $biblionumber = $line{'biblionumber'};
238 my $countbiblio = CountBiblioInOrders
($biblionumber);
239 my $ordernumber = $line{'ordernumber'};
240 my @subscriptions = GetSubscriptionsId
($biblionumber);
241 my $itemcount = GetItemsCount
($biblionumber);
242 my $holds = GetHolds
($biblionumber);
243 my @items = GetItemnumbersFromOrder
( $ordernumber );
245 foreach my $item (@items){
246 my $nb = GetItemHolds
($biblionumber, $item);
252 my $suggestion = GetSuggestionInfoFromBiblionumber
($line{biblionumber
});
253 $line{suggestionid
} = $suggestion->{suggestionid
};
254 $line{surnamesuggestedby
} = $suggestion->{surnamesuggestedby
};
255 $line{firstnamesuggestedby
} = $suggestion->{firstnamesuggestedby
};
257 # 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
258 $line{can_del_bib
} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
259 $line{items
} = ($itemcount) - (scalar @items);
260 $line{left_item
} = 1 if $line{items
} >= 1;
261 $line{left_biblio
} = 1 if $countbiblio > 1;
262 $line{biblios
} = $countbiblio - 1;
263 $line{left_subscription
} = 1 if scalar @subscriptions >= 1;
264 $line{subscriptions
} = scalar @subscriptions;
265 $line{left_holds
} = ($holds >= 1) ?
1 : 0;
266 $line{left_holds_on_order
} = 1 if $line{left_holds
}==1 && ($line{items
} == 0 || $itemholds );
267 $line{holds
} = $holds;
268 $line{holds_on_order
} = $itemholds?
$itemholds:$holds if $line{left_holds_on_order
};
270 my $budget_name = GetBudgetName
( $line{budget_id
} );
271 $line{budget_name
} = $budget_name;
273 push @loop_orders, \
%line;
277 loop_orders
=> \
@loop_orders,
282 invoiceid
=> $invoice->{invoiceid
},
283 invoice
=> $invoice->{invoicenumber
},
284 invoiceclosedate
=> $invoice->{closedate
},
285 datereceived
=> dt_from_string
,
286 name
=> $bookseller->{'name'},
287 booksellerid
=> $bookseller->{id
},
288 loop_received
=> \
@loop_received,
289 loop_orders
=> \
@loop_orders,
290 book_foot_loop
=> \
@book_foot_loop,
291 (uc(C4
::Context
->preference("marcflavour"))) => 1,
292 total_tax_excluded
=> $total_tax_excluded,
293 total_tax_included
=> $total_tax_included,
294 subtotal_for_funds
=> $subtotal_for_funds,
295 sticky_filters
=> $sticky_filters,
297 output_html_with_http_headers
$input, $cookie, $template->output;