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

(-)a/C4/Items.pm (-1 / +16 lines)
Lines 1828-1833 sub ToggleNewStatus { Link Here
1828
    my $report;
1828
    my $report;
1829
    for my $rule ( @rules ) {
1829
    for my $rule ( @rules ) {
1830
        my $age = $rule->{age};
1830
        my $age = $rule->{age};
1831
        # Default to using Days if there's an old item modification rule
1832
        # missing an ageunit value
1833
        my $unit = $rule->{ageunit} ? $rule->{ageunit} : 'Days';
1831
        # Default to using items.dateaccessioned if there's an old item modification rule
1834
        # Default to using items.dateaccessioned if there's an old item modification rule
1832
        # missing an agefield value
1835
        # missing an agefield value
1833
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1836
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
Lines 1863-1869 sub ToggleNewStatus { Link Here
1863
            }
1866
            }
1864
        }
1867
        }
1865
        if ( defined $age ) {
1868
        if ( defined $age ) {
1866
            $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1869
            if ( defined $rule
1870
                && $unit eq "Hours"
1871
                && (
1872
                    $agefield eq "items.damaged_on"
1873
                    || $agefield eq "items.itemlost_on"
1874
                    || $agefield eq "items.withdrawn_on" )
1875
            ) {
1876
                # Calculate item age based on hours since damaged_on, itemlost_on, withdrawn_on
1877
                $query .= qq| AND HOUR(TIMEDIFF(NOW(), $agefield)) >= ? |;
1878
            } else {
1879
                # Calculate item age based on days
1880
                $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |;
1881
            }
1867
            push @params, $age;
1882
            push @params, $age;
1868
        }
1883
        }
1869
        my $sth = $dbh->prepare($query);
1884
        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