simple A/P
[freeside.git] / FS / FS / vend_main.pm
1 package FS::vend_main;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs ); # qsearch qsearchs );
6 use FS::vend_class;
7
8 =head1 NAME
9
10 FS::vend_main - Object methods for vend_main records
11
12 =head1 SYNOPSIS
13
14   use FS::vend_main;
15
16   $record = new FS::vend_main \%hash;
17   $record = new FS::vend_main { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::vend_main object represents a vendor.  FS::vend_main inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item vendnum
35
36 primary key
37
38 =item vendname
39
40 vendname
41
42 =item classnum
43
44 classnum
45
46 =item disabled
47
48 disabled
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new vendor.  To add the vendor to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 sub table { 'vend_main'; }
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 =item delete
74
75 Delete this record from the database.
76
77 =item replace OLD_RECORD
78
79 Replaces the OLD_RECORD with this one in the database.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =item check
83
84 Checks all fields to make sure this is a valid vendor.  If there is
85 an error, returns the error, otherwise returns false.  Called by the insert
86 and replace methods.
87
88 =cut
89
90 sub check {
91   my $self = shift;
92
93   my $error = 
94     $self->ut_numbern('vendnum')
95     || $self->ut_text('vendname')
96     || $self->ut_foreign_key('classnum', 'vend_class', 'classnum')
97     || $self->ut_enum('disabled', [ '', 'Y' ] )
98   ;
99   return $error if $error;
100
101   $self->SUPER::check;
102 }
103
104 =item vend_class
105
106 =cut
107
108 sub vend_class {
109   my $self = shift;
110   qsearchs('vend_class', { 'classnum' => $self->classnum } );
111 }
112
113 =back
114
115 =head1 BUGS
116
117 =head1 SEE ALSO
118
119 L<FS::Record>, schema.html from the base documentation.
120
121 =cut
122
123 1;
124