per-agent disable_previous_balance, #15863
[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 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item new HASHREF
55
56 Creates a new column constraint.  To add the column constraint to the database, see L<"insert">.
57
58 =cut
59
60 sub table { 'part_svc_column'; }
61
62 =item insert
63
64 Adds this service definition to the database.  If there is an error, returns
65 the error, otherwise returns false.
66
67 =item delete
68
69 Deletes this record from the database.  If there is an error, returns the
70 error, otherwise returns false.
71
72 =item replace OLD_RECORD
73
74 Replaces OLD_RECORD with this one in the database.  If there is an error,
75 returns the error, otherwise returns false.
76
77 =item check
78
79 Checks all fields to make sure this is a valid record.  If there is an error,
80 returns the error, otherwise returns false.  Called by the insert and replace
81 methods.
82
83 =cut
84
85 sub check {
86   my $self = shift;
87
88   my $error =
89     $self->ut_numbern('columnnum')
90     || $self->ut_number('svcpart')
91     || $self->ut_alpha('columnname')
92     || $self->ut_textn('columnlabel')
93     || $self->ut_anything('columnvalue')
94   ;
95   return $error if $error;
96
97   $self->columnflag =~ /^([DFSMAHX]?)$/
98     or return "illegal columnflag ". $self->columnflag;
99   $self->columnflag(uc($1));
100
101   if ( $self->columnflag =~ /^[MA]$/ ) {
102     $error =
103       $self->ut_foreign_key( 'columnvalue', 'inventory_class', 'classnum' );
104   }
105   if ( $self->columnflag eq 'H' ) {
106     $error = 
107       $self->ut_foreign_key( 'columnvalue', 'hardware_class', 'classnum' );
108   }
109   return $error if $error;
110
111   $self->SUPER::check;
112 }
113
114 =back
115
116 =head1 BUGS
117
118 =head1 SEE ALSO
119
120 L<FS::Record>, L<FS::part_svc>, L<FS::part_pkg>, L<FS::pkg_svc>,
121 L<FS::cust_svc>, L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>,
122 schema.html from the base documentation.
123
124 =cut
125
126 1;
127