X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fquotation_pkg.pm;h=cc45a85e9ebf9c9ef5c879b9dde8004b4f3567a1;hb=abc56e03d9cff03757f9a2f8a3d8f35e97cbb7c5;hp=48d59065e4e9323ce6aac5dd7ca1b3697a426be1;hpb=4b65016d2e366d5a8f0956ec99ecb6d7d85351d7;p=freeside.git diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm index 48d59065e..cc45a85e9 100644 --- a/FS/FS/quotation_pkg.pm +++ b/FS/FS/quotation_pkg.pm @@ -1,10 +1,12 @@ package FS::quotation_pkg; use strict; -use base qw( FS::Record ); -use FS::Record; # qw( qsearch qsearchs ); +use base qw( FS::TemplateItem_Mixin FS::Record ); +use FS::Record qw( qsearchs ); #qsearch use FS::part_pkg; use FS::cust_location; +use FS::quotation; +use FS::quotation_pkg_discount; #so its loaded when TemplateItem_Mixin needs it =head1 NAME @@ -80,6 +82,14 @@ points to. You can ask the object for a copy with the I method. sub table { 'quotation_pkg'; } +sub display_table { 'quotation_pkg'; } + +#forget it, just overriding cust_bill_pkg_display entirely +#sub display_table_orderby { 'quotationpkgnum'; } # something else? +# # (for invoice display order) + +sub discount_table { 'quotation_pkg_discount'; } + =item insert Adds this record to the database. If there is an error, returns the error, @@ -107,8 +117,9 @@ sub check { my $error = $self->ut_numbern('quotationpkgnum') - || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart' ) - || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum' ) + || $self->ut_foreign_key( 'quotationnum', 'quotation', 'quotationnum' ) + || $self->ut_foreign_key( 'pkgpart', 'part_pkg', 'pkgpart' ) + || $self->ut_foreign_keyn( 'locationnum', 'cust_location', 'locationnum' ) || $self->ut_numbern('start_date') || $self->ut_numbern('contract_end') || $self->ut_numbern('quantity') @@ -119,6 +130,109 @@ sub check { $self->SUPER::check; } +sub part_pkg { + my $self = shift; + qsearchs('part_pkg', { 'pkgpart' => $self->pkgpart } ); +} + +sub desc { + my $self = shift; + $self->part_pkg->pkg; +} + +sub setup { + my $self = shift; + return '0.00' if $self->waive_setup eq 'Y' || $self->{'_NO_SETUP_KLUDGE'}; + my $part_pkg = $self->part_pkg; + #my $setup = $part_pkg->can('base_setup') ? $part_pkg->base_setup + # : $part_pkg->option('setup_fee'); + my $setup = $part_pkg->option('setup_fee'); + #XXX discounts + $setup *= $self->quantity if $self->quantity; + sprintf('%.2f', $setup); + +} + +sub recur { + my $self = shift; + return '0.00' if $self->{'_NO_RECUR_KLUDGE'}; + my $part_pkg = $self->part_pkg; + my $recur = $part_pkg->can('base_recur') ? $part_pkg->base_recur + : $part_pkg->option('recur_fee'); + #XXX discounts + $recur *= $self->quantity if $self->quantity; + sprintf('%.2f', $recur); +} + +sub unitsetup { + my $self = shift; + return '0.00' if $self->waive_setup eq 'Y' || $self->{'_NO_SETUP_KLUDGE'}; + my $part_pkg = $self->part_pkg; + my $setup = $part_pkg->option('setup_fee'); + + #XXX discounts + sprintf('%.2f', $setup); +} + +sub unitrecur { + my $self = shift; + return '0.00' if $self->{'_NO_RECUR_KLUDGE'}; + my $part_pkg = $self->part_pkg; + my $recur = $part_pkg->can('base_recur') ? $part_pkg->base_recur + : $part_pkg->option('recur_fee'); + #XXX discounts + sprintf('%.2f', $recur); +} + +=item cust_bill_pkg_display [ type => TYPE ] + +=cut + +sub cust_bill_pkg_display { + my ( $self, %opt ) = @_; + + my $type = $opt{type} if exists $opt{type}; + return () if $type eq 'U'; #quotations don't have usage + + if ( $self->get('display') ) { + return ( grep { defined($type) ? ($type eq $_->type) : 1 } + @{ $self->get('display') } + ); + } else { + + #?? + my $setup = $self->new($self->hashref); + $setup->{'_NO_RECUR_KLUDGE'} = 1; + $setup->{'type'} = 'S'; + my $recur = $self->new($self->hashref); + $recur->{'_NO_SETUP_KLUDGE'} = 1; + $recur->{'type'} = 'R'; + + if ( $type eq 'S' ) { + return ($setup); + } elsif ( $type eq 'R' ) { + return ($recur); + } else { + #return ($setup, $recur); + return ($self); + } + + } + +} + +=item cust_main + +Returns the customer (L object). + +=cut + +sub cust_main { + my $self = shift; + my $quotation = FS::quotation->by_key($self->quotationnum) or return ''; + $quotation->cust_main; +} + =back =head1 BUGS