Add date fields to track when an item was marked as lost or withdrawn.
Display those fields on catalogue/moredetail.pl
Test Plan:
1) Apply patch
2) Run updatedatabase.pl
3) Pick a record with items, browse to the 'items' tab ( moredetail.pl )
4) Mark an item as lost, verify the field "Lost on:" displays below
the "Lost status" field with todays date.
5) Mark the item as not lost, verify the field no longer displays
6) Repeat steps 4 and 5 with the Withdrawn field.
Signed-off-by: Mathieu Saby <mathieu.saby@univ-rennes2.fr>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
use C4::Log;
use List::MoreUtils qw/any/;
use YAML qw/Load/;
+use DateTime::Format::MySQL;
use Data::Dumper; # used as part of logging item record changes, not just for
# debugging; so please don't remove this
+use Koha::DateUtils qw/dt_from_string/;
use vars qw($VERSION @ISA @EXPORT);
$item->{onloan} = undef if $item->{itemlost};
+ my @fields = qw( itemlost withdrawn );
+
+ # Only call GetItem if we need to set an "on" date field
+ if ( $item->{itemlost} || $item->{withdrawn} ) {
+ my $pre_mod_item = GetItem( $item->{'itemnumber'} );
+ for my $field (@fields) {
+ if ( defined( $item->{$field} )
+ and not $pre_mod_item->{$field}
+ and $item->{$field} )
+ {
+ $item->{ $field . '_on' } =
+ DateTime::Format::MySQL->format_datetime( dt_from_string() );
+ }
+ }
+ }
+
+ # If the field is defined but empty, we are removing and,
+ # and thus need to clear out the 'on' field as well
+ for my $field (@fields) {
+ if ( defined( $item->{$field} ) && !$item->{$field} ) {
+ $item->{ $field . '_on' } = undef;
+ }
+ }
+
+
_set_derived_columns_for_mod($item);
_do_column_fixes_for_mod($item);
# FIXME add checks
`notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
`damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
`itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
+ `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost
`withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
+ `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn
`itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
`coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f)
`issues` smallint(6) default NULL, -- number of times this item has been checked out
`notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
`damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
`itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
+ `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost
`withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
+ `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn
`itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
`coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f)
`issues` smallint(6) default NULL, -- number of times this item has been checked out/issued
SetVersion($DBversion);
}
+$DBversion = "3.13.00.XXX";
+if ( CheckVersion($DBversion) ) {
+ $dbh->do("ALTER TABLE items ADD itemlost_on DATETIME NULL AFTER itemlost");
+ $dbh->do("ALTER TABLE items ADD withdrawn_on DATETIME NULL AFTER wthdrawn");
+ $dbh->do("ALTER TABLE deleteditems ADD itemlost_on DATETIME NULL AFTER itemlost");
+ $dbh->do("ALTER TABLE deleteditems ADD withdrawn_on DATETIME NULL AFTER wthdrawn");
+ print "Upgrade to $DBversion done (Bug 9673 - Track when items are marked as lost or withdrawn)\n";
+ SetVersion ($DBversion);
+}
+
=head1 FUNCTIONS
=head2 TableExists($table)
[% END %]
</li>
+ [% IF ITEM_DAT.itemlost_on %]<li><span class="label">Lost on:</span>[% ITEM_DAT.itemlost_on | $KohaDates %] </li>[% END %]
[% END %]
[% IF ( ITEM_DAT.itemdamagedloop ) %]
<li><span class="label">Damaged status:</span>
</form>
[% END %]
</li>
+ [% IF ITEM_DAT.withdrawn_on %]<li><span class="label">Withdrawn on:</span>[% ITEM_DAT.withdrawn_on | $KohaDates %] </li>[% END %]
</ol></div>
<div class="listgroup"><h4>History</h4>
<ol class="bibliodetails">