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} |
151 |
&& !$pre_mod_item->$field ) |
152 |
{ |
153 |
my $field_on = "${field}_on"; |
154 |
$self->$field_on( |
155 |
DateTime::Format::MySQL->format_datetime( |
156 |
dt_from_string() |
157 |
) |
158 |
); |
149 |
} |
159 |
} |
150 |
} |
160 |
} |
151 |
|
161 |
|
152 |
my %updated_columns = $self->_result->get_dirty_columns; |
|
|
153 |
return $self->SUPER::store unless %updated_columns; |
154 |
|
155 |
if ( exists $updated_columns{itemcallnumber} |
162 |
if ( exists $updated_columns{itemcallnumber} |
156 |
or exists $updated_columns{cn_source} ) |
163 |
or exists $updated_columns{cn_source} ) |
157 |
{ |
164 |
{ |
Lines 168-180
sub store {
Link Here
|
168 |
$self->permanent_location( $self->location ); |
175 |
$self->permanent_location( $self->location ); |
169 |
} |
176 |
} |
170 |
|
177 |
|
171 |
# If item was lost, it has now been found, reverse any list item charges if necessary. |
178 |
# If item was lost and has now been found, |
172 |
if ( exists $updated_columns{itemlost} |
179 |
# reverse any list item charges if necessary. |
173 |
and $self->itemlost != $updated_columns{itemlost} |
180 |
if ( exists $updated_columns{itemlost} |
174 |
and $self->itemlost >= 1 |
181 |
and $updated_columns{itemlost} <= 0 |
175 |
and $updated_columns{itemlost} <= 0 |
182 |
and $pre_mod_item->itemlost > 0 ) |
176 |
) { |
183 |
{ |
177 |
$self->_set_found_trigger; |
184 |
$self->_set_found_trigger($pre_mod_item); |
178 |
$self->paidfor(''); |
185 |
$self->paidfor(''); |
179 |
} |
186 |
} |
180 |
|
187 |
|
Lines 785-800
Internal function, not exported, called only by Koha::Item->store.
Link Here
|
785 |
=cut |
792 |
=cut |
786 |
|
793 |
|
787 |
sub _set_found_trigger { |
794 |
sub _set_found_trigger { |
788 |
my ( $self, $params ) = @_; |
795 |
my ( $self, $pre_mod_item ) = @_; |
789 |
|
796 |
|
790 |
## If item was lost, it has now been found, reverse any list item charges if necessary. |
797 |
## 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 = |
798 |
my $no_refund_after_days = |
793 |
C4::Context->preference('NoRefundOnLostReturnedItemsAge'); |
799 |
C4::Context->preference('NoRefundOnLostReturnedItemsAge'); |
794 |
if ($no_refund_after_days) { |
800 |
if ($no_refund_after_days) { |
795 |
my $today = dt_from_string(); |
801 |
my $today = dt_from_string(); |
796 |
my $lost_age_in_days = |
802 |
my $lost_age_in_days = |
797 |
dt_from_string( $self->itemlost_on )->delta_days($today) |
803 |
dt_from_string( $pre_mod_item->itemlost_on )->delta_days($today) |
798 |
->in_units('days'); |
804 |
->in_units('days'); |
799 |
|
805 |
|
800 |
return $self unless $lost_age_in_days < $no_refund_after_days; |
806 |
return $self unless $lost_age_in_days < $no_refund_after_days; |
Lines 878-884
sub _set_found_trigger {
Link Here
|
878 |
|
884 |
|
879 |
# Update the account status |
885 |
# Update the account status |
880 |
$accountline->status('FOUND'); |
886 |
$accountline->status('FOUND'); |
881 |
$accountline->store; |
887 |
$accountline->store(); |
882 |
|
888 |
|
883 |
if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) { |
889 |
if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) { |
884 |
$account->reconcile_balance; |
890 |
$account->reconcile_balance; |
885 |
- |
|
|