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

(-)a/C4/Items.pm (-2 / +15 lines)
Lines 2807-2812 sub ToggleNewStatus { Link Here
2807
    my $report;
2807
    my $report;
2808
    for my $rule ( @rules ) {
2808
    for my $rule ( @rules ) {
2809
        my $age = $rule->{age};
2809
        my $age = $rule->{age};
2810
        my $unit = $rule->{unit};
2811
        my $age_starting_point = $rule->{age_starting_point};
2810
        my $conditions = $rule->{conditions};
2812
        my $conditions = $rule->{conditions};
2811
        my $substitutions = $rule->{substitutions};
2813
        my $substitutions = $rule->{substitutions};
2812
        my @params;
2814
        my @params;
Lines 2835-2842 sub ToggleNewStatus { Link Here
2835
            }
2837
            }
2836
        }
2838
        }
2837
        if ( defined $age ) {
2839
        if ( defined $age ) {
2838
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
2840
            # Calculate item age based on hours since item last altered
2839
            push @params, $age;
2841
            if ( defined $rule && defined $age_starting_point && $unit eq "hours" && $age_starting_point eq "itemaltered" ) {
2842
                $query .= q| AND HOUR(TIMEDIFF(NOW(), timestamp)) >= ? |;
2843
                push @params, $age;
2844
            } elsif ( defined $rule && defined $age_starting_point && $unit eq "days" && $age_starting_point eq "itemaltered" ) {
2845
            # Calculate item age based on days since item last altered
2846
                $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(timestamp) >= ? |;
2847
                push @params, $age;
2848
            } else {
2849
            # Calculate item age based on days since item was created 
2850
                $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
2851
                push @params, $age;
2852
            }
2840
        }
2853
        }
2841
        my $sth = $dbh->prepare($query);
2854
        my $sth = $dbh->prepare($query);
2842
        $sth->execute( @params );
2855
        $sth->execute( @params );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt (-9 / +67 lines)
Lines 70-79 Link Here
70
                    <legend>Rule <span class="rulecount">[% loop.count %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
70
                    <legend>Rule <span class="rulecount">[% loop.count %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
71
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
71
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
72
                    <div class="age">
72
                    <div class="age">
73
                      <h5>Age in days</h5>
73
                      <h5>Age</h5>
74
                      <input class="age" type="number" value="[% rule.age %]" name="age_[% id %]" />
74
                      <input class="age" type="number" value="[% rule.age %]" name="age_[% id %]" />
75
                    </div>
75
                    </div>
76
                    <div class="blocks">
76
                    <div>
77
                      <h5>Unit</h5>
78
                      <p>Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point wil default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.</p>
79
                      <select id="existing_rule_unit" name="unit_[% id %]" id="unit">
80
                       <option value="">Choose a unit</option>
81
                       [% IF rule.unit == "hours" %]
82
                          <option value="hours" selected="selected">Hours</option>
83
                          <option value="days">Days</option>
84
                       [% ELSIF rule.unit == "days" %]
85
                          <option value="days" selected="selected">Days</option>
86
                          <option value="hours">Hours</option>
87
                       [% END %]
88
                      </select>
89
                    </div>
90
                    [% IF rule.unit == "days" %]
91
                       <div id="age_starting_point_div">
92
                          <h5>Age starting point (starting point from which the item age is calculated)</h5>
93
                          <select name="age_starting_point_[% id %]" id="age_starting_point">
94
                            <option value="">Choose age starting point</option>
95
                            [% IF rule.age_starting_point == "itemcreation" %]
96
                               <option value="itemcreation" selected="selected">Created</option>
97
                               <option value="itemaltered">Item last altered</option>
98
                            [% ELSIF rule.age_starting_point == "itemaltered" %]
99
                               <option value="itemaltered" selected="selected">Last altered</option>
100
                               <option value="itemcreation">Item creation</option>
101
                            [% END %]
102
                          </select>
103
                       </div>
104
                    [% END %]
105
                   <div class="blocks">
77
                      <h5>Conditions</h5>
106
                      <h5>Conditions</h5>
78
                      [% FOR condition IN rule.conditions %]
107
                      [% FOR condition IN rule.conditions %]
79
                        <div class="block">
108
                        <div class="block">
Lines 87-93 Link Here
87
                              [% END %]
116
                              [% END %]
88
                            [% END %]
117
                            [% END %]
89
                          </select>
118
                          </select>
90
                          =
91
                          <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" />
119
                          <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" />
92
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
120
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
93
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
121
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
Lines 108-114 Link Here
108
                              [% END %]
136
                              [% END %]
109
                            [% END %]
137
                            [% END %]
110
                          </select>
138
                          </select>
111
                          =
112
                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" />
139
                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" />
113
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
140
                          <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
114
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
141
                          <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
Lines 131-139 Link Here
131
            <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
158
            <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend>
132
            <input type="hidden" name="unique_id" />
159
            <input type="hidden" name="unique_id" />
133
            <div class="age">
160
            <div class="age">
134
              <h5>Age in days</h5>
161
              <h5>Age</h5>
135
              <input class="age" type="number" value="" name="age" />
162
              <input class="age" type="number" value="" name="age" />
136
            </div>
163
            </div>
164
            <div>
165
              <h5>Unit</h5>
166
              <p>Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point wil     default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.</p>
167
              <select id="new_rule_unit" name="unit" />
168
               <option value="">Choose an age unit</option>
169
               <option id="hours" value="hours">Hours</option>
170
               <option id="days" value="days">Days</option>
171
              </select>
172
            </div>
173
            <div id="new_rule_age_starting_point_div">
174
              <h5>Age starting point (starting point from which the item age is calculated)</h5>
175
               <select name="age_starting_point">
176
                <option value="">Choose age starting point</option>
177
                <option value="itemcreation">Created</option>
178
                <option value="itemaltered">Last altered</option>
179
               </select>
180
            </div>
137
            <div class="blocks">
181
            <div class="blocks">
138
              <h5>Conditions</h5>
182
              <h5>Conditions</h5>
139
              <div class="block">
183
              <div class="block">
Lines 143-149 Link Here
143
                    <option value="[% field %]">[% field %]</option>
187
                    <option value="[% field %]">[% field %]</option>
144
                  [% END %]
188
                  [% END %]
145
                </select>
189
                </select>
146
                =
147
                <input type="text" value="" name="condition_value" />
190
                <input type="text" value="" name="condition_value" />
148
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
191
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a>
149
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
192
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a>
Lines 158-164 Link Here
158
                    <option value="[% field %]">[% field %]</option>
201
                    <option value="[% field %]">[% field %]</option>
159
                  [% END %]
202
                  [% END %]
160
                </select>
203
                </select>
161
                =
162
                <input type="text" value="" name="substitution_value" />
204
                <input type="text" value="" name="substitution_value" />
163
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
205
                <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a>
164
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
206
                <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a>
Lines 173-178 Link Here
173
                        <thead>
215
                        <thead>
174
                          <tr>
216
                          <tr>
175
                               <th>Age</th>
217
                               <th>Age</th>
218
                               <th>Age starting point</th>
176
                                <th>Conditions</th>
219
                                <th>Conditions</th>
177
                                <th>Substitutions</th>
220
                                <th>Substitutions</th>
178
                            </tr>
221
                            </tr>
Lines 181-193 Link Here
181
                            [% FOR rule IN rules %]
224
                            [% FOR rule IN rules %]
182
                                <tr>
225
                                <tr>
183
                                    <td>
226
                                    <td>
184
                                        [% IF rule.age.defined and rule.age.length > 0 %]
227
                                        [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %]
185
                                            [% rule.age %] days
228
                                            [% IF rule.age == 1 %]
229
                                                [% IF rule.unit == "days" %]
230
                                                   [% rule.age %] day
231
                                                [% ELSE %]
232
                                                   [% rule.age %] hour
233
                                                [% END %]
234
                                            [% ELSE %]
235
                                                [% rule.age %] [% rule.unit %]
236
                                            [% END %]
186
                                        [% ELSE %]
237
                                        [% ELSE %]
187
                                            There is no age for this rule.
238
                                            There is no age for this rule.
188
                                        [% END %]
239
                                        [% END %]
189
                                    </td>
240
                                    </td>
190
                                    <td>
241
                                    <td>
242
                                        [% IF rule.age_starting_point.defined %]
243
                                            [% rule.age_starting_point %]
244
                                        [% ELSE %]
245
                                            There is no age starting point for this rule.
246
                                        [% END %]
247
                                    </td>
248
                                    <td>
191
                                        [% FOR condition IN rule.conditions %]
249
                                        [% FOR condition IN rule.conditions %]
192
                                            [% IF condition.field %]
250
                                            [% IF condition.field %]
193
                                                <div class="block">
251
                                                <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