4 use base qw( FS::option_Common );
5 use FS::Record qw( qsearch qsearchs );
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.
77 # the insert method can be inherited from FS::Record
81 Delete this record from the database.
85 # the delete method can be inherited from FS::Record
87 =item replace OLD_RECORD
89 Replaces the OLD_RECORD with this one in the database. If there is an error,
90 returns the error, otherwise returns false.
94 # the replace method can be inherited from FS::Record
98 Checks all fields to make sure this is a valid qualification. If there is
99 an error, returns the error, otherwise returns false. Called by the insert
104 # the check method should currently be supplied - FS::Record contains some
105 # data checking routines
111 $self->ut_numbern('qualnum')
112 || $self->ut_foreign_keyn('custnum', 'cust_main', 'qualnum')
113 || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
114 || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
115 || $self->ut_numbern('phonenum')
116 || $self->ut_foreign_keyn('exportnum', 'part_export', 'exportnum')
117 || $self->ut_textn('vendor_qual_id')
118 || $self->ut_alpha('status')
120 return $error if $error;
122 return "Invalid prospect/customer/location combination" if (
123 ( $self->locationnum && $self->prospectnum && $self->custnum ) ||
124 ( !$self->locationnum && !$self->prospectnum && !$self->custnum )
132 if ( $self->exportnum ) {
133 return qsearchs('part_export', { exportnum => $self->exportnum } )
134 or die 'invalid exportnum';
141 if ( $self->locationnum ) {
142 my $l = qsearchs( 'cust_location',
143 { 'locationnum' => $self->locationnum });
145 my %loc_hash = $l->location_hash;
146 $loc_hash{locationnum} = $self->locationnum;
150 if ( $self->custnum ) {
151 my $c = qsearchs( 'cust_main', { 'custnum' => $self->custnum });
154 # always override location_kind as it would never be known in the
155 # case of cust_main "default service address"
156 my %loc_hash = $c->location_hash;
157 $loc_hash{location_kind} = $c->company ? 'B' : 'R';
161 # prospectnum does not imply any particular address! must specify locationnum
166 sub cust_or_prospect {
168 if ( $self->locationnum ) {
169 my $l = qsearchs( 'cust_location',
170 { 'locationnum' => $self->locationnum });
171 return qsearchs('cust_main',{ 'custnum' => $l->custnum })
173 return qsearchs('prospect_main',{ 'prospectnum' => $l->prospectnum })
176 return qsearchs('cust_main', { 'custnum' => $self->custnum })
178 return qsearchs('prospect_main', { 'prospectnum' => $self->prospectnum })
179 if $self->prospectnum;
186 'D' => 'Does not Qualify',
189 return $s->{$self->status} if defined $s->{$self->status};
197 L<FS::Record>, schema.html from the base documentation.