Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/GADS/Column/Calc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ after build_values => sub {
# Convert return format to database column field
sub _format_to_field
{ my $return_type = shift;
$return_type eq 'datetime' ?
'value_datetime' :
$return_type eq 'date'
? 'value_date'
: $return_type eq 'daterange'
Expand Down
11 changes: 7 additions & 4 deletions lib/GADS/Datum/Calc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ sub as_strings
? ''
: ref $value eq 'DateTime'
? $self->date_as_string($value, $format)
: $self->column->return_type eq 'daterange'
? $self->daterange_as_string($value, $format)
: $self->column->return_type eq 'numeric'
? ( ($dc //= $self->column->decimal_places // 0)
? sprintf("%.${dc}f", $value)
Expand Down Expand Up @@ -115,6 +113,11 @@ sub convert_value
$val->truncate(to => 'day') if $val;
push @return, $val || undef;
}
elsif ($column->return_type eq "datetime")
{
$val = $self->_convert_date($val);
push @return, $val || undef;
}
elsif ($column->return_type eq "daterange") # Currently always has time element
{
if (!$val)
Expand Down Expand Up @@ -206,7 +209,7 @@ sub equal
$a2 += 0; $b2 += 0; # Remove trailing zeros
return 0 if $a2 != $b2;
}
elsif ($rt eq 'date')
elsif ($rt eq 'date' || $rt eq 'datetime')
{
# Type might have changed and old value be string
ref $a2 eq 'DateTime' && ref $b2 eq 'DateTime' or return 0;
Expand Down Expand Up @@ -240,7 +243,7 @@ sub _build_for_code
my @return;
foreach my $val (@{$self->value})
{
if ($rt eq 'date')
if ($rt eq 'date' || $rt eq 'datetime')
{
push @return, $self->date_for_code($val);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/GADS/Datum/Code.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ sub _write_unique

sub _delete_unique
{ my ($self, %values) = @_;
%values = map { $_ => $values{$_} } grep $values{$_}, keys %values;
if (my $table = $self->column->table_unique)
{
$self->schema->resultset($table)->search({
Expand Down Expand Up @@ -204,7 +205,7 @@ sub write_cache
{
foreach my $oldval (@{$old->value})
{
my $sv = $oldval && $self->column->value_field eq 'value_date'
my $sv = $oldval && ($self->column->value_field eq 'value_date' || $self->column->value_field eq 'value_datetime')
? $formatter->format_date($oldval)
: $oldval;
# Ignore values from this record itself as it hasn't been
Expand Down Expand Up @@ -250,7 +251,7 @@ sub write_cache
my $old_value = $row->$vfield;
$row->update({ %blank, %to_write });
# Delete unique cache, unless exists in another
my $sv = $old_value && $self->column->value_field eq 'value_date'
my $sv = $old_value && ($self->column->value_field eq 'value_date' || $self->column->value_field eq 'value_datetime')
? $formatter->format_date($old_value)
: $old_value;
$self->_delete_unique(%old)
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use base 'DBIx::Class::Schema';

__PACKAGE__->load_namespaces;

our $VERSION = 110;
our $VERSION = 111;

our $IGNORE_PERMISSIONS;
our $IGNORE_PERMISSIONS_SEARCH;
Expand Down
3 changes: 3 additions & 0 deletions lib/GADS/Schema/Result/CalcUnique.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ __PACKAGE__->add_columns(
{ data_type => "bigint", is_nullable => 1 },
"value_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
"value_datetime",
{ data_type => "datetime", datetime_undef_if_invalid => 1, is_nullable => 1 },
"value_numeric",
{ data_type => "decimal", is_nullable => 1, size => [20, 5] },
"value_date_from",
Expand All @@ -36,6 +38,7 @@ __PACKAGE__->add_unique_constraint("calc_unique_ux_layout_int", ["layout_id", "v
__PACKAGE__->add_unique_constraint("calc_unique_ux_layout_date", ["layout_id", "value_date"]);
__PACKAGE__->add_unique_constraint("calc_unique_ux_layout_numeric", ["layout_id", "value_numeric"]);
__PACKAGE__->add_unique_constraint("calc_unique_ux_layout_daterange", ["layout_id", "value_date_from", "value_date_to"]);
__PACKAGE__->add_unique_constraint("calc_unique_ux_layout_datetime", ["layout_id", "value_datetime"]);

__PACKAGE__->belongs_to(
"layout",
Expand Down
5 changes: 4 additions & 1 deletion lib/GADS/Schema/Result/Calcval.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ __PACKAGE__->add_columns(
{ data_type => "bigint", is_nullable => 1 },
"value_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
"value_datetime",
{ data_type => "datetime", datetime_undef_if_invalid => 1, is_nullable => 1 },
"value_numeric",
{ data_type => "decimal", is_nullable => 1, size => [20, 5] },
"value_date_from",
Expand Down Expand Up @@ -69,8 +71,9 @@ sub sqlt_deploy_hook {
$sqlt_table->add_index(name => 'calcval_idx_value_numeric', fields => [ 'value_numeric' ]);
$sqlt_table->add_index(name => 'calcval_idx_value_int', fields => [ 'value_int' ]);
$sqlt_table->add_index(name => 'calcval_idx_value_date', fields => [ 'value_date' ]);
$sqlt_table->add_index(name => 'calcval_idx_value_datetime', fields => [ 'value_datetime' ]);
}

sub _build_valuefield { ('value_text','value_numeric','value_int','value_date','value_date_from','value_date_to'); }
sub _build_valuefield { ('value_text','value_numeric','value_int','value_date','value_datetime','value_date_from','value_date_to'); }

1;
Loading
Loading