mostly properly OO, some work still to be done with svc_ stuff
[freeside.git] / site_perl / part_pkg.pm
1 package FS::part_pkg;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record;
6
7 @ISA = qw( FS::Record );
8
9 =head1 NAME
10
11 FS::part_pkg - Object methods for part_pkg objects
12
13 =head1 SYNOPSIS
14
15   use FS::part_pkg;
16
17   $record = new FS::part_pkg \%hash
18   $record = new FS::part_pkg { 'column' => 'value' };
19
20   $custom_record = $template_record->clone;
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 new 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 table { 'part_pkg'; }
66
67 =item clone
68
69 An alternate constructor.  Creates a new billing item definition by duplicating
70 an existing definition.  A new pkgpart is assigned and `(CUSTOM) ' is prepended
71 to the comment field.  To add the billing item definition to the database, see
72 L<"insert">.
73
74 =cut
75
76 sub clone {
77   my $self = shift;
78   my $class = ref($self);
79   my %hash = $self->hash;
80   $hash{'pkgpart'} = '';
81   $hash{'comment'} = "(CUSTOM) ". $hash{'comment'}
82     unless $hash{'comment'} =~ /^\(CUSTOM\) /;
83   #new FS::part_pkg ( \%hash ); # ?
84   new $class ( \%hash ); # ?
85 }
86
87 =item insert
88
89 Adds this billing item definition to the database.  If there is an error,
90 returns the error, otherwise returns false.
91
92 =item delete
93
94 Currently unimplemented.
95
96 =cut
97
98 sub delete {
99   return "Can't (yet?) delete package definitions.";
100 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
101 }
102
103 =item replace OLD_RECORD
104
105 Replaces OLD_RECORD with this one in the database.  If there is an error,
106 returns the error, otherwise returns false.
107
108 =item check
109
110 Checks all fields to make sure this is a valid billing item definition.  If
111 there is an error, returns the error, otherwise returns false.  Called by the
112 insert and replace methods.
113
114 =cut
115
116 sub check {
117   my $self = shift;
118
119   $self->ut_numbern('pkgpart')
120     || $self->ut_text('pkg')
121     || $self->ut_text('comment')
122     || $self->ut_anything('setup')
123     || $self->ut_number('freq')
124     || $self->ut_anything('recur')
125   ;
126 }
127
128 =back
129
130 =head1 VERSION
131
132 $Id: part_pkg.pm,v 1.4 1998-12-29 11:59:48 ivan Exp $
133
134 =head1 BUGS
135
136 The delete method is unimplemented.
137
138 setup and recur semantics are not yet defined (and are implemented in
139 FS::cust_bill.  hmm.).
140
141 =head1 SEE ALSO
142
143 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
144 schema.html from the base documentation.
145
146 =head1 HISTORY
147
148 ivan@sisd.com 97-dec-5
149
150 pod ivan@sisd.com 98-sep-21
151
152 $Log: part_pkg.pm,v $
153 Revision 1.4  1998-12-29 11:59:48  ivan
154 mostly properly OO, some work still to be done with svc_ stuff
155
156 Revision 1.3  1998/11/15 13:00:15  ivan
157 bugfix in clone method, clone method doc clarification
158
159
160 =cut
161
162 1;
163