From c58ca5dd5a2ca731bc33f2c63dc44029620f5807 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Jan 2008 12:36:16 -0600 Subject: [PATCH] items rework: fix several non-NULL columns during ModItem Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Items.pm | 61 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 6603b18a77..29e4da53c8 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -192,7 +192,7 @@ sub ModItem { $item->{'itemnumber'} = $itemnumber; _set_derived_columns_for_mod($item); - # FIXME add fixes + _do_column_fixes_for_mod($item); # FIXME add checks # update items table @@ -359,6 +359,57 @@ sub _set_derived_columns_for_mod { } } +=head2 _do_column_fixes_for_mod + +=over 4 + +_do_column_fixes_for_mod($item); + +=back + +Given an item hashref containing one or more +columns to modify, fix up certain values. +Specifically, set to 0 any passed value +of C, C, C, or +C that is either undefined or +contains the empty string. + +=cut + +sub _do_column_fixes_for_mod { + my $item = shift; + + if (exists $item->{'notforloan'} and + (not defined $item->{'notforloan'} or $item->{'notforloan'} eq '')) { + $item->{'notforloan'} = 0; + } + if (exists $item->{'damaged'} and + (not defined $item->{'damaged'} or $item->{'damaged'} eq '')) { + $item->{'damaged'} = 0; + } + if (exists $item->{'itemlost'} and + (not defined $item->{'itemlost'} or $item->{'itemlost'} eq '')) { + $item->{'itemlost'} = 0; + } + if (exists $item->{'wthdrawn'} and + (not defined $item->{'wthdrawn'} or $item->{'wthdrawn'} eq '')) { + $item->{'wthdrawn'} = 0; + } +} + +=head2 _get_single_item_column + +=over 4 + +_get_single_item_column($column, $itemnumber); + +=back + +Retrieves the value of a single column from an C +row specified by C<$itemnumber>. + +=cut + sub _get_single_item_column { my $column = shift; my $itemnumber = shift; @@ -440,10 +491,10 @@ sub _set_defaults_for_add { } # various item status fields cannot be null - $item->{'notforloan'} = 0 unless exists $item->{'notforloan'}; - $item->{'damaged'} = 0 unless exists $item->{'damaged'}; - $item->{'itemlost'} = 0 unless exists $item->{'itemlost'}; - $item->{'wthdrawn'} = 0 unless exists $item->{'wthdrawn'}; + $item->{'notforloan'} = 0 unless exists $item->{'notforloan'} and defined $item->{'notforloan'}; + $item->{'damaged'} = 0 unless exists $item->{'damaged'} and defined $item->{'damaged'}; + $item->{'itemlost'} = 0 unless exists $item->{'itemlost'} and defined $item->{'itemlost'}; + $item->{'wthdrawn'} = 0 unless exists $item->{'wthdrawn'} and defined $item->{'wthdrawn'}; } =head2 _set_calculated_values -- 2.39.5