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