1 package FS::acct_rt_transaction;
5 use FS::Record qw( qsearch qsearchs dbh );
11 FS::acct_rt_transaction - Object methods for acct_rt_transaction records
15 use FS::acct_rt_transaction;
17 $record = new FS::acct_rt_transaction \%hash;
18 $record = new FS::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::acct_rt_transaction object represents an application of time
31 from a rt transaction to a svc_acct. FS::acct_rt_transaction inherits from
32 FS::Record. The following fields are currently supported:
42 The svcnum of the svc_acct to which the time applies
46 The id of the rt transtaction from which the time applies
50 The amount of time applied from tickets
54 The amount of time applied to support services
64 Creates a new acct_rt_transaction. To add the example to the database, see L<"insert">.
66 Note that this stores the hash reference, not a distinct copy of the hash it
67 points to. You can ask the object for a copy with the I<hash> method.
71 sub table { 'acct_rt_transaction'; }
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
81 my( $self, %options ) = @_;
83 local $SIG{HUP} = 'IGNORE';
84 local $SIG{INT} = 'IGNORE';
85 local $SIG{QUIT} = 'IGNORE';
86 local $SIG{TERM} = 'IGNORE';
87 local $SIG{TSTP} = 'IGNORE';
88 local $SIG{PIPE} = 'IGNORE';
90 my $oldAutoCommit = $FS::UID::AutoCommit;
91 local $FS::UID::AutoCommit = 0;
94 my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ());
96 $dbh->rollback if $oldAutoCommit;
100 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
102 $dbh->rollback if $oldAutoCommit;
103 return "Can't find svc_acct " . $self->svcnum;
106 $error = $svc_acct->decrement_seconds($self->support);
108 $dbh->rollback if $oldAutoCommit;
109 return "Error incrementing service seconds: $error";
112 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
120 Delete this record from the database.
127 local $SIG{HUP} = 'IGNORE';
128 local $SIG{INT} = 'IGNORE';
129 local $SIG{QUIT} = 'IGNORE';
130 local $SIG{TERM} = 'IGNORE';
131 local $SIG{TSTP} = 'IGNORE';
132 local $SIG{PIPE} = 'IGNORE';
134 my $oldAutoCommit = $FS::UID::AutoCommit;
135 local $FS::UID::AutoCommit = 0;
138 my $error = $self->SUPER::delete;
140 $dbh->rollback if $oldAutoCommit;
144 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
146 $dbh->rollback if $oldAutoCommit;
147 return "Can't find svc_acct " . $self->svcnum;
150 $error = $svc_acct->increment_seconds($self->support);
152 $dbh->rollback if $oldAutoCommit;
153 return "Error incrementing service seconds: $error";
156 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
161 =item replace OLD_RECORD
163 Replaces the OLD_RECORD with this one in the database. If there is an error,
164 returns the error, otherwise returns false.
170 Checks all fields to make sure this is a valid acct_rt_transaction. If there is
171 an error, returns the error, otherwise returns false. Called by the insert
179 my ($selfref) = $self->hashref;
182 $self->ut_numbern('svcrtid')
183 || $self->ut_numbern('svcnum')
184 || $self->ut_number('transaction_id')
185 || $self->ut_numbern('_date')
186 || $self->ut_snumber('seconds')
187 || $self->ut_snumber('support')
189 return $error if $error;
191 $self->_date(time) unless $self->_date;
193 if ($selfref->{custnum}) {
194 my $conf = new FS::Conf;
195 my %packages = map { $_ => 1 } $conf->config('support_packages');
196 my $cust_main = qsearchs('cust_main',{ 'custnum' => $selfref->{custnum} } );
197 return "Invalid custnum: " . $selfref->{custnum} unless $cust_main;
199 my (@svcs) = map { $_->svcnum } $cust_main->support_services;
200 return "svcnum ". $self->svcnum. " invalid for custnum ".$selfref->{custnum}
201 unless (!$self->svcnum || scalar(grep { $_ == $self->svcnum } @svcs));
203 $self->svcnum($svcs[0]) unless $self->svcnum;
204 return "Can't find support service for custnum ".$selfref->{custnum}
205 unless $self->svcnum;
213 Returns the creator of the RT transaction associated with this object.
219 FS::TicketSystem->transaction_creator($self->transaction_id);
224 Returns the number of the RT ticket associated with this object.
230 FS::TicketSystem->transaction_ticketid($self->transaction_id);
235 Returns the subject of the RT ticket associated with this object.
241 FS::TicketSystem->transaction_subject($self->transaction_id);
246 Returns the status of the RT ticket associated with this object.
252 FS::TicketSystem->transaction_status($self->transaction_id);
255 =item batch_insert SVC_ACCT_RT_TRANSACTION_OBJECT, ...
257 Class method which inserts multiple time applications. Takes a list of
258 FS::acct_rt_transaction objects. If there is an error inserting any
259 application, the entire transaction is rolled back, i.e. all time is applied
264 my $errors = FS::acct_rt_transaction->batch_insert(@transactions);
266 #success; all payments were inserted
268 #failure; no payments were inserted.
274 my $self = shift; #class method
276 local $SIG{HUP} = 'IGNORE';
277 local $SIG{INT} = 'IGNORE';
278 local $SIG{QUIT} = 'IGNORE';
279 local $SIG{TERM} = 'IGNORE';
280 local $SIG{TSTP} = 'IGNORE';
281 local $SIG{PIPE} = 'IGNORE';
283 my $oldAutoCommit = $FS::UID::AutoCommit;
284 local $FS::UID::AutoCommit = 0;
294 $dbh->rollback if $oldAutoCommit;
296 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
307 Possibly the delete method or others.
311 L<FS::Record>, schema.html from the base documentation.