3952f198c086e8c0579af9cf26497dea64c38316
[freeside.git] / FS / FS / cust_main_Mixin.pm
1 package FS::cust_main_Mixin;
2
3 use strict;
4 use vars qw( $DEBUG );
5 use FS::cust_main;
6
7 $DEBUG = 0;
8
9 =head1 NAME
10
11 FS::cust_main_Mixin - Mixin class for records that contain fields from cust_main
12
13 =head1 SYNOPSIS
14
15 package FS::some_table;
16 use vars qw(@ISA);
17 @ISA = qw( FS::cust_main_Mixin FS::Record );
18
19 =head1 DESCRIPTION
20
21 This is a mixin class for records that contain fields from the cust_main table,
22 for example, from a JOINed search.  See httemplate/search/ for examples.
23
24 =head1 METHODS
25
26 =over 4
27
28 =item name
29
30 Given an object that contains fields from cust_main (say, from a JOINed
31 search; see httemplate/search/ for examples), returns the equivalent of the
32 FS::cust_main I<name> method, or "(unlinked)" if this object is not linked to
33 a customer.
34
35 =cut
36
37 sub cust_unlinked_msg { '(unlinked)'; }
38 sub cust_linked { $_[0]->custnum; }
39
40 sub name {
41   my $self = shift;
42   $self->cust_linked
43     ? FS::cust_main::name($self)
44     : $self->cust_unlinked_msg;
45 }
46
47 =item ship_name
48
49 Given an object that contains fields from cust_main (say, from a JOINed
50 search; see httemplate/search/ for examples), returns the equivalent of the
51 FS::cust_main I<ship_name> method, or "(unlinked)" if this object is not
52 linked to a customer.
53
54 =cut
55
56 sub ship_name {
57   my $self = shift;
58   $self->cust_linked
59     ? FS::cust_main::ship_name($self)
60     : $self->cust_unlinked_msg;
61 }
62
63 =item contact
64
65 Given an object that contains fields from cust_main (say, from a JOINed
66 search; see httemplate/search/ for examples), returns the equivalent of the
67 FS::cust_main I<contact> method, or "(unlinked)" if this object is not linked
68 to a customer.
69
70 =cut
71
72 sub contact {
73   my $self = shift;
74   $self->cust_linked
75     ? FS::cust_main::contact($self)
76     : $self->cust_unlinked_msg;
77 }
78
79 =item ship_contact
80
81 Given an object that contains fields from cust_main (say, from a JOINed
82 search; see httemplate/search/ for examples), returns the equivalent of the
83 FS::cust_main I<ship_contact> method, or "(unlinked)" if this object is not
84 linked to a customer.
85
86 =cut
87
88 sub ship_contact {
89   my $self = shift;
90   $self->cust_linked
91     ? FS::cust_main::ship_contact($self)
92     : $self->cust_unlinked_msg;
93 }
94
95 =item country_full
96
97 Given an object that contains fields from cust_main (say, from a JOINed
98 search; see httemplate/search/ for examples), returns the equivalent of the
99 FS::cust_main I<country_full> method, or "(unlinked)" if this object is not
100 linked to a customer.
101
102 =cut
103
104 sub country_full {
105   my $self = shift;
106   $self->cust_linked
107     ? FS::cust_main::country_full($self)
108     : $self->cust_unlinked_msg;
109 }
110
111 =item invoicing_list_emailonly
112
113 Given an object that contains fields from cust_main (say, from a JOINed
114 search; see httemplate/search/ for examples), returns the equivalent of the
115 FS::cust_main I<invoicing_list_emailonly> method, or "(unlinked)" if this
116 object is not linked to a customer.
117
118 =cut
119
120 sub invoicing_list_emailonly {
121   my $self = shift;
122   warn "invoicing_list_email only called on $self, ".
123        "custnum ". $self->custnum. "\n"
124     if $DEBUG;
125   $self->cust_linked
126     ? FS::cust_main::invoicing_list_emailonly($self)
127     : $self->cust_unlinked_msg;
128 }
129
130 =item invoicing_list_emailonly_scalar
131
132 Given an object that contains fields from cust_main (say, from a JOINed
133 search; see httemplate/search/ for examples), returns the equivalent of the
134 FS::cust_main I<invoicing_list_emailonly_scalar> method, or "(unlinked)" if
135 this object is not linked to a customer.
136
137 =cut
138
139 sub invoicing_list_emailonly_scalar {
140   my $self = shift;
141   warn "invoicing_list_email only called on $self, ".
142        "custnum ". $self->custnum. "\n"
143     if $DEBUG;
144   $self->cust_linked
145     ? FS::cust_main::invoicing_list_emailonly_scalar($self)
146     : $self->cust_unlinked_msg;
147 }
148
149 =item invoicing_list
150
151 Given an object that contains fields from cust_main (say, from a JOINed
152 search; see httemplate/search/ for examples), returns the equivalent of the
153 FS::cust_main I<invoicing_list> method, or "(unlinked)" if this object is not
154 linked to a customer.
155
156 Note: this method is read-only.
157
158 =cut
159
160 #read-only
161 sub invoicing_list {
162   my $self = shift;
163   $self->cust_linked
164     ? FS::cust_main::invoicing_list($self)
165     : ();
166 }
167
168 =cut
169
170 =back
171
172 =head1 BUGS
173
174 =head1 SEE ALSO
175
176 L<FS::cust_main>, L<FS::Record>
177
178 =cut
179
180 1;
181