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

(-)a/C4/Items.pm (-1 / +4 lines)
Lines 1820-1825 sub ToggleNewStatus { Link Here
1820
    my $report;
1820
    my $report;
1821
    for my $rule ( @rules ) {
1821
    for my $rule ( @rules ) {
1822
        my $age = $rule->{age};
1822
        my $age = $rule->{age};
1823
        # Default to using items.dateaccessioned if there's an old item modification rule
1824
        # missing an agefield value
1825
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1823
        my $conditions = $rule->{conditions};
1826
        my $conditions = $rule->{conditions};
1824
        my $substitutions = $rule->{substitutions};
1827
        my $substitutions = $rule->{substitutions};
1825
        foreach ( @$substitutions ) {
1828
        foreach ( @$substitutions ) {
Lines 1851-1857 sub ToggleNewStatus { Link Here
1851
            }
1854
            }
1852
        }
1855
        }
1853
        if ( defined $age ) {
1856
        if ( defined $age ) {
1854
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
1857
            $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1855
            push @params, $age;
1858
            push @params, $age;
1856
        }
1859
        }
1857
        my $sth = $dbh->prepare($query);
1860
        my $sth = $dbh->prepare($query);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt (+33 lines)
Lines 91-96 Link Here
91
                    <div class="age">
91
                    <div class="age">
92
                      <h5>Age in days</h5>
92
                      <h5>Age in days</h5>
93
                      <input class="age" type="text" inputmode="numeric" pattern="[0-9]*"  value="[% rule.age | html %]" name="age_[% id | html %]" />
93
                      <input class="age" type="text" inputmode="numeric" pattern="[0-9]*"  value="[% rule.age | html %]" name="age_[% id | html %]" />
94
                      <h5>Age field</h5>
95
                          <div class="blocks">
96
                              <select name="agefield_[% id | html %]">
97
                                  <option value="">Choose an age field</option>
98
                                  [% FOR field IN agefields %]
99
                                    [% IF rule.agefield == field %]
100
                                     <option value="[% field | html %]" selected="selected">[% field | html %]</option>
101
                                    [% ELSE %]
102
                                     <option value="[% field | html %]">[% field | html %]</option>
103
                                    [% END %]
104
                                  [% END %]
105
                              </select>
106
                              <span class="hint">If not set then items.dateaccessioned will be used</span>
107
                          </div>
94
                    </div>
108
                    </div>
95
                    <div class="blocks">
109
                    <div class="blocks">
96
                      <h5>Conditions</h5>
110
                      <h5>Conditions</h5>
Lines 152-157 Link Here
152
            <div class="age">
166
            <div class="age">
153
              <h5>Age in days</h5>
167
              <h5>Age in days</h5>
154
              <input class="age" type="text" inputmode="numeric" pattern="[0-9]*" value="" name="age" />
168
              <input class="age" type="text" inputmode="numeric" pattern="[0-9]*" value="" name="age" />
169
              <h5>Age field</h5>
170
              <div class="block">
171
                  <select name="agefield">
172
                      <option value="">Choose an age field</option>
173
                      [% FOR field IN agefields %]
174
                           <option value="[% field | html %]">[% field | html %]</option>
175
                      [% END %]
176
                  </select>
177
                  <span class="hint">If not set then items.dateaccessioned will be used</span>
178
              </div>
155
            </div>
179
            </div>
156
            <div class="blocks">
180
            <div class="blocks">
157
              <h5>Conditions</h5>
181
              <h5>Conditions</h5>
Lines 192-197 Link Here
192
                        <thead>
216
                        <thead>
193
                          <tr>
217
                          <tr>
194
                               <th>Age</th>
218
                               <th>Age</th>
219
                                <th>Age field</th>
195
                                <th>Conditions</th>
220
                                <th>Conditions</th>
196
                                <th>Substitutions</th>
221
                                <th>Substitutions</th>
197
                            </tr>
222
                            </tr>
Lines 206-211 Link Here
206
                                            There is no age for this rule.
231
                                            There is no age for this rule.
207
                                        [% END %]
232
                                        [% END %]
208
                                    </td>
233
                                    </td>
234
                                    <td>
235
                                        [% IF rule.agefield %]
236
                                            [% rule.agefield | html %]
237
                                        [% ELSE %]
238
                                            <!-- In case old rules do not contain an agefield value display that items.dateaccessioned will be used -->
239
                                            items.dateaccessioned
240
                                        [% END %]
241
                                    </td>
209
                                    <td>
242
                                    <td>
210
                                        [% FOR condition IN rule.conditions %]
243
                                        [% FOR condition IN rule.conditions %]
211
                                            [% IF condition.field %]
244
                                            [% IF condition.field %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js (+1 lines)
Lines 75-80 $(document).ready(function() { Link Here
75
        new_rule.find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
75
        new_rule.find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
76
        new_rule.find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
76
        new_rule.find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
77
        new_rule.find("input[name='age']").attr('name', 'age_' + unique_id);
77
        new_rule.find("input[name='age']").attr('name', 'age_' + unique_id);
78
        new_rule.find("select[name='agefield']").attr('name', 'agefield_' + unique_id);
78
        new_rule.find("input[name='unique_id']").val(unique_id);
79
        new_rule.find("input[name='unique_id']").val(unique_id);
79
80
80
        $("#rules").append(new_rule);
81
        $("#rules").append(new_rule);
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-2 / +37 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 17;
4
use Test::More tests => 19;
5
use MARC::Record;
5
use MARC::Record;
6
use MARC::Field;
6
use MARC::Field;
7
use DateTime;
7
use DateTime;
Lines 140-146 $modified_item->dateaccessioned($days5ago)->store; Link Here
140
                value => 'new_updated_value',
140
                value => 'new_updated_value',
141
             },
141
             },
142
        ],
142
        ],
143
        age => '10',
143
        age => '10', # Confirm not defining agefield, will default to using items.dateaccessioned
144
    },
144
    },
145
);
145
);
146
C4::Items::ToggleNewStatus( { rules => \@rules } );
146
C4::Items::ToggleNewStatus( { rules => \@rules } );
Lines 275-280 is( $modified_item->new_status, 'new_updated_value', q|ToggleNewStatus: conditio Link Here
275
275
276
@rules = (
276
@rules = (
277
    {
277
    {
278
        # does not exist
278
        conditions => [
279
        conditions => [
279
            {
280
            {
280
                field => 'biblioitems.itemtype',
281
                field => 'biblioitems.itemtype',
Lines 296-301 C4::Items::ToggleNewStatus( { rules => \@rules } ); Link Here
296
$modified_item = Koha::Items->find( $itemnumber );
297
$modified_item = Koha::Items->find( $itemnumber );
297
is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
298
is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
298
299
300
# Play with the 'Age field'
301
my $days2ago = $dt_today->add_duration( DateTime::Duration->new( days => -10 ) );
302
my $days20ago = $dt_today->add_duration( DateTime::Duration->new( days => -20 ) );
303
$modified_item->datelastseen($days2ago)->store;
304
$modified_item->dateaccessioned($days20ago)->store;
305
306
# When agefield='items.datelastseen'
307
@rules = (
308
    {
309
        conditions => [
310
            {
311
                field => 'biblioitems.itemtype',
312
                value => 'ITEMTYPE_T',
313
            },
314
        ],
315
        substitutions => [
316
            {
317
                field => 'items.new_status',
318
                value => 'agefield_new_value',
319
             },
320
        ],
321
        age => '5',
322
        agefield => 'items.datelastseen' # Confirm defining agefield => 'items.datelastseen' will use items.datelastseen
323
    },
324
);
325
C4::Items::ToggleNewStatus( { rules => \@rules } );
326
$modified_item = Koha::Items->find( $itemnumber );
327
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, agefield = 'items.datelastseen' : The new_status value is not updated|);
328
329
$rules[0]->{age} = 2;
330
C4::Items::ToggleNewStatus( { rules => \@rules } );
331
$modified_item = Koha::Items->find( $itemnumber );
332
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|);
333
299
# Run twice
334
# Run twice
300
t::lib::Mocks::mock_preference('CataloguingLog', 1);
335
t::lib::Mocks::mock_preference('CataloguingLog', 1);
301
my $actions_nb = $schema->resultset('ActionLog')->count();
336
my $actions_nb = $schema->resultset('ActionLog')->count();
(-)a/tools/automatic_item_modification_by_age.pl (-1 / +8 lines)
Lines 3-8 Link Here
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
5
# Copyright 2013 BibLibre
5
# Copyright 2013 BibLibre
6
# Copyright 2021 Catalyst IT
6
#
7
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# under the terms of the GNU General Public License as published by
Lines 65-70 if ( $op eq 'update' ) { Link Here
65
        my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
66
        my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
66
        my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
67
        my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
67
        my @condition_values = $cgi->multi_param("condition_value_$unique_id");
68
        my @condition_values = $cgi->multi_param("condition_value_$unique_id");
69
        my @age_fields = $cgi->multi_param("agefield_$unique_id");
68
        my $rule = {
70
        my $rule = {
69
            substitutions => [],
71
            substitutions => [],
70
            conditions => [],
72
            conditions => [],
Lines 84-89 if ( $op eq 'update' ) { Link Here
84
        push @{ $rule->{conditions} }, {}
86
        push @{ $rule->{conditions} }, {}
85
            unless @{ $rule->{conditions} };
87
            unless @{ $rule->{conditions} };
86
        $rule->{age} = $cgi->param("age_$unique_id");
88
        $rule->{age} = $cgi->param("age_$unique_id");
89
90
        for my $age_field ( @age_fields ) {
91
            $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned";
92
        }
87
        push @rules, $rule;
93
        push @rules, $rule;
88
    }
94
    }
89
    my $syspref_content = to_json( \@rules );
95
    my $syspref_content = to_json( \@rules );
Lines 109-117 if ( $@ ) { Link Here
109
115
110
my @item_fields = map { "items.$_" } Koha::Items->columns;
116
my @item_fields = map { "items.$_" } Koha::Items->columns;
111
my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
117
my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
118
my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on');
112
$template->param(
119
$template->param(
113
    op => $op,
120
    op => $op,
114
    messages => \@messages,
121
    messages => \@messages,
122
    agefields => [ @age_fields ],
115
    condition_fields => [ @item_fields, @biblioitem_fields ],
123
    condition_fields => [ @item_fields, @biblioitem_fields ],
116
    substitution_fields => \@item_fields,
124
    substitution_fields => \@item_fields,
117
    rules => $rules,
125
    rules => $rules,
118
- 

Return to bug 22827