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/;
74 sub get_value_with_gst_params
{
77 my $bookseller = shift;
78 if ( $bookseller->{listincgst
} ) {
79 if ( $bookseller->{invoiceincgst
} ) {
82 return $value / ( 1 + $gstrate );
85 if ( $bookseller->{invoiceincgst
} ) {
86 return $value * ( 1 + $gstrate );
96 my $bookseller = shift;
97 return $bookseller->{invoiceincgst
}
98 ?
$value / ( 1 + $gstrate )
105 my $bookseller = shift;
106 return $bookseller->{invoiceincgst
}
107 ?
$value / ( 1 + $gstrate ) * $gstrate
108 : $value * ( 1 + $gstrate ) - $value;
111 my ($template, $loggedinuser, $cookie)
112 = get_template_and_user
({template_name
=> "acqui/parcel.tmpl",
115 authnotrequired
=> 0,
116 flagsrequired
=> {acquisition
=> 'order_receive'},
120 my $invoiceid = $input->param('invoiceid');
122 $invoice = GetInvoiceDetails
($invoiceid) if $invoiceid;
124 unless( $invoiceid and $invoice->{invoiceid
} ) {
126 error_invoice_not_known
=> 1,
127 no_orders_to_display
=> 1
129 output_html_with_http_headers
$input, $cookie, $template->output;
133 my $op = $input->param('op') // '';
135 if ($op eq 'cancelreceipt') {
136 my $ordernumber = $input->param('ordernumber');
137 my $parent_ordernumber = CancelReceipt
($ordernumber);
138 unless($parent_ordernumber) {
139 $template->param(error_cancelling_receipt
=> 1);
143 my $booksellerid = $invoice->{booksellerid
};
144 my $bookseller = GetBookSellerFromId
($booksellerid);
145 my $gst = $bookseller->{gstrate
} // C4
::Context
->preference("gist") // 0;
146 my $datereceived = C4
::Dates
->new();
148 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
149 my @parcelitems = @
{ $invoice->{orders
} };
150 my $countlines = scalar @parcelitems;
152 my $totalquantity = 0;
154 my @loop_received = ();
157 my $total_quantity = 0;
161 for my $item ( @parcelitems ) {
162 $item->{unitprice
} = get_value_with_gst_params
( $item->{unitprice
}, $item->{gstrate
}, $bookseller );
163 $total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'};
164 $item->{'unitprice'} += 0;
167 my $ecost = get_value_with_gst_params
( $line{ecost
}, $line{gstrate
}, $bookseller );
168 $line{ecost
} = sprintf( "%.2f", $ecost );
169 $line{invoice
} = $invoice->{invoicenumber
};
170 $line{total
} = sprintf($cfstr, $total);
171 $line{booksellerid
} = $invoice->{booksellerid
};
172 $totalprice += $item->{'unitprice'};
173 $line{unitprice
} = sprintf( $cfstr, $item->{'unitprice'} );
174 my $gste = get_gste
( $line{total
}, $line{gstrate
}, $bookseller );
175 my $gst = get_gst
( $line{total
}, $line{gstrate
}, $bookseller );
176 $foot{$line{gstrate
}}{gstrate
} = $line{gstrate
};
177 $foot{$line{gstrate
}}{value
} += sprintf( "%.2f", $gst );
178 $total_quantity += $line{quantity
};
179 $total_gste += $gste;
180 $total_gsti += $gste + $gst;
182 my $suggestion = GetSuggestionInfoFromBiblionumber
($line{biblionumber
});
183 $line{suggestionid
} = $suggestion->{suggestionid
};
184 $line{surnamesuggestedby
} = $suggestion->{surnamesuggestedby
};
185 $line{firstnamesuggestedby
} = $suggestion->{firstnamesuggestedby
};
187 if ( $line{parent_ordernumber
} != $line{ordernumber
} ) {
188 if ( grep { $_->{ordernumber
} == $line{parent_ordernumber
} }
191 $line{cannot_cancel
} = 1;
195 my $budget = GetBudget
( $line{budget_id
} );
196 $line{budget_name
} = $budget->{'budget_name'};
198 push @loop_received, \
%line;
199 $totalquantity += $item->{'quantityreceived'};
202 push @book_foot_loop, map { $_ } values %foot;
204 my @loop_orders = ();
205 if(!defined $invoice->{closedate
}) {
207 if($input->param('op') eq "search"){
208 my $search = $input->param('summaryfilter') || '';
209 my $ean = $input->param('eanfilter') || '';
210 my $basketno = $input->param('basketfilter') || '';
211 my $orderno = $input->param('orderfilter') || '';
214 $pendingorders = GetPendingOrders
($booksellerid,$grouped,$owner,$basketno,$orderno,$search,$ean);
216 $pendingorders = GetPendingOrders
($booksellerid);
218 my $countpendings = scalar @
$pendingorders;
220 for (my $i = 0 ; $i < $countpendings ; $i++) {
222 %line = %{$pendingorders->[$i]};
224 my $ecost = get_value_with_gst_params
( $line{ecost
}, $line{gstrate
}, $bookseller );
225 $line{unitprice
} = get_value_with_gst_params
( $line{unitprice
}, $line{gstrate
}, $bookseller );
226 $line{quantity
} += 0;
227 $line{quantityreceived
} += 0;
229 $line{ecost
} = sprintf( "%.2f", $ecost );
230 $line{ordertotal
} = sprintf( "%.2f", $ecost * $line{quantity
} );
231 $line{unitprice
} = sprintf("%.2f",$line{unitprice
});
232 $line{invoice
} = $invoice;
233 $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 = GetBudget
( $line{budget_id
} );
271 $line{budget_name
} = $budget->{'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
=> $datereceived->output('iso'),
286 invoicedatereceived
=> $datereceived->output('iso'),
287 formatteddatereceived
=> $datereceived->output(),
288 name
=> $bookseller->{'name'},
289 booksellerid
=> $bookseller->{id
},
290 countreceived
=> $countlines,
291 loop_received
=> \
@loop_received,
292 loop_orders
=> \
@loop_orders,
293 book_foot_loop
=> \
@book_foot_loop,
294 totalprice
=> sprintf($cfstr, $totalprice),
295 totalquantity
=> $totalquantity,
296 (uc(C4
::Context
->preference("marcflavour"))) => 1,
297 total_quantity
=> $total_quantity,
298 total_gste
=> sprintf( "%.2f", $total_gste ),
299 total_gsti
=> sprintf( "%.2f", $total_gsti ),
301 output_html_with_http_headers
$input, $cookie, $template->output;