1 package FS::part_referral;
4 use vars qw( @ISA $setup_hack );
5 use FS::Record qw( qsearch qsearchs dbh );
8 @ISA = qw( FS::Record );
13 FS::part_referral - Object methods for part_referral objects
17 use FS::part_referral;
19 $record = new FS::part_referral \%hash
20 $record = new FS::part_referral { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::part_referral represents a advertising source - where a customer heard
33 of your services. This can be used to track the effectiveness of a particular
34 piece of advertising, for example. FS::part_referral inherits from FS::Record.
35 The following fields are currently supported:
39 =item refnum - primary key (assigned automatically for new referrals)
41 =item referral - Text name of this advertising source
43 =item disabled - Disabled flag, empty or 'Y'
45 =item agentnum - Optional agentnum (see L<FS::agent>)
51 These were called B<referrals> before version 1.4.0 - the name was changed
52 so as not to be confused with the new customer-to-customer referrals.
60 Creates a new advertising source. To add the referral to the database, see
65 sub table { 'part_referral'; }
69 Adds this advertising source to the database. If there is an error, returns
70 the error, otherwise returns false.
74 Currently unimplemented.
80 return "Can't (yet?) delete part_referral records";
81 #need to make sure no customers have this referral!
84 =item replace OLD_RECORD
86 Replaces OLD_RECORD with this one in the database. If there is an error,
87 returns the error, otherwise returns false.
91 Checks all fields to make sure this is a valid advertising source. If there is
92 an error, returns the error, otherwise returns false. Called by the insert and
100 my $error = $self->ut_numbern('refnum')
101 || $self->ut_text('referral')
102 || $self->ut_enum('disabled', [ '', 'Y' ] )
103 #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
105 ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
106 : $self->ut_agentnum_acl('agentnum', 'Edit global advertising sources')
109 return $error if $error;
116 Returns the associated agent for this referral, if any, as an FS::agent object.
122 qsearchs('agent', { 'agentnum' => $self->agentnum } );
131 =item acl_agentnum_sql [ INCLUDE_GLOBAL_BOOL ]
133 Returns an SQL fragment for searching for part_referral records allowed by the
134 current users's agent ACLs (and "Edit global advertising sources" right).
136 Pass a true value to include global advertising sources (for example, when
137 simply using rather than editing advertising sources).
141 sub acl_agentnum_sql {
144 my $curuser = $FS::CurrentUser::CurrentUser;
145 my $sql = $curuser->agentnums_sql;
146 $sql = " ( $sql OR agentnum IS NULL ) "
147 if $curuser->access_right('Edit global advertising sources')
148 or defined($_[0]) && $_[0];
154 =item all_part_referral [ INCLUDE_GLOBAL_BOOL ]
156 Returns all part_referral records allowed by the current users's agent ACLs
157 (and "Edit global advertising sources" right).
159 Pass a true value to include global advertising sources (for example, when
160 simply using rather than editing advertising sources).
164 sub all_part_referral {
166 my $global = @_ ? shift : '';
167 my $disabled = @_ ? shift : '';
169 my $hashref = $disabled ? {} : { 'disabled' => '' };
170 my $and = $disabled ? ' WHERE ' : ' AND ';
173 'table' => 'part_referral',
174 'hashref' => $hashref,
175 'extra_sql' => $and. $self->acl_agentnum_sql($global). ' ORDER BY refnum ',
180 =item num_part_referral [ INCLUDE_GLOBAL_BOOL ]
182 Returns the number of part_referral records allowed by the current users's
183 agent ACLs (and "Edit global advertising sources" right).
187 sub num_part_referral {
190 my $sth = dbh->prepare(
191 'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql(@_)
192 ) or die dbh->errstr;
193 $sth->execute() or die $sth->errstr;
194 $sth->fetchrow_arrayref->[0];
201 The delete method is unimplemented.
203 `Advertising source'. Yes, it's a sucky name. The only other ones I could
204 come up with were "Marketing channel" and "Heard Abouts" and those are
205 definately both worse.
209 L<FS::Record>, L<FS::cust_main>, schema.html from the base documentation.