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