4 use base qw( FS::option_Common );
5 use FS::Record qw( qsearch qsearchs dbh );
9 FS::qual - Object methods for qual records
15 $record = new FS::qual \%hash;
16 $record = new FS::qual { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::qual object represents a qualification for service. FS::qual inherits from
29 FS::Record. The following fields are currently supported:
33 =item qualnum - primary key
41 =item phonenum - Service Telephone Number
43 =item exportnum - export instance providing service-qualification capabilities,
44 see L<FS::part_export>
46 =item vendor_qual_id - qualification id from vendor/telco
48 =item status - qualification status (e.g. (N)ew, (P)ending, (Q)ualifies)
59 Creates a new qualification. To add the qualification to the database, see L<"insert">.
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to. You can ask the object for a copy with the I<hash> method.
66 # the new method can be inherited from FS::Record, if a table method is defined
72 Adds this record to the database. If there is an error, returns the error,
73 otherwise returns false.
81 local $SIG{HUP} = 'IGNORE';
82 local $SIG{INT} = 'IGNORE';
83 local $SIG{QUIT} = 'IGNORE';
84 local $SIG{TERM} = 'IGNORE';
85 local $SIG{TSTP} = 'IGNORE';
86 local $SIG{PIPE} = 'IGNORE';
88 my $oldAutoCommit = $FS::UID::AutoCommit;
89 local $FS::UID::AutoCommit = 0;
92 if ( $options{'cust_location'} ) {
93 my $cust_location = $options{'cust_location'};
94 my $error = $cust_location->insert;
96 $dbh->rollback if $oldAutoCommit;
99 $self->locationnum( $cust_location->locationnum );
102 my @qual_option = ();
103 if ( $self->exportnum ) {
104 my $export = qsearchs( 'part_export', { 'exportnum' => $self->exportnum } )
105 or die 'Invalid exportnum';
107 my $qres = $export->qual($self);
108 unless ( ref($qres) ) {
109 $dbh->rollback if $oldAutoCommit;
110 return "Qualification error: $qres";
113 $self->$_($qres->{$_}) foreach grep $qres->{$_}, qw(status vendor_qual_id);
114 @qual_option = ( $qres->{'options'} ) if ref($qres->{'options'});
117 my $error = $self->SUPER::insert(@qual_option);
119 $dbh->rollback if $oldAutoCommit;
123 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
129 Delete this record from the database.
133 # the delete method can be inherited from FS::Record
135 =item replace OLD_RECORD
137 Replaces the OLD_RECORD with this one in the database. If there is an error,
138 returns the error, otherwise returns false.
142 # the replace method can be inherited from FS::Record
146 Checks all fields to make sure this is a valid qualification. If there is
147 an error, returns the error, otherwise returns false. Called by the insert
152 # the check method should currently be supplied - FS::Record contains some
153 # data checking routines
159 $self->ut_numbern('qualnum')
160 || $self->ut_foreign_keyn('custnum', 'cust_main', 'qualnum')
161 || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
162 || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
163 || $self->ut_numbern('phonenum')
164 || $self->ut_foreign_keyn('exportnum', 'part_export', 'exportnum')
165 || $self->ut_textn('vendor_qual_id')
166 || $self->ut_alpha('status')
168 return $error if $error;
170 return "Invalid prospect/customer/location combination" if (
171 ( $self->locationnum && $self->prospectnum && $self->custnum ) ||
172 ( !$self->locationnum && !$self->prospectnum && !$self->custnum )
180 if ( $self->exportnum ) {
181 return qsearchs('part_export', { exportnum => $self->exportnum } )
182 or die 'invalid exportnum';
189 if ( $self->locationnum ) {
190 my $l = qsearchs( 'cust_location',
191 { 'locationnum' => $self->locationnum });
193 my %loc_hash = $l->location_hash;
194 $loc_hash{locationnum} = $self->locationnum;
198 if ( $self->custnum ) {
199 my $c = qsearchs( 'cust_main', { 'custnum' => $self->custnum });
202 # always override location_kind as it would never be known in the
203 # case of cust_main "default service address"
204 my %loc_hash = $c->location_hash;
205 $loc_hash{location_kind} = $c->company ? 'B' : 'R';
209 # prospectnum does not imply any particular address! must specify locationnum
214 sub cust_or_prospect {
216 if ( $self->locationnum ) {
217 my $l = qsearchs( 'cust_location',
218 { 'locationnum' => $self->locationnum });
219 return qsearchs('cust_main',{ 'custnum' => $l->custnum })
221 return qsearchs('prospect_main',{ 'prospectnum' => $l->prospectnum })
224 return qsearchs('cust_main', { 'custnum' => $self->custnum })
226 return qsearchs('prospect_main', { 'prospectnum' => $self->prospectnum })
227 if $self->prospectnum;
234 'D' => 'Does not Qualify',
237 return $s->{$self->status} if defined $s->{$self->status};
245 L<FS::Record>, schema.html from the base documentation.