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

(-)a/Koha/Item.pm (-40 / +44 lines)
Lines 120-157 sub store { Link Here
120
120
121
    } else { # ModItem
121
    } else { # ModItem
122
122
123
        { # Update *_on  fields if needed
123
        my %updated_columns = $self->_result->get_dirty_columns;
124
          # Why not for AddItem as well?
124
        return $self->SUPER::store unless %updated_columns;
125
            my @fields = qw( itemlost withdrawn damaged );
126
127
            # Only retrieve the item if we need to set an "on" date field
128
            if ( $self->itemlost || $self->withdrawn || $self->damaged ) {
129
                my $pre_mod_item = $self->get_from_storage;
130
                for my $field (@fields) {
131
                    if (    $self->$field
132
                        and not $pre_mod_item->$field )
133
                    {
134
                        my $field_on = "${field}_on";
135
                        $self->$field_on(
136
                          DateTime::Format::MySQL->format_datetime( dt_from_string() )
137
                        );
138
                    }
139
                }
140
            }
141
125
142
            # If the field is defined but empty, we are removing and,
126
        # Retreive the item for comparison if we need to
143
            # and thus need to clear out the 'on' field as well
127
        my $pre_mod_item = $self->get_from_storage
144
            for my $field (@fields) {
128
          if ( exists $updated_columns{itemlost}
145
                if ( defined( $self->$field ) && !$self->$field ) {
129
            or exists $updated_columns{withdrawn}
146
                    my $field_on = "${field}_on";
130
            or exists $updated_columns{damaged} );
147
                    $self->$field_on(undef);
131
148
                }
132
        # Update *_on  fields if needed
133
        # FIXME: Why not for AddItem as well?
134
        my @fields = qw( itemlost withdrawn damaged );
135
        for my $field (@fields) {
136
137
            # If the field is defined but empty or 0, we are 
138
            # removing/unsetting and thus need to clear out 
139
            # the 'on' field
140
            if (   exists $updated_columns{$field}
141
                && defined( $self->$field )
142
                && !$self->$field )
143
            {
144
                my $field_on = "${field}_on";
145
                $self->$field_on(undef);
146
            }
147
            # If the field has changed otherwise, we much update
148
            # the 'on' field
149
            elsif ( exists $updated_columns{$field}
150
                && $updated_columns{$field} ne $pre_mod_item->$field )
151
            {
152
                my $field_on = "${field}_on";
153
                $self->$field_on(
154
                    DateTime::Format::MySQL->format_datetime(
155
                        dt_from_string()
156
                    )
157
                );
149
            }
158
            }
150
        }
159
        }
151
160
152
        my %updated_columns = $self->_result->get_dirty_columns;
153
        return $self->SUPER::store unless %updated_columns;
154
155
        if (   exists $updated_columns{itemcallnumber}
161
        if (   exists $updated_columns{itemcallnumber}
156
            or exists $updated_columns{cn_source} )
162
            or exists $updated_columns{cn_source} )
157
        {
163
        {
Lines 168-180 sub store { Link Here
168
            $self->permanent_location( $self->location );
174
            $self->permanent_location( $self->location );
169
        }
175
        }
170
176
171
        # If item was lost, it has now been found, reverse any list item charges if necessary.
177
        # If item was lost and has now been found, 
172
        if ( exists $updated_columns{itemlost}
178
        # reverse any list item charges if necessary.
173
                and $self->itemlost != $updated_columns{itemlost}
179
        if (    exists $updated_columns{itemlost}
174
                and $self->itemlost >= 1
180
            and $updated_columns{itemlost} <= 0
175
                and $updated_columns{itemlost} <= 0
181
            and $pre_mod_item->itemlost > 0 )
176
        ) {
182
        {
177
            $self->_set_found_trigger;
183
            $self->_set_found_trigger($pre_mod_item);
178
            $self->paidfor('');
184
            $self->paidfor('');
179
        }
185
        }
180
186
Lines 785-800 Internal function, not exported, called only by Koha::Item->store. Link Here
785
=cut
791
=cut
786
792
787
sub _set_found_trigger {
793
sub _set_found_trigger {
788
    my ( $self, $params ) = @_;
794
    my ( $self, $pre_mod_item ) = @_;
789
795
790
    ## If item was lost, it has now been found, reverse any list item charges if necessary.
796
    ## If item was lost, it has now been found, reverse any list item charges if necessary.
791
    my $refund = 1;
792
    my $no_refund_after_days =
797
    my $no_refund_after_days =
793
      C4::Context->preference('NoRefundOnLostReturnedItemsAge');
798
      C4::Context->preference('NoRefundOnLostReturnedItemsAge');
794
    if ($no_refund_after_days) {
799
    if ($no_refund_after_days) {
795
        my $today = dt_from_string();
800
        my $today = dt_from_string();
796
        my $lost_age_in_days =
801
        my $lost_age_in_days =
797
          dt_from_string( $self->itemlost_on )->delta_days($today)
802
          dt_from_string( $pre_mod_item->itemlost_on )->delta_days($today)
798
          ->in_units('days');
803
          ->in_units('days');
799
804
800
        return $self unless $lost_age_in_days < $no_refund_after_days;
805
        return $self unless $lost_age_in_days < $no_refund_after_days;
Lines 878-884 sub _set_found_trigger { Link Here
878
883
879
    # Update the account status
884
    # Update the account status
880
    $accountline->status('FOUND');
885
    $accountline->status('FOUND');
881
    $accountline->store;
886
    $accountline->store();
882
887
883
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
888
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
884
        $account->reconcile_balance;
889
        $account->reconcile_balance;
885
- 

Return to bug 18501