This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / site_perl / pkg_svc.pm
1 package FS::pkg_svc;
2
3 use strict;
4 use vars qw(@ISA @EXPORT_OK);
5 use Exporter;
6 use FS::Record qw(fields hfields qsearchs);
7
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(hfields);
10
11 =head1 NAME
12
13 FS::pkg_svc - Object methods for pkg_svc records
14
15 =head1 SYNOPSIS
16
17   use FS::pkg_svc;
18
19   $record = create FS::pkg_svc \%hash;
20   $record = create FS::pkg_svc { '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::pkg_svc record links a billing item definition (see L<FS::part_pkg>) to
33 a service definition (see L<FS::part_svc>).  FS::pkg_svc inherits from
34 FS::Record.  The following fields are currently supported:
35
36 =over 4
37
38 =item pkgpart - Billing item definition (see L<FS::part_pkg>)
39
40 =item svcpart - Service definition (see L<FS::part_svc>)
41
42 =item quantity - Quantity of this service definition that this billing item
43 definition includes
44
45 =back
46
47 =head1 METHODS
48
49 =over 4
50
51 =item create HASHREF
52
53 Create a new record.  To add the record to the database, see L<"insert">.
54
55 =cut
56
57 sub create {
58   my($proto,$hashref)=@_;
59
60   #now in FS::Record::new
61   #my($field);
62   #foreach $field (fields('pkg_svc')) {
63   #  $hashref->{$field}='' unless defined $hashref->{$field};
64   #}
65
66   $proto->new('pkg_svc',$hashref);
67
68 }
69
70 =item insert
71
72 Adds this record to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =cut
76
77 sub insert {
78   my($self)=@_;
79
80   $self->check or
81   $self->add;
82 }
83
84 =item delete
85
86 Deletes this record from the database.  If there is an error, returns the
87 error, otherwise returns false.
88
89 =cut
90
91 sub delete {
92   my($self)=@_;
93
94   $self->del;
95 }
96
97 =item replace OLD_RECORD
98
99 Replaces OLD_RECORD with this one in the database.  If there is an error,
100 returns the error, otherwise returns false.
101
102 =cut
103
104 sub replace {
105   my($new,$old)=@_;
106   return "(Old) Not a pkg_svc record!" unless $old->table eq "pkg_svc";
107   return "Can't change pkgpart!"
108     if $old->getfield('pkgpart') ne $new->getfield('pkgpart');
109   return "Can't change svcpart!"
110     if $old->getfield('svcpart') ne $new->getfield('svcpart');
111
112   $new->check or
113   $new->rep($old);
114 }
115
116 =item check
117
118 Checks all fields to make sure this is a valid record.  If there is an error,
119 returns the error, otherwise returns false.  Called by the insert and replace
120 methods.
121
122 =cut
123
124 sub check {
125   my($self)=@_;
126   return "Not a pkg_svc record!" unless $self->table eq "pkg_svc";
127   my($recref) = $self->hashref;
128
129   my($error);
130   return $error if $error =
131     $self->ut_number('pkgpart')
132     || $self->ut_number('svcpart')
133     || $self->ut_number('quantity')
134   ;
135
136   return "Unknown pkgpart!"
137     unless qsearchs('part_pkg',{'pkgpart'=> $self->getfield('pkgpart')});
138
139   return "Unknown svcpart!"
140     unless qsearchs('part_svc',{'svcpart'=> $self->getfield('svcpart')});
141
142   ''; #no error
143 }
144
145 =back
146
147 =head1 BUGS
148
149 It doesn't properly override FS::Record yet.
150
151 =head1 SEE ALSO
152
153 L<FS::Record>, L<FS::part_pkg>, L<FS::part_svc>, schema.html from the base
154 documentation.
155
156 =head1 HISTORY
157
158 ivan@voicenet.com 97-jul-1
159  
160 added hfields
161 ivan@sisd.com 97-nov-13
162
163 pod ivan@sisd.com 98-sep-22
164
165 =cut
166
167 1;
168