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:
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 applied from tickets
44 =item support - the amount of time applied to support services
55 Creates a new acct_rt_transaction. To add the example to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 sub table { 'acct_rt_transaction'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
72 my( $self, %options ) = @_;
74 local $SIG{HUP} = 'IGNORE';
75 local $SIG{INT} = 'IGNORE';
76 local $SIG{QUIT} = 'IGNORE';
77 local $SIG{TERM} = 'IGNORE';
78 local $SIG{TSTP} = 'IGNORE';
79 local $SIG{PIPE} = 'IGNORE';
81 my $oldAutoCommit = $FS::UID::AutoCommit;
82 local $FS::UID::AutoCommit = 0;
85 my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ());
87 $dbh->rollback if $oldAutoCommit;
91 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
93 $dbh->rollback if $oldAutoCommit;
94 return "Can't find svc_acct " . $self->svcnum;
97 $error = $svc_acct->decrement_seconds($self->support);
99 $dbh->rollback if $oldAutoCommit;
100 return "Error incrementing service seconds: $error";
103 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
111 Delete this record from the database.
118 local $SIG{HUP} = 'IGNORE';
119 local $SIG{INT} = 'IGNORE';
120 local $SIG{QUIT} = 'IGNORE';
121 local $SIG{TERM} = 'IGNORE';
122 local $SIG{TSTP} = 'IGNORE';
123 local $SIG{PIPE} = 'IGNORE';
125 my $oldAutoCommit = $FS::UID::AutoCommit;
126 local $FS::UID::AutoCommit = 0;
129 my $error = $self->SUPER::delete;
131 $dbh->rollback if $oldAutoCommit;
135 my $svc_acct = qsearchs('svc_acct', {'svcnum' => $self->svcnum});
137 $dbh->rollback if $oldAutoCommit;
138 return "Can't find svc_acct " . $self->svcnum;
141 $error = $svc_acct->increment_seconds($self->support);
143 $dbh->rollback if $oldAutoCommit;
144 return "Error incrementing service seconds: $error";
147 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
152 =item replace OLD_RECORD
154 Replaces the OLD_RECORD with this one in the database. If there is an error,
155 returns the error, otherwise returns false.
161 Checks all fields to make sure this is a valid acct_rt_transaction. If there is
162 an error, returns the error, otherwise returns false. Called by the insert
170 my ($selfref) = $self->hashref;
173 $self->ut_numbern('svcrtid')
174 || $self->ut_numbern('svcnum')
175 || $self->ut_number('transaction_id')
176 || $self->ut_numbern('_date')
177 || $self->ut_snumber('seconds')
178 || $self->ut_snumber('support')
180 return $error if $error;
182 $self->_date(time) unless $self->_date;
184 if ($selfref->{custnum}) {
185 my $conf = new FS::Conf;
186 my %packages = map { $_ => 1 } $conf->config('support_packages');
187 my $cust_main = qsearchs('cust_main',{ 'custnum' => $selfref->{custnum} } );
188 return "Invalid custnum: " . $selfref->{custnum} unless $cust_main;
190 my (@svcs) = map { $_->svcnum } $cust_main->support_services;
191 return "svcnum ". $self->svcnum. " invalid for custnum ".$selfref->{custnum}
192 unless (!$self->svcnum || scalar(grep { $_ == $self->svcnum } @svcs));
194 $self->svcnum($svcs[0]) unless $self->svcnum;
195 return "Can't find support service for custnum ".$selfref->{custnum}
196 unless $self->svcnum;
204 Returns the creator of the RT transaction associated with this object.
210 FS::TicketSystem->transaction_creator($self->transaction_id);
215 Returns the number of the RT ticket associated with this object.
221 FS::TicketSystem->transaction_ticketid($self->transaction_id);
226 Returns the subject of the RT ticket associated with this object.
232 FS::TicketSystem->transaction_subject($self->transaction_id);
237 Returns the status of the RT ticket associated with this object.
243 FS::TicketSystem->transaction_status($self->transaction_id);
246 =item batch_insert SVC_ACCT_RT_TRANSACTION_OBJECT, ...
248 Class method which inserts multiple time applications. Takes a list of
249 FS::acct_rt_transaction objects. If there is an error inserting any
250 application, the entire transaction is rolled back, i.e. all time is applied
255 my $errors = FS::acct_rt_transaction->batch_insert(@transactions);
257 #success; all payments were inserted
259 #failure; no payments were inserted.
265 my $self = shift; #class method
267 local $SIG{HUP} = 'IGNORE';
268 local $SIG{INT} = 'IGNORE';
269 local $SIG{QUIT} = 'IGNORE';
270 local $SIG{TERM} = 'IGNORE';
271 local $SIG{TSTP} = 'IGNORE';
272 local $SIG{PIPE} = 'IGNORE';
274 my $oldAutoCommit = $FS::UID::AutoCommit;
275 local $FS::UID::AutoCommit = 0;
285 $dbh->rollback if $oldAutoCommit;
287 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
298 Possibly the delete method or others.
302 L<FS::Record>, schema.html from the base documentation.