2 use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin FS::Record
10 FS::quotation - Object methods for quotation records
16 $record = new FS::quotation \%hash;
17 $record = new FS::quotation { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::quotation object represents a quotation. FS::quotation inherits from
30 FS::Record. The following fields are currently supported:
67 Creates a new quotation. To add the quotation to the database, see L<"insert">.
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to. You can ask the object for a copy with the I<hash> method.
74 sub table { 'quotation'; }
75 sub notice_name { 'Quotation'; }
76 sub template_conf { 'quotation_'; }
80 Adds this record to the database. If there is an error, returns the error,
81 otherwise returns false.
85 Delete this record from the database.
87 =item replace OLD_RECORD
89 Replaces the OLD_RECORD with this one in the database. If there is an error,
90 returns the error, otherwise returns false.
94 Checks all fields to make sure this is a valid quotation. If there is
95 an error, returns the error, otherwise returns false. Called by the insert
104 $self->ut_numbern('quotationnum')
105 || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum' )
106 || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum' )
107 || $self->ut_numbern('_date')
108 || $self->ut_enum('disabled', [ '', 'Y' ])
109 || $self->ut_numbern('usernum')
111 return $error if $error;
113 $self->_date(time) unless $self->_date;
115 $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
128 sub cust_bill_pkg { #actually quotation_pkg objects
129 shift->quotation_pkg(@_);
138 $self->_total('setup');
141 =item total_recur [ FREQ ]
147 #=item total_recur [ FREQ ]
148 #my $freq = @_ ? shift : '';
149 $self->_total('recur');
153 my( $self, $method ) = @_;
156 $total += $_->$method() for $self->cust_bill_pkg;
157 sprintf('%.2f', $total);
161 #prevent things from falsely showing up as taxes, at least until we support
162 # quoting tax amounts..
167 shift->cust_bill_pkg;
171 my( $self, $total_items ) = @_;
173 if ( $self->total_setup > 0 ) {
174 push @$total_items, {
175 'total_item' => $self->mt( $self->total_recur > 0 ? 'Total Setup' : 'Total' ),
176 'total_amount' => $self->total_setup,
180 #could/should add up the different recurring frequencies on lines of their own
181 # but this will cover the 95% cases for now
182 if ( $self->total_recur > 0 ) {
183 push @$total_items, {
184 'total_item' => $self->mt('Total Recurring'),
185 'total_amount' => $self->total_recur,
191 =item enable_previous
195 sub enable_previous { 0 }
204 =item search_sql_where HASHREF
206 Class method which returns an SQL WHERE fragment to search for parameters
207 specified in HASHREF. Valid parameters are
213 List reference of start date, end date, as UNIX timestamps.
223 List reference of charged limits (exclusive).
227 List reference of charged limits (exclusive).
231 flag, return open invoices only
235 flag, return net invoices only
243 Note: validates all passed-in data; i.e. safe to use with unchecked CGI params.
247 sub search_sql_where {
248 my($class, $param) = @_;
250 # warn "$me search_sql_where called with params: \n".
251 # join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n";
257 if ( $param->{'agentnum'} =~ /^(\d+)$/ ) {
258 push @search, "( prospect_main.agentnum = $1 OR cust_main.agentnum = $1 )";
262 # if ( $param->{'refnum'} =~ /^(\d+)$/ ) {
263 # push @search, "cust_main.refnum = $1";
267 if ( $param->{'prospectnum'} =~ /^(\d+)$/ ) {
268 push @search, "quotation.prospectnum = $1";
272 if ( $param->{'custnum'} =~ /^(\d+)$/ ) {
273 push @search, "cust_bill.custnum = $1";
277 if ( $param->{_date} ) {
278 my($beginning, $ending) = @{$param->{_date}};
280 push @search, "quotation._date >= $beginning",
281 "quotation._date < $ending";
285 if ( $param->{'quotationnum_min'} =~ /^(\d+)$/ ) {
286 push @search, "quotation.quotationnum >= $1";
288 if ( $param->{'quotationnum_max'} =~ /^(\d+)$/ ) {
289 push @search, "quotation.quotationnum <= $1";
293 # if ( $param->{charged} ) {
294 # my @charged = ref($param->{charged})
295 # ? @{ $param->{charged} }
296 # : ($param->{charged});
298 # push @search, map { s/^charged/cust_bill.charged/; $_; }
302 my $owed_sql = FS::cust_bill->owed_sql;
305 push @search, "quotation._date < ". (time-86400*$param->{'days'})
308 #agent virtualization
309 my $curuser = $FS::CurrentUser::CurrentUser;
310 #false laziness w/search/quotation.html
311 push @search,' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
312 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
315 join(' AND ', @search );
325 L<FS::Record>, schema.html from the base documentation.