1 package FS::cust_bill_pkg_void;
2 use base qw( FS::TemplateItem_Mixin FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh fields );
6 use FS::cust_bill_void;
7 use FS::cust_bill_pkg_detail;
8 use FS::cust_bill_pkg_display;
9 use FS::cust_bill_pkg_discount;
10 use FS::cust_bill_pkg;
11 use FS::cust_bill_pkg_fee;
12 use FS::cust_bill_pkg_tax_location;
13 use FS::cust_bill_pkg_tax_rate_location;
14 use FS::cust_tax_exempt_pkg;
19 FS::cust_bill_pkg_void - Object methods for cust_bill_pkg_void records
23 use FS::cust_bill_pkg_void;
25 $record = new FS::cust_bill_pkg_void \%hash;
26 $record = new FS::cust_bill_pkg_void { 'column' => 'value' };
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
38 An FS::cust_bill_pkg_void object represents a voided invoice line item.
39 FS::cust_bill_pkg_void inherits from FS::Record. The following fields are
56 =item pkgpart_override
117 Creates a new record. To add the record to the database, see L<"insert">.
119 Note that this stores the hash reference, not a distinct copy of the hash it
120 points to. You can ask the object for a copy with the I<hash> method.
124 sub table { 'cust_bill_pkg_void'; }
126 sub detail_table { 'cust_bill_pkg_detail_void'; }
127 sub display_table { 'cust_bill_pkg_display_void'; }
128 sub discount_table { 'cust_bill_pkg_discount_void'; }
129 #sub tax_location_table { 'cust_bill_pkg_tax_location'; }
130 #sub tax_rate_location_table { 'cust_bill_pkg_tax_rate_location'; }
131 #sub tax_exempt_pkg_table { 'cust_tax_exempt_pkg'; }
135 Adds this record to the database. If there is an error, returns the error,
136 otherwise returns false.
140 "Un-void"s this line item: Deletes the voided line item from the database and
141 adds back a normal line item (and related tables).
148 local $SIG{HUP} = 'IGNORE';
149 local $SIG{INT} = 'IGNORE';
150 local $SIG{QUIT} = 'IGNORE';
151 local $SIG{TERM} = 'IGNORE';
152 local $SIG{TSTP} = 'IGNORE';
153 local $SIG{PIPE} = 'IGNORE';
155 my $oldAutoCommit = $FS::UID::AutoCommit;
156 local $FS::UID::AutoCommit = 0;
159 my $cust_bill_pkg = new FS::cust_bill_pkg ( {
160 map { $_ => $self->get($_) } fields('cust_bill_pkg')
162 my $error = $cust_bill_pkg->insert;
164 $dbh->rollback if $oldAutoCommit;
168 foreach my $table (qw(
170 cust_bill_pkg_display
171 cust_bill_pkg_discount
172 cust_bill_pkg_tax_location
173 cust_bill_pkg_tax_rate_location
179 qsearch($table.'_void', { billpkgnum=>$self->billpkgnum })
182 my $class = 'FS::'.$table;
183 my $unvoid = $class->new( {
184 map { $_ => $voided->get($_) } fields($table)
186 my $error = $unvoid->insert || $voided->delete;
188 $dbh->rollback if $oldAutoCommit;
196 $error = $self->delete;
198 $dbh->rollback if $oldAutoCommit;
202 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
210 Delete this record from the database.
212 =item replace OLD_RECORD
214 Replaces the OLD_RECORD with this one in the database. If there is an error,
215 returns the error, otherwise returns false.
219 Checks all fields to make sure this is a valid record. If there is
220 an error, returns the error, otherwise returns false. Called by the insert
229 $self->ut_number('billpkgnum')
230 || $self->ut_snumber('pkgnum')
231 || $self->ut_number('invnum') #cust_bill or cust_bill_void, if we ever support line item voiding
232 || $self->ut_numbern('pkgpart_override')
233 || $self->ut_money('setup')
234 || $self->ut_money('recur')
235 || $self->ut_numbern('sdate')
236 || $self->ut_numbern('edate')
237 || $self->ut_textn('itemdesc')
238 || $self->ut_textn('itemcomment')
239 || $self->ut_textn('section')
240 || $self->ut_textn('freq')
241 || $self->ut_numbern('quantity')
242 || $self->ut_moneyn('unitsetup')
243 || $self->ut_moneyn('unitrecur')
244 || $self->ut_enum('hidden', [ '', 'Y' ])
245 || $self->ut_numbern('feepart')
247 return $error if $error;
254 Returns the voided invoice (see L<FS::cust_bill_void>) for this voided line
261 #cust_bill or cust_bill_void, if we ever support line item voiding
262 qsearchs( 'cust_bill_void', { 'invnum' => $self->invnum } );
265 sub cust_bill_pkg_fee {
267 qsearch( 'cust_bill_pkg_fee_void', { 'billpkgnum' => $self->billpkgnum } );
272 # Used by FS::Upgrade to migrate to a new database.
273 sub _upgrade_data { # class method
274 my ($class, %opts) = @_;
277 # fix voids with tax from before July 2013, when the taxable_billpkgnum
278 # field was added to the void table
279 local $FS::Record::nowarn_classload = 1;
280 my $search = FS::Cursor->new({
281 'table' => 'cust_bill_pkg_tax_location_void',
282 'hashref' => { 'taxable_billpkgnum' => '' }
284 while (my $void = $search->fetch) {
285 # the history for the unvoided record should have the correct
287 my $num = $void->billpkgtaxlocationnum;
288 my $unvoid = qsearchs({
289 'table' => 'h_cust_bill_pkg_tax_location',
290 'hashref' => { 'billpkgtaxlocationnum' => $num },
291 'extra_sql' => ' AND taxable_billpkgnum IS NOT NULL',
292 'order_by' => ' ORDER BY history_date DESC LIMIT 1'
295 # should never happen
296 # but should this be fatal? or wait until someone actually tries to
298 warn "billpkgtaxlocationnum $num: could not find pre-void history record to restore taxable_billpkgnum.";
301 $void->set('taxable_billpkgnum', $unvoid->taxable_billpkgnum);
302 $error = $void->replace;
303 die "billpkgtaxlocationnum $num: $error\n" if $error;
315 L<FS::Record>, schema.html from the base documentation.