estimate tax on quotations, #32489
[freeside.git] / FS / FS / quotation_pkg_tax.pm
1 package FS::quotation_pkg_tax;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cust_main_county;
7 use FS::quotation_pkg;
8
9 =head1 NAME
10
11 FS::quotation_pkg_tax - Object methods for quotation_pkg_tax records
12
13 =head1 SYNOPSIS
14
15   use FS::quotation_pkg_tax;
16
17   $record = new FS::quotation_pkg_tax \%hash;
18   $record = new FS::quotation_pkg_tax { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::quotation_pkg_tax object represents tax on a quoted package. 
31 FS::quotation_pkg_tax inherits from FS::Record (though it should eventually
32 inherit from some shared superclass of L<FS::cust_bill_pkg_tax_location>). 
33 The following fields are currently supported:
34
35 =over 4
36
37 =item quotationtaxnum - primary key
38
39 =item quotationpkgnum - the L<FS::quotation_pkg> record that the tax applies 
40 to.
41
42 =item itemdesc - the name of the tax
43
44 =item taxnum - the L<FS::cust_main_county> or L<FS::tax_rate> defining the 
45 tax.
46
47 =item taxtype - the class of the tax rate represented by C<taxnum>.
48
49 =item setup_amount - the amount of tax calculated on one-time charges
50
51 =item recur_amount - the amount of tax calculated on recurring charges
52
53 =back
54
55 =head1 METHODS
56
57 =over 4
58
59 =item new HASHREF
60
61 Creates a new estimated tax amount.  To add the record to the database, 
62 see L<"insert">.
63
64 =cut
65
66 sub table { 'quotation_pkg_tax'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =item delete
74
75 Delete this record from the database.
76
77 =item replace OLD_RECORD
78
79 Replaces the OLD_RECORD with this one in the database.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =item check
83
84 Checks all fields to make sure this is a valid example.  If there is
85 an error, returns the error, otherwise returns false.  Called by the insert
86 and replace methods.
87
88 =cut
89
90 sub check {
91   my $self = shift;
92
93   my $error = 
94     $self->ut_numbern('quotationtaxnum')
95     || $self->ut_foreign_key('quotationpkgnum', 'quotation_pkg', 'quotationpkgnum')
96     || $self->ut_text('itemdesc')
97     || $self->ut_number('taxnum')
98     || $self->ut_enum('taxtype', [ 'FS::cust_main_county', 'FS::tax_rate' ])
99     || $self->ut_money('setup_amount')
100     || $self->ut_money('recur_amount')
101   ;
102   return $error if $error;
103
104   $self->SUPER::check;
105 }
106
107 =back
108
109 =head1 SEE ALSO
110
111 L<FS::Record>, schema.html from the base documentation.
112
113 =cut
114
115 1;
116