1 package FS::cust_credit_void;
2 use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin FS::Record );
5 use FS::Record qw(qsearchs); # qsearch qsearchs);
13 FS::cust_credit_void - Object methods for cust_credit_void objects
17 use FS::cust_credit_void;
19 $record = new FS::cust_credit_void \%hash;
20 $record = new FS::cust_credit_void { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::cust_credit_void object represents a voided credit. All fields in
33 FS::cust_credit are present, as well as:
37 =item void_date - the date (unix timestamp) that the credit was voided
39 =item void_reason - the reason (a freeform string)
41 =item void_usernum - the user (L<FS::access_user>) who voided it
51 Creates a new voided credit record.
55 sub table { 'cust_credit_void'; }
59 Adds this voided credit to the database.
63 Checks all fields to make sure this is a valid voided credit. If there is an
64 error, returns the error, otherwise returns false. Called by the insert
73 $self->ut_numbern('crednum')
74 || $self->ut_number('custnum')
75 || $self->ut_numbern('_date')
76 || $self->ut_money('amount')
77 || $self->ut_alphan('otaker')
78 || $self->ut_textn('reason')
79 || $self->ut_textn('addlinfo')
80 || $self->ut_enum('closed', [ '', 'Y' ])
81 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
82 || $self->ut_foreign_keyn('eventnum', 'cust_event', 'eventnum')
83 || $self->ut_foreign_keyn('commission_agentnum', 'agent', 'agentnum')
84 || $self->ut_foreign_keyn('commission_salesnum', 'sales', 'salesnum')
85 || $self->ut_foreign_keyn('commission_pkgnum', 'cust_pkg', 'pkgnum')
86 || $self->ut_numbern('void_date')
87 || $self->ut_textn('void_reason')
88 || $self->ut_foreign_keyn('void_usernum', 'access_user', 'usernum')
89 || $self->ut_foreign_keyn('void_reasonnum', 'reason', 'reasonnum')
91 return $error if $error;
93 $self->void_date(time) unless $self->void_date;
95 $self->void_usernum($FS::CurrentUser::CurrentUser->usernum)
96 unless $self->void_usernum;
103 "Un-void"s this credit: Deletes the voided credit from the database and adds
104 back (but does not re-apply) a normal credit.
111 local $SIG{HUP} = 'IGNORE';
112 local $SIG{INT} = 'IGNORE';
113 local $SIG{QUIT} = 'IGNORE';
114 local $SIG{TERM} = 'IGNORE';
115 local $SIG{TSTP} = 'IGNORE';
116 local $SIG{PIPE} = 'IGNORE';
118 my $oldAutoCommit = $FS::UID::AutoCommit;
119 local $FS::UID::AutoCommit = 0;
122 my $cust_credit = new FS::cust_credit ( {
123 map { $_ => $self->get($_) } grep { $_ !~ /void/ } $self->fields
125 my $error = $cust_credit->insert;
128 $dbh->rollback if $oldAutoCommit;
132 $error ||= $self->delete;
134 $dbh->rollback if $oldAutoCommit;
138 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
146 Returns the parent customer object (see L<FS::cust_main>).
148 =item void_access_user
150 Returns the voiding employee object (see L<FS::access_user>).
154 sub void_access_user {
156 qsearchs('access_user', { 'usernum' => $self->void_usernum } );
159 =item void_access_user_name
161 Returns the voiding employee name.
165 sub void_access_user_name {
167 my $user = $self->void_access_user;
174 Returns the text of the associated void credit reason (see L<FS::reason>) for this voided credit.
176 The reason for the original credit remains accessible through the reason method.
181 my ($self, $value, %options) = @_;
183 if ( $self->void_reasonnum ) {
184 my $reason = FS::reason->by_key($self->void_reasonnum);
185 $reason_text = $reason->reason;
186 } else { # in case one of these somehow still exists
187 $reason_text = $self->get('void_reason');
197 Doesn't yet support unvoid.
201 L<FS::cust_credit>, L<FS::Record>, schema.html from the base documentation.