ikano, svc_dsl, qual, on-going implementation, RT7111
[freeside.git] / FS / FS / qual.pm
1 package FS::qual;
2
3 use strict;
4 use base qw( FS::option_Common );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::qual - Object methods for qual records
10
11 =head1 SYNOPSIS
12
13   use FS::qual;
14
15   $record = new FS::qual \%hash;
16   $record = new FS::qual { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::qual object represents a qualification for service.  FS::qual inherits from
29 FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item qualnum - primary key
34
35 =item prospectnum
36
37 =item custnum 
38
39 =item locationnum
40
41 Either one of these cases must be true:
42 -locationnum is non-null and prospectnum is null and custnum is null
43 -locationnum is null and (prospectnum is non-null or custnum is non-null, but not both non-null)
44
45 =item phonenum - Service Telephone Number
46
47 =item exportnum - export instance providing service-qualification capabilities,
48 see L<FS::part_export>
49
50 =item vendor_qual_id - qualification id from vendor/telco
51
52 =item status - qualification status (e.g. (N)ew, (P)ending, (Q)ualifies)
53
54
55 =back
56
57 =head1 METHODS
58
59 =over 4
60
61 =item new HASHREF
62
63 Creates a new qualification.  To add the qualification to the database, see L<"insert">.
64
65 Note that this stores the hash reference, not a distinct copy of the hash it
66 points to.  You can ask the object for a copy with the I<hash> method.
67
68 =cut
69
70 # the new method can be inherited from FS::Record, if a table method is defined
71
72 sub table { 'qual'; }
73
74 =item insert
75
76 Adds this record to the database.  If there is an error, returns the error,
77 otherwise returns false.
78
79 =cut
80
81 # the insert method can be inherited from FS::Record
82
83 =item delete
84
85 Delete this record from the database.
86
87 =cut
88
89 # the delete method can be inherited from FS::Record
90
91 =item replace OLD_RECORD
92
93 Replaces the OLD_RECORD with this one in the database.  If there is an error,
94 returns the error, otherwise returns false.
95
96 =cut
97
98 # the replace method can be inherited from FS::Record
99
100 =item check
101
102 Checks all fields to make sure this is a valid qualification.  If there is
103 an error, returns the error, otherwise returns false.  Called by the insert
104 and replace methods.
105
106 =cut
107
108 # the check method should currently be supplied - FS::Record contains some
109 # data checking routines
110
111 sub check {
112   my $self = shift;
113
114   my $error = 
115     $self->ut_numbern('qualnum')
116     || $self->ut_foreign_keyn('custnum', 'cust_main', 'qualnum')
117     || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
118     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
119     || $self->ut_numbern('phonenum')
120     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
121     || $self->ut_textn('vendor_qual_id')
122     || $self->ut_alpha('status')
123   ;
124   return $error if $error;
125
126 #Either one of these cases must be true:
127 #1. locationnum is non-null and prospectnum is null and custnum is null
128 #2. locationnum is null and (prospectnum is non-null or custnum is non-null, but not both non-null)
129   return "Invalid prospect/customer/location combination" unless (
130     ( $self->locationnum && !$self->prospectcnum && !$self->custnum  ) #1
131  ||
132     ( !$self->locationnum && ( $self->prospectnum || $self->custnum ) 
133         && !( $self->custnum && $self->prospectnum )  ) #2
134   );
135
136   $self->SUPER::check;
137 }
138
139 =back
140
141 =head1 SEE ALSO
142
143 L<FS::Record>, schema.html from the base documentation.
144
145 =cut
146
147 1;
148