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

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

Return to bug 18501