fix big in RADIUS session viewing when using an ignored-accounting export
[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 typenum - Agent type, see L<FS::agent_type>
39
40 =item pkgpart - Billing item definition, see L<FS::part_pkg>
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Create a new record.  To add the record to the database, see L<"insert">.
51
52 =cut
53
54 sub table { 'type_pkgs'; }
55
56 =item insert
57
58 Adds this record to the database.  If there is an error, returns the error,
59 otherwise returns false.
60
61 =item delete
62
63 Deletes this record from the database.  If there is an error, returns the
64 error, otherwise returns false.
65
66 =item replace OLD_RECORD
67
68 Replaces OLD_RECORD with this one in the database.  If there is an error,
69 returns the error, otherwise returns false.
70
71 =item check
72
73 Checks all fields to make sure this is a valid record.  If there is an error,
74 returns the error, otherwise returns false.  Called by the insert and replace
75 methods.
76
77 =cut
78
79 sub check {
80   my $self = shift;
81
82   my $error = 
83     $self->ut_number('typenum')
84     || $self->ut_number('pkgpart')
85   ;
86   return $error if $error;
87
88   return "Unknown typenum"
89     unless qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
90
91   return "Unknown pkgpart"
92     unless qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
93
94   $self->SUPER::check;
95 }
96
97 =item part_pkg
98
99 Returns the FS::part_pkg object associated with this record.
100
101 =cut
102
103 sub part_pkg {
104   my $self = shift;
105   qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
106 }
107
108 =cut
109
110 =back
111
112 =head1 VERSION
113
114 $Id: type_pkgs.pm,v 1.3 2003-08-05 00:20:48 khoff Exp $
115
116 =head1 BUGS
117
118 =head1 SEE ALSO
119
120 L<FS::Record>, L<FS::agent_type>, L<FS::part_pkgs>, schema.html from the base
121 documentation.
122
123 =cut
124
125 1;
126