diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-05-06 19:10:47 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-05-06 19:10:47 -0700 |
commit | f921a017cd3dd987bd48e05c7fd462a1ef9cb79d (patch) | |
tree | 4f772a73dc1852860d1d646fb7d8e866eb46d2a3 /FS | |
parent | a9129b5b8b7a69d1d0a7fce6dc9d72665eaec568 (diff) | |
parent | 95606bc9db41352511c886773a311f2166cc6cf2 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cdr/earthlink.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_svc.pm | 196 | ||||
-rw-r--r-- | FS/FS/svc_Common.pm | 44 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 1 | ||||
-rwxr-xr-x | FS/FS/svc_broadband.pm | 1 | ||||
-rw-r--r-- | FS/FS/svc_dish.pm | 3 | ||||
-rw-r--r-- | FS/FS/svc_domain.pm | 5 | ||||
-rw-r--r-- | FS/FS/svc_hardware.pm | 2 |
8 files changed, 142 insertions, 112 deletions
diff --git a/FS/FS/cdr/earthlink.pm b/FS/FS/cdr/earthlink.pm index da0d54527..60cba654f 100644 --- a/FS/FS/cdr/earthlink.pm +++ b/FS/FS/cdr/earthlink.pm @@ -17,7 +17,7 @@ use Date::Parse; 'accountcode', #Account number skip(2), #SERVICE LOC / BILL NUMBER sub { my($cdr, $date) = @_; - + $date; }, #date sub { my($cdr, $time) = @_; diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index 1da30cbb4..ca26074a3 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -142,56 +142,53 @@ sub insert { # add part_svc_column records my $svcdb = $self->svcdb; -# my @rows = map { /^${svcdb}__(.*)$/; $1 } -# grep ! /_flag$/, -# grep /^${svcdb}__/, -# fields('part_svc'); - foreach my $field ( - grep { $_ ne 'svcnum' - && ( defined( $self->getfield($svcdb.'__'.$_.'_flag') ) - || defined($self->getfield($svcdb.'__'.$_.'_required')) - || $self->getfield($svcdb.'__'.$_.'_label') !~ /^\s*$/ ) - } (fields($svcdb), @fields) - ) { - my $part_svc_column = $self->part_svc_column($field); - my $previous = qsearchs('part_svc_column', { - 'svcpart' => $self->svcpart, - 'columnname' => $field, - } ); + foreach my $field (fields($svcdb), @fields) { + next if $field eq 'svcnum'; + my $prefix = $svcdb.'__'; + if ( defined( $self->getfield($prefix.$_.'_flag')) + or defined($self->getfield($prefix.$_.'_required')) + or length($self->getfield($prefix.$_.'_label')) + ) { + my $part_svc_column = $self->part_svc_column($field); + my $previous = qsearchs('part_svc_column', { + 'svcpart' => $self->svcpart, + 'columnname' => $field, + } ); - my $flag = $self->getfield($svcdb.'__'.$field.'_flag'); - my $label = $self->getfield($svcdb.'__'.$field.'_label'); - my $required = $self->getfield($svcdb.'__'.$field.'_required') ? 'Y' : ''; - if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) { - - if ( uc($flag) =~ /^([A-Z])$/ ) { - my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} - || sub { shift }; - $part_svc_column->setfield('columnflag', $1); - $part_svc_column->setfield('columnvalue', - &$parser($self->getfield($svcdb.'__'.$field)) - ); - } + my $flag = $self->getfield($prefix.$field.'_flag'); + my $label = $self->getfield($prefix.$field.'_label'); + my $required = $self->getfield($prefix.$field.'_required') ? 'Y' : ''; + if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) { - $part_svc_column->setfield('columnlabel', $label) - if $label !~ /^\s*$/; + if ( uc($flag) =~ /^([A-Z])$/ ) { + my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} + || sub { shift }; + $part_svc_column->setfield('columnflag', $1); + $part_svc_column->setfield('columnvalue', + &$parser($self->getfield($prefix.$field)) + ); + } + + $part_svc_column->setfield('columnlabel', $label) + if $label !~ /^\s*$/; - $part_svc_column->setfield('required', $required); + $part_svc_column->setfield('required', $required); + + if ( $previous ) { + $error = $part_svc_column->replace($previous); + } else { + $error = $part_svc_column->insert; + } - if ( $previous ) { - $error = $part_svc_column->replace($previous); } else { - $error = $part_svc_column->insert; + $error = $previous ? $previous->delete : ''; + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; } - } else { - $error = $previous ? $previous->delete : ''; - } - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; } - } # add export_svc records @@ -284,54 +281,54 @@ sub replace { # maintain part_svc_column records my $svcdb = $new->svcdb; - foreach my $field ( - grep { $_ ne 'svcnum' - && ( defined( $new->getfield($svcdb.'__'.$_.'_flag') ) - || defined($new->getfield($svcdb.'__'.$_.'_required')) - || $new->getfield($svcdb.'__'.$_.'_label') !~ /^\s*$/ ) - } (fields($svcdb),@fields) - ) { - - my $part_svc_column = $new->part_svc_column($field); - my $previous = qsearchs('part_svc_column', { - 'svcpart' => $new->svcpart, - 'columnname' => $field, - } ); - - my $flag = $new->getfield($svcdb.'__'.$field.'_flag'); - my $label = $new->getfield($svcdb.'__'.$field.'_label'); - my $required = $new->getfield($svcdb.'__'.$field.'_required') ? 'Y' : ''; + foreach my $field (fields($svcdb),@fields) { + next if $field eq 'svcnum'; + my $prefix = $svcdb.'__'; + if ( defined( $new->getfield($prefix.$_.'_flag')) + or defined($new->getfield($prefix.$_.'_required')) + or length($new->getfield($prefix.$_.'_label')) + ) { + my $part_svc_column = $new->part_svc_column($field); + my $previous = qsearchs('part_svc_column', { + 'svcpart' => $new->svcpart, + 'columnname' => $field, + } ); + + my $flag = $new->getfield($svcdb.'__'.$field.'_flag'); + my $label = $new->getfield($svcdb.'__'.$field.'_label'); + my $required = $new->getfield($svcdb.'__'.$field.'_required') ? 'Y' : ''; - if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) { - - if ( uc($flag) =~ /^([A-Z])$/ ) { - $part_svc_column->setfield('columnflag', $1); - my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} - || sub { shift }; - $part_svc_column->setfield('columnvalue', - &$parser($new->getfield($svcdb.'__'.$field)) - ); - } else { - $part_svc_column->setfield('columnflag', ''); - $part_svc_column->setfield('columnvalue', ''); - } + if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) { + + if ( uc($flag) =~ /^([A-Z])$/ ) { + $part_svc_column->setfield('columnflag', $1); + my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} + || sub { shift }; + $part_svc_column->setfield('columnvalue', + &$parser($new->getfield($svcdb.'__'.$field)) + ); + } else { + $part_svc_column->setfield('columnflag', ''); + $part_svc_column->setfield('columnvalue', ''); + } - $part_svc_column->setfield('columnlabel', $label) - if $label !~ /^\s*$/; + $part_svc_column->setfield('columnlabel', $label) + if $label !~ /^\s*$/; - $part_svc_column->setfield('required', $required); + $part_svc_column->setfield('required', $required); - if ( $previous ) { - $error = $part_svc_column->replace($previous); + if ( $previous ) { + $error = $part_svc_column->replace($previous); + } else { + $error = $part_svc_column->insert; + } } else { - $error = $part_svc_column->insert; + $error = $previous ? $previous->delete : ''; + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; } - } else { - $error = $previous ? $previous->delete : ''; - } - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; } } @@ -605,6 +602,7 @@ sub svc_x { =cut my $svc_defs; +my $svc_info; sub _svc_defs { return $svc_defs if $svc_defs; #cache @@ -659,7 +657,14 @@ sub _svc_defs { sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} } keys %info, ; - + + tie my %svc_info, 'Tie::IxHash', + map { $_ => $info{$_} } + sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} } + keys %info, + ; + + $svc_info = \%svc_info; #access via svc_table_info $svc_defs = \%svc_defs; #cache } @@ -735,6 +740,27 @@ sub svc_table_fields { $def; } +=item svc_table_info TABLE + +Returns table_info for TABLE from cache, or empty +hashref if none is found. + +Caution: caches table_info for ALL services when run; +access a service's table_info directly unless you know +you're loading them all. + +Caution: does not standardize fields into hashrefs; +use L</svc_table_fields> to access fields. + +=cut + +sub svc_table_info { + my $class = shift; + my $table = shift; + $class->_svc_defs; #creates cache if needed + return $svc_info->{$table} || {}; +} + =back =head1 SUBROUTINES diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 8d3b5353e..9d9e50f98 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -167,28 +167,30 @@ sub check { my $required = {}; my $labels = {}; my $tinfo = $self->can('table_info') ? $self->table_info : {}; - my $fields = $tinfo->{'fields'} || {}; - foreach my $field (keys %$fields) { - if (ref($fields->{$field}) && $fields->{$field}->{'required'}) { - $required->{$field} = 1; - $labels->{$field} = $fields->{$field}->{'label'}; + if ($tinfo->{'manual_require'}) { + my $fields = $tinfo->{'fields'} || {}; + foreach my $field (keys %$fields) { + if (ref($fields->{$field}) && $fields->{$field}->{'required'}) { + $required->{$field} = 1; + $labels->{$field} = $fields->{$field}->{'label'}; + } } - } - # add fields marked as required in database - foreach my $column ( - qsearch('part_svc_column',{ - 'svcpart' => $self->svcpart, - 'required' => 'Y' - }) - ) { - $required->{$column->columnname} = 1; - $labels->{$column->columnname} = $column->columnlabel; - } - # do the actual checking - foreach my $field (keys %$required) { - unless ($self->$field) { - my $name = $labels->{$field} || $field; - return "Field $name is required\n" + # add fields marked as required in database + foreach my $column ( + qsearch('part_svc_column',{ + 'svcpart' => $self->svcpart, + 'required' => 'Y' + }) + ) { + $required->{$column->columnname} = 1; + $labels->{$column->columnname} = $column->columnlabel; + } + # do the actual checking + foreach my $field (keys %$required) { + unless (length($self->get($field)) > 0) { + my $name = $labels->{$field} || $field; + return "Field $name is required\n" + } } } diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 790ac3468..0181b1e0e 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -260,6 +260,7 @@ sub table_info { 'display_weight' => 10, 'cancel_weight' => 50, 'ip_field' => 'slipip', + 'manual_require' => 1, 'fields' => { 'dir' => 'Home directory', 'uid' => { diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm index e295f73cc..38594f0df 100755 --- a/FS/FS/svc_broadband.pm +++ b/FS/FS/svc_broadband.pm @@ -103,6 +103,7 @@ sub table_info { 'display_weight' => 50, 'cancel_weight' => 70, 'ip_field' => 'ip_addr', + 'manual_require' => 1, 'fields' => { 'svcnum' => 'Service', 'description' => 'Descriptive label', diff --git a/FS/FS/svc_dish.pm b/FS/FS/svc_dish.pm index 5c9e21710..2d249d17f 100644 --- a/FS/FS/svc_dish.pm +++ b/FS/FS/svc_dish.pm @@ -63,9 +63,10 @@ sub table_info { 'name' => 'Dish service', 'display_weight' => 58, 'cancel_weight' => 85, + 'manual_require' => 1, 'fields' => { 'svcnum' => { label => 'Service' }, - 'acctnum' => { label => 'DISH account#', %opts }, + 'acctnum' => { label => 'DISH account#', required => 1, %opts }, 'installdate' => { label => 'Install date', %opts }, 'note' => { label => 'Installation notes', %opts }, } diff --git a/FS/FS/svc_domain.pm b/FS/FS/svc_domain.pm index 78556cf8b..b01d67310 100644 --- a/FS/FS/svc_domain.pm +++ b/FS/FS/svc_domain.pm @@ -134,10 +134,7 @@ sub table_info { 'display_weight' => 20, 'cancel_weight' => 60, 'fields' => { - 'domain' => { - label => 'Domain', - required => 1, - }, + 'domain' => 'Domain', 'parent_svcnum' => { label => 'Parent domain / Communigate administrator domain', type => 'select', diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index 16a5ea99c..dbb8b6829 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -75,6 +75,7 @@ sub table_info { 'name_plural' => 'Hardware', 'display_weight' => 59, 'cancel_weight' => 86, + 'manual_require' => 1, 'fields' => { 'svcnum' => { label => 'Service' }, 'typenum' => { label => 'Device type', @@ -83,6 +84,7 @@ sub table_info { disable_fixed => 1, disable_default => 1, disable_inventory => 1, + required => 1, }, 'serial' => { label => 'Serial number', %opts }, 'hw_addr' => { label => 'Hardware address', %opts }, |