enable CardFortress in test database, #71513
[freeside.git] / FS / FS / pkg_svc.pm
1 package FS::pkg_svc;
2 use base qw(FS::Record);
3
4 use strict;
5 use FS::Record qw( qsearchs );
6 use FS::part_svc;
7
8 our $cache_enabled = 0;
9
10 sub _simplecache {
11   my( $self, $hashref ) = @_;
12   if ( $cache_enabled && $hashref->{'svc'} ) {
13     $self->{'_svcpart'} = FS::part_svc->new($hashref);
14   }
15 }
16
17 =head1 NAME
18
19 FS::pkg_svc - Object methods for pkg_svc records
20
21 =head1 SYNOPSIS
22
23   use FS::pkg_svc;
24
25   $record = new FS::pkg_svc \%hash;
26   $record = new FS::pkg_svc { 'column' => 'value' };
27
28   $error = $record->insert;
29
30   $error = $new_record->replace($old_record);
31
32   $error = $record->delete;
33
34   $error = $record->check;
35
36   $part_pkg = $record->part_pkg;
37
38   $part_svc = $record->part_svc;
39
40 =head1 DESCRIPTION
41
42 An FS::pkg_svc record links a billing item definition (see L<FS::part_pkg>) to
43 a service definition (see L<FS::part_svc>).  FS::pkg_svc inherits from
44 FS::Record.  The following fields are currently supported:
45
46 =over 4
47
48 =item pkgsvcnum - primary key
49
50 =item pkgpart - Billing item definition (see L<FS::part_pkg>)
51
52 =item svcpart - Service definition (see L<FS::part_svc>)
53
54 =item quantity - Quantity of this service definition that this billing item
55 definition includes
56
57 =item primary_svc - primary flag, empty or 'Y'
58
59 =item hidden - 'Y' to hide this service on invoices, null otherwise.
60
61 =item provision_hold - 'Y' to release package hold when all services marked with this are provisioned
62
63 =back
64
65 =head1 METHODS
66
67 =over 4
68
69 =item new HASHREF
70
71 Create a new record.  To add the record to the database, see L<"insert">.
72
73 =cut
74
75 sub table { 'pkg_svc'; }
76
77 =item insert
78
79 Adds this record to the database.  If there is an error, returns the error,
80 otherwise returns false.
81
82 =item delete
83
84 Deletes this record from the database.  If there is an error, returns the
85 error, otherwise returns false.
86
87 =item replace OLD_RECORD
88
89 Replaces OLD_RECORD with this one in the database.  If there is an error,
90 returns the error, otherwise returns false.
91
92 =cut
93
94 sub replace {
95   my( $new, $old ) = ( shift, shift );
96
97   $old = $new->replace_old unless defined($old);
98
99   return "Can't change pkgpart!" if $old->pkgpart != $new->pkgpart;
100   return "Can't change svcpart!" if $old->svcpart != $new->svcpart;
101
102   $new->SUPER::replace($old);
103 }
104
105 =item check
106
107 Checks all fields to make sure this is a valid record.  If there is an error,
108 returns the error, otherwise returns false.  Called by the insert and replace
109 methods.
110
111 =cut
112
113 sub check {
114   my $self = shift;
115
116   my $error;
117   $error =
118        $self->ut_numbern('pkgsvcnum')
119     || $self->ut_number('pkgpart')
120     || $self->ut_number('svcpart')
121     || $self->ut_number('quantity')
122     || $self->ut_enum('hidden', [ '', 'Y' ] )
123     || $self->ut_flag('provision_hold')
124   ;
125   return $error if $error;
126
127   return "Unknown pkgpart!" unless $self->part_pkg;
128   return "Unknown svcpart!" unless $self->part_svc;
129
130   if ( $self->dbdef_table->column('primary_svc') ) {
131     $error = $self->ut_enum('primary_svc', [ '', 'Y' ] );
132     return $error if $error;
133   }
134
135   $self->SUPER::check;
136 }
137
138 =item part_pkg
139
140 Returns the FS::part_pkg object (see L<FS::part_pkg>).
141
142 =item part_svc
143
144 Returns the FS::part_svc object (see L<FS::part_svc>).
145
146 =cut
147
148 sub part_svc {
149   my $self = shift;
150   return $self->{_svcpart} if $self->{_svcpart};
151   qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
152 }
153
154 =back
155
156 =head1 BUGS
157
158 =head1 SEE ALSO
159
160 L<FS::Record>, L<FS::part_pkg>, L<FS::part_svc>, schema.html from the base
161 documentation.
162
163 =cut
164
165 1;
166