72f9ce4a938405cd9e63089bb4e3def475963ece
[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 =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 new 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 table { 'cust_bill_pkg'; }
68
69 =item insert
70
71 Adds this line item to the database.  If there is an error, returns the error,
72 otherwise returns false.
73
74 =item delete
75
76 Currently unimplemented.  I don't remove line items because there would then be
77 no record the items ever existed (which is bad, no?)
78
79 =cut
80
81 sub delete {
82   return "Can't delete cust_bill_pkg records!";
83 }
84
85 =item replace OLD_RECORD
86
87 Currently unimplemented.  This would be even more of an accounting nightmare
88 than deleteing the items.  Just don't do it.
89
90 =cut
91
92 sub replace {
93   return "Can't modify cust_bill_pkg records!";
94 }
95
96 =item check
97
98 Checks all fields to make sure this is a valid line item.  If there is an
99 error, returns the error, otherwise returns false.  Called by the insert
100 method.
101
102 =cut
103
104 sub check {
105   my $self = shift;
106
107   my $error =
108     $self->ut_number('pkgnum')
109       || $self->ut_number('invnum')
110       || $self->ut_money('setup')
111       || $self->ut_money('recur')
112       || $self->ut_numbern('sdate')
113       || $self->ut_numbern('edate')
114   ;
115   return $error if $error;
116
117   if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
118     return "Unknown pkgnum ". $self->pkgnum
119       unless qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
120   }
121
122   return "Unknown invnum"
123     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
124
125   ''; #no error
126 }
127
128 =item cust_pkg
129
130 Returns the package (see L<FS::cust_pkg>) for this invoice line item.
131
132 =cut
133
134 sub cust_pkg {
135   my $self = shift;
136   qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
137 }
138
139 =back
140
141 =head1 VERSION
142
143 $Id: cust_bill_pkg.pm,v 1.3 2002-04-06 22:32:43 ivan Exp $
144
145 =head1 BUGS
146
147 =head1 SEE ALSO
148
149 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
150 from the base documentation.
151
152 =cut
153
154 1;
155