@@ -, +, @@ --- C4/Suggestions.pm | 33 +++++++++++++++++++++++++++++++++ suggestion/suggestion.pl | 5 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) --- a/C4/Suggestions.pm +++ a/C4/Suggestions.pm @@ -28,6 +28,8 @@ use C4::Output; use C4::Dates qw(format_date format_date_in_iso); use C4::Debug; use C4::Letters; +use Koha::DateUtils qw( dt_from_string ); + use List::MoreUtils qw(any); use C4::Dates qw(format_date_in_iso); use base qw(Exporter); @@ -428,6 +430,21 @@ sub NewSuggestion { $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS}; + for my $field ( qw( + suggestedby + managedby + manageddate + acceptedby + accepteddate + rejectedby + rejecteddate + ) ) { + # Set the fields to NULL if not given. + $suggestion->{$field} ||= undef; + } + + $suggestion->{suggesteddate} = dt_from_string unless $suggestion->{suggesteddate}; + my $rs = Koha::Database->new->schema->resultset('Suggestion'); return $rs->create($suggestion)->id; } @@ -449,6 +466,22 @@ sub ModSuggestion { my ($suggestion) = @_; return unless( $suggestion and defined($suggestion->{suggestionid}) ); + for my $field ( qw( + suggestedby + managedby + manageddate + acceptedby + accepteddate + rejectedby + rejecteddate + ) ) { + # Set the fields to NULL if not given. + $suggestion->{$field} = undef + if exists $suggestion->{$field} + and ($suggestion->{$field} == '0' + or $suggestion->{$field} == '' ); + } + my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid}); my $status_update_table = 1; eval { --- a/suggestion/suggestion.pl +++ a/suggestion/suggestion.pl @@ -124,7 +124,10 @@ $template->param('borrowernumber' => $borrowernumber); ## Operations ## if ( $op =~ /save/i ) { - if ( $suggestion_only->{"STATUS"} ) { + $suggestion_only->{suggesteddate} = dt_from_string( $suggestion_only->{suggesteddate} ) + if $suggestion_only->{suggesteddate}; + + if ( $suggestion_only->{"STATUS"} ) { if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) { $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = dt_from_string; $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" } = C4::Context->userenv->{number}; --