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