1 package FS::part_referral;
5 use FS::Record qw( qsearch qsearchs dbh );
8 @ISA = qw( FS::Record );
12 FS::part_referral - Object methods for part_referral objects
16 use FS::part_referral;
18 $record = new FS::part_referral \%hash
19 $record = new FS::part_referral { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
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:
38 =item refnum - primary key (assigned automatically for new referrals)
40 =item referral - Text name of this advertising source
42 =item disabled - Disabled flag, empty or 'Y'
44 =item agentnum - Optional agentnum (see L<FS::agent>)
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.
59 Creates a new advertising source. To add the referral to the database, see
64 sub table { 'part_referral'; }
68 Adds this advertising source to the database. If there is an error, returns
69 the error, otherwise returns false.
73 Currently unimplemented.
79 return "Can't (yet?) delete part_referral records";
80 #need to make sure no customers have this referral!
83 =item replace OLD_RECORD
85 Replaces OLD_RECORD with this one in the database. If there is an error,
86 returns the error, otherwise returns false.
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
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')
105 return $error if $error;
112 Returns the associated agent for this referral, if any, as an FS::agent object.
118 qsearchs('agent', { 'agentnum' => $self->agentnum } );
127 =item acl_agentnum_sql [ INCLUDE_GLOBAL_BOOL ]
129 Returns an SQL fragment for searching for part_referral records allowed by the
130 current users's agent ACLs (and "Edit global advertising sources" right).
132 Pass a true value to include global advertising sources (for example, when
133 simply using rather than editing advertising sources).
137 sub acl_agentnum_sql {
140 my $curuser = $FS::CurrentUser::CurrentUser;
141 my $sql = $curuser->agentnums_sql;
142 $sql = " ( $sql OR agentnum IS NULL ) "
143 if $curuser->access_right('Edit global advertising sources')
144 or defined($_[0]) && $_[0];
150 =item all_part_referral [ INCLUDE_GLOBAL_BOOL ]
152 Returns all part_referral records allowed by the current users's agent ACLs
153 (and "Edit global advertising sources" right).
155 Pass a true value to include global advertising sources (for example, when
156 simply using rather than editing advertising sources).
160 sub all_part_referral {
164 'table' => 'part_referral',
165 'extra_sql' => ' WHERE '. $self->acl_agentnum_sql(@_). ' ORDER BY refnum ',
170 =item num_part_referral [ INCLUDE_GLOBAL_BOOL ]
172 Returns the number of part_referral records allowed by the current users's
173 agent ACLs (and "Edit global advertising sources" right).
177 sub num_part_referral {
180 my $sth = dbh->prepare(
181 'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql(@_)
182 ) or die dbh->errstr;
183 $sth->execute() or die $sth->errstr;
184 $sth->fetchrow_arrayref->[0];
191 The delete method is unimplemented.
193 `Advertising source'. Yes, it's a sucky name. The only other ones I could
194 come up with were "Marketing channel" and "Heard Abouts" and those are
195 definately both worse.
199 L<FS::Record>, L<FS::cust_main>, schema.html from the base documentation.