1b4a1b65afec36fdced99fe049c7eea376ae506b
[freeside.git] / site_perl / part_referral.pm
1 package FS::part_referral;
2
3 use strict;
4 use vars qw(@ISA @EXPORT_OK);
5 use Exporter;
6 use FS::Record qw(fields qsearchs);
7
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(fields);
10
11 =head1 NAME
12
13 FS::part_referral - Object methods for part_referral objects
14
15 =head1 SYNOPSIS
16
17   use FS::part_referral;
18
19   $record = create FS::part_referral \%hash
20   $record = create FS::part_referral { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::part_referral represents a referral - where a customer heard of your
33 services.  This can be used to track the effectiveness of a particular piece of
34 advertising, for example.  FS::part_referral inherits from FS::Record.  The
35 following fields are currently supported:
36
37 =over 4
38
39 =item refnum - primary key (assigned automatically for new referrals)
40
41 =item referral - Text name of this referral
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =item create HASHREF
50
51 Creates a new referral.  To add the referral to the database, see L<"insert">.
52
53 =cut
54
55 sub create {
56   my($proto,$hashref)=@_;
57
58   #now in FS::Record::new
59   #my($field);
60   #foreach $field (fields('part_referral')) {
61   #  $hashref->{$field}='' unless defined $hashref->{$field};
62   #}
63
64   $proto->new('part_referral',$hashref);
65 }
66
67 =item insert
68
69 Adds this referral to the database.  If there is an error, returns the error,
70 otherwise returns false.
71
72 =cut
73
74 sub insert {
75   my($self)=@_;
76
77   $self->check or
78   $self->add;
79 }
80
81 =item delete
82
83 Currently unimplemented.
84
85 =cut
86
87 sub delete {
88   my($self)=@_;
89   return "Can't (yet?) delete part_referral records";
90   #$self->del;
91 }
92
93 =item replace OLD_RECORD
94
95 Replaces OLD_RECORD with this one in the database.  If there is an error,
96 returns the error, otherwise returns false.
97
98 =cut
99
100 sub replace {
101   my($new,$old)=@_;
102   return "(Old) Not an part_referral record!" 
103     unless $old->table eq "part_referral";
104   return "Can't change refnum!"
105     unless $old->getfield('refnum') eq $new->getfield('refnum');
106   $new->check or
107   $new->rep($old);
108 }
109
110 =item check
111
112 Checks all fields to make sure this is a valid referral.  If there is an error,
113 returns the error, otherwise returns false.  Called by the insert and replace
114 methods.
115
116 =cut
117
118 sub check {
119   my($self)=@_;
120   return "Not a part_referral record!" unless $self->table eq "part_referral";
121
122   my($error)=
123     $self->ut_numbern('refnum')
124       or $self->ut_text('referral')
125   ;
126   return $error if $error;
127
128   '';
129
130 }
131
132 =back
133
134 =head1 BUGS
135
136 It doesn't properly override FS::Record yet.
137
138 The delete method is unimplemented.
139
140 =head1 SEE ALSO
141
142 L<FS::Record>, L<FS::cust_main>, schema.html from the base documentation.
143
144 =head1 HISTORY
145
146 Class dealing with referrals
147
148 ivan@sisd.com 98-feb-23
149
150 pod ivan@sisd.com 98-sep-21
151
152 =cut
153
154 1;
155