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

(-)a/C4/Items.pm (-1 / +2 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
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1823
        my $conditions = $rule->{conditions};
1824
        my $conditions = $rule->{conditions};
1824
        my $substitutions = $rule->{substitutions};
1825
        my $substitutions = $rule->{substitutions};
1825
        foreach ( @$substitutions ) {
1826
        foreach ( @$substitutions ) {
Lines 1851-1857 sub ToggleNewStatus { Link Here
1851
            }
1852
            }
1852
        }
1853
        }
1853
        if ( defined $age ) {
1854
        if ( defined $age ) {
1854
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
1855
            $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1855
            push @params, $age;
1856
            push @params, $age;
1856
        }
1857
        }
1857
        my $sth = $dbh->prepare($query);
1858
        my $sth = $dbh->prepare($query);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt (+32 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 207-212 Link Here
207
                                        [% END %]
232
                                        [% END %]
208
                                    </td>
233
                                    </td>
209
                                    <td>
234
                                    <td>
235
                                        [% IF rule.agefield %]
236
                                            [% rule.agefield | html %]
237
                                        [% ELSE %]
238
                                            There is no age field for this rule.
239
                                        [% END %]
240
                                    </td>
241
                                    <td>
210
                                        [% FOR condition IN rule.conditions %]
242
                                        [% FOR condition IN rule.conditions %]
211
                                            [% IF condition.field %]
243
                                            [% IF condition.field %]
212
                                                <div class="block">
244
                                                <div class="block">
(-)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 (-1 / +35 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 296-301 C4::Items::ToggleNewStatus( { rules => \@rules } ); Link Here
296
$modified_item = Koha::Items->find( $itemnumber );
296
$modified_item = Koha::Items->find( $itemnumber );
297
is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
297
is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
298
298
299
# Play with the 'Age field'
300
my $days2ago = $dt_today->add_duration( DateTime::Duration->new( days => -10 ) );
301
my $days20ago = $dt_today->add_duration( DateTime::Duration->new( days => -20 ) );
302
$modified_item->datelastseen($days2ago)->store;
303
$modified_item->dateaccessioned($days20ago)->store;
304
305
# When agefield='items.datelastseen'
306
@rules = (
307
    {
308
        conditions => [
309
            {
310
                field => 'biblioitems.itemtype',
311
                value => 'ITEMTYPE_T',
312
            },
313
        ],
314
        substitutions => [
315
            {
316
                field => 'items.new_status',
317
                value => 'agefield_new_value',
318
             },
319
        ],
320
        age => '5',
321
        agefield => 'items.datelastseen'
322
    },
323
);
324
C4::Items::ToggleNewStatus( { rules => \@rules } );
325
$modified_item = Koha::Items->find( $itemnumber );
326
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, agefield = 'items.datelastseen' : The new_status value is not updated|);
327
328
$rules[0]->{age} = 2;
329
C4::Items::ToggleNewStatus( { rules => \@rules } );
330
$modified_item = Koha::Items->find( $itemnumber );
331
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|);
332
299
# Run twice
333
# Run twice
300
t::lib::Mocks::mock_preference('CataloguingLog', 1);
334
t::lib::Mocks::mock_preference('CataloguingLog', 1);
301
my $actions_nb = $schema->resultset('ActionLog')->count();
335
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