diff options
author | jeff <jeff> | 2008-06-19 03:18:19 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-06-19 03:18:19 +0000 |
commit | f13afe5e228a220311557e1ca6dacbf847c26baf (patch) | |
tree | 9cd6b6e511234d72dfa9e8dd8278a721e5ad03eb /FS/FS | |
parent | 795a85c10d898120a2a6341c4df32fb60b069a64 (diff) |
package categories (meta package classes) and grouping invoices by them
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Schema.pm | 18 | ||||
-rw-r--r-- | FS/FS/cust_bill.pm | 4 | ||||
-rw-r--r-- | FS/FS/part_pkg.pm | 15 | ||||
-rw-r--r-- | FS/FS/pkg_category.pm | 113 | ||||
-rw-r--r-- | FS/FS/pkg_class.pm | 30 |
5 files changed, 174 insertions, 6 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index ec046cb..22a7317 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1778,11 +1778,23 @@ sub tables_hashref { 'index' => [], }, + 'pkg_category' => { + 'columns' => [ + 'categorynum', 'serial', '', '', '', '', + 'categoryname', 'varchar', '', $char_d, '', '', + 'disabled', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'categorynum', + 'unique' => [], + 'index' => [ ['disabled'] ], + }, + 'pkg_class' => { 'columns' => [ - 'classnum', 'serial', '', '', '', '', - 'classname', 'varchar', '', $char_d, '', '', - 'disabled', 'char', 'NULL', 1, '', '', + 'classnum', 'serial', '', '', '', '', + 'classname', 'varchar', '', $char_d, '', '', + 'categorynum', 'int', 'NULL', '', '', '', + 'disabled', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'classnum', 'unique' => [], diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 06eec57..4618958 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2506,7 +2506,7 @@ sub _items_sections { if ( $cust_bill_pkg->pkgnum > 0 ) { - my $desc = $cust_bill_pkg->part_pkg->classname; + my $desc = $cust_bill_pkg->part_pkg->categoryname; $s{$desc} += $cust_bill_pkg->setup if ( $cust_bill_pkg->setup != 0 ); @@ -2576,7 +2576,7 @@ sub _items_pkg { my @cust_bill_pkg = grep { $_->pkgnum && ( defined($section) - ? $_->part_pkg->classname eq $section->{'description'} + ? $_->part_pkg->categoryname eq $section->{'description'} : 1 ) } $self->cust_bill_pkg; diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 0d77ed9..7bb434d 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -475,6 +475,21 @@ sub pkg_class { } } +=item categoryname + +Returns the package category name, or the empty string if there is no package +category. + +=cut + +sub categoryname { + my $self = shift; + my $pkg_class = $self->pkg_class; + $pkg_class + ? $pkg_class->categoryname + : ''; +} + =item classname Returns the package class name, or the empty string if there is no package diff --git a/FS/FS/pkg_category.pm b/FS/FS/pkg_category.pm new file mode 100644 index 0000000..69578c9 --- /dev/null +++ b/FS/FS/pkg_category.pm @@ -0,0 +1,113 @@ +package FS::pkg_category; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch ); +use FS::part_pkg; + +@ISA = qw( FS::Record ); + +=head1 NAME + +FS::pkg_category - Object methods for pkg_category records + +=head1 SYNOPSIS + + use FS::pkg_category; + + $record = new FS::pkg_category \%hash; + $record = new FS::pkg_category { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::pkg_category object represents an package category. Every package class +(see L<FS::pkg_class>) has, optionally, a package category. FS::pkg_category +inherits from FS::Record. The following fields are currently supported: + +=over 4 + +=item categorynum - primary key (assigned automatically for new package categoryes) + +=item categoryname - Text name of this package category + +=item disabled - Disabled flag, empty or 'Y' + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new package category. To add the package category to the database, see +L<"insert">. + +=cut + +sub table { 'pkg_category'; } + +=item insert + +Adds this package category to the database. If there is an error, returns the +error, otherwise returns false. + +=item delete + +Deletes this package category from the database. Only package categoryes with no +associated package definitions can be deleted. If there is an error, returns +the error, otherwise returns false. + +=cut + +sub delete { + my $self = shift; + + return "Can't delete an pkg_category with pkg_class records!" + if qsearch( 'pkg_class', { 'categorynum' => $self->categorynum } ); + + $self->SUPER::delete; +} + +=item replace OLD_RECORD + +Replaces OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=item check + +Checks all fields to make sure this is a valid package category. If there is an +error, returns the error, otherwise returns false. Called by the insert and +replace methods. + +=cut + +sub check { + my $self = shift; + + $self->ut_numbern('categorynum') + or $self->ut_text('categoryname') + or $self->SUPER::check; + +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/FS/pkg_class.pm b/FS/FS/pkg_class.pm index bab6e5e..254282f 100644 --- a/FS/FS/pkg_class.pm +++ b/FS/FS/pkg_class.pm @@ -2,8 +2,9 @@ package FS::pkg_class; use strict; use vars qw( @ISA ); -use FS::Record qw( qsearch ); +use FS::Record qw( qsearchs qsearch ); use FS::part_pkg; +use FS::pkg_category; @ISA = qw( FS::Record ); @@ -38,6 +39,8 @@ from FS::Record. The following fields are currently supported: =item classname - Text name of this package class +=item categorynum - Number of associated pkg_category (see L<FS::pkg_category>) + =item disabled - Disabled flag, empty or 'Y' =back @@ -95,10 +98,35 @@ sub check { $self->ut_numbern('classnum') or $self->ut_text('classname') + or $self->ut_foreign_keyn('categorynum', 'pkg_category', 'categorynum') or $self->SUPER::check; } +=item pkg_category + +Returns the pkg_category record associated with this class, or false if there +is none. + +=cut + +sub pkg_category { + my $self = shift; + qsearchs('pkg_category', { 'categorynum' => $self->categorynum } ); +} + +=item categoryname + +Returns the category name associated with this class, or false if there +is none. + +=cut + +sub categoryname { + my $pkg_category = shift->pkg_category; + $pkg_category->categoryname if $pkg_category; +} + =back =head1 BUGS |