View | Details | Raw Unified | Return to bug 37941
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt (-15 / +18 lines)
Lines 82-88 Link Here
82
                    [% END %]
82
                    [% END %]
83
83
84
                    [% IF view == 'form' %]
84
                    [% IF view == 'form' %]
85
                        <form method="post" action="/cgi-bin/koha/tools/batch_extend_due_dates.pl" id="extend_due_dates_form">
85
                        <form action="/cgi-bin/koha/tools/batch_extend_due_dates.pl" id="extend_due_dates_form">
86
                            [% INCLUDE 'csrf-token.inc' %]
86
                            [% INCLUDE 'csrf-token.inc' %]
87
                            <fieldset class="rows">
87
                            <fieldset class="rows">
88
                                <legend>Checkout criteria:</legend>
88
                                <legend>Checkout criteria:</legend>
Lines 139-157 Link Here
139
                                    </li>
139
                                    </li>
140
                                </ol>
140
                                </ol>
141
                            </fieldset>
141
                            </fieldset>
142
                            <fieldset class="rows">
143
                                <legend>Options:</legend>
144
                                <ol>
145
                                    <li>
146
                                        <label for="preview_results">Preview results:</label>
147
                                        <input type="checkbox" name="preview_results" id="preview_results" checked />
148
                                        <span class="hint">This is not recommended when changing very large numbers of due dates.</span>
149
                                    </li>
150
                                </ol>
151
                            </fieldset>
152
                            <fieldset class="action">
142
                            <fieldset class="action">
153
                                <input type="hidden" name="op" value="cud-list" />
143
                                <input type="button" class="btn btn-primary submit_extend" value="Preview results" />
154
                                <input type="submit" class="btn btn-primary" value="Continue" />
144
                                <input type="button" class="btn btn-primary submit_extend" value="Update due dates" />
155
                                <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
145
                                <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
156
                            </fieldset>
146
                            </fieldset>
157
                        </form> <!-- /#extend_due_dates_form -->
147
                        </form> <!-- /#extend_due_dates_form -->
Lines 188-194 Link Here
188
                                                    <td>[% checkout.issuedate | $KohaDates %]</td>
178
                                                    <td>[% checkout.issuedate | $KohaDates %]</td>
189
                                                    <td>[% Branches.GetName( checkout.branchcode ) | html %]</td>
179
                                                    <td>[% Branches.GetName( checkout.branchcode ) | html %]</td>
190
                                                    <td>
180
                                                    <td>
191
                                                        [% new_due_dates.shift | $KohaDates as_due_date => 1 %]
181
                                                        [%- SET new_due_date = new_due_dates.shift -%]
182
                                                        [%- new_due_date | $KohaDates as_due_date => 1 -%]
183
                                                        <input type="hidden" name="new_due_date_issue_[% checkout.issue_id | html %]" value="[% new_due_date %]">
192
                                                    </td>
184
                                                    </td>
193
                                                </tr>
185
                                                </tr>
194
                                            [% END %]
186
                                            [% END %]
Lines 197-203 Link Here
197
                                </div> <!-- /.page-section -->
189
                                </div> <!-- /.page-section -->
198
                                <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected checkouts!</div>
190
                                <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected checkouts!</div>
199
                                <fieldset class="action">
191
                                <fieldset class="action">
200
                                    <input type="hidden" name="op" value="cud-modify" />
192
                                    <input type="hidden" name="op" value="cud-commit_preview" />
201
                                    <input type="hidden" name="new_hard_due_date" value="[% new_hard_due_date | $KohaDates dateformat => 'iso' %]" />
193
                                    <input type="hidden" name="new_hard_due_date" value="[% new_hard_due_date | $KohaDates dateformat => 'iso' %]" />
202
                                    <input type="hidden" name="due_date_days" value="[% due_date_days | html %]" />
194
                                    <input type="hidden" name="due_date_days" value="[% due_date_days | html %]" />
203
                                    <input type="submit" class="btn btn-primary" value="Modify selected checkouts" />
195
                                    <input type="submit" class="btn btn-primary" value="Modify selected checkouts" />
Lines 297-302 Link Here
297
                "paginate": false
289
                "paginate": false
298
            }));
290
            }));
299
291
292
            $('.submit_extend').on('click', function(){
293
                let form_action = $(this).val();
294
                if( form_action == 'Update due dates' ){
295
                    let form_input = '<input type="hidden" name="op" value="cud-modify">';
296
                    $("#extend_due_dates_form").append(form_input).attr('method','post').submit();
297
                } else {
298
                    let form_input = '<input type="hidden" name="op" value="list">';
299
                    $("#extend_due_dates_form").append(form_input).attr('method','get').submit();
300
                }
301
            });
302
                        
300
            $("#extend_due_dates_form").on('submit', function(e) {
303
            $("#extend_due_dates_form").on('submit', function(e) {
301
                var new_hard_due_date = $("#new_hard_due_date").val();
304
                var new_hard_due_date = $("#new_hard_due_date").val();
302
                var due_date_days = $("#due_date_days").val();
305
                var due_date_days = $("#due_date_days").val();
(-)a/tools/batch_extend_due_dates.pl (-78 / +68 lines)
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
- 

Return to bug 37941