1 package FS::quotation_pkg;
2 use base qw( FS::TemplateItem_Mixin FS::Record );
5 use FS::Record qw( qsearchs ); #qsearch
7 use FS::quotation_pkg_discount; #so its loaded when TemplateItem_Mixin needs it
11 FS::quotation_pkg - Object methods for quotation_pkg records
15 use FS::quotation_pkg;
17 $record = new FS::quotation_pkg \%hash;
18 $record = new FS::quotation_pkg { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::quotation_pkg object represents a quotation package.
31 FS::quotation_pkg inherits from FS::Record. The following fields are currently
73 Creates a new quotation package. To add the quotation package to the database,
76 Note that this stores the hash reference, not a distinct copy of the hash it
77 points to. You can ask the object for a copy with the I<hash> method.
81 sub table { 'quotation_pkg'; }
83 sub display_table { 'quotation_pkg'; }
85 #forget it, just overriding cust_bill_pkg_display entirely
86 #sub display_table_orderby { 'quotationpkgnum'; } # something else?
87 # # (for invoice display order)
89 sub discount_table { 'quotation_pkg_discount'; }
93 Adds this record to the database. If there is an error, returns the error,
94 otherwise returns false.
98 Delete this record from the database.
100 =item replace OLD_RECORD
102 Replaces the OLD_RECORD with this one in the database. If there is an error,
103 returns the error, otherwise returns false.
107 Checks all fields to make sure this is a valid quotation package. If there is
108 an error, returns the error, otherwise returns false. Called by the insert
117 $self->ut_numbern('quotationpkgnum')
118 || $self->ut_foreign_key( 'quotationnum', 'quotation', 'quotationnum' )
119 || $self->ut_foreign_key( 'pkgpart', 'part_pkg', 'pkgpart' )
120 || $self->ut_foreign_keyn( 'locationnum', 'cust_location', 'locationnum' )
121 || $self->ut_numbern('start_date')
122 || $self->ut_numbern('contract_end')
123 || $self->ut_numbern('quantity')
124 || $self->ut_enum('waive_setup', [ '', 'Y'] )
126 return $error if $error;
131 #it looks redundant with a v4.x+ auto-generated method, but need to override
132 # FS::TemplateItem_Mixin's version
135 qsearchs('part_pkg', { 'pkgpart' => $self->pkgpart } );
140 $self->part_pkg->pkg;
145 return '0.00' if $self->waive_setup eq 'Y' || $self->{'_NO_SETUP_KLUDGE'};
146 my $part_pkg = $self->part_pkg;
147 #my $setup = $part_pkg->can('base_setup') ? $part_pkg->base_setup
148 # : $part_pkg->option('setup_fee');
149 my $setup = $part_pkg->option('setup_fee');
151 $setup *= $self->quantity if $self->quantity;
152 sprintf('%.2f', $setup);
158 return '0.00' if $self->{'_NO_RECUR_KLUDGE'};
159 my $part_pkg = $self->part_pkg;
160 my $recur = $part_pkg->can('base_recur') ? $part_pkg->base_recur($self)
161 : $part_pkg->option('recur_fee');
163 $recur *= $self->quantity if $self->quantity;
164 sprintf('%.2f', $recur);
169 return '0.00' if $self->waive_setup eq 'Y' || $self->{'_NO_SETUP_KLUDGE'};
170 my $part_pkg = $self->part_pkg;
171 my $setup = $part_pkg->option('setup_fee');
174 sprintf('%.2f', $setup);
179 return '0.00' if $self->{'_NO_RECUR_KLUDGE'};
180 my $part_pkg = $self->part_pkg;
181 my $recur = $part_pkg->can('base_recur') ? $part_pkg->base_recur
182 : $part_pkg->option('recur_fee');
184 sprintf('%.2f', $recur);
187 =item part_pkg_currency_option OPTIONNAME
189 Returns a two item list consisting of the currency of this quotation's customer
190 or prospect, if any, and a value for the provided option. If the customer or
191 prospect has a currency, the value is the option value the given name and the
192 currency (see L<FS::part_pkg_currency>). Otherwise, if the customer or
193 prospect has no currency, is the regular option value for the given name (see
194 L<FS::part_pkg_option>).
198 #false laziness w/cust_pkg->part_pkg_currency_option
199 sub part_pkg_currency_option {
200 my( $self, $optionname ) = @_;
201 my $part_pkg = $self->part_pkg;
202 my $prospect_or_customer = $self->cust_main || $self->prospect_main;
203 if ( my $currency = $prospect_or_customer->currency ) {
204 ($currency, $part_pkg->part_pkg_currency_option($currency, $optionname) );
206 ('', $part_pkg->option($optionname) );
211 =item cust_bill_pkg_display [ type => TYPE ]
215 sub cust_bill_pkg_display {
216 my ( $self, %opt ) = @_;
218 my $type = $opt{type} if exists $opt{type};
219 return () if $type eq 'U'; #quotations don't have usage
221 if ( $self->get('display') ) {
222 return ( grep { defined($type) ? ($type eq $_->type) : 1 }
223 @{ $self->get('display') }
228 my $setup = $self->new($self->hashref);
229 $setup->{'_NO_RECUR_KLUDGE'} = 1;
230 $setup->{'type'} = 'S';
231 my $recur = $self->new($self->hashref);
232 $recur->{'_NO_SETUP_KLUDGE'} = 1;
233 $recur->{'type'} = 'R';
235 if ( $type eq 'S' ) {
237 } elsif ( $type eq 'R' ) {
240 #return ($setup, $recur);
250 Returns the customer (L<FS::cust_main> object).
256 my $quotation = FS::quotation->by_key($self->quotationnum) or return '';
257 $quotation->cust_main;
262 Returns the prospect (L<FS::prospect_main> object).
268 my $quotation = FS::quotation->by_key($self->quotationnum) or return '';
269 $quotation->prospect_main;
278 L<FS::Record>, schema.html from the base documentation.