@@ -, +, @@ automatic item modification by age tool and cronjob. --confirm --- 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(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2827,6 +2827,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; @@ -2855,8 +2857,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(), items.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(items.timestamp) >= ? |; + push @params, $age; + } else { + # Calculate item age based on days since item was created + $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.dateaccessioned) >= ? |; + push @params, $age; + } } my $sth = $dbh->prepare($query); $sth->execute( @params ); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt @@ -70,10 +70,39 @@
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'.
+ +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'.
+ + + + + +