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

(-)a/C4/Items.pm (-1 / +16 lines)
Lines 1571-1576 sub ToggleNewStatus { Link Here
1571
    my $report;
1571
    my $report;
1572
    for my $rule ( @rules ) {
1572
    for my $rule ( @rules ) {
1573
        my $age = $rule->{age};
1573
        my $age = $rule->{age};
1574
        # Default to using Days if there's an old item modification rule
1575
        # missing an ageunit value
1576
        my $unit = $rule->{ageunit} ? $rule->{ageunit} : 'Days';
1574
        # Default to using items.dateaccessioned if there's an old item modification rule
1577
        # Default to using items.dateaccessioned if there's an old item modification rule
1575
        # missing an agefield value
1578
        # missing an agefield value
1576
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1579
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
Lines 1606-1612 sub ToggleNewStatus { Link Here
1606
            }
1609
            }
1607
        }
1610
        }
1608
        if ( defined $age ) {
1611
        if ( defined $age ) {
1609
            $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1612
            if ( defined $rule
1613
                && $unit eq "Hours"
1614
                && (
1615
                    $agefield eq "items.damaged_on"
1616
                    || $agefield eq "items.itemlost_on"
1617
                    || $agefield eq "items.withdrawn_on" )
1618
            ) {
1619
                # Calculate item age based on hours since damaged_on, itemlost_on, withdrawn_on
1620
                $query .= qq| AND HOUR(TIMEDIFF(NOW(), $agefield)) >= ? |;
1621
            } else {
1622
                # Calculate item age based on days
1623
                $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1624
            }
1610
            push @params, $age;
1625
            push @params, $age;
1611
        }
1626
        }
1612
        my $sth = $dbh->prepare($query);
1627
        my $sth = $dbh->prepare($query);
(-)a/tools/automatic_item_modification_by_age.pl (-1 / +14 lines)
Lines 67-72 if ( $op eq 'update' ) { Link Here
67
        my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
67
        my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
68
        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");
69
        my @age_fields = $cgi->multi_param("agefield_$unique_id");
70
        my @age_units = $cgi->multi_param("ageunit_$unique_id");
70
        my $rule = {
71
        my $rule = {
71
            substitutions => [],
72
            substitutions => [],
72
            conditions => [],
73
            conditions => [],
Lines 90-95 if ( $op eq 'update' ) { Link Here
90
        for my $age_field ( @age_fields ) {
91
        for my $age_field ( @age_fields ) {
91
            $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned";
92
            $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned";
92
        }
93
        }
94
95
        for my $age_unit ( @age_units ) {
96
            if ($rule->{agefield} ne 'items.damaged_on'
97
                && $rule->{agefield} ne 'items.itemlost_on'
98
                && $rule->{agefield} ne 'items.withdrawn_on') {
99
                $rule->{ageunit} = "Days";
100
            } else {
101
                $rule->{ageunit} = $age_unit ? $age_unit : "Days";
102
            }
103
        }
104
93
        push @rules, $rule;
105
        push @rules, $rule;
94
    }
106
    }
95
    my $syspref_content = to_json( \@rules );
107
    my $syspref_content = to_json( \@rules );
Lines 116-124 if ( $@ ) { Link Here
116
my @item_fields = map { "items.$_" } Koha::Items->columns;
128
my @item_fields = map { "items.$_" } Koha::Items->columns;
117
my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
129
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');
130
my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on');
131
my @age_units = ('Hours', 'Days');
119
$template->param(
132
$template->param(
120
    op => $op,
133
    op => $op,
121
    messages => \@messages,
134
    messages => \@messages,
135
    ageunits => [ @age_units ],
122
    agefields => [ @age_fields ],
136
    agefields => [ @age_fields ],
123
    condition_fields => [ @item_fields, @biblioitem_fields ],
137
    condition_fields => [ @item_fields, @biblioitem_fields ],
124
    substitution_fields => \@item_fields,
138
    substitution_fields => \@item_fields,
125
- 

Return to bug 21173