From 669bd6b315633c99ac61441198c2c4e45401c36b Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 28 Aug 2008 07:38:40 +0000 Subject: [PATCH] multiple usage classes checkpoint --- FS/FS/Schema.pm | 4 + FS/FS/cust_bill_pkg.pm | 69 +++++++++ FS/FS/cust_main.pm | 196 +++++++++++++++++++------ FS/FS/part_pkg.pm | 97 ++++++++++-- FS/FS/part_pkg/voip_cdr.pm | 8 +- httemplate/browse/part_pkg_taxproduct.cgi | 12 +- httemplate/edit/part_pkg.cgi | 107 +++++++++++++- httemplate/edit/part_pkg_taxoverride.html | 5 +- httemplate/edit/process/part_pkg.cgi | 23 +++ httemplate/elements/select-taxoverride.html | 26 ++++ httemplate/elements/select-taxproduct.html | 44 +++--- httemplate/elements/tr-select-taxoverride.html | 18 +++ httemplate/elements/tr-select-taxproduct.html | 18 +-- 13 files changed, 519 insertions(+), 108 deletions(-) create mode 100644 httemplate/elements/select-taxoverride.html create mode 100644 httemplate/elements/tr-select-taxoverride.html diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 3bcd078ab..2043b45ec 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -502,6 +502,7 @@ sub tables_hashref { 'unitrecur', @money_typen, '', '', 'duplicate', 'char', 'NULL', 1, '', '', 'post_total', 'char', 'NULL', 1, '', '', + 'type', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'billpkgnum', 'unique' => [], @@ -514,7 +515,9 @@ sub tables_hashref { 'billpkgnum', 'int', 'NULL', '', '', '', # should not be nullable 'pkgnum', 'int', 'NULL', '', '', '', # deprecated 'invnum', 'int', 'NULL', '', '', '', # deprecated + 'amount', @money_typen, '', '', 'format', 'char', 'NULL', 1, '', '', + 'classnum', 'char', 'NULL', 1, '', '', 'detail', 'varchar', '', $char_d, '', '', ], 'primary_key' => 'detailnum', @@ -1103,6 +1106,7 @@ sub tables_hashref { 'taxoverridenum', 'serial', '', '', '', '', 'pkgpart', 'serial', '', '', '', '', 'taxclassnum', 'serial', '', '', '', '', + 'usage_class', 'varchar', 'NULL', $char_d, '', '', ], 'primary_key' => 'taxoverridenum', 'unique' => [], diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index d3bf65bcb..b481e92a7 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -47,6 +47,8 @@ supported: =item pkgnum - package (see L) or 0 for the special virtual sales tax package, or -1 for the virtual line item (itemdesc is used for the line) =item pkgpart_override - optional package definition (see L) override +=item type - can be set to U for usage; more later + =item setup - setup fee =item recur - recurring fee @@ -137,6 +139,8 @@ sub insert { 'billpkgnum' => $self->billpkgnum, 'format' => (ref($detail) ? $detail->[0] : '' ), 'detail' => (ref($detail) ? $detail->[1] : $detail ), + 'charge' => (ref($detail) ? $detail->[2] : '' ), + 'classnum' => (ref($detail) ? $detail->[3] : '' ), }; $error = $cust_bill_pkg_detail->insert; if ( $error ) { @@ -195,6 +199,7 @@ sub check { || $self->ut_textn('section') || $self->ut_enum('duplicate', [ '', 'Y' ]) || $self->ut_enum('post_total', [ '', 'Y' ]) + || $self->ut_enum('type', [ '', 'U' ]) #only usage for now ; return $error if $error; @@ -458,6 +463,70 @@ sub separate_cdr { $self->pkgnum && $self->section ne $self->part_pkg->categoryname; } +=item usage CLASSNUM + +Returns the amount of the charge associated with usage class CLASSNUM if +CLASSNUM is defined. Otherwise returns the total charge associated with +usage. + +=cut + +sub usage { + my( $self, $classnum ) = @_; + my $sum = 0; + my @values = (); + + if ( $self->get('details') ) { + + @values = + map { $_->[2] } + grep { ref($_) && ( defined($classnum) ? $_->[3] eq $classnum : 1 ) } + $self->get('details'); + + }else{ + + my $hashref = { 'billpkgnum' => $self->billpkgnum }; + $hashref->{ 'classnum' } = $classnum if defined($classnum); + @values = map { $_->charge } qsearch('cust_bill_pkg_detail', $hashref); + + } + + foreach ( @values ) { + $sum += $_ if $_; + } + $sum; +} + +=item usage_classes + +Returns a list of usage classnums associated with this invoice line's +details. + +=cut + +sub usage_classes { + my( $self ) = @_; + + if ( $self->get('details') ) { + + my %seen = (); + foreach my $detail ( grep { ref($_) } @{$self->get('details')} ) { + $seen{ $detail->[3] } = 1; + } + keys %seen; + + }else{ + + map { $_->classnum } + qsearch({ table => 'cust_bill_pkg_detail', + hashref => { billpkgnum => $self->billpkgnum }, + select => 'DISTINCT classnum', + }); + + } + +} + =back =head1 BUGS diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index cc664f30b..b72079cf1 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2047,6 +2047,7 @@ Used in conjunction with the I