|
Lines 76-83
my $bookseller=GetBookSellerFromId($booksellerid);
Link Here
|
| 76 |
|
76 |
|
| 77 |
my $invoice=$input->param('invoice') || ''; |
77 |
my $invoice=$input->param('invoice') || ''; |
| 78 |
my $freight=$input->param('freight'); |
78 |
my $freight=$input->param('freight'); |
| 79 |
my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst')); |
79 |
|
| 80 |
my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
80 |
#my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst')); # FIXME from comm |
|
|
81 |
#my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
| 82 |
|
| 81 |
my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived')) |
83 |
my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived')) |
| 82 |
: C4::Dates->new($input->param('datereceived'), 'iso') ; |
84 |
: C4::Dates->new($input->param('datereceived'), 'iso') ; |
| 83 |
$datereceived = C4::Dates->new() unless $datereceived; |
85 |
$datereceived = C4::Dates->new() unless $datereceived; |
|
Lines 90-105
my $resultsperpage = $input->param('resultsperpage');
Link Here
|
| 90 |
$resultsperpage = 20 unless ($resultsperpage); |
92 |
$resultsperpage = 20 unless ($resultsperpage); |
| 91 |
$startfrom=0 unless ($startfrom); |
93 |
$startfrom=0 unless ($startfrom); |
| 92 |
|
94 |
|
|
|
95 |
sub get_value_with_gst_params { |
| 96 |
my $value = shift; |
| 97 |
my $gstrate = shift; |
| 98 |
my $bookseller = shift; |
| 99 |
if ( $bookseller->{listincgst} ) { |
| 100 |
if ( $bookseller->{invoiceincgst} ) { |
| 101 |
return $value; |
| 102 |
} else { |
| 103 |
return $value / ( 1 + $gstrate ); |
| 104 |
} |
| 105 |
} else { |
| 106 |
if ( $bookseller->{invoiceincgst} ) { |
| 107 |
return $value * ( 1 + $gstrate ); |
| 108 |
} else { |
| 109 |
return $value; |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
sub get_gste { |
| 115 |
my $value = shift; |
| 116 |
my $gstrate = shift; |
| 117 |
my $bookseller = shift; |
| 118 |
return $bookseller->{invoiceincgst} |
| 119 |
? $value / ( 1 + $gstrate ) |
| 120 |
: $value; |
| 121 |
} |
| 122 |
|
| 123 |
sub get_gst { |
| 124 |
my $value = shift; |
| 125 |
my $gstrate = shift; |
| 126 |
my $bookseller = shift; |
| 127 |
return $bookseller->{invoiceincgst} |
| 128 |
? $value / ( 1 + $gstrate ) * $gstrate |
| 129 |
: $value * ( 1 + $gstrate ) - $value; |
| 130 |
} |
| 131 |
|
| 93 |
if($input->param('format') eq "json"){ |
132 |
if($input->param('format') eq "json"){ |
| 94 |
my ($template, $loggedinuser, $cookie) |
133 |
my ($template, $loggedinuser, $cookie) |
| 95 |
= get_template_and_user({template_name => "acqui/ajax.tmpl", |
134 |
= get_template_and_user({template_name => "acqui/ajax.tmpl", |
| 96 |
query => $input, |
135 |
query => $input, |
| 97 |
type => "intranet", |
136 |
type => "intranet", |
| 98 |
authnotrequired => 0, |
137 |
authnotrequired => 0, |
| 99 |
flagsrequired => {acquisition => 'order_receive'}, |
138 |
flagsrequired => {acquisition => 'order_receive'}, |
| 100 |
debug => 1, |
139 |
debug => 1, |
| 101 |
}); |
140 |
}); |
| 102 |
|
141 |
|
| 103 |
my @datas; |
142 |
my @datas; |
| 104 |
my $search = $input->param('search') || ''; |
143 |
my $search = $input->param('search') || ''; |
| 105 |
my $ean = $input->param('ean') || ''; |
144 |
my $ean = $input->param('ean') || ''; |
|
Lines 111-117
if($input->param('format') eq "json"){
Link Here
|
| 111 |
foreach my $order (@$orders) { |
150 |
foreach my $order (@$orders) { |
| 112 |
if ( $order->{quantityreceived} < $order->{quantity} ) { |
151 |
if ( $order->{quantityreceived} < $order->{quantity} ) { |
| 113 |
my $data = {}; |
152 |
my $data = {}; |
| 114 |
|
153 |
my $ecost = get_value_with_gst_params( $order->{ecost}, $order->{gstrate}, $bookseller ); |
|
|
154 |
|
| 115 |
$data->{basketno} = $order->{basketno}; |
155 |
$data->{basketno} = $order->{basketno}; |
| 116 |
$data->{ordernumber} = $order->{ordernumber}; |
156 |
$data->{ordernumber} = $order->{ordernumber}; |
| 117 |
$data->{title} = $order->{title}; |
157 |
$data->{title} = $order->{title}; |
|
Lines 121-132
if($input->param('format') eq "json"){
Link Here
|
| 121 |
$data->{biblionumber} = $order->{biblionumber}; |
161 |
$data->{biblionumber} = $order->{biblionumber}; |
| 122 |
$data->{freight} = $order->{freight}; |
162 |
$data->{freight} = $order->{freight}; |
| 123 |
$data->{quantity} = $order->{quantity}; |
163 |
$data->{quantity} = $order->{quantity}; |
| 124 |
$data->{ecost} = $order->{ecost}; |
164 |
$data->{ecost} = sprintf( "%.2f", $ecost ); |
| 125 |
$data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity}); |
165 |
$data->{ordertotal} = sprintf( "%.2f", $ecost * $order->{quantity} ); |
| 126 |
push @datas, $data; |
166 |
push @datas, $data; |
| 127 |
} |
167 |
} |
| 128 |
} |
168 |
} |
| 129 |
|
169 |
|
| 130 |
my $json_text = to_json(\@datas); |
170 |
my $json_text = to_json(\@datas); |
| 131 |
$template->param(return => $json_text); |
171 |
$template->param(return => $json_text); |
| 132 |
output_html_with_http_headers $input, $cookie, $template->output; |
172 |
output_html_with_http_headers $input, $cookie, $template->output; |
|
Lines 136-142
if($input->param('format') eq "json"){
Link Here
|
| 136 |
my ($template, $loggedinuser, $cookie) |
176 |
my ($template, $loggedinuser, $cookie) |
| 137 |
= get_template_and_user({template_name => "acqui/parcel.tmpl", |
177 |
= get_template_and_user({template_name => "acqui/parcel.tmpl", |
| 138 |
query => $input, |
178 |
query => $input, |
| 139 |
type => "intranet", |
179 |
type => "intranet", |
| 140 |
authnotrequired => 0, |
180 |
authnotrequired => 0, |
| 141 |
flagsrequired => {acquisition => 'order_receive'}, |
181 |
flagsrequired => {acquisition => 'order_receive'}, |
| 142 |
debug => 1, |
182 |
debug => 1, |
|
Lines 157-200
if( scalar(@rcv_err) ) {
Link Here
|
| 157 |
|
197 |
|
| 158 |
my $cfstr = "%.2f"; # currency format string -- could get this from currency table. |
198 |
my $cfstr = "%.2f"; # currency format string -- could get this from currency table. |
| 159 |
my @parcelitems = GetParcel($booksellerid, $invoice, $datereceived->output('iso')); |
199 |
my @parcelitems = GetParcel($booksellerid, $invoice, $datereceived->output('iso')); |
| 160 |
my $countlines = scalar @parcelitems; |
200 |
#my $countlines = scalar @parcelitems; FIXME from comm, it's used ? |
| 161 |
my $totalprice = 0; |
201 |
my $totalprice = 0; |
| 162 |
my $totalfreight = 0; |
202 |
my $totalfreight = 0; |
| 163 |
my $totalquantity = 0; |
203 |
my $totalquantity = 0; |
| 164 |
my $total; |
204 |
my $total; |
| 165 |
my $tototal; |
205 |
my $tototal; |
| 166 |
my @loop_received = (); |
206 |
my @loop_received = (); |
| 167 |
|
207 |
my @book_foot_loop; |
| 168 |
for (my $i = 0 ; $i < $countlines ; $i++) { |
208 |
my %foot; |
| 169 |
|
209 |
my $total_quantity = 0; |
| 170 |
#$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) |
210 |
my $total_gste = 0; |
| 171 |
$total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) |
211 |
my $total_gsti = 0; |
| 172 |
$parcelitems[$i]->{'unitprice'} += 0; |
212 |
|
|
|
213 |
for my $item ( @parcelitems ) { |
| 214 |
$item->{unitprice} = get_value_with_gst_params( $item->{unitprice}, $item->{gstrate}, $bookseller ); |
| 215 |
$total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) |
| 216 |
$item->{'unitprice'} += 0; |
| 173 |
my %line; |
217 |
my %line; |
| 174 |
%line = %{ $parcelitems[$i] }; |
218 |
%line = %{ $item }; |
|
|
219 |
my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller ); |
| 220 |
$line{ecost} = sprintf( "%.2f", $ecost ); |
| 175 |
$line{invoice} = $invoice; |
221 |
$line{invoice} = $invoice; |
| 176 |
$line{gst} = $gst; |
|
|
| 177 |
$line{total} = sprintf($cfstr, $total); |
222 |
$line{total} = sprintf($cfstr, $total); |
| 178 |
$line{booksellerid} = $booksellerid; |
223 |
$line{booksellerid} = $booksellerid; |
| 179 |
push @loop_received, \%line; |
224 |
$totalprice += $item->{'unitprice'}; |
| 180 |
$totalprice += $parcelitems[$i]->{'unitprice'}; |
225 |
$line{unitprice} = sprintf( $cfstr, $item->{'unitprice'} ); |
| 181 |
$line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'}); |
226 |
my $gste = get_gste( $line{total}, $line{gstrate}, $bookseller ); |
|
|
227 |
my $gst = get_gst( $line{total}, $line{gstrate}, $bookseller ); |
| 228 |
$foot{$line{gstrate}}{gstrate} = $line{gstrate}; |
| 229 |
$foot{$line{gstrate}}{value} += sprintf( "%.2f", $gst ); |
| 230 |
$total_quantity += $line{quantity}; |
| 231 |
$total_gste += $gste; |
| 232 |
$total_gsti += $gste + $gst; |
| 182 |
|
233 |
|
| 183 |
my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
234 |
my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
| 184 |
$line{suggestionid} = $suggestion->{suggestionid}; |
235 |
$line{suggestionid} = $suggestion->{suggestionid}; |
| 185 |
$line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; |
236 |
$line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; |
| 186 |
$line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; |
237 |
$line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; |
| 187 |
|
238 |
|
| 188 |
#double FIXME - totalfreight is redefined later. |
239 |
$totalfreight = $item->{'freight'}; |
|
|
240 |
$totalquantity += $item->{'quantityreceived'}; |
| 189 |
|
241 |
|
| 190 |
# FIXME - each order in a parcel holds the freight for the whole parcel. This means if you receive a parcel with items from multiple budgets, you'll see the freight charge in each budget.. |
|
|
| 191 |
if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) { |
| 192 |
warn "FREIGHT CHARGE MISMATCH!!"; |
| 193 |
} |
| 194 |
$totalfreight = $parcelitems[$i]->{'freight'}; |
| 195 |
$totalquantity += $parcelitems[$i]->{'quantityreceived'}; |
| 196 |
$tototal += $total; |
242 |
$tototal += $total; |
| 197 |
} |
243 |
|
|
|
244 |
my $budget = GetBudget( $line{budget_id} ); |
| 245 |
$line{budget_name} = $budget->{'budget_name'}; |
| 246 |
|
| 247 |
push @loop_received, \%line; |
| 248 |
} |
| 249 |
|
| 250 |
push @book_foot_loop, map { $_ } values %foot; |
| 198 |
|
251 |
|
| 199 |
my $pendingorders = GetPendingOrders($booksellerid); |
252 |
my $pendingorders = GetPendingOrders($booksellerid); |
| 200 |
my $countpendings = scalar @$pendingorders; |
253 |
my $countpendings = scalar @$pendingorders; |
|
Lines 206-228
my @loop_orders = ();
Link Here
|
| 206 |
for (my $i = 0 ; $i < $countpendings ; $i++) { |
259 |
for (my $i = 0 ; $i < $countpendings ; $i++) { |
| 207 |
my %line; |
260 |
my %line; |
| 208 |
%line = %{$pendingorders->[$i]}; |
261 |
%line = %{$pendingorders->[$i]}; |
| 209 |
|
262 |
|
|
|
263 |
my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller ); |
| 264 |
$line{unitprice} = get_value_with_gst_params( $line{unitprice}, $line{gstrate}, $bookseller ); |
| 210 |
$line{quantity}+=0; |
265 |
$line{quantity}+=0; |
| 211 |
$line{quantityreceived}+=0; |
266 |
$line{quantityreceived}+=0; |
| 212 |
$line{unitprice}+=0; |
267 |
$line{unitprice}+=0; |
| 213 |
$totalPunitprice += $line{unitprice}; |
268 |
$totalPunitprice += $line{unitprice}; |
| 214 |
$totalPquantity +=$line{quantity}; |
269 |
$totalPquantity +=$line{quantity}; |
| 215 |
$totalPqtyrcvd +=$line{quantityreceived}; |
270 |
$totalPqtyrcvd +=$line{quantityreceived}; |
| 216 |
$totalPecost += $line{ecost}; |
271 |
$totalPecost += $ecost; |
| 217 |
$line{ecost} = sprintf("%.2f",$line{ecost}); |
272 |
$line{ecost} = sprintf( "%.2f", $ecost ); |
| 218 |
$line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity}); |
273 |
$line{ordertotal} = sprintf( "%.2f", $ecost * $line{quantity} ); |
| 219 |
$line{unitprice} = sprintf("%.2f",$line{unitprice}); |
274 |
$line{unitprice} = sprintf("%.2f",$line{unitprice}); |
| 220 |
$line{invoice} = $invoice; |
275 |
$line{invoice} = $invoice; |
| 221 |
$line{gst} = $gst; |
|
|
| 222 |
$line{total} = $total; |
| 223 |
$line{booksellerid} = $booksellerid; |
276 |
$line{booksellerid} = $booksellerid; |
| 224 |
$ordergrandtotal += $line{ecost} * $line{quantity}; |
277 |
$ordergrandtotal += $ecost * $line{quantity}; |
| 225 |
|
278 |
|
| 226 |
my $biblionumber = $line{'biblionumber'}; |
279 |
my $biblionumber = $line{'biblionumber'}; |
| 227 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
280 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
| 228 |
my $ordernumber = $line{'ordernumber'}; |
281 |
my $ordernumber = $line{'ordernumber'}; |
|
Lines 243-248
for (my $i = 0 ; $i < $countpendings ; $i++) {
Link Here
|
| 243 |
$line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; |
296 |
$line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; |
| 244 |
$line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; |
297 |
$line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; |
| 245 |
|
298 |
|
|
|
299 |
my $budget = GetBudget( $line{budget_id} ); |
| 300 |
$line{budget_name} = $budget->{'budget_name'}; |
| 301 |
|
| 246 |
# 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 |
302 |
# 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 |
| 247 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
303 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
| 248 |
$line{items} = ($itemcount) - (scalar @items); |
304 |
$line{items} = ($itemcount) - (scalar @items); |
|
Lines 255-262
for (my $i = 0 ; $i < $countpendings ; $i++) {
Link Here
|
| 255 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
311 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
| 256 |
$line{holds} = $holds; |
312 |
$line{holds} = $holds; |
| 257 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
313 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
| 258 |
|
314 |
|
| 259 |
|
|
|
| 260 |
push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); |
315 |
push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); |
| 261 |
} |
316 |
} |
| 262 |
$freight = $totalfreight unless $freight; |
317 |
$freight = $totalfreight unless $freight; |
|
Lines 294-300
if ($count>$resultsperpage){
Link Here
|
| 294 |
); |
349 |
); |
| 295 |
} |
350 |
} |
| 296 |
|
351 |
|
| 297 |
#$totalfreight=$freight; |
|
|
| 298 |
$tototal = $tototal + $freight; |
352 |
$tototal = $tototal + $freight; |
| 299 |
|
353 |
|
| 300 |
$template->param( |
354 |
$template->param( |
|
Lines 304-329
$template->param(
Link Here
|
| 304 |
formatteddatereceived => $datereceived->output(), |
358 |
formatteddatereceived => $datereceived->output(), |
| 305 |
name => $bookseller->{'name'}, |
359 |
name => $bookseller->{'name'}, |
| 306 |
booksellerid => $booksellerid, |
360 |
booksellerid => $booksellerid, |
| 307 |
gst => $gst, |
|
|
| 308 |
freight => $freight, |
361 |
freight => $freight, |
| 309 |
invoice => $invoice, |
362 |
invoice => $invoice, |
| 310 |
countreceived => $countlines, |
|
|
| 311 |
loop_received => \@loop_received, |
363 |
loop_received => \@loop_received, |
| 312 |
countpending => $countpendings, |
|
|
| 313 |
loop_orders => \@loop_orders, |
364 |
loop_orders => \@loop_orders, |
|
|
365 |
book_foot_loop => \@book_foot_loop, |
| 314 |
totalprice => sprintf($cfstr, $totalprice), |
366 |
totalprice => sprintf($cfstr, $totalprice), |
| 315 |
totalfreight => $totalfreight, |
367 |
totalfreight => $totalfreight, |
| 316 |
totalquantity => $totalquantity, |
368 |
totalquantity => $totalquantity, |
| 317 |
tototal => sprintf($cfstr, $tototal), |
369 |
tototal => sprintf($cfstr, $tototal), |
| 318 |
ordergrandtotal => sprintf($cfstr, $ordergrandtotal), |
370 |
ordergrandtotal => sprintf($cfstr, $ordergrandtotal), |
| 319 |
gst => $gst, |
371 |
grandtot => sprintf($cfstr, $tototal ), |
| 320 |
grandtot => sprintf($cfstr, $tototal + $gst), |
|
|
| 321 |
totalPunitprice => sprintf("%.2f", $totalPunitprice), |
372 |
totalPunitprice => sprintf("%.2f", $totalPunitprice), |
| 322 |
totalPquantity => $totalPquantity, |
373 |
totalPquantity => $totalPquantity, |
| 323 |
totalPqtyrcvd => $totalPqtyrcvd, |
374 |
totalPqtyrcvd => $totalPqtyrcvd, |
| 324 |
totalPecost => sprintf("%.2f", $totalPecost), |
375 |
totalPecost => sprintf("%.2f", $totalPecost), |
| 325 |
resultsperpage => $resultsperpage, |
376 |
resultsperpage => $resultsperpage, |
| 326 |
(uc(C4::Context->preference("marcflavour"))) => 1 |
377 |
(uc(C4::Context->preference("marcflavour"))) => 1, |
|
|
378 |
total_quantity => $total_quantity, |
| 379 |
total_gste => sprintf( "%.2f", $total_gste ), |
| 380 |
total_gsti => sprintf( "%.2f", $total_gsti ), |
| 327 |
); |
381 |
); |
| 328 |
output_html_with_http_headers $input, $cookie, $template->output; |
382 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 329 |
|
383 |
|