diff options
Diffstat (limited to 'FS/FS/part_pkg')
-rw-r--r-- | FS/FS/part_pkg/agent.pm | 175 | ||||
-rw-r--r-- | FS/FS/part_pkg/base_rate.pm | 4 | ||||
-rw-r--r-- | FS/FS/part_pkg/bulk.pm | 34 | ||||
-rw-r--r-- | FS/FS/part_pkg/cdr_termination.pm | 207 | ||||
-rw-r--r-- | FS/FS/part_pkg/flat.pm | 104 | ||||
-rw-r--r-- | FS/FS/part_pkg/flat_delayed.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_pkg/flat_introrate.pm | 58 | ||||
-rw-r--r-- | FS/FS/part_pkg/prepaid.pm | 16 | ||||
-rw-r--r-- | FS/FS/part_pkg/prorate_delayed.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_pkg/recur_Common.pm | 59 | ||||
-rw-r--r-- | FS/FS/part_pkg/voip_cdr.pm | 287 |
11 files changed, 771 insertions, 177 deletions
diff --git a/FS/FS/part_pkg/agent.pm b/FS/FS/part_pkg/agent.pm new file mode 100644 index 0000000..d41978c --- /dev/null +++ b/FS/FS/part_pkg/agent.pm @@ -0,0 +1,175 @@ +package FS::part_pkg::agent; + +use strict; +use vars qw(@ISA $DEBUG $me %info); +use Date::Format; +use FS::Record qw( qsearch ); +use FS::agent; +use FS::cust_main; + +#use FS::part_pkg::recur_Common;; +#@ISA = qw(FS::part_pkg::recur_Common); +use FS::part_pkg::prorate; +@ISA = qw(FS::part_pkg::prorate); + +$DEBUG = 0; + +$me = '[FS::part_pkg::agent]'; + +%info = ( + 'name' => 'Wholesale bulk billing, for master customers of an agent.', + 'shortname' => 'Wholesale bulk billing for agent.', + + 'fields' => { + 'setup_fee' => { 'name' => 'Setup fee for this package', + 'default' => 0, + }, + 'recur_fee' => { 'name' => 'Base recurring fee for this package', + 'default' => 0, + }, + + + #'recur_method' => { 'name' => 'Recurring fee method', + # #'type' => 'radio', + # #'options' => \%recur_method, + # 'type' => 'select', + # 'select_options' => \%recur_Common::recur_method, + # }, + 'cutoff_day' => { 'name' => 'Billing Day (1 - 28)', + 'default' => '1', + }, + + 'no_pkg_prorate' => { 'name' => 'Disable prorating bulk packages (charge full price for packages active only a portion of the month)', + 'type' => 'checkbox', + }, + + }, + + #'fieldorder' => [qw( setup_fee recur_fee recur_method cutoff_day ) ], + 'fieldorder' => [qw( setup_fee recur_fee cutoff_day no_pkg_prorate ) ], + + 'weight' => 51, + +); + +#some false laziness-ish w/bulk.pm... not a lot +sub calc_recur { + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; + + my $last_bill = $cust_pkg->last_bill; + + return sprintf("%.2f", $self->SUPER::calc_recur(@_) ) + unless $$sdate > $last_bill; + + my $conf = new FS::Conf; + my $money_char = $conf->config('money_char') || '$'; + + my $total_agent_charge = 0; + + warn "$me billing for agent packages from ". time2str('%x', $last_bill). + " to ". time2str('%x', $$sdate). "\n" + if $DEBUG; + + my $prorate_ratio = ( $$sdate - $last_bill ) + / ( $self->add_freq($last_bill) - $last_bill ); + + #almost always just one, + #unless you have multiple agents with same master customer0 + my @agents = qsearch('agent', { 'agent_custnum' => $cust_pkg->custnum } ); + + foreach my $agent (@agents) { + + warn "$me billing for agent ". $agent->agent. "\n" + if $DEBUG; + + #not the most efficient to load them all into memory, + #but good enough for our current needs + my @cust_main = qsearch('cust_main', { 'agentnum' => $agent->agentnum } ); + + foreach my $cust_main (@cust_main) { + + warn "$me billing agent charges for ". $cust_main->name_short. "\n" + if $DEBUG; + + #make sure setup dates are filled in + my $error = $cust_main->bill; #options don't propogate from freeside-daily + die "Error pre-billing agent customer: $error" if $error; + + my @cust_pkg = grep { my $setup = $_->get('setup'); + my $cancel = $_->get('cancel'); + + $setup < $$sdate # END + && ( ! $cancel || $cancel > $last_bill ) #START + } + $cust_main->all_pkgs; + + foreach my $cust_pkg ( @cust_pkg ) { + + warn "$me billing agent charges for pkgnum ". $cust_pkg->pkgnum. "\n" + if $DEBUG; + + my $pkg_details = $cust_main->name_short. ': '; #name? + # + something to identify package... primary service probably + + my $pkg_charge = 0; + + my $part_pkg = $cust_pkg->part_pkg; + #option to not fallback? via options above + my $pkg_setup_fee = + $part_pkg->setup_cost || $part_pkg->option('setup_fee'); + my $pkg_base_recur = + $part_pkg->recur_cost || $part_pkg->base_recur_permonth($cust_pkg); + + my $pkg_start = $cust_pkg->get('setup'); + if ( $pkg_start < $last_bill ) { + $pkg_start = $last_bill; + } elsif ( $pkg_setup_fee ) { + $pkg_charge += $pkg_setup_fee; + $pkg_details .= $money_char. sprintf('%.2f setup, ', $pkg_setup_fee ); + } + + my $pkg_end = $cust_pkg->get('cancel'); + $pkg_end = ( !$pkg_end || $pkg_end > $$sdate ) ? $$sdate : $pkg_end; + + + my $pkg_recur_charge = $prorate_ratio * $pkg_base_recur; + $pkg_recur_charge *= ( $pkg_end - $pkg_start ) + / ( $$sdate - $last_bill ) + unless $self->option('no_pkg_prorate'); + + my $recur_charge += $pkg_recur_charge; + + $pkg_details .= $money_char. sprintf('%.2f', $recur_charge ). + ' ('. time2str('%x', $pkg_start). + ' - '. time2str('%x', $pkg_end ). ')' + if $recur_charge; + + $pkg_charge += $recur_charge; + + push @$details, $pkg_details + if $pkg_charge; + $total_agent_charge += $pkg_charge; + + } #foreach $cust_pkg + + } #foreach $cust_main + + } #foreach $agent; + + my $charges = $total_agent_charge + $self->SUPER::calc_recur(@_); #prorate + + sprintf('%.2f', $charges ); + +} + +sub hide_svc_detail { + 1; +} + +sub is_free { + 0; +} + +1; + diff --git a/FS/FS/part_pkg/base_rate.pm b/FS/FS/part_pkg/base_rate.pm index 64636d9..440e985 100644 --- a/FS/FS/part_pkg/base_rate.pm +++ b/FS/FS/part_pkg/base_rate.pm @@ -63,7 +63,7 @@ sub calc_remain { my $time = time; #should be able to pass this in for credit calculation my $next_bill = $cust_pkg->getfield('bill') || 0; my $last_bill = $cust_pkg->last_bill || 0; - return 0 if ! $self->base_recur + return 0 if ! $self->base_recur($cust_pkg) || ! $self->option('unused_credit', 1) || ! $last_bill || ! $next_bill @@ -81,7 +81,7 @@ sub calc_remain { my $freq_sec = $1 * $sec{$2||'m'}; return 0 unless $freq_sec; - sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec ); + sprintf("%.2f", $self->base_recur($cust_pkg) * ( $next_bill - $time ) / $freq_sec ); } diff --git a/FS/FS/part_pkg/bulk.pm b/FS/FS/part_pkg/bulk.pm index 63d344d..1b52d9f 100644 --- a/FS/FS/part_pkg/bulk.pm +++ b/FS/FS/part_pkg/bulk.pm @@ -7,7 +7,7 @@ use FS::part_pkg::flat; @ISA = qw(FS::part_pkg::flat); -$DEBUG = 0; +$DEBUG = 1; $me = '[FS::part_pkg::bulk]'; %info = ( @@ -35,6 +35,7 @@ $me = '[FS::part_pkg::bulk]'; 'weight' => 50, ); +#some false laziness-ish w/agent.pm... not a lot sub calc_recur { my($self, $cust_pkg, $sdate, $details ) = @_; @@ -45,6 +46,9 @@ sub calc_recur { my $last_bill = $cust_pkg->last_bill; + return sprintf("%.2f", $self->base_recur($cust_pkg) ) + unless $$sdate > $last_bill; + my $total_svc_charge = 0; warn "$me billing for bulk services from ". time2str('%x', $last_bill). @@ -52,16 +56,15 @@ sub calc_recur { if $DEBUG; # END START - foreach my $h_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) { + foreach my $h_cust_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) { - my @label = $h_svc->label( $$sdate, $last_bill ); + my @label = $h_cust_svc->label_long( $$sdate, $last_bill ); die "fatal: no historical label found, wtf?" unless scalar(@label); #? - #my $svc_details = $label[0].': '. $label[1]. ': '; - my $svc_details = $label[1]. ': '; + my $svc_details = $label[0]. ': '. $label[1]. ': '; my $svc_charge = 0; - my $svc_start = $h_svc->date_inserted; + my $svc_start = $h_cust_svc->date_inserted; if ( $svc_start < $last_bill ) { $svc_start = $last_bill; } elsif ( $svc_setup_fee ) { @@ -69,23 +72,30 @@ sub calc_recur { $svc_details .= $money_char. sprintf('%.2f setup, ', $svc_setup_fee); } - my $svc_end = $h_svc->date_deleted; + my $svc_end = $h_cust_svc->date_deleted; $svc_end = ( !$svc_end || $svc_end > $$sdate ) ? $$sdate : $svc_end; - $svc_charge = $self->option('svc_recur_fee') * ( $svc_end - $svc_start ) - / ( $$sdate - $last_bill ); + my $recur_charge = + $self->option('svc_recur_fee') * ( $svc_end - $svc_start ) + / ( $$sdate - $last_bill ); - $svc_details .= $money_char. sprintf('%.2f', $svc_charge ). + $svc_details .= $money_char. sprintf('%.2f', $recur_charge ). ' ('. time2str('%x', $svc_start). ' - '. time2str('%x', $svc_end ). ')' - if $self->option('svc_recur_fee'); + if $recur_charge; + + $svc_charge += $recur_charge; push @$details, $svc_details; $total_svc_charge += $svc_charge; } - sprintf("%.2f", $self->base_recur($cust_pkg) + $total_svc_charge ); + sprintf('%.2f', $self->base_recur($cust_pkg) + $total_svc_charge ); +} + +sub hide_svc_detail { + 1; } sub is_free_options { diff --git a/FS/FS/part_pkg/cdr_termination.pm b/FS/FS/part_pkg/cdr_termination.pm new file mode 100644 index 0000000..d99903d --- /dev/null +++ b/FS/FS/part_pkg/cdr_termination.pm @@ -0,0 +1,207 @@ +package FS::part_pkg::cdr_termination; + +use strict; +use base qw( FS::part_pkg::recur_Common ); +use vars qw( $DEBUG %info ); +use Tie::IxHash; +use FS::Record qw( qsearch ); #qsearchs ); +use FS::cdr; +use FS::cdr_termination; + +tie my %temporalities, 'Tie::IxHash', + 'upcoming' => "Upcoming (future)", + 'preceding' => "Preceding (past)", +; + +%info = ( + 'name' => 'VoIP rating of CDR records for termination partners.', + 'shortname' => 'VoIP/telco CDR termination', + 'fields' => { + + 'setup_fee' => { 'name' => 'Setup fee for this package', + 'default' => 0, + }, + 'recur_fee' => { 'name' => 'Base recurring fee for this package', + 'default' => 0, + }, + + #'cdr_column' => { 'name' => 'Column from CDR records', + # 'type' => 'select', + # 'select_enum' => [qw( + # dcontext + # channel + # dstchannel + # lastapp + # lastdata + # accountcode + # userfield + # cdrtypenum + # calltypenum + # description + # carrierid + # upstream_rateid + # )], + # }, + + #false laziness w/flat.pm + 'recur_temporality' => { 'name' => 'Charge recurring fee for period', + 'type' => 'select', + 'select_options' => \%temporalities, + }, + + 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'. + ' of service at cancellation', + 'type' => 'checkbox', + }, + + 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '. + 'subscription', + 'default' => '1', + }, + + 'recur_method' => { 'name' => 'Recurring fee method', + #'type' => 'radio', + #'options' => \%recur_method, + 'type' => 'select', + 'select_options' => \%FS::part_pkg::recur_Common::recur_method, + }, + + #false laziness w/cdr_termination.pm + 'output_format' => { 'name' => 'CDR invoice display format', + 'type' => 'select', + 'select_options' => { FS::cdr::invoice_formats() }, + 'default' => 'simple2', #XXX test + }, + + 'usage_section' => { 'name' => 'Section in which to place separate usage charges', + }, + + 'summarize_usage' => { 'name' => 'Include usage summary with recurring charges when usage is in separate section', + 'type' => 'checkbox', + }, + + }, + #cdr_column + 'fieldorder' => [qw( + setup_fee recur_fee + recur_temporality unused_credit recur_method cutoff_day + output_format usage_section summarize_usage + ) + ], + + 'weight' => 48, + +); + +sub calc_setup { + my($self, $cust_pkg ) = @_; + $self->option('setup_fee'); +} + +sub calc_recur { + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; + + #my $last_bill = $cust_pkg->last_bill; + my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup + + return 0 + if $self->option('recur_temporality', 1) eq 'preceding' + && ( $last_bill eq '' || $last_bill == 0 ); + + # termination calculations + + my $term_percent = $cust_pkg->cust_main->cdr_termination_percentage; + die "no customer termination percentage" unless $term_percent; + + my $output_format = $self->option('output_format', 'Hush!') || 'simple2'; + + my $charges = 0; + + #find an svc_external record + my @svc_external = map { $_->svc_x } + grep { $_->part_svc->svcdb eq 'svc_external' } + $cust_pkg->cust_svc; + + die "cdr_termination package has no svc_external service" + unless @svc_external; + die "cdr_termination package has multiple svc_external services" + if scalar(@svc_external) > 1; + + my $svc_external = $svc_external[0]; + + # find CDRs: + # - matching our customer via svc_external.id/title? (and via what field?) + + #let's try carrierid for now, can always make it configurable or rewrite + my $cdr_column = 'carrierid'; + + my %hashref = ( 'freesidestatus' => 'done' ); + + # try matching on svc_external.id for now... (or title? if ints don't cut it) + $hashref{$cdr_column} = $svc_external[0]->id; + + # - with no cdr_termination.status + + my $termpart = 1; #or from an option + + #false lazienss w/search/cdr.html (i should be a part_termination method) + my $where_term = + "( cdr.acctid = cdr_termination.acctid AND termpart = $termpart ) "; + #my $join_term = "LEFT JOIN cdr_termination ON ( $where_term )"; + my $extra_sql = + "AND NOT EXISTS ( SELECT 1 FROM cdr_termination WHERE $where_term )"; + + #may need to process in batches if there's waaay too many + my @cdrs = qsearch({ + 'table' => 'cdr', + #'addl_from' => $join_term, + 'hashref' => \%hashref, + 'extra_sql' => "$extra_sql FOR UPDATE", + }); + + foreach my $cdr (@cdrs) { + + #add a cdr_termination record and the charges + + # XXX config? + #my $term_price = sprintf('%.2f', $cdr->rated_price * $term_percent / 100 ); + my $term_price = sprintf('%.4f', $cdr->rated_price * $term_percent / 100 ); + + my $cdr_termination = new FS::cdr_termination { + 'acctid' => $cdr->acctid, + 'termpart' => $termpart, + 'rated_price' => $term_price, + 'status' => 'done', + }; + + my $error = $cdr_termination->insert; + die $error if $error; #next if $error; #or just skip this one??? why? + + $charges += $term_price; + + # and add a line to the invoice + + my $call_details = $cdr->downstream_csv( 'format' => $output_format, + 'charge' => $term_price, + ); + + my $classnum = ''; #usage class? + + #option to turn off? or just use squelch_cdr for the customer probably + push @$details, [ 'C', $call_details, $term_price, $classnum ]; + + } + + # eotermiation calculation + + $charges += $self->calc_recur_Common(@_); + + $charges; +} + +sub is_free { + 0; +} + +1; diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 3ac44c4..02ac6ae 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -1,7 +1,10 @@ package FS::part_pkg::flat; use strict; -use vars qw(@ISA %info); +use vars qw( @ISA %info + %usage_fields %usage_recharge_fields + @usage_fieldorder @usage_recharge_fieldorder + ); use Tie::IxHash; #use FS::Record qw(qsearch); use FS::UI::bytecount; @@ -14,30 +17,8 @@ tie my %temporalities, 'Tie::IxHash', 'preceding' => "Preceding (past)", ; -%info = ( - 'name' => 'Flat rate (anniversary billing)', - 'shortname' => 'Anniversary', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', - 'default' => 0, - }, - 'recur_fee' => { 'name' => 'Recurring fee for this package', - 'default' => 0, - }, - - #false laziness w/voip_cdr.pm - 'recur_temporality' => { 'name' => 'Charge recurring fee for period', - 'type' => 'select', - 'select_options' => \%temporalities, - }, +%usage_fields = ( - 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'. - ' of service at cancellation', - 'type' => 'checkbox', - }, - 'externalid' => { 'name' => 'Optional External ID', - 'default' => '', - }, 'seconds' => { 'name' => 'Time limit for this package', 'default' => '', 'check' => sub { shift =~ /^\d*$/ }, @@ -60,6 +41,10 @@ tie my %temporalities, 'Tie::IxHash', 'format' => \&FS::UI::bytecount::display_bytecount, 'parse' => \&FS::UI::bytecount::parse_bytecount, }, +); + +%usage_recharge_fields = ( + 'recharge_amount' => { 'name' => 'Cost of recharge for this package', 'default' => '', 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ }, @@ -94,13 +79,46 @@ tie my %temporalities, 'Tie::IxHash', 'package recharge', 'type' => 'checkbox', }, +); + +@usage_fieldorder = qw( seconds upbytes downbytes totalbytes ); +@usage_recharge_fieldorder = qw( + recharge_amount recharge_seconds recharge_upbytes + recharge_downbytes recharge_totalbytes + usage_rollover recharge_reset +); + +%info = ( + 'name' => 'Flat rate (anniversary billing)', + 'shortname' => 'Anniversary', + 'fields' => { + 'setup_fee' => { 'name' => 'Setup fee for this package', + 'default' => 0, + }, + 'recur_fee' => { 'name' => 'Recurring fee for this package', + 'default' => 0, + }, + + #false laziness w/voip_cdr.pm + 'recur_temporality' => { 'name' => 'Charge recurring fee for period', + 'type' => 'select', + 'select_options' => \%temporalities, + }, + + %usage_fields, + %usage_recharge_fields, + + 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'. + ' of service at cancellation', + 'type' => 'checkbox', + }, + 'externalid' => { 'name' => 'Optional External ID', + 'default' => '', + }, }, - 'fieldorder' => [qw( setup_fee recur_fee recur_temporality unused_credit - seconds upbytes downbytes totalbytes - recharge_amount recharge_seconds recharge_upbytes - recharge_downbytes recharge_totalbytes - usage_rollover recharge_reset externalid - ) + 'fieldorder' => [ qw( setup_fee recur_fee recur_temporality unused_credit ), + @usage_fieldorder, @usage_recharge_fieldorder, + qw( externalid ), ], 'weight' => 10, ); @@ -126,7 +144,8 @@ sub unit_setup { } sub calc_recur { - my($self, $cust_pkg) = @_; + my $self = shift; + my($cust_pkg) = @_; #my $last_bill = $cust_pkg->last_bill; my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup @@ -134,7 +153,7 @@ sub calc_recur { return 0 if $self->option('recur_temporality', 1) eq 'preceding' && $last_bill == 0; - $self->base_recur($cust_pkg); + $self->base_recur(@_); } sub base_recur { @@ -143,11 +162,11 @@ sub base_recur { } sub base_recur_permonth { - my($self, $cust_pkg) = @_; #$cust_pkg? + my($self, $cust_pkg) = @_; return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0; - sprintf('%.2f', $self->base_recur / $self->freq ); + sprintf('%.2f', $self->base_recur($cust_pkg) / $self->freq ); } sub calc_remain { @@ -165,7 +184,7 @@ sub calc_remain { #my $last_bill = $cust_pkg->last_bill || 0; my $last_bill = $cust_pkg->get('last_bill') || 0; #->last_bill falls back to setup - return 0 if ! $self->base_recur + return 0 if ! $self->base_recur($cust_pkg) || ! $self->option('unused_credit', 1) || ! $last_bill || ! $next_bill @@ -183,7 +202,7 @@ sub calc_remain { my $freq_sec = $1 * $sec{$2||'m'}; return 0 unless $freq_sec; - sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec ); + sprintf("%.2f", $self->base_recur($cust_pkg) * ( $next_bill - $time ) / $freq_sec ); } @@ -195,16 +214,21 @@ sub is_prepaid { 0; #no, we're postpaid } +sub usage_valuehash { + my $self = shift; + map { $_, $self->option($_) } + grep { $self->option($_, 'hush') } + qw(seconds upbytes downbytes totalbytes); +} + sub reset_usage { my($self, $cust_pkg, %opt) = @_; warn " resetting usage counters" if $opt{debug} > 1; - my %values = map { $_, $self->option($_) } - grep { $self->option($_, 'hush') } - qw(seconds upbytes downbytes totalbytes); + my %values = $self->usage_valuehash; if ($self->option('usage_rollover', 1)) { $cust_pkg->recharge(\%values); }else{ - $cust_pkg->set_usage(\%values); + $cust_pkg->set_usage(\%values, %opt); } } diff --git a/FS/FS/part_pkg/flat_delayed.pm b/FS/FS/part_pkg/flat_delayed.pm index 4a2f1ba..33f9dd8 100644 --- a/FS/FS/part_pkg/flat_delayed.pm +++ b/FS/FS/part_pkg/flat_delayed.pm @@ -58,7 +58,7 @@ sub calc_remain { return 0 if $last_bill + (86400 * $free_days) == $next_bill && $last_bill == $cust_pkg->setup; - return 0 if ! $self->base_recur + return 0 if ! $self->base_recur($cust_pkg) || ! $self->option('unused_credit', 1) || ! $last_bill || ! $next_bill; diff --git a/FS/FS/part_pkg/flat_introrate.pm b/FS/FS/part_pkg/flat_introrate.pm index 2568afa..2d551f1 100644 --- a/FS/FS/part_pkg/flat_introrate.pm +++ b/FS/FS/part_pkg/flat_introrate.pm @@ -1,46 +1,38 @@ package FS::part_pkg::flat_introrate; use strict; -use vars qw(@ISA %info $DEBUG $DEBUG_PRE); +use vars qw(@ISA %info $DEBUG $me); #use FS::Record qw(qsearch qsearchs); use FS::part_pkg::flat; use Date::Manip qw(DateCalc UnixDate ParseDate); @ISA = qw(FS::part_pkg::flat); +$me = '[' . __PACKAGE__ . ']'; $DEBUG = 0; -$DEBUG_PRE = '[' . __PACKAGE__ . ']: '; -%info = ( - 'name' => 'Introductory price for X months, then flat rate,'. - 'relative to setup date (anniversary billing)', - 'shortname' => 'Anniversary, with intro price', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', +(%info) = (%FS::part_pkg::flat::info); +$info{name} = 'Introductory price for X months, then flat rate,'. + 'relative to setup date (anniversary billing)'; +$info{shortname} = 'Anniversary, with intro price'; +$info{fields} = { %{$info{fields}} }; +$info{fields}{intro_fee} = + { 'name' => 'Introductory recurring fee for this package', 'default' => 0, - }, - 'intro_fee' => { 'name' => 'Introductory recurring free for this package', - 'default' => 0, - }, - 'intro_duration' => { 'name' => 'Duration of the introductory period, ' . - 'in number of months', - 'default' => 0, - }, - 'recur_fee' => { 'name' => 'Recurring fee for this package', - 'default' => 0, - }, - 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'. - ' of service at cancellation', - 'type' => 'checkbox', - }, - }, - 'fieldorder' => [ 'setup_fee', 'intro_duration', 'intro_fee', 'recur_fee', 'unused_credit' ], - 'weight' => 14, -); - -sub calc_recur { + }; +$info{fields}{intro_duration} = + { 'name' => 'Duration of the introductory period, in number of months', + 'default' => 0, + }; +$info{fieldorder} = [ @{ $info{fieldorder} } ]; +splice @{$info{fieldorder}}, 1, 0, qw( intro_duration intro_fee ); +$info{weight} = 14; + +sub base_recur { my($self, $cust_pkg, $time ) = @_; + my $now = $time ? $$time : time; + my ($duration) = ($self->option('intro_duration') =~ /^(\d+)$/); unless ($duration) { die "Invalid intro_duration: " . $self->option('intro_duration'); @@ -50,11 +42,11 @@ sub calc_recur { my $intro_end = &DateCalc($setup, "+${duration} month"); my $recur; - warn $DEBUG_PRE . "\$duration = ${duration}" if $DEBUG; - warn $DEBUG_PRE . "\$intro_end = ${intro_end}" if $DEBUG; - warn $DEBUG_PRE . "$$time < " . &UnixDate($intro_end, '%s') if $DEBUG; + warn "$me: \$duration = ${duration}" if $DEBUG; + warn "$me: \$intro_end = ${intro_end}" if $DEBUG; + warn "$me: $now < " . &UnixDate($intro_end, '%s') if $DEBUG; - if ($$time < &UnixDate($intro_end, '%s')) { + if ($now < &UnixDate($intro_end, '%s')) { $recur = $self->option('intro_fee'); } else { $recur = $self->option('recur_fee'); diff --git a/FS/FS/part_pkg/prepaid.pm b/FS/FS/part_pkg/prepaid.pm index 4499d0e..cff165a 100644 --- a/FS/FS/part_pkg/prepaid.pm +++ b/FS/FS/part_pkg/prepaid.pm @@ -12,6 +12,11 @@ tie %recur_action, 'Tie::IxHash', 'cancel' => 'cancel', ; +tie my %overlimit_action, 'Tie::IxHash', + 'overlimit' => 'Default overlimit processing', + 'cancel' => 'Cancel', +; + %info = ( 'name' => 'Prepaid, flat rate', #'name' => 'Prepaid (no automatic recurring)', #maybe use it here too @@ -27,8 +32,17 @@ tie %recur_action, 'Tie::IxHash', 'type' => 'select', 'select_options' => \%recur_action, }, + %FS::part_pkg::flat::usage_fields, + 'overlimit_action' => { 'name' => 'Action to take upon reaching a usage limit.', + 'type' => 'select', + 'select_options' => \%overlimit_action, + }, + #XXX if you set overlimit_action to 'cancel', should also have the ability + # to select a reason }, - 'fieldorder' => [ 'setup_fee', 'recur_fee', 'recur_action', ], + 'fieldorder' => [ qw( setup_fee recur_fee recur_action ), + @FS::part_pkg::flat::usage_fieldorder, 'overlimit_action', + ], 'weight' => 25, ); diff --git a/FS/FS/part_pkg/prorate_delayed.pm b/FS/FS/part_pkg/prorate_delayed.pm index 1d22798..0073493 100644 --- a/FS/FS/part_pkg/prorate_delayed.pm +++ b/FS/FS/part_pkg/prorate_delayed.pm @@ -56,7 +56,7 @@ sub calc_remain { return 0 if $last_bill + (86400 * $free_days) == $next_bill && $last_bill == $cust_pkg->setup; - return 0 if ! $self->base_recur + return 0 if ! $self->base_recur($cust_pkg) || ! $self->option('unused_credit', 1) || ! $last_bill || ! $next_bill; diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm new file mode 100644 index 0000000..2739cbc --- /dev/null +++ b/FS/FS/part_pkg/recur_Common.pm @@ -0,0 +1,59 @@ +package FS::part_pkg::recur_Common; + +use strict; +use vars qw( @ISA %info %recur_method ); +use Tie::IxHash; +use Time::Local; +use FS::part_pkg::prorate; + +@ISA = qw(FS::part_pkg::prorate); + +%info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly + +tie %recur_method, 'Tie::IxHash', + 'anniversary' => 'Charge the recurring fee at the frequency specified above', + 'prorate' => 'Charge a prorated fee the first time (selectable billing date)', + 'subscription' => 'Charge the full fee for the first partial period (selectable billing date)', +; + +sub calc_recur_Common { + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param + + my $charges = 0; + + if ( $param->{'increment_next_bill'} ) { + + my $recur_method = $self->option('recur_method', 1) || 'anniversary'; + + if ( $recur_method eq 'prorate' ) { + + $charges = $self->SUPER::calc_recur(@_); + + } else { + + $charges = $self->option('recur_fee'); + + if ( $recur_method eq 'subscription' ) { + + my $cutoff_day = $self->option('cutoff_day', 1) || 1; + my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ]; + + if ( $day < $cutoff_day ) { + if ( $mon == 0 ) { $mon=11; $year--; } + else { $mon--; } + } + + $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year); + + }#$recur_method eq 'subscription' + + }#$recur_method eq 'prorate' + + }#increment_next_bill + + $charges; + +} + +1; diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index a691fda..eccf2c1 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -6,20 +6,22 @@ use Date::Format; use Tie::IxHash; use FS::Conf; use FS::Record qw(qsearchs qsearch); -use FS::part_pkg::flat; +use FS::part_pkg::recur_Common; use FS::cdr; use FS::rate; use FS::rate_prefix; use FS::rate_detail; +use FS::part_pkg::recur_Common; -@ISA = qw(FS::part_pkg::flat); +@ISA = qw(FS::part_pkg::recur_Common); $DEBUG = 0; tie my %rating_method, 'Tie::IxHash', 'prefix' => 'Rate calls by using destination prefix to look up a region and rate according to the internal prefix and rate tables', - 'upstream' => 'Rate calls based on upstream data: If the call type is "1", map the upstream rate ID directly to an internal rate (rate_detail), otherwise, pass the upstream price through directly.', +# 'upstream' => 'Rate calls based on upstream data: If the call type is "1", map the upstream rate ID directly to an internal rate (rate_detail), otherwise, pass the upstream price through directly.', 'upstream_simple' => 'Simply pass through and charge the "upstream_price" amount.', + 'single_price' => 'A single price per minute for all calls.', ; #tie my %cdr_location, 'Tie::IxHash', @@ -33,6 +35,8 @@ tie my %temporalities, 'Tie::IxHash', 'preceding' => "Preceding (past)", ; +tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); + %info = ( 'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table', 'shortname' => 'VoIP/telco CDR rating (standard)', @@ -55,7 +59,19 @@ tie my %temporalities, 'Tie::IxHash', 'type' => 'checkbox', }, - 'rating_method' => { 'name' => 'Region rating method', + 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '. + 'subscription', + 'default' => '1', + }, + + 'recur_method' => { 'name' => 'Recurring fee method', + #'type' => 'radio', + #'options' => \%recur_method, + 'type' => 'select', + 'select_options' => \%FS::part_pkg::recur_Common::recur_method, + }, + + 'rating_method' => { 'name' => 'Rating method', 'type' => 'radio', 'options' => \%rating_method, }, @@ -67,6 +83,14 @@ tie my %temporalities, 'Tie::IxHash', 'select_label' => 'ratename', }, + 'min_charge' => { 'name' => 'Charge per minute when using "single price per minute" rating method', + }, + + 'sec_granularity' => { 'name' => 'Granularity when using "single price per minute" rating method', + 'type' => 'select', + 'select_options' => \%granularity, + }, + 'ignore_unrateable' => { 'name' => 'Ignore calls without a rate in the rate tables. By default, the system will throw a fatal error upon encountering unrateable calls.', 'type' => 'checkbox', }, @@ -119,6 +143,12 @@ tie my %temporalities, 'Tie::IxHash', 'skip_dstchannel_prefix' => { 'name' => 'Do not charge for CDRs where the dstchannel starts with:', }, + 'skip_dst_length_less' => { 'name' => 'Do not charge for CDRs where the destination is less than this many digits:', + }, + + 'skip_lastapp' => { 'name' => 'Do not charge for CDRs where the lastapp matches this value', + }, + 'use_duration' => { 'name' => 'Calculate usage based on the duration field instead of the billsec field', 'type' => 'checkbox', }, @@ -126,23 +156,33 @@ tie my %temporalities, 'Tie::IxHash', '411_rewrite' => { 'name' => 'Rewrite these (comma-separated) destination numbers to 411 for rating purposes (also ignore any carrierid check): ', }, + #false laziness w/cdr_termination.pm 'output_format' => { 'name' => 'CDR invoice display format', 'type' => 'select', 'select_options' => { FS::cdr::invoice_formats() }, 'default' => 'default', #XXX test }, - 'usage_section' => { 'name' => 'Section in which to place separate usage charges', + 'usage_section' => { 'name' => 'Section in which to place usage charges (whether separated or not)', }, 'summarize_usage' => { 'name' => 'Include usage summary with recurring charges when usage is in separate section', 'type' => 'checkbox', }, + 'usage_mandate' => { 'name' => 'Always put usage details in separate section', + 'type' => 'checkbox', + }, + #eofalse + 'bill_every_call' => { 'name' => 'Generate an invoice immediately for every call. Useful for prepaid.', 'type' => 'checkbox', }, + 'count_available_phones' => { 'name' => 'Consider for tax purposes the number of lines to be svc_phones that may be provisioned rather than those that actually are.', + 'type' => 'checkbox', + }, + #XXX also have option for an external db # 'cdr_location' => { 'name' => 'CDR database location' # 'type' => 'select', @@ -169,7 +209,9 @@ tie my %temporalities, 'Tie::IxHash', }, 'fieldorder' => [qw( setup_fee recur_fee recur_temporality unused_credit - rating_method ratenum ignore_unrateable + recur_method cutoff_day + rating_method ratenum min_charge sec_granularity + ignore_unrateable default_prefix disable_src domestic_prefix international_prefix @@ -177,10 +219,12 @@ tie my %temporalities, 'Tie::IxHash', use_amaflags use_disposition use_disposition_taqua use_carrierid use_cdrtypenum skip_dcontext skip_dstchannel_prefix + skip_dst_length_less skip_lastapp use_duration 411_rewrite - output_format summarize_usage usage_section + output_format usage_mandate summarize_usage usage_section bill_every_call + count_available_phones ) ], 'weight' => 40, @@ -191,15 +235,38 @@ sub calc_setup { $self->option('setup_fee'); } -#false laziness w/voip_sqlradacct calc_recur resolve it if that one ever gets used again sub calc_recur { - my($self, $cust_pkg, $sdate, $details, $param ) = @_; + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; + + my $charges = 0; + + $charges += $self->calc_usage(@_); + $charges += $self->calc_recur_Common(@_); + + $charges; + +} + +sub calc_cancel { + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; + + $self->calc_usage(@_); +} + +#false laziness w/voip_sqlradacct calc_recur resolve it if that one ever gets used again + +sub calc_usage { + my $self = shift; + my($cust_pkg, $sdate, $details, $param ) = @_; #my $last_bill = $cust_pkg->last_bill; my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup return 0 - if $self->option('recur_temporality', 1) eq 'preceding' && $last_bill == 0; + if $self->option('recur_temporality', 1) eq 'preceding' + && ( $last_bill eq '' || $last_bill == 0 ); my $ratenum = $cust_pkg->part_pkg->option('ratenum'); @@ -209,7 +276,7 @@ sub calc_recur { my $charges = 0; - my $downstream_cdr = ''; +# my $downstream_cdr = ''; my $rating_method = $self->option('rating_method') || 'prefix'; my $intl = $self->option('international_prefix') || '011'; @@ -285,9 +352,7 @@ sub calc_recur { ### my( $to_or_from, $number ); - if ( $cdr->dst =~ /^(\+?1)?8([02-8])\1/ - && ! $disable_tollfree - ) + if ( $cdr->is_tollfree && ! $disable_tollfree ) { #tollfree call $to_or_from = 'from'; $number = $cdr->src; @@ -364,48 +429,78 @@ sub calc_recur { } - } elsif ( $rating_method eq 'upstream' ) { #XXX this was convergent, not currently used. very much becoming the odd one out. remove? +# } elsif ( $rating_method eq 'upstream' ) { #XXX this was convergent, not currently used. very much becoming the odd one out. remove? +# +# if ( $cdr->cdrtypenum == 1 ) { #rate based on upstream rateid +# +# $rate_detail = $cdr->cdr_upstream_rate->rate_detail; +# +# $regionnum = $rate_detail->dest_regionnum; +# $rate_region = $rate_detail->dest_region; +# +# $pretty_destnum = $cdr->dst; +# +# warn " found rate for regionnum $regionnum and ". +# "rate detail $rate_detail\n" +# if $DEBUG; +# +# } else { #pass upstream price through +# +# $charge = sprintf('%.2f', $cdr->upstream_price); +# $charges += $charge; +# +# @call_details = ( +# #time2str("%Y %b %d - %r", $cdr->calldate_unix ), +# time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot +# 'N/A', #minutes... +# '$'.$charge, +# #$pretty_destnum, +# $cdr->description, #$rate_region->regionname, +# ); +# +# } - if ( $cdr->cdrtypenum == 1 ) { #rate based on upstream rateid + } elsif ( $rating_method eq 'upstream_simple' ) { - $rate_detail = $cdr->cdr_upstream_rate->rate_detail; + #XXX $charge = sprintf('%.2f', $cdr->upstream_price); + $charge = sprintf('%.3f', $cdr->upstream_price); + $charges += $charge; - $regionnum = $rate_detail->dest_regionnum; - $rate_region = $rate_detail->dest_region; + @call_details = ($cdr->downstream_csv( 'format' => $output_format, + 'charge' => $charge, + ) + ); + $classnum = $cdr->calltypenum; - $pretty_destnum = $cdr->dst; + } elsif ( $rating_method eq 'single_price' ) { - warn " found rate for regionnum $regionnum and ". - "rate detail $rate_detail\n" - if $DEBUG; + # a little false laziness w/below - } else { #pass upstream price through + my $granularity = length($self->option('sec_granularity')) + ? $self->option('sec_granularity') + : 60; - $charge = sprintf('%.2f', $cdr->upstream_price); - $charges += $charge; - - @call_details = ( - #time2str("%Y %b %d - %r", $cdr->calldate_unix ), - time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot - 'N/A', #minutes... - '$'.$charge, - #$pretty_destnum, - $cdr->description, #$rate_region->regionname, - ); + # length($cdr->billsec) ? $cdr->billsec : $cdr->duration; + my $seconds = $use_duration ? $cdr->duration : $cdr->billsec; - } + $seconds += $granularity - ( $seconds % $granularity ) + if $seconds # don't granular-ize 0 billsec calls (bills them) + && $granularity; # 0 is per call + my $minutes = $seconds / 60; # sprintf("%.1f", + #$minutes =~ s/\.0$// if $granularity == 60; - } elsif ( $rating_method eq 'upstream_simple' ) { + # XXX config? + #$charge = sprintf('%.2f', ( $self->option('min_charge') * $minutes ) + #+ 0.00000001 ); #so 1.005 rounds to 1.01 + $charge = sprintf('%.4f', ( $self->option('min_charge') * $minutes ) + + 0.0000000001 ); #so 1.00005 rounds to 1.0001 - #XXX $charge = sprintf('%.2f', $cdr->upstream_price); - $charge = sprintf('%.3f', $cdr->upstream_price); $charges += $charge; @call_details = ($cdr->downstream_csv( 'format' => $output_format, 'charge' => $charge, ) ); - $classnum = $cdr->calltypenum; } else { die "don't know how to rate CDRs using method: $rating_method\n"; @@ -449,9 +544,11 @@ sub calc_recur { $included_min{$regionnum} -= $minutes; if ( $included_min{$regionnum} < 0 ) { - my $charge_min = 0 - $included_min{$regionnum}; + my $charge_min = 0 - $included_min{$regionnum}; #XXX should preserve + #(display?) this $included_min{$regionnum} = 0; - $charge = sprintf('%.2f', $rate_detail->min_charge * $charge_min ); + $charge = sprintf('%.2f', ( $rate_detail->min_charge * $charge_min ) + + 0.00000001 ); #so 1.005 rounds to 1.01 $charges += $charge; } @@ -475,13 +572,16 @@ sub calc_recur { if ( $charge > 0 ) { #just use FS::cust_bill_pkg_detail objects? my $call_details; + my $phonenum = $cust_svc->svc_x->phonenum; #if ( $self->option('rating_method') eq 'upstream_simple' ) { if ( scalar(@call_details) == 1 ) { - $call_details = [ 'C', $call_details[0], $charge, $classnum ]; + $call_details = + [ 'C', $call_details[0], $charge, $classnum, $phonenum ]; } else { #only used for $rating_method eq 'upstream' now $csv->combine(@call_details); - $call_details = [ 'C', $csv->string, $charge, $classnum ]; + $call_details = + [ 'C', $csv->string, $charge, $classnum, $phonenum ]; } warn " adding details on charge to invoice: [ ". join(', ', @{$call_details} ). " ]" @@ -492,10 +592,13 @@ sub calc_recur { # if the customer flag is on, call "downstream_csv" or something # like it to export the call downstream! # XXX price plan option to pick format, or something... - $downstream_cdr .= $cdr->downstream_csv( 'format' => 'convergent' ) - if $spool_cdr; + #$downstream_cdr .= $cdr->downstream_csv( 'format' => 'XXX format' ) + # if $spool_cdr; - my $error = $cdr->set_status_and_rated_price('done', $charge); + my $error = $cdr->set_status_and_rated_price( 'done', + $charge, + $cust_svc->svcnum, + ); die $error if $error; } @@ -507,35 +610,32 @@ sub calc_recur { unshift @$details, [ 'C', FS::cdr::invoice_header($output_format) ] if @$details && $rating_method ne 'upstream'; - if ( $spool_cdr && length($downstream_cdr) ) { - - use FS::UID qw(datasrc); - my $dir = '/usr/local/etc/freeside/export.'. datasrc. '/cdr'; - mkdir $dir, 0700 unless -d $dir; - $dir .= '/'. $cust_pkg->custnum. - mkdir $dir, 0700 unless -d $dir; - my $filename = time2str("$dir/CDR%Y%m%d-spool.CSV", time); #XXX invoice date instead? would require changing the order things are generated in cust_main::bill insert cust_bill first - with transactions it could be done though - - push @{ $param->{'precommit_hooks'} }, - sub { - #lock the downstream spool file and append the records - use Fcntl qw(:flock); - use IO::File; - my $spool = new IO::File ">>$filename" - or die "can't open $filename: $!\n"; - flock( $spool, LOCK_EX) - or die "can't lock $filename: $!\n"; - seek($spool, 0, 2) - or die "can't seek to end of $filename: $!\n"; - print $spool $downstream_cdr; - flock( $spool, LOCK_UN ); - close $spool; - }; - - } #if ( $spool_cdr && length($downstream_cdr) ) - - $charges += $self->option('recur_fee') - if $param->{'increment_next_bill'}; +# if ( $spool_cdr && length($downstream_cdr) ) { +# +# use FS::UID qw(datasrc); +# my $dir = '/usr/local/etc/freeside/export.'. datasrc. '/cdr'; +# mkdir $dir, 0700 unless -d $dir; +# $dir .= '/'. $cust_pkg->custnum. +# mkdir $dir, 0700 unless -d $dir; +# my $filename = time2str("$dir/CDR%Y%m%d-spool.CSV", time); #XXX invoice date instead? would require changing the order things are generated in cust_main::bill insert cust_bill first - with transactions it could be done though +# +# push @{ $param->{'precommit_hooks'} }, +# sub { +# #lock the downstream spool file and append the records +# use Fcntl qw(:flock); +# use IO::File; +# my $spool = new IO::File ">>$filename" +# or die "can't open $filename: $!\n"; +# flock( $spool, LOCK_EX) +# or die "can't lock $filename: $!\n"; +# seek($spool, 0, 2) +# or die "can't seek to end of $filename: $!\n"; +# print $spool $downstream_cdr; +# flock( $spool, LOCK_UN ); +# close $spool; +# }; +# +# } #if ( $spool_cdr && length($downstream_cdr) ) $charges; } @@ -554,10 +654,12 @@ sub check_chargable { use_carrierid use_cdrtypenum skip_dcontext - skip_dstchannel_prefix; + skip_dstchannel_prefix + skip_dst_length_less + skip_lastapp ); foreach my $opt (grep !exists($flags{option_cache}->{$_}), @opt ) { - $flags{option_cache}->{$opt} = $self->option($opt); + $flags{option_cache}->{$opt} = $self->option($opt, 1); } my %opt = %{ $flags{option_cache} }; @@ -583,10 +685,17 @@ sub check_chargable { if $opt{'skip_dcontext'} =~ /\S/ && grep { $cdr->dcontext eq $_ } split(/\s*,\s*/, $opt{'skip_dcontext'}); - my $len = length($opt{'skip_dstchannel_prefix'}); + my $len_prefix = length($opt{'skip_dstchannel_prefix'}); return "dstchannel starts with $opt{'skip_dstchannel_prefix'}" - if $len - && substr($cdr->dstchannel, 0, $len) eq $opt{'skip_dstchannel_prefix'}; + if $len_prefix + && substr($cdr->dstchannel,0,$len_prefix) eq $opt{'skip_dstchannel_prefix'}; + + my $dst_length = $opt{'skip_dst_length_less'}; + return "destination less than $dst_length digits" + if $dst_length && length($cdr->dst) < $dst_length; + + return "lastapp is $opt{'skip_lastapp'}" + if length($opt{'skip_lastapp'}) && $cdr->lastapp eq $opt{'skip_lastapp'}; #all right then, rate it ''; @@ -596,16 +705,20 @@ sub is_free { 0; } -sub base_recur { - my($self, $cust_pkg) = @_; - $self->option('recur_fee'); -} - # This equates svc_phone records; perhaps svc_phone should have a field # to indicate it represents a line sub calc_units { my($self, $cust_pkg ) = @_; - scalar(grep { $_->part_svc->svcdb eq 'svc_phone' } $cust_pkg->cust_svc); + my $count = 0; + if ( $self->option('count_available_phones', 1)) { + map { $count += ( $_->quantity || 0 ) } + grep { $_->part_svc->svcdb eq 'svc_phone' } + $cust_pkg->part_pkg->pkg_svc; + } else { + $count = + scalar(grep { $_->part_svc->svcdb eq 'svc_phone' } $cust_pkg->cust_svc); + } + $count; } 1; |