4643b9f1581e6dc1dfe7a812113c346f646f12f8
[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   $custom_record = $template_record->clone;
23
24   $error = $record->insert;
25
26   $error = $new_record->replace($old_record);
27
28   $error = $record->delete;
29
30   $error = $record->check;
31
32 =head1 DESCRIPTION
33
34 An FS::part_pkg represents a billing item definition.  FS::part_pkg inherits
35 from FS::Record.  The following fields are currently supported:
36
37 =over 4
38
39 =item pkgpart - primary key (assigned automatically for new billing item definitions)
40
41 =item pkg - Text name of this billing item definition (customer-viewable)
42
43 =item comment - Text name of this billing item definition (non-customer-viewable)
44
45 =item setup - Setup fee
46
47 =item freq - Frequency of recurring fee
48
49 =item recur - Recurring fee
50
51 =back
52
53 setup and recur are evaluated as Safe perl expressions.  You can use numbers
54 just as you would normally.  More advanced semantics are not yet defined.
55
56 =head1 METHODS
57
58 =over 4 
59
60 =item create HASHREF
61
62 Creates a new billing item definition.  To add the billing item definition to
63 the database, see L<"insert">.
64
65 =cut
66
67 sub create {
68   my($proto,$hashref)=@_;
69
70   #now in FS::Record::new
71   #my($field);
72   #foreach $field (fields('part_pkg')) {
73   #  $hashref->{$field}='' unless defined $hashref->{$field};
74   #}
75
76   $proto->new('part_pkg',$hashref);
77 }
78
79 =item clone
80
81 Creates a new billing item definition by duplicating an existing definition.
82 A new pkgpart is assigned and "(CUSTOM) " is prepended to the comment field.
83 To add the billing item definition to the database, see L<"insert">.
84
85 =cut
86
87 sub clone {
88   my $self = shift;
89   my %hash = $self->hash;
90   $hash{'pkgpart'} = '';
91   $hash{'comment'} = "(CUSTOM) ". $hash{'comment'}
92     unless $hash{'comment'} =~ /^\(CUSTOM\) /;
93   create FS::part_pkg ( \%hash ); # ?
94 }
95
96 =item insert
97
98 Adds this billing item definition to the database.  If there is an error,
99 returns the error, otherwise returns false.
100
101 =cut
102
103 sub insert {
104   my($self)=@_;
105
106   $self->check or
107   $self->add;
108 }
109
110 =item delete
111
112 Currently unimplemented.
113
114 =cut
115
116 sub delete {
117   return "Can't (yet?) delete package definitions.";
118 # maybe check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
119 #  my($self)=@_;
120 #
121 #  $self->del;
122 }
123
124 =item replace OLD_RECORD
125
126 Replaces OLD_RECORD with this one in the database.  If there is an error,
127 returns the error, otherwise returns false.
128
129 =cut
130
131 sub replace {
132   my($new,$old)=@_;
133   return "(Old) Not a part_pkg record!" unless $old->table eq "part_pkg";
134   return "Can't change pkgpart!"
135     unless $old->getfield('pkgpart') eq $new->getfield('pkgpart');
136   $new->check or
137   $new->rep($old);
138 }
139
140 =item check
141
142 Checks all fields to make sure this is a valid billing item definition.  If
143 there is an error, returns the error, otherwise returns false.  Called by the
144 insert and replace methods.
145
146 =cut
147
148 sub check {
149   my($self)=@_;
150   return "Not a part_pkg record!" unless $self->table eq "part_pkg";
151
152   $self->ut_numbern('pkgpart')
153     or $self->ut_text('pkg')
154     or $self->ut_text('comment')
155     or $self->ut_anything('setup')
156     or $self->ut_number('freq')
157     or $self->ut_anything('recur')
158   ;
159
160 }
161
162 =back
163
164 =head1 VERSION
165
166 $Id: part_pkg.pm,v 1.3 1998-11-15 13:00:15 ivan Exp $
167
168 =head1 BUGS
169
170 It doesn't properly override FS::Record yet.
171
172 The delete method is unimplemented.
173
174 setup and recur semantics are not yet defined (and are implemented in
175 FS::cust_bill.  hmm.).
176
177 =head1 SEE ALSO
178
179 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
180 schema.html from the base documentation.
181
182 =head1 HISTORY
183
184 ivan@sisd.com 97-dec-5
185
186 pod ivan@sisd.com 98-sep-21
187
188 $Log: part_pkg.pm,v $
189 Revision 1.3  1998-11-15 13:00:15  ivan
190 bugfix in clone method, clone method doc clarification
191
192
193 =cut
194
195 1;
196