Bugzilla – Attachment 77547 Details for
Bug 21173
Add hours as age unit to auto item modifications by age for damaged_on, itemlost_on and withdrawn_on fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.
Bug-21173---Customize-age-unit-and-starting-point-.patch (text/plain), 14.23 KB, created by
Alex Buckley
on 2018-08-08 00:59:08 UTC
(
hide
)
Description:
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2018-08-08 00:59:08 UTC
Size:
14.23 KB
patch
obsolete
>From 0b278682d25cc232d7b0faf6815b8e5283e21b03 Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Mon, 6 Aug 2018 14:08:57 +0000 >Subject: [PATCH] Bug 21173 - Customize age unit and starting point for > automatic item modification by age tool and cronjob. > >This allows librarians to define either the item creation date or items >last altered timestamp as the starting point for the age of the item so >the autmatic_item_modification_by_age.pl can alter item statuses for >example for items which have been in the catalogue for a while. > >A use case for this functionality is: >* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob. > >Sponsored-By: Toi Ohomai Institute of Technology, New Zealand >--- > C4/Items.pm | 17 ++++- > .../tools/automatic_item_modification_by_age.tt | 76 +++++++++++++++++++--- > .../prog/js/automatic_item_modification_by_age.js | 12 ++++ > tools/automatic_item_modification_by_age.pl | 18 ++++- > 4 files changed, 111 insertions(+), 12 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index bf464c3..64a6b86 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -2807,6 +2807,8 @@ sub ToggleNewStatus { > my $report; > for my $rule ( @rules ) { > my $age = $rule->{age}; >+ my $unit = $rule->{unit}; >+ my $age_starting_point = $rule->{age_starting_point}; > my $conditions = $rule->{conditions}; > my $substitutions = $rule->{substitutions}; > my @params; >@@ -2835,8 +2837,19 @@ sub ToggleNewStatus { > } > } > if ( defined $age ) { >- $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; >- push @params, $age; >+ # Calculate item age based on hours since item last altered >+ if ( defined $rule && defined $age_starting_point && $unit eq "hours" && $age_starting_point eq "itemaltered" ) { >+ $query .= q| AND HOUR(TIMEDIFF(NOW(), timestamp)) >= ? |; >+ push @params, $age; >+ } elsif ( defined $rule && defined $age_starting_point && $unit eq "days" && $age_starting_point eq "itemaltered" ) { >+ # Calculate item age based on days since item last altered >+ $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(timestamp) >= ? |; >+ push @params, $age; >+ } else { >+ # Calculate item age based on days since item was created >+ $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; >+ push @params, $age; >+ } > } > my $sth = $dbh->prepare($query); > $sth->execute( @params ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >index 7e1d5a3..44cf3b1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >@@ -70,10 +70,39 @@ > <legend>Rule <span class="rulecount">[% loop.count %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend> > <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled --> > <div class="age"> >- <h5>Age in days</h5> >+ <h5>Age</h5> > <input class="age" type="number" value="[% rule.age %]" name="age_[% id %]" /> > </div> >- <div class="blocks"> >+ <div> >+ <h5>Unit</h5> >+ <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> >+ <select id="existing_rule_unit" name="unit_[% id %]" id="unit"> >+ <option value="">Choose a unit</option> >+ [% IF rule.unit == "hours" %] >+ <option value="hours" selected="selected">Hours</option> >+ <option value="days">Days</option> >+ [% ELSIF rule.unit == "days" %] >+ <option value="days" selected="selected">Days</option> >+ <option value="hours">Hours</option> >+ [% END %] >+ </select> >+ </div> >+ [% IF rule.unit == "days" %] >+ <div id="age_starting_point_div"> >+ <h5>Age starting point (starting point from which the item age is calculated)</h5> >+ <select name="age_starting_point_[% id %]" id="age_starting_point"> >+ <option value="">Choose age starting point</option> >+ [% IF rule.age_starting_point == "itemcreation" %] >+ <option value="itemcreation" selected="selected">Created</option> >+ <option value="itemaltered">Item last altered</option> >+ [% ELSIF rule.age_starting_point == "itemaltered" %] >+ <option value="itemaltered" selected="selected">Last altered</option> >+ <option value="itemcreation">Item creation</option> >+ [% END %] >+ </select> >+ </div> >+ [% END %] >+ <div class="blocks"> > <h5>Conditions</h5> > [% FOR condition IN rule.conditions %] > <div class="block"> >@@ -87,7 +116,6 @@ > [% END %] > [% END %] > </select> >- = > <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a> >@@ -108,7 +136,6 @@ > [% END %] > [% END %] > </select> >- = > <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a> >@@ -131,9 +158,26 @@ > <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend> > <input type="hidden" name="unique_id" /> > <div class="age"> >- <h5>Age in days</h5> >+ <h5>Age</h5> > <input class="age" type="number" value="" name="age" /> > </div> >+ <div> >+ <h5>Unit</h5> >+ <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> >+ <select id="new_rule_unit" name="unit" /> >+ <option value="">Choose an age unit</option> >+ <option id="hours" value="hours">Hours</option> >+ <option id="days" value="days">Days</option> >+ </select> >+ </div> >+ <div id="new_rule_age_starting_point_div"> >+ <h5>Age starting point (starting point from which the item age is calculated)</h5> >+ <select name="age_starting_point"> >+ <option value="">Choose age starting point</option> >+ <option value="itemcreation">Created</option> >+ <option value="itemaltered">Last altered</option> >+ </select> >+ </div> > <div class="blocks"> > <h5>Conditions</h5> > <div class="block"> >@@ -143,7 +187,6 @@ > <option value="[% field %]">[% field %]</option> > [% END %] > </select> >- = > <input type="text" value="" name="condition_value" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a> >@@ -158,7 +201,6 @@ > <option value="[% field %]">[% field %]</option> > [% END %] > </select> >- = > <input type="text" value="" name="substitution_value" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a> >@@ -173,6 +215,7 @@ > <thead> > <tr> > <th>Age</th> >+ <th>Age starting point</th> > <th>Conditions</th> > <th>Substitutions</th> > </tr> >@@ -181,13 +224,28 @@ > [% FOR rule IN rules %] > <tr> > <td> >- [% IF rule.age.defined and rule.age.length > 0 %] >- [% rule.age %] days >+ [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %] >+ [% IF rule.age == 1 %] >+ [% IF rule.unit == "days" %] >+ [% rule.age %] day >+ [% ELSE %] >+ [% rule.age %] hour >+ [% END %] >+ [% ELSE %] >+ [% rule.age %] [% rule.unit %] >+ [% END %] > [% ELSE %] > There is no age for this rule. > [% END %] > </td> > <td> >+ [% IF rule.age_starting_point.defined %] >+ [% rule.age_starting_point %] >+ [% ELSE %] >+ There is no age starting point for this rule. >+ [% END %] >+ </td> >+ <td> > [% FOR condition IN rule.conditions %] > [% IF condition.field %] > <div class="block"> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >index 6c37d9b..ea5e686 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >@@ -52,6 +52,8 @@ function update_rule_count(){ > $(document).ready(function() { > $("#new_rule .remove_rule").hide(); > $("#new_rule a.remove_block").hide(); >+ $("#new_rule_age_starting_point_div").hide(); >+ > $("#rules a.remove_block").click(function(e){ > e.preventDefault(); > remove_block_action($(this)); >@@ -61,6 +63,16 @@ $(document).ready(function() { > remove_rule_action($(this)); > }); > >+ $("#new_rule_unit").change(function(){ >+ var unitselected = $(this).find("option:selected").attr("id"); >+ var newruleagestart = document.getElementById("new_rule_age_starting_point_div"); >+ if (unitselected == "days") { >+ newruleagestart.style.display = "block" >+ } else { >+ newruleagestart.style.display = "none"; >+ } >+ }); >+ > var unique_id = $(".rule").length + 1; > $(".add_rule").click(function(e){ > e.preventDefault(); >diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl >index 12a1c00..807d79b 100755 >--- a/tools/automatic_item_modification_by_age.pl >+++ b/tools/automatic_item_modification_by_age.pl >@@ -39,7 +39,7 @@ use C4::Context; > use C4::Items; > use C4::Output; > use C4::Koha; >- >+use Data::Dumper; > use Koha::Items; > use Koha::Biblioitems; > >@@ -86,9 +86,25 @@ if ( $op eq 'update' ) { > push @{ $rule->{conditions} }, {} > unless @{ $rule->{conditions} }; > $rule->{age} = $cgi->param("age_$unique_id"); >+ >+ if ($cgi->param("unit_$unique_id")) { >+ $rule->{unit} = $cgi->param("unit_$unique_id"); >+ } else { >+ $rule->{unit} = $cgi->param("unit"); >+ } >+ >+ if ($cgi->param("age_starting_point_$unique_id")) { >+ $rule->{age_starting_point} = $cgi->param("age_starting_point_$unique_id"); >+ } elsif ($cgi->param("age_starting_point")) { >+ $rule->{age_starting_point} = $cgi->param("age_starting_point"); >+ } else { >+ $rule->{age_starting_point} = "itemaltered" >+ } >+ > push @rules, $rule; > } > my $syspref_content = to_json( \@rules ); >+ > C4::Context->set_preference($syspref_name, $syspref_content); > > $op = 'show'; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21173
:
77547
|
77548
|
77604
|
77605
|
78917
|
79914
|
138870
|
138871
|
138872
|
138894
|
138895
|
138896
|
156137
|
156138
|
156139
|
158574
|
158575
|
160715
|
160716