This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / site_perl / part_pkg.pm
1 package FS::part_pkg;
2
3 use strict;
4 use vars qw(@ISA @EXPORT_OK);
5 use Exporter;
6 use FS::Record qw(fields hfields);
7
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(hfields fields);
10
11 =head1 NAME
12
13 FS::part_pkg - Object methods for part_pkg objects
14
15 =head1 SYNOPSIS
16
17   use FS::part_pkg;
18
19   $record = create FS::part_pkg \%hash
20   $record = create FS::part_pkg { '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::part_pkg represents a billing item definition.  FS::part_pkg inherits
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item pkgpart - primary key (assigned automatically for new billing item definitions)
38
39 =item pkg - Text name of this billing item definition (customer-viewable)
40
41 =item comment - Text name of this billing item definition (non-customer-viewable)
42
43 =item setup - Setup fee
44
45 =item freq - Frequency of recurring fee
46
47 =item recur - Recurring fee
48
49 =back
50
51 setup and recur are evaluated as Safe perl expressions.  You can use numbers
52 just as you would normally.  More advanced semantics are not yet defined.
53
54 =head1 METHODS
55
56 =over 4 
57
58 =item create HASHREF
59
60 Creates a new billing item definition.  To add the billing item definition to
61 the database, see L<"insert">.
62
63 =cut
64
65 sub create {
66   my($proto,$hashref)=@_;
67
68   #now in FS::Record::new
69   #my($field);
70   #foreach $field (fields('part_pkg')) {
71   #  $hashref->{$field}='' unless defined $hashref->{$field};
72   #}
73
74   $proto->new('part_pkg',$hashref);
75 }
76
77 =item insert
78
79 Adds this billing item definition to the database.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =cut
83
84 sub insert {
85   my($self)=@_;
86
87   $self->check or
88   $self->add;
89 }
90
91 =item delete
92
93 Currently unimplemented.
94
95 =cut
96
97 sub delete {
98   return "Can't (yet?) delete package definitions.";
99 # maybe check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
100 #  my($self)=@_;
101 #
102 #  $self->del;
103 }
104
105 =item replace OLD_RECORD
106
107 Replaces OLD_RECORD with this one in the database.  If there is an error,
108 returns the error, otherwise returns false.
109
110 =cut
111
112 sub replace {
113   my($new,$old)=@_;
114   return "(Old) Not a part_pkg record!" unless $old->table eq "part_pkg";
115   return "Can't change pkgpart!"
116     unless $old->getfield('pkgpart') eq $new->getfield('pkgpart');
117   $new->check or
118   $new->rep($old);
119 }
120
121 =item check
122
123 Checks all fields to make sure this is a valid billing item definition.  If
124 there is an error, returns the error, otherwise returns false.  Called by the
125 insert and replace methods.
126
127 =cut
128
129 sub check {
130   my($self)=@_;
131   return "Not a part_pkg record!" unless $self->table eq "part_pkg";
132
133   $self->ut_numbern('pkgpart')
134     or $self->ut_text('pkg')
135     or $self->ut_text('comment')
136     or $self->ut_anything('setup')
137     or $self->ut_number('freq')
138     or $self->ut_anything('recur')
139   ;
140
141 }
142
143 =back
144
145 =head1 BUGS
146
147 It doesn't properly override FS::Record yet.
148
149 The delete method is unimplemented.
150
151 setup and recur semantics are not yet defined (and are implemented in
152 FS::cust_bill.  hmm.).
153
154 =head1 SEE ALSO
155
156 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
157 schema.html from the base documentation.
158
159 =head1 HISTORY
160
161 ivan@sisd.com 97-dec-5
162
163 pod ivan@sisd.com 98-sep-21
164
165 =cut
166
167 1;
168