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.
63 use C4
::Bookseller qw
/ GetBookSellerFromId /;
68 use C4
::Dates qw
/format_date format_date_in_iso/;
70 use C4
::Reserves qw
/GetReservesFromBiblionumber/;
74 my $sticky_filters = $input->param('sticky_filters') || 0;
76 sub get_value_with_gst_params
{
79 my $bookseller = shift;
80 if ( $bookseller->{listincgst
} ) {
81 if ( $bookseller->{invoiceincgst
} ) {
84 return $value / ( 1 + $gstrate );
87 if ( $bookseller->{invoiceincgst
} ) {
88 return $value * ( 1 + $gstrate );
98 my $bookseller = shift;
99 return $bookseller->{invoiceincgst
}
100 ?
$value / ( 1 + $gstrate )
107 my $bookseller = shift;
108 return $bookseller->{invoiceincgst
}
109 ?
$value / ( 1 + $gstrate ) * $gstrate
110 : $value * ( 1 + $gstrate ) - $value;
113 my ($template, $loggedinuser, $cookie)
114 = get_template_and_user
({template_name
=> "acqui/parcel.tmpl",
117 authnotrequired
=> 0,
118 flagsrequired
=> {acquisition
=> 'order_receive'},
122 my $op = $input->param('op') // '';
124 # process cancellation first so that list of
125 # orders to display is calculated after
126 if ($op eq 'cancelreceipt') {
127 my $ordernumber = $input->param('ordernumber');
128 my $parent_ordernumber = CancelReceipt
($ordernumber);
129 unless($parent_ordernumber) {
130 $template->param(error_cancelling_receipt
=> 1);
134 my $invoiceid = $input->param('invoiceid');
136 $invoice = GetInvoiceDetails
($invoiceid) if $invoiceid;
138 unless( $invoiceid and $invoice->{invoiceid
} ) {
140 error_invoice_not_known
=> 1,
141 no_orders_to_display
=> 1
143 output_html_with_http_headers
$input, $cookie, $template->output;
147 my $booksellerid = $invoice->{booksellerid
};
148 my $bookseller = GetBookSellerFromId
($booksellerid);
149 my $gst = $bookseller->{gstrate
} // C4
::Context
->preference("gist") // 0;
150 my $datereceived = C4
::Dates
->new();
152 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
153 my @orders = @
{ $invoice->{orders
} };
154 my $countlines = scalar @orders;
156 my $totalquantity = 0;
158 my @loop_received = ();
161 my $total_quantity = 0;
165 for my $order ( @orders ) {
166 $order->{unitprice
} = get_value_with_gst_params
( $order->{unitprice
}, $order->{gstrate
}, $bookseller );
167 $total = ( $order->{unitprice
} ) * $order->{quantityreceived
};
168 $order->{'unitprice'} += 0;
169 my %line = %{ $order };
170 my $ecost = get_value_with_gst_params
( $line{ecost
}, $line{gstrate
}, $bookseller );
171 $line{ecost
} = sprintf( "%.2f", $ecost );
172 $line{invoice
} = $invoice->{invoicenumber
};
173 $line{total
} = sprintf($cfstr, $total);
174 $line{booksellerid
} = $invoice->{booksellerid
};
176 my @itemnumbers = GetItemnumbersFromOrder
( $order->{ordernumber
} );
177 for my $itemnumber ( @itemnumbers ) {
178 my $holds = GetReservesFromBiblionumber
({ biblionumber
=> $line{biblionumber
}, itemnumber
=> $itemnumber });
179 $line{holds
} += scalar( @
$holds );
181 $line{budget
} = GetBudgetByOrderNumber
( $line{ordernumber
} );
182 $totalprice += $order->{unitprice
};
183 $line{unitprice
} = sprintf( $cfstr, $order->{unitprice
} );
184 my $gste = get_gste
( $line{total
}, $line{gstrate
}, $bookseller );
185 my $gst = get_gst
( $line{total
}, $line{gstrate
}, $bookseller );
186 $foot{$line{gstrate
}}{gstrate
} = $line{gstrate
};
187 $foot{$line{gstrate
}}{value
} += sprintf( "%.2f", $gst );
188 $total_quantity += $line{quantity
};
189 $total_gste += $gste;
190 $total_gsti += $gste + $gst;
192 my $suggestion = GetSuggestionInfoFromBiblionumber
($line{biblionumber
});
193 $line{suggestionid
} = $suggestion->{suggestionid
};
194 $line{surnamesuggestedby
} = $suggestion->{surnamesuggestedby
};
195 $line{firstnamesuggestedby
} = $suggestion->{firstnamesuggestedby
};
197 if ( $line{parent_ordernumber
} != $line{ordernumber
} ) {
198 if ( grep { $_->{ordernumber
} == $line{parent_ordernumber
} }
202 $line{cannot_cancel
} = 1;
206 my $budget = GetBudget
( $line{budget_id
} );
207 $line{budget_name
} = $budget->{'budget_name'};
209 push @loop_received, \
%line;
210 $totalquantity += $order->{quantityreceived
};
213 push @book_foot_loop, map { $_ } values %foot;
215 my @loop_orders = ();
216 unless( defined $invoice->{closedate
} ) {
218 if ( $op eq "search" or $sticky_filters ) {
219 my ( $search, $ean, $basketname, $orderno, $basketgroupname );
220 if ( $sticky_filters ) {
221 $search = $input->cookie("filter_parcel_summary");
222 $ean = $input->cookie("filter_parcel_ean");
223 $basketname = $input->cookie("filter_parcel_basketname");
224 $orderno = $input->cookie("filter_parcel_orderno");
225 $basketgroupname = $input->cookie("filter_parcel_basketgroupname");
227 $search = $input->param('summaryfilter') || '';
228 $ean = $input->param('eanfilter') || '';
229 $basketname = $input->param('basketfilter') || '';
230 $orderno = $input->param('orderfilter') || '';
231 $basketgroupname = $input->param('basketgroupnamefilter') || '';
233 $pendingorders = SearchOrders
({
234 booksellerid
=> $booksellerid,
235 basketname
=> $basketname,
236 ordernumber
=> $orderno,
239 basketgroupname
=> $basketgroupname,
244 summaryfilter
=> $search,
246 basketfilter
=> $basketname,
247 orderfilter
=> $orderno,
248 basketgroupnamefilter
=> $basketgroupname,
251 $pendingorders = SearchOrders
({
252 booksellerid
=> $booksellerid,
256 my $countpendings = scalar @
$pendingorders;
258 for (my $i = 0 ; $i < $countpendings ; $i++) {
260 %line = %{$pendingorders->[$i]};
262 my $ecost = get_value_with_gst_params
( $line{ecost
}, $line{gstrate
}, $bookseller );
263 $line{unitprice
} = get_value_with_gst_params
( $line{unitprice
}, $line{gstrate
}, $bookseller );
264 $line{quantity
} += 0;
265 $line{quantityreceived
} += 0;
267 $line{ecost
} = sprintf( "%.2f", $ecost );
268 $line{ordertotal
} = sprintf( "%.2f", $ecost * $line{quantity
} );
269 $line{unitprice
} = sprintf("%.2f",$line{unitprice
});
270 $line{invoice
} = $invoice;
271 $line{booksellerid
} = $booksellerid;
275 my $biblionumber = $line{'biblionumber'};
276 my $countbiblio = CountBiblioInOrders
($biblionumber);
277 my $ordernumber = $line{'ordernumber'};
278 my @subscriptions = GetSubscriptionsId
($biblionumber);
279 my $itemcount = GetItemsCount
($biblionumber);
280 my $holds = GetHolds
($biblionumber);
281 my @items = GetItemnumbersFromOrder
( $ordernumber );
283 foreach my $item (@items){
284 my $nb = GetItemHolds
($biblionumber, $item);
290 my $suggestion = GetSuggestionInfoFromBiblionumber
($line{biblionumber
});
291 $line{suggestionid
} = $suggestion->{suggestionid
};
292 $line{surnamesuggestedby
} = $suggestion->{surnamesuggestedby
};
293 $line{firstnamesuggestedby
} = $suggestion->{firstnamesuggestedby
};
295 # 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
296 $line{can_del_bib
} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
297 $line{items
} = ($itemcount) - (scalar @items);
298 $line{left_item
} = 1 if $line{items
} >= 1;
299 $line{left_biblio
} = 1 if $countbiblio > 1;
300 $line{biblios
} = $countbiblio - 1;
301 $line{left_subscription
} = 1 if scalar @subscriptions >= 1;
302 $line{subscriptions
} = scalar @subscriptions;
303 $line{left_holds
} = ($holds >= 1) ?
1 : 0;
304 $line{left_holds_on_order
} = 1 if $line{left_holds
}==1 && ($line{items
} == 0 || $itemholds );
305 $line{holds
} = $holds;
306 $line{holds_on_order
} = $itemholds?
$itemholds:$holds if $line{left_holds_on_order
};
308 my $budget = GetBudget
( $line{budget_id
} );
309 $line{budget_name
} = $budget->{'budget_name'};
311 push @loop_orders, \
%line;
315 loop_orders
=> \
@loop_orders,
320 invoiceid
=> $invoice->{invoiceid
},
321 invoice
=> $invoice->{invoicenumber
},
322 invoiceclosedate
=> $invoice->{closedate
},
323 datereceived
=> $datereceived->output('iso'),
324 invoicedatereceived
=> $datereceived->output('iso'),
325 formatteddatereceived
=> $datereceived->output(),
326 name
=> $bookseller->{'name'},
327 booksellerid
=> $bookseller->{id
},
328 countreceived
=> $countlines,
329 loop_received
=> \
@loop_received,
330 loop_orders
=> \
@loop_orders,
331 book_foot_loop
=> \
@book_foot_loop,
332 totalprice
=> sprintf($cfstr, $totalprice),
333 totalquantity
=> $totalquantity,
334 (uc(C4
::Context
->preference("marcflavour"))) => 1,
335 total_quantity
=> $total_quantity,
336 total_gste
=> sprintf( "%.2f", $total_gste ),
337 total_gsti
=> sprintf( "%.2f", $total_gsti ),
338 sticky_filters
=> $sticky_filters,
340 output_html_with_http_headers
$input, $cookie, $template->output;