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

(-)a/C4/Items.pm (-2 / +15 lines)
Lines 2697-2702 sub ToggleNewStatus { Link Here
2697
    my $report;
2697
    my $report;
2698
    for my $rule ( @rules ) {
2698
    for my $rule ( @rules ) {
2699
        my $age = $rule->{age};
2699
        my $age = $rule->{age};
2700
        my $unit = $rule->{unit};
2701
        my $age_starting_point = $rule->{age_starting_point};
2700
        my $conditions = $rule->{conditions};
2702
        my $conditions = $rule->{conditions};
2701
        my $substitutions = $rule->{substitutions};
2703
        my $substitutions = $rule->{substitutions};
2702
        my @params;
2704
        my @params;
Lines 2725-2732 sub ToggleNewStatus { Link Here
2725
            }
2727
            }
2726
        }
2728
        }
2727
        if ( defined $age ) {
2729
        if ( defined $age ) {
2728
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
2730
            # Calculate item age based on hours since item last altered
2729
            push @params, $age;
2731
            if ( defined $rule && defined $age_starting_point && $unit eq "hours" && $age_starting_point eq "itemaltered" ) {
2732
                $query .= q| AND HOUR(TIMEDIFF(NOW(), items.timestamp)) >= ? |;
2733
                push @params, $age;
2734
            } elsif ( defined $rule && defined $age_starting_point && $unit eq "days" && $age_starting_point eq "itemaltered" ) {
2735
            # Calculate item age based on days since item last altered
2736
                $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.timestamp) >= ? |;
2737
                push @params, $age;
2738
            } else {
2739
            # Calculate item age based on days since item was created
2740
                $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.dateaccessioned) >= ? |;
2741
                push @params, $age;
2742
            }
2730
        }
2743
        }
2731
        my $sth = $dbh->prepare($query);
2744
        my $sth = $dbh->prepare($query);
2732
        $sth->execute( @params );
2745
        $sth->execute( @params );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt (-12 / +70 lines)
Lines 71-80 Link Here
71
                    <legend>Rule <span class="rulecount">[% loop.count | html %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
71
                    <legend>Rule <span class="rulecount">[% loop.count | html %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
72
                    <input type="hidden" name="unique_id" value="[% loop.count | html %]" /> <!-- FIXME on update, the unique_id should be filled -->
72
                    <input type="hidden" name="unique_id" value="[% loop.count | html %]" /> <!-- FIXME on update, the unique_id should be filled -->
73
                    <div class="age">
73
                    <div class="age">
74
                      <h5>Age in days</h5>
74
                      <h5>Age</h5>
75
                      <input class="age" type="number" value="[% rule.age | html %]" name="age_[% id | html %]" />
75
                      <input class="age" type="number" value="[% rule.age %]" name="age_[% id %]" />
76
                    </div>
76
                    </div>
77
                    <div class="blocks">
77
                    <div>
78
                      <h5>Unit</h5>
79
                      <p>Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point will default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.</p>
80
                      <select id="existing_rule_unit" name="unit_[% id %]" id="unit">
81
                       <option value="">Choose a unit</option>
82
                       [% IF rule.unit == "hours" %]
83
                          <option value="hours" selected="selected">Hours</option>
84
                          <option value="days">Days</option>
85
                       [% ELSIF rule.unit == "days" %]
86
                          <option value="days" selected="selected">Days</option>
87
                          <option value="hours">Hours</option>
88
                       [% END %]
89
                      </select>
90
                    </div>
91
                    [% IF rule.unit == "days" %]
92
                       <div id="age_starting_point_div">
93
                          <h5>Age starting point (starting point from which the item age is calculated)</h5>
94
                          <select name="age_starting_point_[% id %]" id="age_starting_point">
95
                            <option value="">Choose age starting point</option>
96
                            [% IF rule.age_starting_point == "itemcreation" %]
97
                               <option value="itemcreation" selected="selected">Created</option>
98
                               <option value="itemaltered">Item last altered</option>
99
                            [% ELSIF rule.age_starting_point == "itemaltered" %]
100
                               <option value="itemaltered" selected="selected">Last altered</option>
101
                               <option value="itemcreation">Item creation</option>
102
                            [% END %]
103
                          </select>
104
                       </div>
105
                    [% END %]
106
                   <div class="blocks">
78
                      <h5>Conditions</h5>
107
                      <h5>Conditions</h5>
79
                      [% FOR condition IN rule.conditions %]
108
                      [% FOR condition IN rule.conditions %]
80
                        <div class="block">
109
                        <div class="block">
Lines 88-95 Link Here
88
                              [% END %]
117
                              [% END %]
89
                            [% END %]
118
                            [% END %]
90
                          </select>
119
                          </select>
91
                          =
120
                          <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" />
92
                          <input type="text" value="[% condition.value | html %]" name="condition_value_[% id | html %]" />
93
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
121
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
94
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
122
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
95
                        </div>
123
                        </div>
Lines 109-116 Link Here
109
                              [% END %]
137
                              [% END %]
110
                            [% END %]
138
                            [% END %]
111
                          </select>
139
                          </select>
112
                          =
140
                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" />
113
                          <input type="text" value="[% substitution.value | html %]" name="substitution_value_[% id | html %]" />
114
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
141
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
115
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
142
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
116
                          <span class="required">A field name is required</span>
143
                          <span class="required">A field name is required</span>
Lines 132-140 Link Here
132
            <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
159
            <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
133
            <input type="hidden" name="unique_id" />
160
            <input type="hidden" name="unique_id" />
134
            <div class="age">
161
            <div class="age">
135
              <h5>Age in days</h5>
162
              <h5>Age</h5>
136
              <input class="age" type="number" value="" name="age" />
163
              <input class="age" type="number" value="" name="age" />
137
            </div>
164
            </div>
165
            <div>
166
              <h5>Unit</h5>
167
              <p>Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point will default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.</p>
168
              <select id="new_rule_unit" name="unit" />
169
               <option value="">Choose an age unit</option>
170
               <option id="hours" value="hours">Hours</option>
171
               <option id="days" value="days">Days</option>
172
              </select>
173
            </div>
174
            <div id="new_rule_age_starting_point_div">
175
              <h5>Age starting point (starting point from which the item age is calculated)</h5>
176
               <select name="age_starting_point">
177
                <option value="">Choose age starting point</option>
178
                <option value="itemcreation">Created</option>
179
                <option value="itemaltered">Last altered</option>
180
               </select>
181
            </div>
138
            <div class="blocks">
182
            <div class="blocks">
139
              <h5>Conditions</h5>
183
              <h5>Conditions</h5>
140
              <div class="block">
184
              <div class="block">
Lines 144-150 Link Here
144
                    <option value="[% field | html %]">[% field | html %]</option>
188
                    <option value="[% field | html %]">[% field | html %]</option>
145
                  [% END %]
189
                  [% END %]
146
                </select>
190
                </select>
147
                =
148
                <input type="text" value="" name="condition_value" />
191
                <input type="text" value="" name="condition_value" />
149
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
192
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
150
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
193
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
Lines 159-165 Link Here
159
                    <option value="[% field | html %]">[% field | html %]</option>
202
                    <option value="[% field | html %]">[% field | html %]</option>
160
                  [% END %]
203
                  [% END %]
161
                </select>
204
                </select>
162
                =
163
                <input type="text" value="" name="substitution_value" />
205
                <input type="text" value="" name="substitution_value" />
164
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
206
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
165
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
207
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
Lines 174-179 Link Here
174
                        <thead>
216
                        <thead>
175
                          <tr>
217
                          <tr>
176
                               <th>Age</th>
218
                               <th>Age</th>
219
                               <th>Age starting point</th>
177
                                <th>Conditions</th>
220
                                <th>Conditions</th>
178
                                <th>Substitutions</th>
221
                                <th>Substitutions</th>
179
                            </tr>
222
                            </tr>
Lines 182-194 Link Here
182
                            [% FOR rule IN rules %]
225
                            [% FOR rule IN rules %]
183
                                <tr>
226
                                <tr>
184
                                    <td>
227
                                    <td>
185
                                        [% IF rule.age.defined and rule.age.length > 0 %]
228
                                        [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %]
186
                                            [% rule.age | html %] days
229
                                            [% IF rule.age == 1 %]
230
                                                [% IF rule.unit == "days" %]
231
                                                   [% rule.age %] day
232
                                                [% ELSE %]
233
                                                   [% rule.age %] hour
234
                                                [% END %]
235
                                            [% ELSE %]
236
                                                [% rule.age %] [% rule.unit %]
237
                                            [% END %]
187
                                        [% ELSE %]
238
                                        [% ELSE %]
188
                                            There is no age for this rule.
239
                                            There is no age for this rule.
189
                                        [% END %]
240
                                        [% END %]
190
                                    </td>
241
                                    </td>
191
                                    <td>
242
                                    <td>
243
                                        [% IF rule.age_starting_point.defined %]
244
                                            [% rule.age_starting_point %]
245
                                        [% ELSE %]
246
                                            There is no age starting point for this rule.
247
                                        [% END %]
248
                                    </td>
249
                                    <td>
192
                                        [% FOR condition IN rule.conditions %]
250
                                        [% FOR condition IN rule.conditions %]
193
                                            [% IF condition.field %]
251
                                            [% IF condition.field %]
194
                                                <div class="block">
252
                                                <div class="block">
(-)a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js (+12 lines)
Lines 52-57 function update_rule_count(){ Link Here
52
$(document).ready(function() {
52
$(document).ready(function() {
53
    $("#new_rule .remove_rule").hide();
53
    $("#new_rule .remove_rule").hide();
54
    $("#new_rule a.remove_block").hide();
54
    $("#new_rule a.remove_block").hide();
55
    $("#new_rule_age_starting_point_div").hide();
56
55
    $("#rules a.remove_block").click(function(e){
57
    $("#rules a.remove_block").click(function(e){
56
        e.preventDefault();
58
        e.preventDefault();
57
        remove_block_action($(this));
59
        remove_block_action($(this));
Lines 61-66 $(document).ready(function() { Link Here
61
        remove_rule_action($(this));
63
        remove_rule_action($(this));
62
    });
64
    });
63
65
66
    $("#new_rule_unit").change(function(){
67
        var unitselected = $(this).find("option:selected").attr("id");
68
        var newruleagestart = document.getElementById("new_rule_age_starting_point_div");
69
        if (unitselected == "days") {
70
            newruleagestart.style.display = "block"
71
        } else {
72
            newruleagestart.style.display = "none";
73
        }
74
    });
75
64
    var unique_id = $(".rule").length + 1;
76
    var unique_id = $(".rule").length + 1;
65
    $(".add_rule").click(function(e){
77
    $(".add_rule").click(function(e){
66
        e.preventDefault();
78
        e.preventDefault();
(-)a/tools/automatic_item_modification_by_age.pl (-2 / +17 lines)
Lines 39-45 use C4::Context; Link Here
39
use C4::Items;
39
use C4::Items;
40
use C4::Output;
40
use C4::Output;
41
use C4::Koha;
41
use C4::Koha;
42
42
use Data::Dumper;
43
use Koha::Items;
43
use Koha::Items;
44
use Koha::Biblioitems;
44
use Koha::Biblioitems;
45
45
Lines 86-94 if ( $op eq 'update' ) { Link Here
86
        push @{ $rule->{conditions} }, {}
86
        push @{ $rule->{conditions} }, {}
87
            unless @{ $rule->{conditions} };
87
            unless @{ $rule->{conditions} };
88
        $rule->{age} = $cgi->param("age_$unique_id");
88
        $rule->{age} = $cgi->param("age_$unique_id");
89
90
        if ($cgi->param("unit_$unique_id")) {
91
            $rule->{unit} = $cgi->param("unit_$unique_id");
92
        } else {
93
            $rule->{unit} = $cgi->param("unit");
94
        }
95
96
        if ($cgi->param("age_starting_point_$unique_id")) {
97
            $rule->{age_starting_point} = $cgi->param("age_starting_point_$unique_id");
98
        } elsif ($cgi->param("age_starting_point")) {
99
            $rule->{age_starting_point} = $cgi->param("age_starting_point");
100
        } else {
101
            $rule->{age_starting_point} = "itemaltered"
102
        }
103
89
        push @rules, $rule;
104
        push @rules, $rule;
90
    }
105
    }
91
    my $syspref_content = to_json( \@rules );
106
    my $syspref_content = to_json( \@rules );
107
92
    C4::Context->set_preference($syspref_name, $syspref_content);
108
    C4::Context->set_preference($syspref_name, $syspref_content);
93
109
94
    $op = 'show';
110
    $op = 'show';
95
- 

Return to bug 21173