agent-virtualize advertising sources
[freeside.git] / FS / FS / part_referral.pm
1 package FS::part_referral;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw(qsearchs);
6 use FS::agent;
7
8 @ISA = qw( FS::Record );
9
10 =head1 NAME
11
12 FS::part_referral - Object methods for part_referral objects
13
14 =head1 SYNOPSIS
15
16   use FS::part_referral;
17
18   $record = new FS::part_referral \%hash
19   $record = new FS::part_referral { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::part_referral represents a advertising source - where a customer heard
32 of your services.  This can be used to track the effectiveness of a particular
33 piece of advertising, for example.  FS::part_referral inherits from FS::Record.
34 The following fields are currently supported:
35
36 =over 4
37
38 =item refnum - primary key (assigned automatically for new referrals)
39
40 =item referral - Text name of this advertising source
41
42 =item disabled - Disabled flag, empty or 'Y'
43
44 =item agentnum - Optional agentnum (see L<FS::agent>)
45
46 =back
47
48 =head1 NOTE
49
50 These were called B<referrals> before version 1.4.0 - the name was changed
51 so as not to be confused with the new customer-to-customer referrals.
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new advertising source.  To add the referral to the database, see
60 L<"insert">.
61
62 =cut
63
64 sub table { 'part_referral'; }
65
66 =item insert
67
68 Adds this advertising source to the database.  If there is an error, returns
69 the error, otherwise returns false.
70
71 =item delete
72
73 Currently unimplemented.
74
75 =cut
76
77 sub delete {
78   my $self = shift;
79   return "Can't (yet?) delete part_referral records";
80   #need to make sure no customers have this referral!
81 }
82
83 =item replace OLD_RECORD
84
85 Replaces OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =item check
89
90 Checks all fields to make sure this is a valid advertising source.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert and
92 replace methods.
93
94 =cut
95
96 sub check {
97   my $self = shift;
98
99   my $error = $self->ut_numbern('refnum')
100     || $self->ut_text('referral')
101     || $self->ut_enum('disabled', [ '', 'Y' ] )
102     #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
103     || $self->ut_agentnum_acl('agentnum', 'Edit global advertising sources')
104   ;
105   return $error if $error;
106
107   $self->SUPER::check;
108 }
109
110 =item agent 
111
112 Returns the associated agent for this referral, if any, as an FS::agent object.
113
114 =cut
115
116 sub agent {
117   my $self = shift;
118   qsearchs('agent', { 'agentnum' => $self->agentnum } );
119 }
120
121 =back
122
123 =head1 BUGS
124
125 The delete method is unimplemented.
126
127 `Advertising source'.  Yes, it's a sucky name.  The only other ones I could
128 come up with were "Marketing channel" and "Heard Abouts" and those are
129 definately both worse.
130
131 =head1 SEE ALSO
132
133 L<FS::Record>, L<FS::cust_main>, schema.html from the base documentation.
134
135 =cut
136
137 1;
138