1 package FS::quotation_pkg;
4 use base qw( FS::TemplateItem_Mixin FS::Record );
5 use FS::Record qw( qsearchs ); #qsearch
9 use FS::quotation_pkg_discount; #so its loaded when TemplateItem_Mixin needs it
13 FS::quotation_pkg - Object methods for quotation_pkg records
17 use FS::quotation_pkg;
19 $record = new FS::quotation_pkg \%hash;
20 $record = new FS::quotation_pkg { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::quotation_pkg object represents a quotation package.
33 FS::quotation_pkg inherits from FS::Record. The following fields are currently
75 Creates a new quotation package. To add the quotation package to the database,
78 Note that this stores the hash reference, not a distinct copy of the hash it
79 points to. You can ask the object for a copy with the I<hash> method.
83 sub table { 'quotation_pkg'; }
85 sub display_table { 'quotation_pkg'; }
87 #forget it, just overriding cust_bill_pkg_display entirely
88 #sub display_table_orderby { 'quotationpkgnum'; } # something else?
89 # # (for invoice display order)
91 sub discount_table { 'quotation_pkg_discount'; }
95 Adds this record to the database. If there is an error, returns the error,
96 otherwise returns false.
100 Delete this record from the database.
102 =item replace OLD_RECORD
104 Replaces the OLD_RECORD with this one in the database. If there is an error,
105 returns the error, otherwise returns false.
109 Checks all fields to make sure this is a valid quotation package. If there is
110 an error, returns the error, otherwise returns false. Called by the insert
119 $self->ut_numbern('quotationpkgnum')
120 || $self->ut_foreign_key( 'quotationnum', 'quotation', 'quotationnum' )
121 || $self->ut_foreign_key( 'pkgpart', 'part_pkg', 'pkgpart' )
122 || $self->ut_foreign_keyn( 'locationnum', 'cust_location', 'locationnum' )
123 || $self->ut_numbern('start_date')
124 || $self->ut_numbern('contract_end')
125 || $self->ut_numbern('quantity')
126 || $self->ut_enum('waive_setup', [ '', 'Y'] )
128 return $error if $error;
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
161 : $part_pkg->option('recur_fee');
163 $recur *= $self->quantity if $self->quantity;
164 sprintf('%.2f', $recur);
167 =item cust_bill_pkg_display [ type => TYPE ]
171 sub cust_bill_pkg_display {
172 my ( $self, %opt ) = @_;
174 my $type = $opt{type} if exists $opt{type};
175 return () if $type eq 'U'; #quotations don't have usage
177 if ( $self->get('display') ) {
178 return ( grep { defined($type) ? ($type eq $_->type) : 1 }
179 @{ $self->get('display') }
184 my $setup = $self->new($self->hashref);
185 $setup->{'_NO_RECUR_KLUDGE'} = 1;
186 $setup->{'type'} = 'S';
187 my $recur = $self->new($self->hashref);
188 $recur->{'_NO_SETUP_KLUDGE'} = 1;
189 $recur->{'type'} = 'R';
191 if ( $type eq 'S' ) {
193 } elsif ( $type eq 'R' ) {
196 #return ($setup, $recur);
206 Returns the customer (L<FS::cust_main> object).
212 my $quotation = FS::quotation->by_key($self->quotationnum) or return '';
213 $quotation->cust_main;
222 L<FS::Record>, schema.html from the base documentation.