e41d7c12c965f6244da99a5de7346b7294c88b23
[freeside.git] / site_perl / cust_bill_pkg.pm
1 package FS::cust_bill_pkg;
2
3 use strict;
4 use vars qw(@ISA @EXPORT_OK);
5 use Exporter;
6 use FS::Record qw(fields qsearchs);
7
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(fields);
10
11 =head1 NAME
12
13 FS::cust_bill_pkg - Object methods for cust_bill_pkg records
14
15 =head1 SYNOPSIS
16
17   use FS::cust_bill_pkg;
18
19   $record = create FS::cust_bill_pkg \%hash;
20   $record = create FS::cust_bill_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::cust_bill_pkg object represents an invoice line item.
33 FS::cust_bill_pkg inherits from FS::Record.  The following fields are currently
34 supported:
35
36 =over 4
37
38 =item invnum - invoice (see L<FS::cust_bill>)
39
40 =item pkgnum - package (see L<FS::cust_pkg>)
41
42 =item setup - setup fee
43
44 =item recur - recurring fee
45
46 =item sdate - starting date of recurring fee
47
48 =item edate - ending date of recurring fee
49
50 =back
51
52 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">.  Also
53 see L<Time::Local> and L<Date::Parse> for conversion functions.
54
55 =head1 METHODS
56
57 =over 4
58
59 =item create HASHREF
60
61 Creates a new line item.  To add the line item to the database, see
62 L<"insert">.  Line items are normally created by calling the bill method of a
63 customer object (see L<FS::cust_main>).
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('cust_bill_pkg')) {
73   #  $hashref->{$field}='' unless defined $hashref->{$field};
74   #}
75
76   $proto->new('cust_bill_pkg',$hashref);
77
78 }
79
80 =item insert
81
82 Adds this line item to the database.  If there is an error, returns the error,
83 otherwise returns false.
84
85 =cut
86
87 sub insert {
88   my($self)=@_;
89
90   $self->check or
91   $self->add;
92 }
93
94 =item delete
95
96 Currently unimplemented.  I don't remove line items because there would then be
97 no record the items ever existed (which is bad, no?)
98
99 =cut
100
101 sub delete {
102   return "Can't delete cust_bill_pkg records!";
103   #my($self)=@_;
104   #$self->del;
105 }
106
107 =item replace OLD_RECORD
108
109 Currently unimplemented.  This would be even more of an accounting nightmare
110 than deleteing the items.  Just don't do it.
111
112 =cut
113
114 sub replace {
115   return "Can't modify cust_bill_pkg records!";
116   #my($new,$old)=@_;
117   #return "(Old) Not a cust_bill_pkg record!" 
118   #  unless $old->table eq "cust_bill_pkg";
119   #
120   #$new->check or
121   #$new->rep($old);
122 }
123
124 =item check
125
126 Checks all fields to make sure this is a valid line item.  If there is an
127 error, returns the error, otherwise returns false.  Called by the insert
128 method.
129
130 =cut
131
132 sub check {
133   my($self)=@_;
134   return "Not a cust_bill_pkg record!" unless $self->table eq "cust_bill_pkg";
135
136   my($error)=
137     $self->ut_number('pkgnum')
138       or $self->ut_number('invnum')
139       or $self->ut_money('setup')
140       or $self->ut_money('recur')
141       or $self->ut_numbern('sdate')
142       or $self->ut_numbern('edate')
143   ;
144   return $error if $error;
145
146   if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
147     return "Unknown pkgnum ".$self->pkgnum
148     unless qsearchs('cust_pkg',{'pkgnum'=> $self->pkgnum });
149   }
150
151   return "Unknown invnum"
152     unless qsearchs('cust_bill',{'invnum'=> $self->invnum });
153
154   ''; #no error
155 }
156
157 =back
158
159 =head1 BUGS
160
161 It doesn't properly override FS::Record yet.
162
163 =head1 SEE ALSO
164
165 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
166 from the base documentation.
167
168 =head1 HISTORY
169
170 ivan@sisd.com 98-mar-13
171
172 pod ivan@sisd.com 98-sep-21
173
174 =cut
175
176 1;
177