Lines 22-43
use Modern::Perl;
Link Here
|
22 |
|
22 |
|
23 |
use CGI; |
23 |
use CGI; |
24 |
|
24 |
|
25 |
use C4::Auth qw( get_template_and_user ); |
25 |
use C4::Auth qw( get_template_and_user ); |
26 |
use C4::Output qw( output_html_with_http_headers ); |
26 |
use C4::Output qw( output_html_with_http_headers ); |
27 |
use Koha::Checkouts; |
27 |
use Koha::Checkouts; |
28 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
use Koha::DateUtils qw( dt_from_string ); |
29 |
use Koha::Items; |
29 |
use Koha::Items; |
30 |
|
30 |
|
31 |
my $input = CGI->new; |
31 |
my $input = CGI->new; |
32 |
my $op = $input->param('op') // q|form|; |
32 |
my $op = $input->param('op') // q|form|; |
33 |
my $preview_results = $input->param('preview_results'); |
33 |
my $preview_results = $input->param('preview_results'); |
34 |
|
34 |
|
35 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
35 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
36 |
{ |
36 |
{ |
37 |
template_name => 'tools/batch_extend_due_dates.tt', |
37 |
template_name => 'tools/batch_extend_due_dates.tt', |
38 |
query => $input, |
38 |
query => $input, |
39 |
type => "intranet", |
39 |
type => "intranet", |
40 |
flagsrequired => { tools => 'batch_extend_due_dates' }, |
40 |
flagsrequired => { tools => 'batch_extend_due_dates' }, |
41 |
} |
41 |
} |
42 |
); |
42 |
); |
43 |
|
43 |
|
Lines 45-52
my @issue_ids;
Link Here
|
45 |
|
45 |
|
46 |
if ( $op eq 'form' ) { |
46 |
if ( $op eq 'form' ) { |
47 |
$template->param( view => 'form', ); |
47 |
$template->param( view => 'form', ); |
48 |
} |
48 |
} elsif ( $op eq 'cud-commit_preview' ) { |
49 |
elsif ( $op eq 'list' ) { |
49 |
@issue_ids = $input->multi_param('issue_id') unless @issue_ids; |
|
|
50 |
|
51 |
my $checkouts = |
52 |
Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } ); |
53 |
while ( my $checkout = $checkouts->next ) { |
54 |
my $new_due_date = $input->param( 'new_date_due_issue_' . $checkout->issue_id ); |
55 |
|
56 |
# Update checkout's due date |
57 |
$checkout->date_due($new_due_date)->store; |
58 |
|
59 |
# Update items.onloan |
60 |
$checkout->item->onloan($new_due_date)->store; |
61 |
} |
62 |
|
63 |
$template->param( |
64 |
view => 'report', |
65 |
checkouts => $checkouts, |
66 |
); |
67 |
|
68 |
} else { |
50 |
|
69 |
|
51 |
my @categorycodes = $input->multi_param('categorycodes'); |
70 |
my @categorycodes = $input->multi_param('categorycodes'); |
52 |
my @itemtypecodes = $input->multi_param('itemtypecodes'); |
71 |
my @itemtypecodes = $input->multi_param('itemtypecodes'); |
Lines 75-167
elsif ( $op eq 'list' ) {
Link Here
|
75 |
|
94 |
|
76 |
if ( $from_due_date and $to_due_date ) { |
95 |
if ( $from_due_date and $to_due_date ) { |
77 |
my $to_due_date_endday = dt_from_string($to_due_date); |
96 |
my $to_due_date_endday = dt_from_string($to_due_date); |
78 |
$to_due_date_endday |
97 |
$to_due_date_endday->set( # We set last second of day to see all checkouts from that day |
79 |
->set( # We set last second of day to see all checkouts from that day |
|
|
80 |
hour => 23, |
98 |
hour => 23, |
81 |
minute => 59, |
99 |
minute => 59, |
82 |
second => 59 |
100 |
second => 59 |
83 |
); |
101 |
); |
84 |
$search_params->{'me.date_due'} = { |
102 |
$search_params->{'me.date_due'} = { |
85 |
-between => [ |
103 |
-between => [ |
86 |
$dtf->format_datetime( dt_from_string($from_due_date) ), |
104 |
$dtf->format_datetime( dt_from_string($from_due_date) ), |
87 |
$dtf->format_datetime($to_due_date_endday), |
105 |
$dtf->format_datetime($to_due_date_endday), |
88 |
] |
106 |
] |
89 |
}; |
107 |
}; |
90 |
} |
108 |
} elsif ($from_due_date) { |
91 |
elsif ($from_due_date) { |
|
|
92 |
$search_params->{'me.date_due'} = |
109 |
$search_params->{'me.date_due'} = |
93 |
{ '>=' => $dtf->format_datetime( dt_from_string($from_due_date) ) }; |
110 |
{ '>=' => $dtf->format_datetime( dt_from_string($from_due_date) ) }; |
94 |
} |
111 |
} elsif ($to_due_date) { |
95 |
elsif ($to_due_date) { |
|
|
96 |
my $to_due_date_endday = dt_from_string($to_due_date); |
112 |
my $to_due_date_endday = dt_from_string($to_due_date); |
97 |
$to_due_date_endday |
113 |
$to_due_date_endday->set( # We set last second of day to see all checkouts from that day |
98 |
->set( # We set last second of day to see all checkouts from that day |
|
|
99 |
hour => 23, |
114 |
hour => 23, |
100 |
minute => 59, |
115 |
minute => 59, |
101 |
second => 59 |
116 |
second => 59 |
102 |
); |
117 |
); |
103 |
$search_params->{'me.date_due'} = |
118 |
$search_params->{'me.date_due'} = |
104 |
{ '<=' => $dtf->format_datetime($to_due_date_endday) }; |
119 |
{ '<=' => $dtf->format_datetime($to_due_date_endday) }; |
105 |
} |
120 |
} |
106 |
|
121 |
|
107 |
my $checkouts = Koha::Checkouts->search( |
122 |
my $checkouts = Koha::Checkouts->search( |
108 |
$search_params, |
123 |
$search_params, |
109 |
{ |
124 |
{ join => [ 'item', 'patron' ] } |
110 |
join => [ 'item', 'patron' ] |
|
|
111 |
} |
112 |
); |
125 |
); |
113 |
|
126 |
|
114 |
my @new_due_dates; |
127 |
my @new_due_dates; |
115 |
while ( my $checkout = $checkouts->next ) { |
128 |
while ( my $checkout = $checkouts->next ) { |
116 |
if ($preview_results) { |
129 |
push( |
117 |
push( |
130 |
@new_due_dates, |
118 |
@new_due_dates, |
131 |
calc_new_due_date( |
119 |
calc_new_due_date( |
132 |
{ |
120 |
{ |
133 |
due_date => dt_from_string( $checkout->date_due ), |
121 |
due_date => dt_from_string( $checkout->date_due ), |
134 |
new_hard_due_date => $new_hard_due_date, |
122 |
new_hard_due_date => $new_hard_due_date, |
135 |
add_days => $due_date_days |
123 |
add_days => $due_date_days |
136 |
} |
124 |
} |
137 |
), |
125 |
), |
|
|
126 |
); |
127 |
} else { |
128 |
push( @issue_ids, $checkout->id ); |
129 |
} |
130 |
} |
131 |
|
132 |
if ( $preview_results ) { |
133 |
$template->param( |
134 |
checkouts => $checkouts, |
135 |
new_hard_due_date => $new_hard_due_date, |
136 |
due_date_days => $due_date_days, |
137 |
new_due_dates => \@new_due_dates, |
138 |
view => 'list', |
139 |
); |
138 |
); |
140 |
} else { |
|
|
141 |
$op = 'cud-modify'; |
142 |
} |
139 |
} |
143 |
} |
|
|
144 |
|
145 |
if ( $op eq 'cud-modify' ) { |
146 |
|
140 |
|
147 |
# We want to modify selected checkouts! |
141 |
} |
148 |
my $new_hard_due_date = $input->param('new_hard_due_date'); |
|
|
149 |
my $due_date_days = $input->param('due_date_days'); |
150 |
|
142 |
|
151 |
# @issue_ids will already be populated if we are skipping the results display |
143 |
if ( $op = 'list' ) { |
152 |
@issue_ids = $input->multi_param('issue_id') unless @issue_ids; |
144 |
$template->param( |
|
|
145 |
checkouts => $checkouts, |
146 |
new_hard_due_date => $new_hard_due_date, |
147 |
due_date_days => $due_date_days, |
148 |
new_due_dates => \@new_due_dates, |
149 |
view => 'list', |
150 |
); |
151 |
} elsif ( $op eq 'cud-modify' ) { |
153 |
|
152 |
|
154 |
$new_hard_due_date &&= dt_from_string($new_hard_due_date); |
153 |
$checkouts->reset; |
155 |
my $checkouts = |
|
|
156 |
Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } ); |
157 |
while ( my $checkout = $checkouts->next ) { |
154 |
while ( my $checkout = $checkouts->next ) { |
158 |
my $new_due_date = calc_new_due_date( |
155 |
my $new_due_date = shift(@new_due_dates); |
159 |
{ |
|
|
160 |
due_date => dt_from_string($checkout->date_due), |
161 |
new_hard_due_date => $new_hard_due_date, |
162 |
add_days => $due_date_days |
163 |
} |
164 |
); |
165 |
|
156 |
|
166 |
# Update checkout's due date |
157 |
# Update checkout's due date |
167 |
$checkout->date_due($new_due_date)->store; |
158 |
$checkout->date_due($new_due_date)->store; |
Lines 183-198
sub calc_new_due_date {
Link Here
|
183 |
my $add_days = $params->{add_days}; |
174 |
my $add_days = $params->{add_days}; |
184 |
|
175 |
|
185 |
my $new; |
176 |
my $new; |
186 |
if ( $new_hard_due_date ) { |
177 |
if ($new_hard_due_date) { |
187 |
$new = $new_hard_due_date->clone->set( |
178 |
$new = $new_hard_due_date->clone->set( |
188 |
hour => $due_date->hour, |
179 |
hour => $due_date->hour, |
189 |
minute => $due_date->minute, |
180 |
minute => $due_date->minute, |
190 |
second => $due_date->second, |
181 |
second => $due_date->second, |
191 |
) |
182 |
); |
192 |
} else { |
183 |
} else { |
193 |
$new = $due_date->clone->add( days => $add_days ); |
184 |
$new = $due_date->clone->add( days => $add_days ); |
194 |
} |
185 |
} |
195 |
return $new; |
186 |
return $new; |
196 |
} |
187 |
} |
197 |
|
188 |
|
198 |
output_html_with_http_headers $input, $cookie, $template->output; |
189 |
output_html_with_http_headers $input, $cookie, $template->output; |
199 |
- |
|
|