1 package FS::part_pkg_taxclass;
6 use FS::Record qw( qsearch qsearchs );
12 FS::part_pkg_taxclass - Object methods for part_pkg_taxclass records
16 use FS::part_pkg_taxclass;
18 $record = new FS::part_pkg_taxclass \%hash;
19 $record = new FS::part_pkg_taxclass { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::part_pkg_taxclass object represents a tax class. FS::part_pkg_taxclass
32 inherits from FS::Record. The following fields are currently supported:
52 Creates a new tax class. To add the tax class to the database, see L<"insert">.
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to. You can ask the object for a copy with the I<hash> method.
59 # the new method can be inherited from FS::Record, if a table method is defined
61 sub table { 'part_pkg_taxclass'; }
65 Adds this record to the database. If there is an error, returns the error,
66 otherwise returns false.
70 # the insert method can be inherited from FS::Record
74 Delete this record from the database.
78 # the delete method can be inherited from FS::Record
80 =item replace OLD_RECORD
82 Replaces the OLD_RECORD with this one in the database. If there is an error,
83 returns the error, otherwise returns false.
87 # the replace method can be inherited from FS::Record
91 Checks all fields to make sure this is a valid tax class. If there is
92 an error, returns the error, otherwise returns false. Called by the insert
97 # the check method should currently be supplied - FS::Record contains some
98 # data checking routines
104 $self->ut_numbern('taxclassnum')
105 || $self->ut_text('taxclass')
107 return $error if $error;
118 # Used by FS::Upgrade to migrate to a new database.
120 sub _upgrade_data { # class method
121 my ($class, %opts) = @_;
123 my $sth = dbh->prepare('
124 SELECT DISTINCT taxclass
125 FROM cust_main_county
126 LEFT JOIN part_pkg_taxclass USING ( taxclass )
127 WHERE taxclassnum IS NULL
128 AND taxclass IS NOT NULL
129 ') or die dbh->errstr;
130 $sth->execute or die $sth->errstr;
131 my %taxclass = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
132 my @taxclass = grep $_, keys %taxclass;
134 foreach my $taxclass ( @taxclass ) {
136 my $part_pkg_taxclass = new FS::part_pkg_taxclass ( {
137 'taxclass' => $taxclass,
139 my $error = $part_pkg_taxclass->insert;
140 die $error if $error;
148 Other tables (cust_main_county, part_pkg, agent_payment_gateway) have a text
149 taxclass instead of a key to this table.
153 L<FS::Record>, schema.html from the base documentation.