svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / part_svc_column.pm
1 package FS::part_svc_column;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( fields );
6
7 @ISA = qw(FS::Record);
8
9 =head1 NAME
10
11 FS::part_svc_column - Object methods for part_svc_column objects
12
13 =head1 SYNOPSIS
14
15   use FS::part_svc_column;
16
17   $record = new FS::part_svc_column \%hash
18   $record = new FS::part_svc_column { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::part_svc_column record represents a service definition column
31 constraint.  FS::part_svc_column inherits from FS::Record.  The following
32 fields are currently supported:
33
34 =over 4
35
36 =item columnnum - primary key (assigned automatcially for new records)
37
38 =item svcpart - service definition (see L<FS::part_svc>)
39
40 =item columnname - column name in part_svc.svcdb table
41
42 =item columnlabel - label for the column
43
44 =item columnvalue - default or fixed value for the column
45
46 =item columnflag - null or empty (no default), `D' for default, `F' for fixed (unchangeable), `S' for selectable choice, `M' for manual selection from inventory, `A' for automatic selection from inventory, or `H' for selection from a hardware class.  For virtual fields, can also be 'X' for excluded.
47
48 =item required - column value expected to be true
49
50 =back
51
52 =head1 METHODS
53
54 =over 4
55
56 =item new HASHREF
57
58 Creates a new column constraint.  To add the column constraint to the database, see L<"insert">.
59
60 =cut
61
62 sub table { 'part_svc_column'; }
63
64 =item insert
65
66 Adds this service definition to the database.  If there is an error, returns
67 the error, otherwise returns false.
68
69 =item delete
70
71 Deletes this record from the database.  If there is an error, returns the
72 error, otherwise returns false.
73
74 =item replace OLD_RECORD
75
76 Replaces OLD_RECORD with this one in the database.  If there is an error,
77 returns the error, otherwise returns false.
78
79 =item check
80
81 Checks all fields to make sure this is a valid record.  If there is an error,
82 returns the error, otherwise returns false.  Called by the insert and replace
83 methods.
84
85 =cut
86
87 sub check {
88   my $self = shift;
89
90   my $error =
91     $self->ut_numbern('columnnum')
92     || $self->ut_number('svcpart')
93     || $self->ut_alpha('columnname')
94     || $self->ut_textn('columnlabel')
95     || $self->ut_anything('columnvalue')
96     || $self->ut_flag('required')
97   ;
98   return $error if $error;
99
100   $self->columnflag =~ /^([DFSMAHXP]?)$/
101     or return "illegal columnflag ". $self->columnflag;
102   $self->columnflag(uc($1));
103
104   if ( $self->columnflag =~ /^[MA]$/ ) {
105     # split, check all values independently, and normalize
106     my @classnums = split(/\s*,\s*/, $self->columnvalue);
107     foreach (@classnums) {
108       $self->set('columnvalue', $_);
109       $error = $self->ut_foreign_key( 'columnvalue', 'inventory_class', 'classnum' );
110       return $error if $error;
111     }
112     $self->set('columnvalue', join(',', @classnums));
113   }
114   if ( $self->columnflag eq 'H' ) {
115     $error = 
116       $self->ut_foreign_key( 'columnvalue', 'hardware_class', 'classnum' );
117   }
118   return $error if $error;
119
120   $self->SUPER::check;
121 }
122
123 =back
124
125 =head1 BUGS
126
127 =head1 SEE ALSO
128
129 L<FS::Record>, L<FS::part_svc>, L<FS::part_pkg>, L<FS::pkg_svc>,
130 L<FS::cust_svc>, L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>,
131 schema.html from the base documentation.
132
133 =cut
134
135 1;
136