Lines 47-55
basket.pl
Link Here
|
47 |
|
47 |
|
48 |
=head1 DESCRIPTION |
48 |
=head1 DESCRIPTION |
49 |
|
49 |
|
50 |
This script display all informations about basket for the supplier given |
50 |
This script display all informations about basket for the supplier given |
51 |
on input arg. Moreover, it allows us to add a new order for this supplier from |
51 |
on input arg. Moreover, it allows us to add a new order for this supplier from |
52 |
an existing record, a suggestion or a new record. |
52 |
an existing record, a suggestion or a new record. |
53 |
|
53 |
|
54 |
=head1 CGI PARAMETERS |
54 |
=head1 CGI PARAMETERS |
55 |
|
55 |
|
Lines 76-89
our $booksellerid = $query->param('booksellerid');
Link Here
|
76 |
my $duplinbatch = $query->param('duplinbatch'); |
76 |
my $duplinbatch = $query->param('duplinbatch'); |
77 |
|
77 |
|
78 |
our ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( |
78 |
our ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( |
79 |
{ |
79 |
{ |
80 |
template_name => "acqui/basket.tt", |
80 |
template_name => "acqui/basket.tt", |
81 |
query => $query, |
81 |
query => $query, |
82 |
type => "intranet", |
82 |
type => "intranet", |
83 |
authnotrequired => 0, |
83 |
authnotrequired => 0, |
84 |
flagsrequired => { acquisition => 'order_manage' }, |
84 |
flagsrequired => { acquisition => 'order_manage' }, |
85 |
debug => 1, |
85 |
debug => 1, |
86 |
} |
86 |
} |
87 |
); |
87 |
); |
88 |
|
88 |
|
89 |
our $basket = GetBasket($basketno); |
89 |
our $basket = GetBasket($basketno); |
Lines 91-109
$booksellerid = $basket->{booksellerid} unless $booksellerid;
Link Here
|
91 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
91 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
92 |
my $schema = Koha::Database->new()->schema(); |
92 |
my $schema = Koha::Database->new()->schema(); |
93 |
my $rs = $schema->resultset('VendorEdiAccount')->search( |
93 |
my $rs = $schema->resultset('VendorEdiAccount')->search( |
94 |
{ vendor_id => $booksellerid, } ); |
94 |
{ vendor_id => $booksellerid, } ); |
95 |
$template->param( ediaccount => ($rs->count > 0)); |
95 |
$template->param( ediaccount => ($rs->count > 0)); |
96 |
|
96 |
|
97 |
unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { |
97 |
unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { |
98 |
$template->param( |
98 |
$template->param( |
99 |
cannot_manage_basket => 1, |
99 |
cannot_manage_basket => 1, |
100 |
basketno => $basketno, |
100 |
basketno => $basketno, |
101 |
basketname => $basket->{basketname}, |
101 |
basketname => $basket->{basketname}, |
102 |
booksellerid => $booksellerid, |
102 |
booksellerid => $booksellerid, |
103 |
name => $bookseller->name, |
103 |
name => $bookseller->name, |
104 |
); |
104 |
); |
105 |
output_html_with_http_headers $query, $cookie, $template->output; |
105 |
output_html_with_http_headers $query, $cookie, $template->output; |
106 |
exit; |
106 |
exit; |
107 |
} |
107 |
} |
108 |
|
108 |
|
109 |
# FIXME : what about the "discount" percentage? |
109 |
# FIXME : what about the "discount" percentage? |
Lines 118-493
$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
Link Here
|
118 |
my @messages; |
118 |
my @messages; |
119 |
|
119 |
|
120 |
if ( $op eq 'delete_confirm' ) { |
120 |
if ( $op eq 'delete_confirm' ) { |
121 |
my $basketno = $query->param('basketno'); |
121 |
my $basketno = $query->param('basketno'); |
122 |
my $delbiblio = $query->param('delbiblio'); |
122 |
my $delbiblio = $query->param('delbiblio'); |
123 |
my @orders = GetOrders($basketno); |
123 |
my @orders = GetOrders($basketno); |
124 |
#Delete all orders included in that basket, and all items received. |
124 |
#Delete all orders included in that basket, and all items received. |
125 |
foreach my $myorder (@orders){ |
125 |
foreach my $myorder (@orders){ |
126 |
DelOrder($myorder->{biblionumber},$myorder->{ordernumber}); |
126 |
DelOrder($myorder->{biblionumber},$myorder->{ordernumber}); |
127 |
} |
127 |
} |
128 |
# if $delbiblio = 1, delete the records if possible |
128 |
# if $delbiblio = 1, delete the records if possible |
129 |
if ((defined $delbiblio)and ($delbiblio ==1)){ |
129 |
if ((defined $delbiblio)and ($delbiblio ==1)){ |
130 |
my @cannotdelbiblios ; |
130 |
my @cannotdelbiblios ; |
131 |
foreach my $myorder (@orders){ |
131 |
foreach my $myorder (@orders){ |
132 |
my $biblionumber = $myorder->{'biblionumber'}; |
132 |
my $biblionumber = $myorder->{'biblionumber'}; |
133 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
133 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
134 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
134 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
135 |
my $ordernumber = $myorder->{'ordernumber'}; |
135 |
my $ordernumber = $myorder->{'ordernumber'}; |
136 |
my $subscriptions = scalar GetSubscriptionsId ($biblionumber); |
136 |
my $has_subscriptions = $biblio->subscriptions->count; |
137 |
my $itemcount = $biblio->items->count; |
137 |
my $itemcount = $biblio->items->count; |
138 |
my $error; |
138 |
my $error; |
139 |
if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) { |
139 |
if ($countbiblio == 0 && $itemcount == 0 && not $has_subscriptions ) { |
140 |
$error = DelBiblio($myorder->{biblionumber}) } |
140 |
$error = DelBiblio($myorder->{biblionumber}) } |
141 |
else { |
141 |
else { |
142 |
push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), |
142 |
push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), |
143 |
title=> $myorder->{'title'}, |
143 |
title=> $myorder->{'title'}, |
144 |
author=> $myorder->{'author'}, |
144 |
author=> $myorder->{'author'}, |
145 |
countbiblio=> $countbiblio, |
145 |
countbiblio=> $countbiblio, |
146 |
itemcount=>$itemcount, |
146 |
itemcount=>$itemcount, |
147 |
subscriptions=>$subscriptions}; |
147 |
subscriptions => $has_subscriptions}; |
148 |
} |
148 |
} |
149 |
if ($error) { |
149 |
if ($error) { |
150 |
push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), |
150 |
push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), |
151 |
title=> $myorder->{'title'}, |
151 |
title=> $myorder->{'title'}, |
152 |
author=> $myorder->{'author'}, |
152 |
author=> $myorder->{'author'}, |
153 |
othererror=> $error}; |
153 |
othererror=> $error}; |
154 |
} |
|
|
155 |
} |
154 |
} |
156 |
$template->param( cannotdelbiblios => \@cannotdelbiblios ); |
|
|
157 |
} |
155 |
} |
158 |
# delete the basket |
156 |
$template->param( cannotdelbiblios => \@cannotdelbiblios ); |
159 |
DelBasket($basketno,); |
157 |
} |
160 |
$template->param( |
158 |
# delete the basket |
161 |
delete_confirmed => 1, |
159 |
DelBasket($basketno,); |
162 |
name => $bookseller->name, |
160 |
$template->param( |
163 |
booksellerid => $booksellerid, |
161 |
delete_confirmed => 1, |
164 |
); |
162 |
name => $bookseller->name, |
|
|
163 |
booksellerid => $booksellerid, |
164 |
); |
165 |
} elsif ( !$bookseller ) { |
165 |
} elsif ( !$bookseller ) { |
166 |
$template->param( NO_BOOKSELLER => 1 ); |
166 |
$template->param( NO_BOOKSELLER => 1 ); |
167 |
} elsif ($op eq 'export') { |
167 |
} elsif ($op eq 'export') { |
168 |
print $query->header( |
168 |
print $query->header( |
169 |
-type => 'text/csv', |
169 |
-type => 'text/csv', |
170 |
-attachment => 'basket' . $basket->{'basketno'} . '.csv', |
170 |
-attachment => 'basket' . $basket->{'basketno'} . '.csv', |
171 |
); |
171 |
); |
172 |
print GetBasketAsCSV($query->param('basketno'), $query); |
172 |
print GetBasketAsCSV($query->param('basketno'), $query); |
173 |
exit; |
173 |
exit; |
174 |
} elsif ($op eq 'email') { |
174 |
} elsif ($op eq 'email') { |
175 |
my $err = eval { |
175 |
my $err = eval { |
176 |
SendAlerts( 'orderacquisition', $query->param('basketno'), 'ACQORDER' ); |
176 |
SendAlerts( 'orderacquisition', $query->param('basketno'), 'ACQORDER' ); |
177 |
}; |
177 |
}; |
178 |
if ( $@ ) { |
178 |
if ( $@ ) { |
179 |
push @messages, { type => 'error', code => $@ }; |
179 |
push @messages, { type => 'error', code => $@ }; |
180 |
} elsif ( ref $err and exists $err->{error} ) { |
180 |
} elsif ( ref $err and exists $err->{error} ) { |
181 |
push @messages, { type => 'error', code => $err->{error} }; |
181 |
push @messages, { type => 'error', code => $err->{error} }; |
182 |
} else { |
182 |
} else { |
183 |
push @messages, { type => 'message', code => 'email_sent' }; |
183 |
push @messages, { type => 'message', code => 'email_sent' }; |
184 |
} |
184 |
} |
185 |
|
185 |
|
186 |
$op = 'list'; |
186 |
$op = 'list'; |
187 |
} elsif ($op eq 'close') { |
187 |
} elsif ($op eq 'close') { |
188 |
my $confirm = $query->param('confirm') || $confirm_pref eq '2'; |
188 |
my $confirm = $query->param('confirm') || $confirm_pref eq '2'; |
189 |
if ($confirm) { |
189 |
if ($confirm) { |
190 |
my $basketno = $query->param('basketno'); |
190 |
my $basketno = $query->param('basketno'); |
191 |
my $booksellerid = $query->param('booksellerid'); |
191 |
my $booksellerid = $query->param('booksellerid'); |
192 |
$basketno =~ /^\d+$/ and CloseBasket($basketno); |
192 |
$basketno =~ /^\d+$/ and CloseBasket($basketno); |
193 |
# if requested, create basket group, close it and attach the basket |
193 |
# if requested, create basket group, close it and attach the basket |
194 |
if ($query->param('createbasketgroup')) { |
194 |
if ($query->param('createbasketgroup')) { |
195 |
my $branchcode; |
195 |
my $branchcode; |
196 |
if(C4::Context->userenv and C4::Context->userenv->{'branch'} |
196 |
if(C4::Context->userenv and C4::Context->userenv->{'branch'} |
197 |
and C4::Context->userenv->{'branch'} ne "NO_LIBRARY_SET") { |
197 |
and C4::Context->userenv->{'branch'} ne "NO_LIBRARY_SET") { |
198 |
$branchcode = C4::Context->userenv->{'branch'}; |
198 |
$branchcode = C4::Context->userenv->{'branch'}; |
199 |
} |
|
|
200 |
my $basketgroupid = NewBasketgroup( { name => $basket->{basketname}, |
201 |
booksellerid => $booksellerid, |
202 |
deliveryplace => $branchcode, |
203 |
billingplace => $branchcode, |
204 |
closed => 1, |
205 |
}); |
206 |
ModBasket( { basketno => $basketno, |
207 |
basketgroupid => $basketgroupid } ); |
208 |
print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid='.$booksellerid.'&closed=1'); |
209 |
} else { |
210 |
print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' . $booksellerid); |
211 |
} |
199 |
} |
212 |
exit; |
200 |
my $basketgroupid = NewBasketgroup( { name => $basket->{basketname}, |
|
|
201 |
booksellerid => $booksellerid, |
202 |
deliveryplace => $branchcode, |
203 |
billingplace => $branchcode, |
204 |
closed => 1, |
205 |
}); |
206 |
ModBasket( { basketno => $basketno, |
207 |
basketgroupid => $basketgroupid } ); |
208 |
print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid='.$booksellerid.'&closed=1'); |
213 |
} else { |
209 |
} else { |
214 |
$template->param( |
210 |
print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' . $booksellerid); |
215 |
confirm_close => "1", |
|
|
216 |
booksellerid => $booksellerid, |
217 |
basketno => $basket->{'basketno'}, |
218 |
basketname => $basket->{'basketname'}, |
219 |
basketgroupname => $basket->{'basketname'}, |
220 |
); |
221 |
} |
211 |
} |
|
|
212 |
exit; |
213 |
} else { |
214 |
$template->param( |
215 |
confirm_close => "1", |
216 |
booksellerid => $booksellerid, |
217 |
basketno => $basket->{'basketno'}, |
218 |
basketname => $basket->{'basketname'}, |
219 |
basketgroupname => $basket->{'basketname'}, |
220 |
); |
221 |
} |
222 |
} elsif ($op eq 'reopen') { |
222 |
} elsif ($op eq 'reopen') { |
223 |
ReopenBasket($query->param('basketno')); |
223 |
ReopenBasket($query->param('basketno')); |
224 |
print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'}) |
224 |
print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'}) |
225 |
} |
225 |
} |
226 |
elsif ( $op eq 'ediorder' ) { |
226 |
elsif ( $op eq 'ediorder' ) { |
227 |
edi_close_and_order() |
227 |
edi_close_and_order() |
228 |
} elsif ( $op eq 'mod_users' ) { |
228 |
} elsif ( $op eq 'mod_users' ) { |
229 |
my $basketusers_ids = $query->param('users_ids'); |
229 |
my $basketusers_ids = $query->param('users_ids'); |
230 |
my @basketusers = split( /:/, $basketusers_ids ); |
230 |
my @basketusers = split( /:/, $basketusers_ids ); |
231 |
ModBasketUsers($basketno, @basketusers); |
231 |
ModBasketUsers($basketno, @basketusers); |
232 |
print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); |
232 |
print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); |
233 |
exit; |
233 |
exit; |
234 |
} elsif ( $op eq 'mod_branch' ) { |
234 |
} elsif ( $op eq 'mod_branch' ) { |
235 |
my $branch = $query->param('branch'); |
235 |
my $branch = $query->param('branch'); |
236 |
$branch = undef if(defined $branch and $branch eq ''); |
236 |
$branch = undef if(defined $branch and $branch eq ''); |
237 |
ModBasket({ |
237 |
ModBasket({ |
238 |
basketno => $basket->{basketno}, |
238 |
basketno => $basket->{basketno}, |
239 |
branch => $branch |
239 |
branch => $branch |
240 |
}); |
240 |
}); |
241 |
print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); |
241 |
print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); |
242 |
exit; |
242 |
exit; |
243 |
} |
243 |
} |
244 |
|
244 |
|
245 |
if ( $op eq 'list' ) { |
245 |
if ( $op eq 'list' ) { |
246 |
my @branches_loop; |
246 |
my @branches_loop; |
247 |
# get librarian branch... |
247 |
# get librarian branch... |
248 |
if ( C4::Context->preference("IndependentBranches") ) { |
248 |
if ( C4::Context->preference("IndependentBranches") ) { |
249 |
my $userenv = C4::Context->userenv; |
249 |
my $userenv = C4::Context->userenv; |
250 |
unless ( C4::Context->IsSuperLibrarian() ) { |
250 |
unless ( C4::Context->IsSuperLibrarian() ) { |
251 |
my $validtest = ( $basket->{creationdate} eq '' ) |
251 |
my $validtest = ( $basket->{creationdate} eq '' ) |
252 |
|| ( $userenv->{branch} eq $basket->{branch} ) |
252 |
|| ( $userenv->{branch} eq $basket->{branch} ) |
253 |
|| ( $userenv->{branch} eq '' ) |
253 |
|| ( $userenv->{branch} eq '' ) |
254 |
|| ( $basket->{branch} eq '' ); |
254 |
|| ( $basket->{branch} eq '' ); |
255 |
unless ($validtest) { |
255 |
unless ($validtest) { |
256 |
print $query->redirect("../mainpage.pl"); |
256 |
print $query->redirect("../mainpage.pl"); |
257 |
exit 0; |
257 |
exit 0; |
258 |
} |
|
|
259 |
} |
258 |
} |
|
|
259 |
} |
260 |
|
260 |
|
261 |
if (!defined $basket->{branch} or $basket->{branch} eq $userenv->{branch}) { |
261 |
if (!defined $basket->{branch} or $basket->{branch} eq $userenv->{branch}) { |
262 |
push @branches_loop, { |
262 |
push @branches_loop, { |
263 |
branchcode => $userenv->{branch}, |
263 |
branchcode => $userenv->{branch}, |
264 |
branchname => $userenv->{branchname}, |
264 |
branchname => $userenv->{branchname}, |
265 |
selected => 1, |
265 |
selected => 1, |
266 |
}; |
266 |
}; |
267 |
} |
267 |
} |
268 |
} else { |
268 |
} else { |
269 |
# get branches |
269 |
# get branches |
270 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; |
270 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; |
271 |
foreach my $branch (@$branches) { |
271 |
foreach my $branch (@$branches) { |
272 |
my $selected = 0; |
272 |
my $selected = 0; |
273 |
if (defined $basket->{branch}) { |
273 |
if (defined $basket->{branch}) { |
274 |
$selected = 1 if $branch->{branchcode} eq $basket->{branch}; |
274 |
$selected = 1 if $branch->{branchcode} eq $basket->{branch}; |
275 |
} else { |
275 |
} else { |
276 |
$selected = 1 if $branch->{branchcode} eq C4::Context->userenv->{branch}; |
276 |
$selected = 1 if $branch->{branchcode} eq C4::Context->userenv->{branch}; |
277 |
} |
|
|
278 |
push @branches_loop, { |
279 |
branchcode => $branch->{branchcode}, |
280 |
branchname => $branch->{branchname}, |
281 |
selected => $selected |
282 |
}; |
283 |
} |
277 |
} |
|
|
278 |
push @branches_loop, { |
279 |
branchcode => $branch->{branchcode}, |
280 |
branchname => $branch->{branchname}, |
281 |
selected => $selected |
282 |
}; |
284 |
} |
283 |
} |
|
|
284 |
} |
285 |
|
285 |
|
286 |
#if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups |
286 |
#if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups |
287 |
my ($basketgroup, $basketgroups); |
287 |
my ($basketgroup, $basketgroups); |
288 |
my $staffuser = GetMember(borrowernumber => $loggedinuser); |
288 |
my $staffuser = GetMember(borrowernumber => $loggedinuser); |
289 |
if ($basket->{closedate} && haspermission($staffuser->{userid}, { acquisition => 'group_manage'} )) { |
289 |
if ($basket->{closedate} && haspermission($staffuser->{userid}, { acquisition => 'group_manage'} )) { |
290 |
$basketgroups = GetBasketgroups($basket->{booksellerid}); |
290 |
$basketgroups = GetBasketgroups($basket->{booksellerid}); |
291 |
for my $bg ( @{$basketgroups} ) { |
291 |
for my $bg ( @{$basketgroups} ) { |
292 |
if ($basket->{basketgroupid} && $basket->{basketgroupid} == $bg->{id}){ |
292 |
if ($basket->{basketgroupid} && $basket->{basketgroupid} == $bg->{id}){ |
293 |
$bg->{default} = 1; |
293 |
$bg->{default} = 1; |
294 |
$basketgroup = $bg; |
294 |
$basketgroup = $bg; |
295 |
} |
|
|
296 |
} |
295 |
} |
297 |
} |
296 |
} |
|
|
297 |
} |
298 |
|
298 |
|
299 |
# if the basket is closed, calculate estimated delivery date |
299 |
# if the basket is closed, calculate estimated delivery date |
300 |
my $estimateddeliverydate; |
300 |
my $estimateddeliverydate; |
301 |
if( $basket->{closedate} ) { |
301 |
if( $basket->{closedate} ) { |
302 |
my ($year, $month, $day) = ($basket->{closedate} =~ /(\d+)-(\d+)-(\d+)/); |
302 |
my ($year, $month, $day) = ($basket->{closedate} =~ /(\d+)-(\d+)-(\d+)/); |
303 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->deliverytime); |
303 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $bookseller->deliverytime); |
304 |
$estimateddeliverydate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); |
304 |
$estimateddeliverydate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); |
305 |
} |
305 |
} |
306 |
|
306 |
|
307 |
# if new basket, pre-fill infos |
307 |
# if new basket, pre-fill infos |
308 |
$basket->{creationdate} = "" unless ( $basket->{creationdate} ); |
308 |
$basket->{creationdate} = "" unless ( $basket->{creationdate} ); |
309 |
$basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} ); |
309 |
$basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} ); |
310 |
$debug |
310 |
$debug |
311 |
and warn sprintf |
311 |
and warn sprintf |
312 |
"loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", |
312 |
"loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", |
313 |
$basket->{creationdate}, $basket->{authorisedby}; |
313 |
$basket->{creationdate}, $basket->{authorisedby}; |
314 |
|
314 |
|
315 |
my @basketusers_ids = GetBasketUsers($basketno); |
315 |
my @basketusers_ids = GetBasketUsers($basketno); |
316 |
my @basketusers; |
316 |
my @basketusers; |
317 |
foreach my $basketuser_id (@basketusers_ids) { |
317 |
foreach my $basketuser_id (@basketusers_ids) { |
318 |
my $basketuser = GetMember(borrowernumber => $basketuser_id); |
318 |
my $basketuser = GetMember(borrowernumber => $basketuser_id); |
319 |
push @basketusers, $basketuser if $basketuser; |
319 |
push @basketusers, $basketuser if $basketuser; |
320 |
} |
320 |
} |
321 |
|
321 |
|
322 |
my $active_currency = Koha::Acquisition::Currencies->get_active; |
322 |
my $active_currency = Koha::Acquisition::Currencies->get_active; |
323 |
|
323 |
|
324 |
my @orders = GetOrders( $basketno ); |
324 |
my @orders = GetOrders( $basketno ); |
325 |
my @books_loop; |
325 |
my @books_loop; |
326 |
|
326 |
|
327 |
my @book_foot_loop; |
327 |
my @book_foot_loop; |
328 |
my %foot; |
328 |
my %foot; |
329 |
my $total_quantity = 0; |
329 |
my $total_quantity = 0; |
330 |
my $total_tax_excluded = 0; |
330 |
my $total_tax_excluded = 0; |
331 |
my $total_tax_included = 0; |
331 |
my $total_tax_included = 0; |
332 |
my $total_tax_value = 0; |
332 |
my $total_tax_value = 0; |
333 |
for my $order (@orders) { |
333 |
for my $order (@orders) { |
334 |
my $line = get_order_infos( $order, $bookseller); |
334 |
my $line = get_order_infos( $order, $bookseller); |
335 |
if ( $line->{uncertainprice} ) { |
335 |
if ( $line->{uncertainprice} ) { |
336 |
$template->param( uncertainprices => 1 ); |
336 |
$template->param( uncertainprices => 1 ); |
337 |
} |
337 |
} |
338 |
|
338 |
|
339 |
$line->{tax_rate} = $line->{tax_rate_on_ordering}; |
339 |
$line->{tax_rate} = $line->{tax_rate_on_ordering}; |
340 |
$line->{tax_value} = $line->{tax_value_on_ordering}; |
340 |
$line->{tax_value} = $line->{tax_value_on_ordering}; |
341 |
|
341 |
|
342 |
push @books_loop, $line; |
342 |
push @books_loop, $line; |
343 |
|
343 |
|
344 |
$foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; |
344 |
$foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; |
345 |
$foot{$$line{tax_rate}}{tax_value} += $$line{tax_value}; |
345 |
$foot{$$line{tax_rate}}{tax_value} += $$line{tax_value}; |
346 |
$total_tax_value += $$line{tax_value}; |
346 |
$total_tax_value += $$line{tax_value}; |
347 |
$foot{$$line{tax_rate}}{quantity} += $$line{quantity}; |
347 |
$foot{$$line{tax_rate}}{quantity} += $$line{quantity}; |
348 |
$total_quantity += $$line{quantity}; |
348 |
$total_quantity += $$line{quantity}; |
349 |
$foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; |
349 |
$foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; |
350 |
$total_tax_excluded += $$line{total_tax_excluded}; |
350 |
$total_tax_excluded += $$line{total_tax_excluded}; |
351 |
$foot{$$line{tax_rate}}{total_tax_included} += $$line{total_tax_included}; |
351 |
$foot{$$line{tax_rate}}{total_tax_included} += $$line{total_tax_included}; |
352 |
$total_tax_included += $$line{total_tax_included}; |
352 |
$total_tax_included += $$line{total_tax_included}; |
353 |
} |
353 |
} |
354 |
|
354 |
|
355 |
push @book_foot_loop, map {$_} values %foot; |
355 |
push @book_foot_loop, map {$_} values %foot; |
356 |
|
356 |
|
357 |
# Get cancelled orders |
357 |
# Get cancelled orders |
358 |
my @cancelledorders = GetOrders($basketno, { cancelled => 1 }); |
358 |
my @cancelledorders = GetOrders($basketno, { cancelled => 1 }); |
359 |
my @cancelledorders_loop; |
359 |
my @cancelledorders_loop; |
360 |
for my $order (@cancelledorders) { |
360 |
for my $order (@cancelledorders) { |
361 |
my $line = get_order_infos( $order, $bookseller); |
361 |
my $line = get_order_infos( $order, $bookseller); |
362 |
push @cancelledorders_loop, $line; |
362 |
push @cancelledorders_loop, $line; |
363 |
} |
363 |
} |
364 |
|
364 |
|
365 |
my $contract = GetContract({ |
365 |
my $contract = GetContract({ |
366 |
contractnumber => $basket->{contractnumber} |
366 |
contractnumber => $basket->{contractnumber} |
367 |
}); |
367 |
}); |
368 |
|
368 |
|
369 |
if ($basket->{basketgroupid}){ |
369 |
if ($basket->{basketgroupid}){ |
370 |
$basketgroup = GetBasketgroup($basket->{basketgroupid}); |
370 |
$basketgroup = GetBasketgroup($basket->{basketgroupid}); |
|
|
371 |
} |
372 |
my $borrower= GetMember('borrowernumber' => $loggedinuser); |
373 |
my $budgets = GetBudgetHierarchy; |
374 |
my $has_budgets = 0; |
375 |
foreach my $r (@{$budgets}) { |
376 |
if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) { |
377 |
next; |
371 |
} |
378 |
} |
372 |
my $borrower= GetMember('borrowernumber' => $loggedinuser); |
379 |
next unless (CanUserUseBudget($loggedinuser, $r, $userflags)); |
373 |
my $budgets = GetBudgetHierarchy; |
|
|
374 |
my $has_budgets = 0; |
375 |
foreach my $r (@{$budgets}) { |
376 |
if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) { |
377 |
next; |
378 |
} |
379 |
next unless (CanUserUseBudget($loggedinuser, $r, $userflags)); |
380 |
|
380 |
|
381 |
$has_budgets = 1; |
381 |
$has_budgets = 1; |
382 |
last; |
382 |
last; |
383 |
} |
383 |
} |
384 |
|
384 |
|
385 |
$template->param( |
385 |
$template->param( |
386 |
basketno => $basketno, |
386 |
basketno => $basketno, |
387 |
basket => $basket, |
387 |
basket => $basket, |
388 |
basketname => $basket->{'basketname'}, |
388 |
basketname => $basket->{'basketname'}, |
389 |
basketbranchcode => $basket->{branch}, |
389 |
basketbranchcode => $basket->{branch}, |
390 |
basketnote => $basket->{note}, |
390 |
basketnote => $basket->{note}, |
391 |
basketbooksellernote => $basket->{booksellernote}, |
391 |
basketbooksellernote => $basket->{booksellernote}, |
392 |
basketcontractno => $basket->{contractnumber}, |
392 |
basketcontractno => $basket->{contractnumber}, |
393 |
basketcontractname => $contract->{contractname}, |
393 |
basketcontractname => $contract->{contractname}, |
394 |
branches_loop => \@branches_loop, |
394 |
branches_loop => \@branches_loop, |
395 |
creationdate => $basket->{creationdate}, |
395 |
creationdate => $basket->{creationdate}, |
396 |
authorisedby => $basket->{authorisedby}, |
396 |
authorisedby => $basket->{authorisedby}, |
397 |
authorisedbyname => $basket->{authorisedbyname}, |
397 |
authorisedbyname => $basket->{authorisedbyname}, |
398 |
users_ids => join(':', @basketusers_ids), |
398 |
users_ids => join(':', @basketusers_ids), |
399 |
users => \@basketusers, |
399 |
users => \@basketusers, |
400 |
closedate => $basket->{closedate}, |
400 |
closedate => $basket->{closedate}, |
401 |
estimateddeliverydate=> $estimateddeliverydate, |
401 |
estimateddeliverydate=> $estimateddeliverydate, |
402 |
is_standing => $basket->{is_standing}, |
402 |
is_standing => $basket->{is_standing}, |
403 |
deliveryplace => $basket->{deliveryplace}, |
403 |
deliveryplace => $basket->{deliveryplace}, |
404 |
billingplace => $basket->{billingplace}, |
404 |
billingplace => $basket->{billingplace}, |
405 |
active => $bookseller->active, |
405 |
active => $bookseller->active, |
406 |
booksellerid => $bookseller->id, |
406 |
booksellerid => $bookseller->id, |
407 |
name => $bookseller->name, |
407 |
name => $bookseller->name, |
408 |
books_loop => \@books_loop, |
408 |
books_loop => \@books_loop, |
409 |
book_foot_loop => \@book_foot_loop, |
409 |
book_foot_loop => \@book_foot_loop, |
410 |
cancelledorders_loop => \@cancelledorders_loop, |
410 |
cancelledorders_loop => \@cancelledorders_loop, |
411 |
total_quantity => $total_quantity, |
411 |
total_quantity => $total_quantity, |
412 |
total_tax_excluded => $total_tax_excluded, |
412 |
total_tax_excluded => $total_tax_excluded, |
413 |
total_tax_included => $total_tax_included, |
413 |
total_tax_included => $total_tax_included, |
414 |
total_tax_value => $total_tax_value, |
414 |
total_tax_value => $total_tax_value, |
415 |
currency => $active_currency->currency, |
415 |
currency => $active_currency->currency, |
416 |
listincgst => $bookseller->listincgst, |
416 |
listincgst => $bookseller->listincgst, |
417 |
basketgroups => $basketgroups, |
417 |
basketgroups => $basketgroups, |
418 |
basketgroup => $basketgroup, |
418 |
basketgroup => $basketgroup, |
419 |
grouped => $basket->{basketgroupid}, |
419 |
grouped => $basket->{basketgroupid}, |
420 |
# The double negatives and booleans here mean: |
420 |
# The double negatives and booleans here mean: |
421 |
# "A basket cannot be closed if there are no orders in it or it's a standing order basket." |
421 |
# "A basket cannot be closed if there are no orders in it or it's a standing order basket." |
422 |
# |
422 |
# |
423 |
# (The template has another implicit restriction that the order cannot be closed if there |
423 |
# (The template has another implicit restriction that the order cannot be closed if there |
424 |
# are any orders with uncertain prices.) |
424 |
# are any orders with uncertain prices.) |
425 |
unclosable => @orders ? $basket->{is_standing} : 1, |
425 |
unclosable => @orders ? $basket->{is_standing} : 1, |
426 |
has_budgets => $has_budgets, |
426 |
has_budgets => $has_budgets, |
427 |
duplinbatch => $duplinbatch, |
427 |
duplinbatch => $duplinbatch, |
428 |
); |
428 |
); |
429 |
} |
429 |
} |
430 |
|
430 |
|
431 |
$template->param( messages => \@messages ); |
431 |
$template->param( messages => \@messages ); |
432 |
output_html_with_http_headers $query, $cookie, $template->output; |
432 |
output_html_with_http_headers $query, $cookie, $template->output; |
433 |
|
433 |
|
434 |
sub get_order_infos { |
434 |
sub get_order_infos { |
435 |
my $order = shift; |
435 |
my $order = shift; |
436 |
my $bookseller = shift; |
436 |
my $bookseller = shift; |
437 |
my $qty = $order->{'quantity'} || 0; |
437 |
my $qty = $order->{'quantity'} || 0; |
438 |
if ( !defined $order->{quantityreceived} ) { |
438 |
if ( !defined $order->{quantityreceived} ) { |
439 |
$order->{quantityreceived} = 0; |
439 |
$order->{quantityreceived} = 0; |
440 |
} |
440 |
} |
441 |
my $budget = GetBudget($order->{budget_id}); |
441 |
my $budget = GetBudget($order->{budget_id}); |
442 |
my $basket = GetBasket($order->{basketno}); |
442 |
my $basket = GetBasket($order->{basketno}); |
443 |
|
443 |
|
444 |
my %line = %{ $order }; |
444 |
my %line = %{ $order }; |
445 |
# Don't show unreceived standing orders as received |
445 |
# Don't show unreceived standing orders as received |
446 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} && ( $basket->{is_standing} ? $qty : 1 ) ); |
446 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} && ( $basket->{is_standing} ? $qty : 1 ) ); |
447 |
$line{basketno} = $basketno; |
447 |
$line{basketno} = $basketno; |
448 |
$line{budget_name} = $budget->{budget_name}; |
448 |
$line{budget_name} = $budget->{budget_name}; |
449 |
|
449 |
|
450 |
$line{total_tax_included} = $line{ecost_tax_included} * $line{quantity}; |
450 |
$line{total_tax_included} = $line{ecost_tax_included} * $line{quantity}; |
451 |
$line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity}; |
451 |
$line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity}; |
452 |
$line{tax_value} = $line{tax_value_on_ordering}; |
452 |
$line{tax_value} = $line{tax_value_on_ordering}; |
453 |
$line{tax_rate} = $line{tax_rate_on_ordering}; |
453 |
$line{tax_rate} = $line{tax_rate_on_ordering}; |
454 |
|
454 |
|
455 |
if ( $line{uncertainprice} ) { |
455 |
if ( $line{uncertainprice} ) { |
456 |
$line{rrp_tax_excluded} .= ' (Uncertain)'; |
456 |
$line{rrp_tax_excluded} .= ' (Uncertain)'; |
457 |
} |
457 |
} |
458 |
if ( $line{'title'} ) { |
458 |
if ( $line{'title'} ) { |
459 |
my $volume = $order->{'volume'}; |
459 |
my $volume = $order->{'volume'}; |
460 |
my $seriestitle = $order->{'seriestitle'}; |
460 |
my $seriestitle = $order->{'seriestitle'}; |
461 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
461 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
462 |
$line{'title'} .= " / $volume" if $volume; |
462 |
$line{'title'} .= " / $volume" if $volume; |
463 |
} |
463 |
} |
464 |
|
464 |
|
465 |
my $biblionumber = $order->{'biblionumber'}; |
465 |
my $biblionumber = $order->{'biblionumber'}; |
466 |
if ( $biblionumber ) { # The biblio still exists |
466 |
if ( $biblionumber ) { # The biblio still exists |
467 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
467 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
468 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
468 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
469 |
my $ordernumber = $order->{'ordernumber'}; |
469 |
my $ordernumber = $order->{'ordernumber'}; |
470 |
my @subscriptions = GetSubscriptionsId ($biblionumber); |
470 |
my $has_subscriptions = $biblio->subscriptions->count; |
471 |
my $itemcount = $biblio->items->count; |
471 |
my $itemcount = $biblio->items->count; |
472 |
my $holds_count = $biblio->holds->count; |
472 |
my $holds_count = $biblio->holds->count; |
473 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
473 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
474 |
my $itemholds = $biblio->holds->search({ itemnumber => { -in => \@items } })->count; |
474 |
my $itemholds = $biblio->holds->search({ itemnumber => { -in => \@items } })->count; |
475 |
|
475 |
|
476 |
# 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 |
476 |
# 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 |
477 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count); |
477 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !($has_subscriptions) && !($holds_count); |
478 |
$line{items} = ($itemcount) - (scalar @items); |
478 |
$line{items} = ($itemcount) - (scalar @items); |
479 |
$line{left_item} = 1 if $line{items} >= 1; |
479 |
$line{left_item} = 1 if $line{items} >= 1; |
480 |
$line{left_biblio} = 1 if $countbiblio > 1; |
480 |
$line{left_biblio} = 1 if $countbiblio > 1; |
481 |
$line{biblios} = $countbiblio - 1; |
481 |
$line{biblios} = $countbiblio - 1; |
482 |
$line{left_subscription} = 1 if scalar @subscriptions >= 1; |
482 |
$line{left_subscription} = 1 if $has_subscriptions; |
483 |
$line{subscriptions} = scalar @subscriptions; |
483 |
$line{subscriptions} = $has_subscriptions; |
484 |
($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; |
484 |
($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; |
485 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
485 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
486 |
$line{holds} = $holds_count; |
486 |
$line{holds} = $holds_count; |
487 |
$line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order}; |
487 |
$line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order}; |
488 |
} |
488 |
} |
489 |
|
489 |
|
490 |
|
|
|
491 |
my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
490 |
my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
492 |
$line{suggestionid} = $$suggestion{suggestionid}; |
491 |
$line{suggestionid} = $$suggestion{suggestionid}; |
493 |
$line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; |
492 |
$line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; |