have the UI use full country names, and state names outside the US...
[freeside.git] / FS / FS / pkg_class.pm
1 package FS::pkg_class;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch );
6 use FS::part_pkg;
7
8 @ISA = qw( FS::Record );
9
10 =head1 NAME
11
12 FS::pkg_class - Object methods for pkg_class records
13
14 =head1 SYNOPSIS
15
16   use FS::pkg_class;
17
18   $record = new FS::pkg_class \%hash;
19   $record = new FS::pkg_class { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::pkg_class object represents an package class.  Every package definition
32 (see L<FS::part_pkg>) has, optionally, a package class. FS::pkg_class inherits
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item classnum - primary key (assigned automatically for new package classes)
38
39 =item classname - Text name of this package class
40
41 =back
42
43 =head1 METHODS
44
45 =over 4
46
47 =item new HASHREF
48
49 Creates a new package class.  To add the package class to the database, see
50 L<"insert">.
51
52 =cut
53
54 sub table { 'pkg_class'; }
55
56 =item insert
57
58 Adds this package class to the database.  If there is an error, returns the
59 error, otherwise returns false.
60
61 =item delete
62
63 Deletes this package class from the database.  Only package classes with no
64 associated package definitions can be deleted.  If there is an error, returns
65 the error, otherwise returns false.
66
67 =cut
68
69 sub delete {
70   my $self = shift;
71
72   return "Can't delete an pkg_class with part_pkg records!"
73     if qsearch( 'part_pkg', { 'classnum' => $self->classnum } );
74
75   $self->SUPER::delete;
76 }
77
78 =item replace OLD_RECORD
79
80 Replaces OLD_RECORD with this one in the database.  If there is an error,
81 returns the error, otherwise returns false.
82
83 =item check
84
85 Checks all fields to make sure this is a valid package class.  If there is an
86 error, returns the error, otherwise returns false.  Called by the insert and
87 replace methods.
88
89 =cut
90
91 sub check {
92   my $self = shift;
93
94   $self->ut_numbern('classnum')
95   or $self->ut_text('classname')
96   or $self->SUPER::check;
97
98 }
99
100 =back
101
102 =head1 BUGS
103
104 =head1 SEE ALSO
105
106 L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation.
107
108 =cut
109
110 1;
111