This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / type_pkgs.pm
1 package FS::type_pkgs;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::agent_type;
7 use FS::part_pkg;
8
9 @ISA = qw( FS::Record );
10
11 =head1 NAME
12
13 FS::type_pkgs - Object methods for type_pkgs records
14
15 =head1 SYNOPSIS
16
17   use FS::type_pkgs;
18
19   $record = new FS::type_pkgs \%hash;
20   $record = new FS::type_pkgs { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::type_pkgs record links an agent type (see L<FS::agent_type>) to a
33 billing item definition (see L<FS::part_pkg>).  FS::type_pkgs inherits from
34 FS::Record.  The following fields are currently supported:
35
36 =over 4
37
38 =item typepkgnum - primary key
39
40 =item typenum - Agent type, see L<FS::agent_type>
41
42 =item pkgpart - Billing item definition, see L<FS::part_pkg>
43
44 =back
45
46 =head1 METHODS
47
48 =over 4
49
50 =item new HASHREF
51
52 Create a new record.  To add the record to the database, see L<"insert">.
53
54 =cut
55
56 sub table { 'type_pkgs'; }
57
58 =item insert
59
60 Adds this record to the database.  If there is an error, returns the error,
61 otherwise returns false.
62
63 =item delete
64
65 Deletes this record from the database.  If there is an error, returns the
66 error, otherwise returns false.
67
68 =item replace OLD_RECORD
69
70 Replaces OLD_RECORD with this one in the database.  If there is an error,
71 returns the error, otherwise returns false.
72
73 =item check
74
75 Checks all fields to make sure this is a valid record.  If there is an error,
76 returns the error, otherwise returns false.  Called by the insert and replace
77 methods.
78
79 =cut
80
81 sub check {
82   my $self = shift;
83
84   my $error = 
85        $self->ut_numbern('typepkgnum')
86     || $self->ut_foreign_key('typenum', 'agent_type', 'typenum' )
87     || $self->ut_foreign_key('pkgpart', 'part_pkg',   'pkgpart' )
88   ;
89   return $error if $error;
90
91   $self->SUPER::check;
92 }
93
94 =item part_pkg
95
96 Returns the FS::part_pkg object associated with this record.
97
98 =cut
99
100 sub part_pkg {
101   my $self = shift;
102   qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
103 }
104
105 =item agent_type
106
107 Returns the FS::agent_type object associated with this record.
108
109 =cut
110
111 sub agent_type {
112   my $self = shift;
113   qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
114 }
115
116 =cut
117
118 =back
119
120 =head1 BUGS
121
122 =head1 SEE ALSO
123
124 L<FS::Record>, L<FS::agent_type>, L<FS::part_pkgs>, schema.html from the base
125 documentation.
126
127 =cut
128
129 1;
130