Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / quotation.pm
1 package FS::quotation;
2
3 use strict;
4 use base qw( FS::otaker_Mixin FS::Record );
5 use FS::Record; # qw( qsearch qsearchs );
6 use FS::cust_main;
7 use FS::prospect_main;
8
9 =head1 NAME
10
11 FS::quotation - Object methods for quotation records
12
13 =head1 SYNOPSIS
14
15   use FS::quotation;
16
17   $record = new FS::quotation \%hash;
18   $record = new FS::quotation { '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::quotation object represents a quotation.  FS::quotation inherits from
31 FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item quotationnum
36
37 primary key
38
39 =item prospectnum
40
41 prospectnum
42
43 =item custnum
44
45 custnum
46
47 =item _date
48
49 _date
50
51 =item disabled
52
53 disabled
54
55 =item usernum
56
57 usernum
58
59
60 =back
61
62 =head1 METHODS
63
64 =over 4
65
66 =item new HASHREF
67
68 Creates a new quotation.  To add the quotation to the database, see L<"insert">.
69
70 Note that this stores the hash reference, not a distinct copy of the hash it
71 points to.  You can ask the object for a copy with the I<hash> method.
72
73 =cut
74
75 sub table { 'quotation'; }
76
77 =item insert
78
79 Adds this record to the database.  If there is an error, returns the error,
80 otherwise returns false.
81
82 =item delete
83
84 Delete this record from the database.
85
86 =item replace OLD_RECORD
87
88 Replaces the OLD_RECORD with this one in the database.  If there is an error,
89 returns the error, otherwise returns false.
90
91 =item check
92
93 Checks all fields to make sure this is a valid quotation.  If there is
94 an error, returns the error, otherwise returns false.  Called by the insert
95 and replace methods.
96
97 =cut
98
99 sub check {
100   my $self = shift;
101
102   my $error = 
103     $self->ut_numbern('quotationnum')
104     || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum' )
105     || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum' )
106     || $self->ut_numbern('_date')
107     || $self->ut_enum('disabled', [ '', 'Y' ])
108     || $self->ut_numbern('usernum')
109   ;
110   return $error if $error;
111
112   $self->_date(time) unless $self->_date;
113
114   #XXX set usernum
115
116   $self->SUPER::check;
117 }
118
119 =item prospect_main
120
121 =cut
122
123 sub prospect_main {
124   my $self = shift;
125   qsearchs('prospect_main', { 'prospectnum' => $self->prospectnum } );
126 }
127
128 =item cust_main
129
130 =cut
131
132 sub cust_main {
133   my $self = shift;
134   qsearchs('cust_main', { 'custnum' => $self->custnum } );
135 }
136
137 =back
138
139 =head1 BUGS
140
141 =head1 SEE ALSO
142
143 L<FS::Record>, schema.html from the base documentation.
144
145 =cut
146
147 1;
148