1 package FS::svc_acct_rt_transaction;
5 use FS::Record qw( qsearch qsearchs dbh );
11 FS::svc_acct_rt_transaction - Object methods for svc_acct_rt_transaction records
15 use FS::svc_acct_rt_transaction;
17 $record = new FS::svc_acct_rt_transaction \%hash;
18 $record = new FS::svc_acct_rt_transaction { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::svc_acct_rt_transaction object represents an application of time
31 from a rt transaction to a svc_acct. FS::svc_acct_rt_transaction inherits from
32 FS::Record. The following fields are currently supported:
36 =item svcrtid - primary key
38 =item svcnum - the svcnum of the svc_acct to which the time applies
40 =item transaction_id - the id of the rt transtaction from which the time applies
42 =item seconds - the amount of time which applies
53 Creates a new svc_acct_rt_transaction. To add the example to the database, see L<"insert">.
55 Note that this stores the hash reference, not a distinct copy of the hash it
56 points to. You can ask the object for a copy with the I<hash> method.
60 sub table { 'svc_acct_rt_transaction'; }
64 Adds this record to the database. If there is an error, returns the error,
65 otherwise returns false.
70 my( $self, %options ) = @_;
72 local $SIG{HUP} = 'IGNORE';
73 local $SIG{INT} = 'IGNORE';
74 local $SIG{QUIT} = 'IGNORE';
75 local $SIG{TERM} = 'IGNORE';
76 local $SIG{TSTP} = 'IGNORE';
77 local $SIG{PIPE} = 'IGNORE';
79 my $oldAutoCommit = $FS::UID::AutoCommit;
80 local $FS::UID::AutoCommit = 0;
83 my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ());
85 $dbh->rollback if $oldAutoCommit;
89 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
91 $dbh->rollback if $oldAutoCommit;
92 return "Can't find svc_acct " . $self->svcnum;
95 my $error = $svc_acct->decrement_seconds($self->seconds);
97 $dbh->rollback if $oldAutoCommit;
98 return "Error incrementing service seconds: $error";
101 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
109 Delete this record from the database.
116 local $SIG{HUP} = 'IGNORE';
117 local $SIG{INT} = 'IGNORE';
118 local $SIG{QUIT} = 'IGNORE';
119 local $SIG{TERM} = 'IGNORE';
120 local $SIG{TSTP} = 'IGNORE';
121 local $SIG{PIPE} = 'IGNORE';
123 my $oldAutoCommit = $FS::UID::AutoCommit;
124 local $FS::UID::AutoCommit = 0;
127 my $error = $self->SUPER::delete;
129 $dbh->rollback if $oldAutoCommit;
133 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
135 $dbh->rollback if $oldAutoCommit;
136 return "Can't find svc_acct " . $self->svcnum;
139 my $error = $svc_acct->increment_seconds($self->seconds);
141 $dbh->rollback if $oldAutoCommit;
142 return "Error incrementing service seconds: $error";
145 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
150 =item replace OLD_RECORD
152 Replaces the OLD_RECORD with this one in the database. If there is an error,
153 returns the error, otherwise returns false.
159 Checks all fields to make sure this is a valid svc_acct_rt_transaction. If there is
160 an error, returns the error, otherwise returns false. Called by the insert
168 my ($selfref) = $self->hashref;
171 $self->ut_numbern('svcrtid')
172 || $self->ut_numbern('svcnum')
173 || $self->ut_number('transaction_id')
174 || $self->ut_numbern('_date')
175 || $self->ut_snumber('seconds')
177 return $error if $error;
179 $self->_date(time) unless $self->_date;
181 if ($selfref->{custnum}) {
182 my $conf = new FS::Conf;
183 my %packages = map { $_ => 1 } $conf->config('support_packages');
184 my $cust_main = qsearchs('cust_main',{ 'custnum' => $selfref->{custnum} } );
185 return "Invalid custnum: " . $selfref->{custnum} unless $cust_main;
187 my (@svcs) = map { $_->svcnum } $cust_main->support_services;
188 return "svcnum ". $self->svcnum. " invalid for custnum ".$selfref->{custnum}
189 unless (!$self->svcnum || scalar(grep { $_ == $self->svcnum } @svcs));
191 $self->svcnum($svcs[0]) unless $self->svcnum;
192 return "Can't find support service for custnum ".$selfref->{custnum}
193 unless $self->svcnum;
199 =item batch_insert SVC_ACCT_RT_TRANSACTION_OBJECT, ...
201 Class method which inserts multiple time applications. Takes a list of
202 FS::svc_acct_rt_transaction objects. If there is an error inserting any
203 application, the entire transaction is rolled back, i.e. all time is applied
208 my $errors = FS::svc_acct_rt_transaction->batch_insert(@transactions);
210 #success; all payments were inserted
212 #failure; no payments were inserted.
218 my $self = shift; #class method
220 local $SIG{HUP} = 'IGNORE';
221 local $SIG{INT} = 'IGNORE';
222 local $SIG{QUIT} = 'IGNORE';
223 local $SIG{TERM} = 'IGNORE';
224 local $SIG{TSTP} = 'IGNORE';
225 local $SIG{PIPE} = 'IGNORE';
227 my $oldAutoCommit = $FS::UID::AutoCommit;
228 local $FS::UID::AutoCommit = 0;
238 $dbh->rollback if $oldAutoCommit;
240 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
251 Possibly the delete method or others.
255 L<FS::Record>, schema.html from the base documentation.