split(/\0/, $value)
};
} elsif ( $info->{'type'} eq 'freq' ) {
- $value .= $params->{$cgi_field.'_units'};
+ $value = '0' if !length($value) and !$info->{'allow_blank'};
+ $value = '0' if $value =~ /[^\d]/;
+ $value .= $params->{$cgi_field.'_units'} if length($value);
}
#warn "value of $cgi_field is $value\n";
my $value = join(',', $cgi->param( "$prefix$option" ) );
if ( $option eq 'reasonnum' && $value == -1 ) {
- $value = {
- 'typenum' => scalar( $cgi->param( "new$prefix${option}T" ) ),
- 'reason' => scalar( $cgi->param( "new$prefix${option}" ) ),
- };
+ my $reason_prefix = $object->action . '_' . $option . '_new_';
+ my $new_reason = FS::reason->new;
+ foreach ( qw( reason_type reason unsuspend pkgpart
+ unsuspend_hold unused_credit ) ) {
+ $new_reason->set($_, $cgi->param("$reason_prefix$_"));
+ }
+ warn Dumper $new_reason;
+ my $error = $new_reason->insert;
+ die "error creating reason: $error" if $error;
+ $value = $new_reason->reasonnum;
}
-
( $option => $value );
}
- @{ $object->option_fields_listref };
+ @{ $object->option_fields_listref || [] };
},
'precheck_callback' => sub {
my $cgi = shift;
my $action = $cgi->param('action') or return;
- my %actionfields = map { $_ =~ /^$action\.(.*)/; $1 => $cgi->param($_) }
+ my %actionfields = map { $_ =~ /^$action\.(.*)/; $1 => scalar($cgi->param($_)) }
grep { /^$action\./ } $cgi->param;
if ( exists($actionfields{'reasonnum'}) and
length($actionfields{'reasonnum'}) == 0 ) {
if ( $cgi->param('_initialize') ) {
$cgi->param('disabled', 'Y');
}
+
+ if ( $action eq 'pkg_fee' && !$actionfields{feepart} ) {
+ return "Select a Fee Definition to use this Event Action";
+ }
+
+ my $balance_age_rx = qr/^(condition.+)\.balance_age\.age$/;
+
+ foreach my $param ( keys %{ $cgi->Vars() } ){
+
+ next unless ( $param =~ /$balance_age_rx/ );
+ next unless $cgi->param($1) eq 'balance_age';
+
+ my $errstr = FS::part_event::Condition::balance_age->
+ check_options( { age => scalar($cgi->param($param)),
+ age_units => scalar($cgi->param("${param}_units")),
+ }
+ );
+
+ return $errstr if $errstr;
+ }
+
return '';
},
'noerror_callback' => sub {