1 package FS::cust_bill_pkg_void;
2 use base qw( FS::TemplateItem_Mixin FS::reason_Mixin FS::Record );
5 use vars qw( $me $DEBUG );
6 use FS::Record qw( qsearch qsearchs dbh fields );
7 use FS::cust_bill_void;
8 use FS::cust_bill_pkg_detail;
9 use FS::cust_bill_pkg_display;
10 use FS::cust_bill_pkg_discount;
11 use FS::cust_bill_pkg;
12 use FS::cust_bill_pkg_fee;
13 use FS::cust_bill_pkg_tax_location;
14 use FS::cust_bill_pkg_tax_rate_location;
15 use FS::cust_tax_exempt_pkg;
18 $me = '[ FS::cust_bill_pkg_void ]';
23 FS::cust_bill_pkg_void - Object methods for cust_bill_pkg_void records
27 use FS::cust_bill_pkg_void;
29 $record = new FS::cust_bill_pkg_void \%hash;
30 $record = new FS::cust_bill_pkg_void { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
42 An FS::cust_bill_pkg_void object represents a voided invoice line item.
43 FS::cust_bill_pkg_void inherits from FS::Record. The following fields are
60 =item pkgpart_override
114 freeform string (deprecated)
118 reason for voiding the payment (see L<FS::reson>)
128 Creates a new record. To add the record to the database, see L<"insert">.
130 Note that this stores the hash reference, not a distinct copy of the hash it
131 points to. You can ask the object for a copy with the I<hash> method.
135 sub table { 'cust_bill_pkg_void'; }
137 sub detail_table { 'cust_bill_pkg_detail_void'; }
138 sub display_table { 'cust_bill_pkg_display_void'; }
139 sub discount_table { 'cust_bill_pkg_discount_void'; }
140 #sub tax_location_table { 'cust_bill_pkg_tax_location'; }
141 #sub tax_rate_location_table { 'cust_bill_pkg_tax_rate_location'; }
142 #sub tax_exempt_pkg_table { 'cust_tax_exempt_pkg'; }
146 Adds this record to the database. If there is an error, returns the error,
147 otherwise returns false.
151 Returns the text of the associated void reason (see L<FS::reason>) for this.
155 "Un-void"s this line item: Deletes the voided line item from the database and
156 adds back a normal line item (and related tables).
163 local $SIG{HUP} = 'IGNORE';
164 local $SIG{INT} = 'IGNORE';
165 local $SIG{QUIT} = 'IGNORE';
166 local $SIG{TERM} = 'IGNORE';
167 local $SIG{TSTP} = 'IGNORE';
168 local $SIG{PIPE} = 'IGNORE';
170 my $oldAutoCommit = $FS::UID::AutoCommit;
171 local $FS::UID::AutoCommit = 0;
174 my $cust_bill_pkg = new FS::cust_bill_pkg ( {
175 map { $_ => $self->get($_) } fields('cust_bill_pkg')
177 my $error = $cust_bill_pkg->insert;
179 $dbh->rollback if $oldAutoCommit;
183 foreach my $table (qw(
185 cust_bill_pkg_display
186 cust_bill_pkg_discount
187 cust_bill_pkg_tax_location
188 cust_bill_pkg_tax_rate_location
194 qsearch($table.'_void', { billpkgnum=>$self->billpkgnum })
197 my $class = 'FS::'.$table;
198 my $unvoid = $class->new( {
199 map { $_ => $voided->get($_) } fields($table)
201 my $error = $unvoid->insert || $voided->delete;
203 $dbh->rollback if $oldAutoCommit;
211 $error = $self->delete;
213 $dbh->rollback if $oldAutoCommit;
217 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
225 Delete this record from the database.
227 =item replace OLD_RECORD
229 Replaces the OLD_RECORD with this one in the database. If there is an error,
230 returns the error, otherwise returns false.
234 Checks all fields to make sure this is a valid record. If there is
235 an error, returns the error, otherwise returns false. Called by the insert
244 $self->ut_number('billpkgnum')
245 || $self->ut_snumber('pkgnum')
246 || $self->ut_number('invnum') #cust_bill or cust_bill_void, if we ever support line item voiding
247 || $self->ut_numbern('pkgpart_override')
248 || $self->ut_money('setup')
249 || $self->ut_money('recur')
250 || $self->ut_numbern('sdate')
251 || $self->ut_numbern('edate')
252 || $self->ut_textn('itemdesc')
253 || $self->ut_textn('itemcomment')
254 || $self->ut_textn('section')
255 || $self->ut_textn('freq')
256 || $self->ut_numbern('quantity')
257 || $self->ut_moneyn('unitsetup')
258 || $self->ut_moneyn('unitrecur')
259 || $self->ut_enum('hidden', [ '', 'Y' ])
260 || $self->ut_numbern('feepart')
261 || $self->ut_textn('reason')
262 || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum')
264 return $error if $error;
271 Returns the voided invoice (see L<FS::cust_bill_void>) for this voided line
278 #cust_bill or cust_bill_void, if we ever support line item voiding
279 qsearchs( 'cust_bill_void', { 'invnum' => $self->invnum } );
282 sub cust_bill_pkg_fee {
284 qsearch( 'cust_bill_pkg_fee_void', { 'billpkgnum' => $self->billpkgnum } );
289 # Used by FS::Upgrade to migrate to a new database.
290 sub _upgrade_data { # class method
291 my ($class, %opts) = @_;
293 warn "$me upgrading $class\n" if $DEBUG;
295 $class->_upgrade_reasonnum(%opts);
297 # fix voids with tax from before July 2013, when the taxable_billpkgnum
298 # field was added to the void table
299 local $FS::Record::nowarn_classload = 1;
300 my $search = FS::Cursor->new({
301 'table' => 'cust_bill_pkg_tax_location_void',
302 'hashref' => { 'taxable_billpkgnum' => '' }
304 while (my $void = $search->fetch) {
305 # the history for the unvoided record should have the correct
307 my $num = $void->billpkgtaxlocationnum;
308 my $unvoid = qsearchs({
309 'table' => 'h_cust_bill_pkg_tax_location',
310 'hashref' => { 'billpkgtaxlocationnum' => $num },
311 'extra_sql' => ' AND taxable_billpkgnum IS NOT NULL',
312 'order_by' => ' ORDER BY history_date DESC LIMIT 1'
315 # should never happen
316 # but should this be fatal? or wait until someone actually tries to
318 warn "billpkgtaxlocationnum $num: could not find pre-void history record to restore taxable_billpkgnum.";
321 $void->set('taxable_billpkgnum', $unvoid->taxable_billpkgnum);
322 $error = $void->replace;
323 die "billpkgtaxlocationnum $num: $error\n" if $error;
335 L<FS::Record>, schema.html from the base documentation.