From: jeff Date: Sat, 23 Aug 2008 21:59:46 +0000 (+0000) Subject: add usage classes to rate details X-Git-Tag: root_of_webpay_support~422 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=ef0d8db38d1ee28a65a7ecdc6e11c7a82c0a741b add usage classes to rate details --- diff --git a/FS/FS.pm b/FS/FS.pm index e3580f553..a2f72bc8c 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -190,6 +190,8 @@ L - Rate region prefixes for call billing L - Rate plan detail for call billing +L - Usage class class + L - Agent (reseller) class L - Agent type class diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 77ff66822..cfb12e4ae 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -145,6 +145,8 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use FS::rate; use FS::rate_region; use FS::rate_prefix; + use FS::rate_detail; + use FS::usage_class; use FS::payment_gateway; use FS::agent_payment_gateway; use FS::XMLRPC; diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 86cf4a36c..530f632eb 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1671,6 +1671,7 @@ sub tables_hashref { 'min_charge', 'decimal', '', '10,5', '', '', 'sec_granularity', 'int', '', '', '', '', #time period (link to table of periods)? + 'classnum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'ratedetailnum', 'unique' => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ], @@ -1700,6 +1701,17 @@ sub tables_hashref { 'index' => [ [ 'countrycode' ], [ 'regionnum' ] ], }, + 'usage_class' => { + 'columns' => [ + 'classnum', 'serial', '', '', '', '', + 'classname', 'varchar', '', $char_d, '', '', + 'disabled', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'classnum', + 'unique' => [], + 'index' => [ ['disabled'] ], + }, + 'reg_code' => { 'columns' => [ 'codenum', 'serial', '', '', '', '', diff --git a/FS/FS/Setup.pm b/FS/FS/Setup.pm index d265d937f..2b392e54a 100644 --- a/FS/FS/Setup.pm +++ b/FS/FS/Setup.pm @@ -341,6 +341,10 @@ sub initial_data { #not yet.... #) + + #usage classes + 'usage_class' => [], + ; \%hash; diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index b4c79ea50..fd62f64d2 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -106,6 +106,9 @@ sub upgrade_data { #replace invnum and pkgnum with billpkgnum 'cust_bill_pkg_detail' => [], + #usage_classes if we have none + 'usage_class' => [], + ; \%hash; diff --git a/FS/FS/rate_detail.pm b/FS/FS/rate_detail.pm index 533fb1e7b..a78ea828c 100644 --- a/FS/FS/rate_detail.pm +++ b/FS/FS/rate_detail.pm @@ -49,6 +49,8 @@ inherits from FS::Record. The following fields are currently supported: =item sec_granularity - granularity in seconds, i.e. 6 or 60; 0 for per-call +=item classnum - usage class (see Lut_float('min_charge') || $self->ut_number('sec_granularity') + + || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' ) ; return $error if $error; @@ -187,6 +191,19 @@ sub dest_prefixes_short { $self->dest_region->prefixes_short; } +=item classname + +Returns the name of the usage class (see L) associated with +this call plan rate. + +=cut + +sub classname { + my $self = shift; + my $usage_class = qsearchs('usage_class', { classnum => $self->classnum }); + $usage_class ? $usage_class->classname : ''; +} + =back diff --git a/FS/FS/usage_class.pm b/FS/FS/usage_class.pm new file mode 100644 index 000000000..053d39842 --- /dev/null +++ b/FS/FS/usage_class.pm @@ -0,0 +1,143 @@ +package FS::usage_class; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); + +@ISA = qw(FS::Record); + +=head1 NAME + +FS::usage_class - Object methods for usage_class records + +=head1 SYNOPSIS + + use FS::usage_class; + + $record = new FS::usage_class \%hash; + $record = new FS::usage_class { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::usage_class object represents a usage class. Every rate detail +(see L. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I method. + +=cut + +sub table { 'usage_class'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +=item delete + +Delete this record from the database. + +=cut + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +=item check + +Checks all fields to make sure this is a valid usage class. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('classnum') + || $self->ut_text('classname') + || $self->ut_enum('disabled', [ '', 'Y' ]) + ; + return $error if $error; + + $self->SUPER::check; +} + +sub _populate_initial_data { + my ($class, %opts) = @_; + + foreach ("Intrastate", "Interstate", "International") { + my $object = $class->new( { 'classname' => $_ } ); + my $error = $object->insert; + die "error inserting $class into database: $error\n" + if $error; + } + + ''; + +} + +sub _upgrade_data { + my $class = shift; + + return $class->_populate_initial_data(@_) + unless scalar( qsearch( 'usage_class', {} ) ); + + ''; + +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 5dcd69649..a6fe21911 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -420,3 +420,5 @@ t/phone_avail.t FS/Yori.pm FS/cust_svc_option.pm t/cust_svc_option.t +FS/usage_class.pm +t/usage_class.t diff --git a/FS/t/usage_class.t b/FS/t/usage_class.t new file mode 100644 index 000000000..64fe98e3f --- /dev/null +++ b/FS/t/usage_class.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::usage_class; +$loaded=1; +print "ok 1\n"; diff --git a/httemplate/browse/rate_detail.html b/httemplate/browse/rate_detail.html index 36e808fec..23bc23ff8 100644 --- a/httemplate/browse/rate_detail.html +++ b/httemplate/browse/rate_detail.html @@ -17,6 +17,7 @@ 'Included
minutes', 'Charge per
minute', 'Granularity', + 'Usage class', ], 'fields' => [ 'regionname', @@ -28,10 +29,11 @@ ' (edit)'; }, sub { $granularity{ shift->sec_granularity } }, + 'classname', ], - 'links' => [ '', '', $edit_link, $edit_link, '' ], - 'link_onclicks' => [ '', '', $edit_onclick, $edit_onclick, '' ], - 'align' => 'llrrc', + 'links' => [ '', '', $edit_link, $edit_link, '', '' ], + 'link_onclicks' => [ '', '', $edit_onclick, $edit_onclick, '', '' ], + 'align' => 'llrrcc', ) %> <%once> diff --git a/httemplate/browse/usage_class.html b/httemplate/browse/usage_class.html new file mode 100644 index 000000000..63fd2c5a2 --- /dev/null +++ b/httemplate/browse/usage_class.html @@ -0,0 +1,28 @@ +<% include( 'elements/browse.html', + 'title' => 'Usage classes', + 'html_init' => $html_init, + 'name' => 'usage classes', + 'disableable' => 1, + 'disabled_statuspos' => 2, + 'query' => { 'table' => 'usage_class', + 'hashref' => {}, + 'extra_sql' => 'ORDER BY classnum', + }, + 'count_query' => 'SELECT COUNT(*) FROM usage_class', + 'header' => [ '#', 'Class' ], + 'fields' => [ 'classnum', 'classname' ], + 'links' => [ $link, $link ], + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $html_init = + 'Usage classes define groups of usage for taxation purposes.

'. + qq!Add a usage class

!; + +my $link = [ $p.'edit/usage_class.html?', 'classnum' ]; + + diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 47b246477..3896f1712 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -3,8 +3,12 @@ Example: include( 'elements/edit.html', - 'name' => - 'table' => + 'name_singular' => #singular name for the record + # (preferred, will be pluralized automatically) + 'name' => #name for the record + # (deprecated, will be pluralized simplistically) + 'table' => + #? 'primary_key' => #required when the dbdef doesn't know...??? 'labels' => { 'column' => 'Label', @@ -616,9 +620,9 @@ my @menubar = (); if ( $opt{'menubar'} ) { @menubar = @{ $opt{'menubar'} }; } else { + my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'}); @menubar = ( - #eventually use Lingua::bs to pluralize - "View all $opt{'name'}s" => $viewall_url, + "View all $items" => $viewall_url, ); } diff --git a/httemplate/edit/process/rate_region.cgi b/httemplate/edit/process/rate_region.cgi index d83940632..861a6dc2e 100755 --- a/httemplate/edit/process/rate_region.cgi +++ b/httemplate/edit/process/rate_region.cgi @@ -37,7 +37,7 @@ my @dest_detail = map { new FS::rate_detail { 'ratenum' => $ratenum, map { $_ => $cgi->param("$_$ratenum") } - qw( min_included min_charge sec_granularity ) + qw( min_included min_charge sec_granularity classnum ) }; } qsearch('rate', {} ); diff --git a/httemplate/edit/process/usage_class.html b/httemplate/edit/process/usage_class.html new file mode 100644 index 000000000..cf50cb762 --- /dev/null +++ b/httemplate/edit/process/usage_class.html @@ -0,0 +1,11 @@ +<% include( 'elements/process.html', + 'table' => 'usage_class', + 'viewall_dir' => 'browse', + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/edit/rate_detail.html b/httemplate/edit/rate_detail.html index 73d2d9b41..4860593ac 100644 --- a/httemplate/edit/rate_detail.html +++ b/httemplate/edit/rate_detail.html @@ -8,6 +8,7 @@ 'min_included' => 'Included minutes', 'min_charge' => 'Charge per minute', 'sec_granularity' => 'Granularity', + 'classnum' => 'Usage class', }, 'fields' => [ { field=>'ratenum', type=>'hidden', }, @@ -23,6 +24,13 @@ labels => \%granularity, disable_empty => 1, }, + { field =>'classnum', + type =>'select-table', + table =>'usage_class', + name_col =>'classname', + empty_label =>'(default)', + hashref =>{ disabled => '' }, + }, ], ) diff --git a/httemplate/edit/rate_region.cgi b/httemplate/edit/rate_region.cgi index 496e054b1..f24b9d6ef 100644 --- a/httemplate/edit/rate_region.cgi +++ b/httemplate/edit/rate_region.cgi @@ -57,6 +57,9 @@ Granularity + + Usage class + % foreach my $rate ( qsearch('rate', {}) ) { @@ -96,6 +99,19 @@ + + <% include( '/elements/select-table.html', + 'element_name' => "classnum$n", + 'table' => 'usage_class', + 'name_col' => 'classname', + 'empty_label' => '(default)', + 'hashref' => { disabled => '' }, + 'curr_value' => ( $cgi->param("classnum$n") || + $rate_detail->classnum ), + ) + %> + + % } diff --git a/httemplate/edit/usage_class.html b/httemplate/edit/usage_class.html new file mode 100644 index 000000000..ef4b1fff4 --- /dev/null +++ b/httemplate/edit/usage_class.html @@ -0,0 +1,25 @@ +<% include( 'elements/edit.html', + 'name_singular' => 'Usage Class', + 'table' => 'usage_class', + 'fields' => [ + 'classname', + { field=>'disabled', + type=>'checkbox', + value=>'Y', + }, + ], + 'labels' => { + 'classnum' => 'Class number', + 'classname' => 'Class name', + 'disabled' => 'Disable class', + }, + 'viewall_dir' => 'browse', + ) + +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 321927ec4..d476e3098 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -279,6 +279,7 @@ tie my %config_agent, 'Tie::IxHash', tie my %config_billing_rates, 'Tie::IxHash', 'View/Edit rate plans' => [ $fsurl.'browse/rate.cgi', 'Manage rate plans' ], 'View/Edit regions and prefixes' => [ $fsurl.'browse/rate_region.html', 'Manage regions and prefixes' ], + 'View/Edit usage classes' => [ $fsurl.'browse/usage_class.html', 'Usage classes define groups of usage for taxation purposes.' ], ; tie my %config_billing, 'Tie::IxHash';