1 package FS::cust_main_Mixin;
4 use vars qw( $DEBUG $me );
9 $me = '[FS::cust_main_Mixin]';
13 FS::cust_main_Mixin - Mixin class for records that contain fields from cust_main
17 package FS::some_table;
19 @ISA = qw( FS::cust_main_Mixin FS::Record );
23 This is a mixin class for records that contain fields from the cust_main table,
24 for example, from a JOINed search. See httemplate/search/ for examples.
32 sub cust_unlinked_msg { '(unlinked)'; }
33 sub cust_linked { $_[0]->custnum; }
37 Given an object that contains fields from cust_main (say, from a JOINed
38 search; see httemplate/search/ for examples), returns the equivalent of the
39 FS::cust_main I<name> method, or "(unlinked)" if this object is not linked to
47 ? FS::cust_main::display_custnum($self)
48 : $self->cust_unlinked_msg;
53 Given an object that contains fields from cust_main (say, from a JOINed
54 search; see httemplate/search/ for examples), returns the equivalent of the
55 FS::cust_main I<name> method, or "(unlinked)" if this object is not linked to
63 ? FS::cust_main::name($self)
64 : $self->cust_unlinked_msg;
69 Given an object that contains fields from cust_main (say, from a JOINed
70 search; see httemplate/search/ for examples), returns the equivalent of the
71 FS::cust_main I<ship_name> method, or "(unlinked)" if this object is not
79 ? FS::cust_main::ship_name($self)
80 : $self->cust_unlinked_msg;
85 Given an object that contains fields from cust_main (say, from a JOINed
86 search; see httemplate/search/ for examples), returns the equivalent of the
87 FS::cust_main I<contact> method, or "(unlinked)" if this object is not linked
95 ? FS::cust_main::contact($self)
96 : $self->cust_unlinked_msg;
101 Given an object that contains fields from cust_main (say, from a JOINed
102 search; see httemplate/search/ for examples), returns the equivalent of the
103 FS::cust_main I<ship_contact> method, or "(unlinked)" if this object is not
104 linked to a customer.
111 ? FS::cust_main::ship_contact($self)
112 : $self->cust_unlinked_msg;
117 Given an object that contains fields from cust_main (say, from a JOINed
118 search; see httemplate/search/ for examples), returns the equivalent of the
119 FS::cust_main I<country_full> method, or "(unlinked)" if this object is not
120 linked to a customer.
127 ? FS::cust_main::country_full($self)
128 : $self->cust_unlinked_msg;
131 =item invoicing_list_emailonly
133 Given an object that contains fields from cust_main (say, from a JOINed
134 search; see httemplate/search/ for examples), returns the equivalent of the
135 FS::cust_main I<invoicing_list_emailonly> method, or "(unlinked)" if this
136 object is not linked to a customer.
140 sub invoicing_list_emailonly {
142 warn "invoicing_list_email only called on $self, ".
143 "custnum ". $self->custnum. "\n"
146 ? FS::cust_main::invoicing_list_emailonly($self)
147 : $self->cust_unlinked_msg;
150 =item invoicing_list_emailonly_scalar
152 Given an object that contains fields from cust_main (say, from a JOINed
153 search; see httemplate/search/ for examples), returns the equivalent of the
154 FS::cust_main I<invoicing_list_emailonly_scalar> method, or "(unlinked)" if
155 this object is not linked to a customer.
159 sub invoicing_list_emailonly_scalar {
161 warn "invoicing_list_emailonly called on $self, ".
162 "custnum ". $self->custnum. "\n"
165 ? FS::cust_main::invoicing_list_emailonly_scalar($self)
166 : $self->cust_unlinked_msg;
171 Given an object that contains fields from cust_main (say, from a JOINed
172 search; see httemplate/search/ for examples), returns the equivalent of the
173 FS::cust_main I<invoicing_list> method, or "(unlinked)" if this object is not
174 linked to a customer.
176 Note: this method is read-only.
184 ? FS::cust_main::invoicing_list($self)
190 Given an object that contains fields from cust_main (say, from a JOINed
191 search; see httemplate/search/ for examples), returns the equivalent of the
192 FS::cust_main I<status> method, or "(unlinked)" if this object is not linked to
199 return $self->cust_unlinked_msg unless $self->cust_linked;
201 #FS::cust_main::status($self)
202 #false laziness w/actual cust_main::status
203 # (make sure FS::cust_main methods are called)
204 for my $status (qw( prospect active inactive suspended cancelled )) {
205 my $method = $status.'_sql';
206 my $sql = FS::cust_main->$method();;
207 my $numnum = ( $sql =~ s/cust_main\.custnum/?/g );
208 my $sth = dbh->prepare("SELECT $sql") or die dbh->errstr;
209 $sth->execute( ($self->custnum) x $numnum )
210 or die "Error executing 'SELECT $sql': ". $sth->errstr;
211 return $status if $sth->fetchrow_arrayref->[0];
215 =item ucfirst_cust_status
217 Given an object that contains fields from cust_main (say, from a JOINed
218 search; see httemplate/search/ for examples), returns the equivalent of the
219 FS::cust_main I<ucfirst_status> method, or "(unlinked)" if this object is not
220 linked to a customer.
224 sub ucfirst_cust_status {
227 ? ucfirst( $self->cust_status(@_) )
228 : $self->cust_unlinked_msg;
231 =item cust_statuscolor
233 Given an object that contains fields from cust_main (say, from a JOINed
234 search; see httemplate/search/ for examples), returns the equivalent of the
235 FS::cust_main I<statuscol> method, or "000000" if this object is not linked to
240 sub cust_statuscolor {
244 ? FS::cust_main::cust_statuscolor($self)
258 Given an object that contains fields from cust_main (say, from a JOINed
259 search; see httemplate/search/ for examples), returns the equivalent of the
260 corresponding FS::cust_main method, or "0" if this object is not linked to
265 foreach my $sub (qw( prospect active inactive suspended cancelled )) {
270 ? FS::cust_main::${sub}_sql(\$self)
277 =item cust_search_sql
279 Returns a list of SQL WHERE fragments to search for parameters specified
280 in HASHREF. Valid parameters are:
294 sub cust_search_sql {
295 my($class, $param) = @_;
298 warn "$me cust_search_sql called with params: \n".
299 join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n";
304 if ( $param->{'agentnum'} && $param->{'agentnum'} =~ /^(\d+)$/ ) {
305 push @search, "cust_main.agentnum = $1";
308 #status (prospect active inactive suspended cancelled)
309 if ( grep { $param->{'status'} eq $_ } FS::cust_main->statuses() ) {
310 my $method = $param->{'status'}. '_sql';
311 push @search, $class->$method();
315 my @payby = ref($param->{'payby'})
316 ? @{ $param->{'payby'} }
317 : split(',', $param->{'payby'});
318 @payby = grep /^([A-Z]{4})$/, @payby;
320 push @search, 'cust_main.payby IN ('. join(',', map "'$_'", @payby). ')';
323 #here is the agent virtualization
325 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
337 L<FS::cust_main>, L<FS::Record>