Lines 42-49
To know the supplier this script has to show orders.
Link Here
|
42 |
|
42 |
|
43 |
is the bookseller invoice number. |
43 |
is the bookseller invoice number. |
44 |
|
44 |
|
45 |
=item freight |
|
|
46 |
|
47 |
|
45 |
|
48 |
=item gst |
46 |
=item gst |
49 |
|
47 |
|
Lines 57-63
To filter the results list on this given date.
Link Here
|
57 |
=cut |
55 |
=cut |
58 |
|
56 |
|
59 |
use strict; |
57 |
use strict; |
60 |
#use warnings; FIXME - Bug 2505 |
58 |
use warnings; |
|
|
59 |
|
61 |
use C4::Auth; |
60 |
use C4::Auth; |
62 |
use C4::Acquisition; |
61 |
use C4::Acquisition; |
63 |
use C4::Budgets; |
62 |
use C4::Budgets; |
Lines 70-85
use C4::Dates qw/format_date format_date_in_iso/;
Link Here
|
70 |
use JSON; |
69 |
use JSON; |
71 |
|
70 |
|
72 |
my $input=new CGI; |
71 |
my $input=new CGI; |
73 |
my $supplierid=$input->param('supplierid'); |
72 |
|
74 |
my $bookseller=GetBookSellerFromId($supplierid); |
73 |
my $invoiceid = $input->param('invoiceid'); |
75 |
|
74 |
my $invoice = GetInvoiceDetails($invoiceid); |
76 |
my $invoice=$input->param('invoice') || ''; |
75 |
my $supplierid = $invoice->{booksellerid}; |
77 |
my $freight=$input->param('freight'); |
76 |
my $bookseller = GetBookSellerFromId($supplierid); |
78 |
my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst')); |
77 |
my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
79 |
my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
78 |
my $datereceived = C4::Dates->new(); |
80 |
my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived')) |
|
|
81 |
: C4::Dates->new($input->param('datereceived'), 'iso') ; |
82 |
$datereceived = C4::Dates->new() unless $datereceived; |
83 |
my $code = $input->param('code'); |
79 |
my $code = $input->param('code'); |
84 |
my @rcv_err = $input->param('error'); |
80 |
my @rcv_err = $input->param('error'); |
85 |
my @rcv_err_barcode = $input->param('error_bc'); |
81 |
my @rcv_err_barcode = $input->param('error_bc'); |
Lines 89-104
my $resultsperpage = $input->param('resultsperpage');
Link Here
|
89 |
$resultsperpage = 20 unless ($resultsperpage); |
85 |
$resultsperpage = 20 unless ($resultsperpage); |
90 |
$startfrom=0 unless ($startfrom); |
86 |
$startfrom=0 unless ($startfrom); |
91 |
|
87 |
|
92 |
if($input->param('format') eq "json"){ |
88 |
my $format = $input->param('format') || ''; |
|
|
89 |
if($format eq "json"){ |
93 |
my ($template, $loggedinuser, $cookie) |
90 |
my ($template, $loggedinuser, $cookie) |
94 |
= get_template_and_user({template_name => "acqui/ajax.tmpl", |
91 |
= get_template_and_user({template_name => "acqui/ajax.tmpl", |
95 |
query => $input, |
92 |
query => $input, |
96 |
type => "intranet", |
93 |
type => "intranet", |
97 |
authnotrequired => 0, |
94 |
authnotrequired => 0, |
98 |
flagsrequired => {acquisition => 'order_receive'}, |
95 |
flagsrequired => {acquisition => 'order_receive'}, |
99 |
debug => 1, |
96 |
debug => 1, |
100 |
}); |
97 |
}); |
101 |
|
98 |
|
102 |
my @datas; |
99 |
my @datas; |
103 |
my $search = $input->param('search') || ''; |
100 |
my $search = $input->param('search') || ''; |
104 |
my $supplier = $input->param('supplierid') || ''; |
101 |
my $supplier = $input->param('supplierid') || ''; |
Lines 109-115
if($input->param('format') eq "json"){
Link Here
|
109 |
foreach my $order (@$orders){ |
106 |
foreach my $order (@$orders){ |
110 |
if($order->{quantityreceived} < $order->{quantity}){ |
107 |
if($order->{quantityreceived} < $order->{quantity}){ |
111 |
my $data = {}; |
108 |
my $data = {}; |
112 |
|
109 |
|
113 |
$data->{basketno} = $order->{basketno}; |
110 |
$data->{basketno} = $order->{basketno}; |
114 |
$data->{ordernumber} = $order->{ordernumber}; |
111 |
$data->{ordernumber} = $order->{ordernumber}; |
115 |
$data->{title} = $order->{title}; |
112 |
$data->{title} = $order->{title}; |
Lines 117-130
if($input->param('format') eq "json"){
Link Here
|
117 |
$data->{isbn} = $order->{isbn}; |
114 |
$data->{isbn} = $order->{isbn}; |
118 |
$data->{booksellerid} = $order->{booksellerid}; |
115 |
$data->{booksellerid} = $order->{booksellerid}; |
119 |
$data->{biblionumber} = $order->{biblionumber}; |
116 |
$data->{biblionumber} = $order->{biblionumber}; |
120 |
$data->{freight} = $order->{freight}; |
|
|
121 |
$data->{quantity} = $order->{quantity}; |
117 |
$data->{quantity} = $order->{quantity}; |
122 |
$data->{ecost} = $order->{ecost}; |
118 |
$data->{ecost} = $order->{ecost}; |
123 |
$data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity}); |
119 |
$data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity}); |
124 |
push @datas, $data; |
120 |
push @datas, $data; |
125 |
} |
121 |
} |
126 |
} |
122 |
} |
127 |
|
123 |
|
128 |
my $json_text = to_json(\@datas); |
124 |
my $json_text = to_json(\@datas); |
129 |
$template->param(return => $json_text); |
125 |
$template->param(return => $json_text); |
130 |
output_html_with_http_headers $input, $cookie, $template->output; |
126 |
output_html_with_http_headers $input, $cookie, $template->output; |
Lines 134-140
if($input->param('format') eq "json"){
Link Here
|
134 |
my ($template, $loggedinuser, $cookie) |
130 |
my ($template, $loggedinuser, $cookie) |
135 |
= get_template_and_user({template_name => "acqui/parcel.tmpl", |
131 |
= get_template_and_user({template_name => "acqui/parcel.tmpl", |
136 |
query => $input, |
132 |
query => $input, |
137 |
type => "intranet", |
133 |
type => "intranet", |
138 |
authnotrequired => 0, |
134 |
authnotrequired => 0, |
139 |
flagsrequired => {acquisition => 'order_receive'}, |
135 |
flagsrequired => {acquisition => 'order_receive'}, |
140 |
debug => 1, |
136 |
debug => 1, |
Lines 154-163
if( scalar(@rcv_err) ) {
Link Here
|
154 |
} |
150 |
} |
155 |
|
151 |
|
156 |
my $cfstr = "%.2f"; # currency format string -- could get this from currency table. |
152 |
my $cfstr = "%.2f"; # currency format string -- could get this from currency table. |
157 |
my @parcelitems = GetParcel($supplierid, $invoice, $datereceived->output('iso')); |
153 |
my @parcelitems = @{ $invoice->{orders} }; |
158 |
my $countlines = scalar @parcelitems; |
154 |
my $countlines = scalar @parcelitems; |
159 |
my $totalprice = 0; |
155 |
my $totalprice = 0; |
160 |
my $totalfreight = 0; |
|
|
161 |
my $totalquantity = 0; |
156 |
my $totalquantity = 0; |
162 |
my $total; |
157 |
my $total; |
163 |
my $tototal; |
158 |
my $tototal; |
Lines 165-316
my @loop_received = ();
Link Here
|
165 |
|
160 |
|
166 |
for (my $i = 0 ; $i < $countlines ; $i++) { |
161 |
for (my $i = 0 ; $i < $countlines ; $i++) { |
167 |
|
162 |
|
168 |
#$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) |
163 |
$total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; |
169 |
$total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) |
|
|
170 |
$parcelitems[$i]->{'unitprice'} += 0; |
164 |
$parcelitems[$i]->{'unitprice'} += 0; |
171 |
my %line; |
165 |
my %line; |
172 |
%line = %{ $parcelitems[$i] }; |
166 |
%line = %{ $parcelitems[$i] }; |
173 |
$line{invoice} = $invoice; |
167 |
$line{invoice} = $invoice->{invoicenumber}; |
174 |
$line{gst} = $gst; |
168 |
$line{gst} = $gst; |
175 |
$line{total} = sprintf($cfstr, $total); |
169 |
$line{total} = sprintf($cfstr, $total); |
176 |
$line{supplierid} = $supplierid; |
170 |
$line{supplierid} = $invoice->{booksellerid}; |
177 |
push @loop_received, \%line; |
171 |
push @loop_received, \%line; |
178 |
$totalprice += $parcelitems[$i]->{'unitprice'}; |
172 |
$totalprice += $parcelitems[$i]->{'unitprice'}; |
179 |
$line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'}); |
173 |
$line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'}); |
180 |
|
174 |
|
181 |
#double FIXME - totalfreight is redefined later. |
|
|
182 |
|
183 |
# 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.. |
184 |
if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) { |
185 |
warn "FREIGHT CHARGE MISMATCH!!"; |
186 |
} |
187 |
$totalfreight = $parcelitems[$i]->{'freight'}; |
188 |
$totalquantity += $parcelitems[$i]->{'quantityreceived'}; |
175 |
$totalquantity += $parcelitems[$i]->{'quantityreceived'}; |
189 |
$tototal += $total; |
176 |
$tototal += $total; |
190 |
} |
177 |
} |
191 |
|
178 |
|
192 |
my $pendingorders = GetPendingOrders($supplierid); |
179 |
if(!defined $invoice->{closedate}) { |
193 |
my $countpendings = scalar @$pendingorders; |
180 |
my $pendingorders = GetPendingOrders($supplierid); |
194 |
|
181 |
my $countpendings = scalar @$pendingorders; |
195 |
# pending orders totals |
182 |
|
196 |
my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd); |
183 |
# pending orders totals |
197 |
my $ordergrandtotal; |
184 |
my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd); |
198 |
my @loop_orders = (); |
185 |
my $ordergrandtotal; |
199 |
for (my $i = 0 ; $i < $countpendings ; $i++) { |
186 |
my @loop_orders = (); |
200 |
my %line; |
187 |
for (my $i = 0 ; $i < $countpendings ; $i++) { |
201 |
%line = %{$pendingorders->[$i]}; |
188 |
my %line; |
202 |
|
189 |
%line = %{$pendingorders->[$i]}; |
203 |
$line{quantity}+=0; |
190 |
|
204 |
$line{quantityreceived}+=0; |
191 |
$line{quantity}+=0; |
205 |
$line{unitprice}+=0; |
192 |
$line{quantityreceived}+=0; |
206 |
$totalPunitprice += $line{unitprice}; |
193 |
$line{unitprice}+=0; |
207 |
$totalPquantity +=$line{quantity}; |
194 |
$totalPunitprice += $line{unitprice}; |
208 |
$totalPqtyrcvd +=$line{quantityreceived}; |
195 |
$totalPquantity +=$line{quantity}; |
209 |
$totalPecost += $line{ecost}; |
196 |
$totalPqtyrcvd +=$line{quantityreceived}; |
210 |
$line{ecost} = sprintf("%.2f",$line{ecost}); |
197 |
$totalPecost += $line{ecost}; |
211 |
$line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity}); |
198 |
$line{ecost} = sprintf("%.2f",$line{ecost}); |
212 |
$line{unitprice} = sprintf("%.2f",$line{unitprice}); |
199 |
$line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity}); |
213 |
$line{invoice} = $invoice; |
200 |
$line{unitprice} = sprintf("%.2f",$line{unitprice}); |
214 |
$line{gst} = $gst; |
201 |
$line{invoice} = $invoice; |
215 |
$line{total} = $total; |
202 |
$line{gst} = $gst; |
216 |
$line{supplierid} = $supplierid; |
203 |
$line{total} = $total; |
217 |
$ordergrandtotal += $line{ecost} * $line{quantity}; |
204 |
$line{supplierid} = $supplierid; |
218 |
|
205 |
$ordergrandtotal += $line{ecost} * $line{quantity}; |
219 |
my $biblionumber = $line{'biblionumber'}; |
206 |
|
220 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
207 |
my $biblionumber = $line{'biblionumber'}; |
221 |
my $ordernumber = $line{'ordernumber'}; |
208 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
222 |
my @subscriptions = GetSubscriptionsId ($biblionumber); |
209 |
my $ordernumber = $line{'ordernumber'}; |
223 |
my $itemcount = GetItemsCount($biblionumber); |
210 |
my @subscriptions = GetSubscriptionsId ($biblionumber); |
224 |
my $holds = GetHolds ($biblionumber); |
211 |
my $itemcount = GetItemsCount($biblionumber); |
225 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
212 |
my $holds = GetHolds ($biblionumber); |
226 |
my $itemholds; |
213 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
227 |
foreach my $item (@items){ |
214 |
my $itemholds; |
228 |
my $nb = GetItemHolds($biblionumber, $item); |
215 |
foreach my $item (@items){ |
229 |
if ($nb){ |
216 |
my $nb = GetItemHolds($biblionumber, $item); |
230 |
$itemholds += $nb; |
217 |
if ($nb){ |
|
|
218 |
$itemholds += $nb; |
219 |
} |
231 |
} |
220 |
} |
|
|
221 |
|
222 |
# 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 |
223 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
224 |
$line{items} = ($itemcount) - (scalar @items); |
225 |
$line{left_item} = 1 if $line{items} >= 1; |
226 |
$line{left_biblio} = 1 if $countbiblio > 1; |
227 |
$line{biblios} = $countbiblio - 1; |
228 |
$line{left_subscription} = 1 if scalar @subscriptions >= 1; |
229 |
$line{subscriptions} = scalar @subscriptions; |
230 |
$line{left_holds} = ($holds >= 1) ? 1 : 0; |
231 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
232 |
$line{holds} = $holds; |
233 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
234 |
|
235 |
|
236 |
push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); |
232 |
} |
237 |
} |
233 |
|
|
|
234 |
# 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 |
235 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
236 |
$line{items} = ($itemcount) - (scalar @items); |
237 |
$line{left_item} = 1 if $line{items} >= 1; |
238 |
$line{left_biblio} = 1 if $countbiblio > 1; |
239 |
$line{biblios} = $countbiblio - 1; |
240 |
$line{left_subscription} = 1 if scalar @subscriptions >= 1; |
241 |
$line{subscriptions} = scalar @subscriptions; |
242 |
$line{left_holds} = 1 if $holds >= 1; |
243 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
244 |
$line{holds} = $holds; |
245 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
246 |
|
247 |
|
248 |
push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); |
249 |
} |
250 |
$freight = $totalfreight unless $freight; |
251 |
|
238 |
|
252 |
my $count = $countpendings; |
239 |
my $count = $countpendings; |
253 |
|
240 |
|
254 |
if ($count>$resultsperpage){ |
241 |
if ($count>$resultsperpage){ |
255 |
my $displaynext=0; |
242 |
my $displaynext=0; |
256 |
my $displayprev=$startfrom; |
243 |
my $displayprev=$startfrom; |
257 |
if(($count - ($startfrom+$resultsperpage)) > 0 ) { |
244 |
if(($count - ($startfrom+$resultsperpage)) > 0 ) { |
258 |
$displaynext = 1; |
245 |
$displaynext = 1; |
259 |
} |
246 |
} |
260 |
|
247 |
|
261 |
my @numbers = (); |
248 |
my @numbers = (); |
262 |
for (my $i=1; $i<$count/$resultsperpage+1; $i++) { |
249 |
for (my $i=1; $i<$count/$resultsperpage+1; $i++) { |
263 |
my $highlight=0; |
250 |
my $highlight=0; |
264 |
($startfrom/$resultsperpage==($i-1)) && ($highlight=1); |
251 |
($startfrom/$resultsperpage==($i-1)) && ($highlight=1); |
265 |
push @numbers, { number => $i, |
252 |
push @numbers, { number => $i, |
266 |
highlight => $highlight , |
253 |
highlight => $highlight , |
267 |
startfrom => ($i-1)*$resultsperpage}; |
254 |
startfrom => ($i-1)*$resultsperpage}; |
268 |
} |
255 |
} |
269 |
|
256 |
|
270 |
my $from = $startfrom*$resultsperpage+1; |
257 |
my $from = $startfrom*$resultsperpage+1; |
271 |
my $to; |
258 |
my $to; |
272 |
if($count < (($startfrom+1)*$resultsperpage)){ |
259 |
if($count < (($startfrom+1)*$resultsperpage)){ |
273 |
$to = $count; |
260 |
$to = $count; |
274 |
} else { |
261 |
} else { |
275 |
$to = (($startfrom+1)*$resultsperpage); |
262 |
$to = (($startfrom+1)*$resultsperpage); |
|
|
263 |
} |
264 |
$template->param(numbers=>\@numbers, |
265 |
displaynext=>$displaynext, |
266 |
displayprev=>$displayprev, |
267 |
nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count), |
268 |
prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0) |
269 |
); |
276 |
} |
270 |
} |
277 |
$template->param(numbers=>\@numbers, |
271 |
|
278 |
displaynext=>$displaynext, |
272 |
$template->param( |
279 |
displayprev=>$displayprev, |
273 |
countpending => $countpendings, |
280 |
nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count), |
274 |
loop_orders => \@loop_orders, |
281 |
prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0) |
275 |
ordergrandtotal => sprintf($cfstr, $ordergrandtotal), |
282 |
); |
276 |
totalPunitprice => sprintf("%.2f", $totalPunitprice), |
|
|
277 |
totalPquantity => $totalPquantity, |
278 |
totalPqtyrcvd => $totalPqtyrcvd, |
279 |
totalPecost => sprintf("%.2f", $totalPecost), |
280 |
); |
283 |
} |
281 |
} |
284 |
|
282 |
|
285 |
#$totalfreight=$freight; |
|
|
286 |
$tototal = $tototal + $freight; |
287 |
|
283 |
|
288 |
$template->param( |
284 |
$template->param( |
289 |
invoice => $invoice, |
285 |
invoiceid => $invoice->{invoiceid}, |
|
|
286 |
invoice => $invoice->{invoicenumber}, |
287 |
invoiceclosedate => $invoice->{closedate}, |
290 |
datereceived => $datereceived->output('iso'), |
288 |
datereceived => $datereceived->output('iso'), |
291 |
invoicedatereceived => $datereceived->output('iso'), |
289 |
invoicedatereceived => $datereceived->output('iso'), |
292 |
formatteddatereceived => $datereceived->output(), |
290 |
formatteddatereceived => $datereceived->output(), |
293 |
name => $bookseller->{'name'}, |
291 |
name => $bookseller->{'name'}, |
294 |
supplierid => $supplierid, |
292 |
supplierid => $bookseller->{id}, |
295 |
gst => $gst, |
293 |
gst => $gst, |
296 |
freight => $freight, |
|
|
297 |
invoice => $invoice, |
298 |
countreceived => $countlines, |
294 |
countreceived => $countlines, |
299 |
loop_received => \@loop_received, |
295 |
loop_received => \@loop_received, |
300 |
countpending => $countpendings, |
|
|
301 |
loop_orders => \@loop_orders, |
302 |
totalprice => sprintf($cfstr, $totalprice), |
296 |
totalprice => sprintf($cfstr, $totalprice), |
303 |
totalfreight => $totalfreight, |
|
|
304 |
totalquantity => $totalquantity, |
297 |
totalquantity => $totalquantity, |
305 |
tototal => sprintf($cfstr, $tototal), |
298 |
tototal => sprintf($cfstr, $tototal), |
306 |
ordergrandtotal => sprintf($cfstr, $ordergrandtotal), |
|
|
307 |
gst => $gst, |
299 |
gst => $gst, |
308 |
grandtot => sprintf($cfstr, $tototal + $gst), |
300 |
grandtot => sprintf($cfstr, $tototal + $gst), |
309 |
totalPunitprice => sprintf("%.2f", $totalPunitprice), |
|
|
310 |
totalPquantity => $totalPquantity, |
311 |
totalPqtyrcvd => $totalPqtyrcvd, |
312 |
totalPecost => sprintf("%.2f", $totalPecost), |
313 |
resultsperpage => $resultsperpage, |
301 |
resultsperpage => $resultsperpage, |
314 |
); |
302 |
); |
315 |
output_html_with_http_headers $input, $cookie, $template->output; |
303 |
output_html_with_http_headers $input, $cookie, $template->output; |
316 |
|
|
|