5a1dcd2aa32608b8b811671b70da93a878ec8277
[freeside.git] / FS / FS / cust_bill_pkg.pm
1 package FS::cust_bill_pkg;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::cust_pkg;
7 use FS::cust_bill;
8
9 @ISA = qw(FS::Record );
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 = new FS::cust_bill_pkg \%hash;
20   $record = new 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>) or 0 for the special virtual sales tax package
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 =item itemdesc - Line item description (currentlty used only when pkgnum is 0)
51
52 =back
53
54 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">.  Also
55 see L<Time::Local> and L<Date::Parse> for conversion functions.
56
57 =head1 METHODS
58
59 =over 4
60
61 =item new HASHREF
62
63 Creates a new line item.  To add the line item to the database, see
64 L<"insert">.  Line items are normally created by calling the bill method of a
65 customer object (see L<FS::cust_main>).
66
67 =cut
68
69 sub table { 'cust_bill_pkg'; }
70
71 =item insert
72
73 Adds this line item to the database.  If there is an error, returns the error,
74 otherwise returns false.
75
76 =item delete
77
78 Currently unimplemented.  I don't remove line items because there would then be
79 no record the items ever existed (which is bad, no?)
80
81 =cut
82
83 sub delete {
84   return "Can't delete cust_bill_pkg records!";
85 }
86
87 =item replace OLD_RECORD
88
89 Currently unimplemented.  This would be even more of an accounting nightmare
90 than deleteing the items.  Just don't do it.
91
92 =cut
93
94 sub replace {
95   return "Can't modify cust_bill_pkg records!";
96 }
97
98 =item check
99
100 Checks all fields to make sure this is a valid line item.  If there is an
101 error, returns the error, otherwise returns false.  Called by the insert
102 method.
103
104 =cut
105
106 sub check {
107   my $self = shift;
108
109   my $error =
110     $self->ut_number('pkgnum')
111       || $self->ut_number('invnum')
112       || $self->ut_money('setup')
113       || $self->ut_money('recur')
114       || $self->ut_numbern('sdate')
115       || $self->ut_numbern('edate')
116       || $self->ut_textn('itemdesc')
117   ;
118   return $error if $error;
119
120   if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
121     return "Unknown pkgnum ". $self->pkgnum
122       unless qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
123   }
124
125   return "Unknown invnum"
126     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
127
128   ''; #no error
129 }
130
131 =item cust_pkg
132
133 Returns the package (see L<FS::cust_pkg>) for this invoice line item.
134
135 =cut
136
137 sub cust_pkg {
138   my $self = shift;
139   qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
140 }
141
142 =back
143
144 =head1 VERSION
145
146 $Id: cust_bill_pkg.pm,v 1.4 2002-09-21 11:17:39 ivan Exp $
147
148 =head1 BUGS
149
150 =head1 SEE ALSO
151
152 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
153 from the base documentation.
154
155 =cut
156
157 1;
158