continue sales person work: customer and package selection, commissions, reporting...
[freeside.git] / FS / FS / sales.pm
1 package FS::sales;
2 use base qw( FS::Agent_Mixin FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearchs ); #qsearch qsearchs );
6 use FS::agent;
7 use FS::cust_main;
8
9 =head1 NAME
10
11 FS::sales - Object methods for sales records
12
13 =head1 SYNOPSIS
14
15   use FS::sales;
16
17   $record = new FS::sales \%hash;
18   $record = new FS::sales { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::sales object represents a sales person.  FS::sales inherits from
31 FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item salesnum
36
37 primary key
38
39 =item agentnum
40
41 agentnum
42
43 =item disabled
44
45 disabled
46
47
48 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item new HASHREF
55
56 Creates a new sales person.  To add the sales person to the database, see
57 L<"insert">.
58
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to.  You can ask the object for a copy with the I<hash> method.
61
62 =cut
63
64 # the new method can be inherited from FS::Record, if a table method is defined
65
66 sub table { 'sales'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =cut
74
75 # the insert method can be inherited from FS::Record
76
77 =item delete
78
79 Delete this record from the database.
80
81 =cut
82
83 # the delete method can be inherited from FS::Record
84
85 =item replace OLD_RECORD
86
87 Replaces the OLD_RECORD with this one in the database.  If there is an error,
88 returns the error, otherwise returns false.
89
90 =cut
91
92 # the replace method can be inherited from FS::Record
93
94 =item check
95
96 Checks all fields to make sure this is a valid sales person.  If there is
97 an error, returns the error, otherwise returns false.  Called by the insert
98 and replace methods.
99
100 =cut
101
102 # the check method should currently be supplied - FS::Record contains some
103 # data checking routines
104
105 sub check {
106   my $self = shift;
107
108   my $error = 
109     $self->ut_numbern('salesnum')
110     || $self->ut_text('salesperson')
111     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
112     || $self->ut_foreign_keyn('sales_custnum', 'cust_main', 'custnum')
113     || $self->ut_enum('disabled', [ '', 'Y' ])
114   ;
115   return $error if $error;
116
117   $self->SUPER::check;
118 }
119
120 =item sales_cust_main
121
122 Returns the FS::cust_main object (see L<FS::cust_main>), if any, for this
123 sales person.
124
125 =cut
126
127 sub sales_cust_main {
128   my $self = shift;
129   qsearchs( 'cust_main', { 'custnum' => $self->sales_custnum } );
130 }
131
132 =back
133
134 =head1 BUGS
135
136 =head1 SEE ALSO
137
138 L<FS::Record>, schema.html from the base documentation.
139
140 =cut
141
142 1;
143