[freeside-commits] freeside/FS/FS/part_pkg business_elec_generic.pm, NONE, 1.1.2.1 energy_base_discount_500kwh.pm, NONE, 1.1.2.1 energy_base_discount_tiers.pm, NONE, 1.1.2.1 residential_elec_generic.pm, NONE, 1.1.2.1 residential_elec_generic_var.pm, NONE, 1.1.2.1
Jeff Finucane,420,,
jeff at wavetail.420.am
Mon Aug 2 12:49:22 PDT 2010
- Previous message: [freeside-commits] freeside/FS/FS Conf.pm, 1.378, 1.378.2.1 Mason.pm, 1.47, 1.47.2.1 Schema.pm, 1.226, 1.226.2.1 cust_bill.pm, 1.288, 1.288.2.1 cust_bill_pkg.pm, 1.51, 1.51.2.1 cust_bill_pkg_detail.pm, 1.13, 1.13.2.1 cust_main.pm, 1.527, 1.527.2.1 elec_general.pm, NONE, 1.1.2.1 part_pkg.pm, 1.105, 1.105.2.1 svc_elec.pm, NONE, 1.1.2.1 transaction810.pm, NONE, 1.1.2.1 transaction867.pm, NONE, 1.1.2.1 usage_elec.pm, NONE, 1.1.2.1 usage_elec_transaction867.pm, NONE, 1.1.2.1
- Next message: [freeside-commits] freeside/FS/t elec_general.t, NONE, 1.1.2.1 svc_elec.t, NONE, 1.1.2.1 transaction810.t, NONE, 1.1.2.1 transaction867.t, NONE, 1.1.2.1 usage_elec.t, NONE, 1.1.2.1 usage_elec_transaction867.t, NONE, 1.1.2.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv14262/FS/FS/part_pkg
Added Files:
Tag: svc_elec_features
business_elec_generic.pm energy_base_discount_500kwh.pm
energy_base_discount_tiers.pm residential_elec_generic.pm
residential_elec_generic_var.pm
Log Message:
add svc_elec_features merged from reference code RT#7643
--- NEW FILE: residential_elec_generic.pm ---
package FS::part_pkg::residential_elec_generic;
use strict;
use vars qw(@ISA %info %penalty_fee $DEBUG);
use DBI;
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg::flat;
use FS::usage_elec;
@ISA = qw(FS::part_pkg::flat);
$DEBUG = 0;
tie %penalty_fee,'Tie::IxHash',
'0'=>0,
'0.05'=>0.05,
;
%info = (
'name' => 'Residential base package',
'svc_elec_compatible' => 1,
'fields' => {
'setup_fee' => { 'name' => 'Setup fee for this package',
'default' => 0,
},
'base_fee' => { 'name' => 'Base fee for this package',
'default' => 0,
},
'rate' => { 'name' => 'Rate for customer',
'default' => 1,
},
'rate1_discount' => { 'name' => 'Discount rate #1 (blank=disable)',
'default' => '',
},
'penalty' => { 'name'=>'Late fee',
'type' =>'select',
'select_options'=> \%penalty_fee,
},
},
'fieldorder' => [ 'setup_fee', 'base_fee','rate', 'rate1_discount', 'penalty' ],
'weight' => '70',
);
sub calc_recur {
my($self, $cust_pkg ) = @_;
my $date =0;
# -cal 7/5/07 added debug comment to those line that tommy use for debugging
# then comment them out
my $cust_svc=qsearchs('cust_svc',{'pkgnum' => $cust_pkg->pkgnum});
my $lastdate =$cust_pkg -> last_bill ||0;
warn $lastdate."\n" if $DEBUG;
warn $cust_svc->svcnum."\n" if $DEBUG;
warn $cust_pkg->pkgnum."\n" if $DEBUG;
my @usage_elecs=qsearch('usage_elec',{'svcnum' => $cust_svc->svcnum,
'_date'=> { op=>'>', value=>$lastdate },
'extra_sql' => 'ORDER BY _date_'});
warn "test". at usage_elecs."\n" if $DEBUG;
if(defined($usage_elecs[0])){
warn "test2".$usage_elecs[0]->id."\n" if $DEBUG;
warn $usage_elecs[0]->getUsage."usage\n" if $DEBUG;
my $base=$self->option('base_fee');
my $rate=$self->option('rate');
my $sum= $base + ($usage_elecs[0]->getUsage)*$rate+$usage_elecs[0]->tdsp;
warn $sum."\n" if $DEBUG;
warn "$base * $rate = ".$base*$rate if $DEBUG;
return round($sum);
}
return 0;
#$hours -= $self->option('recur_included_hours');
#$hours = 0 if $hours < 0;
#$self->option('recur_flat') + $hours * $self->option('recur_hourly_charge');
#return 99;
}
sub is_free_options {
qw( setup_fee recur_flat recur_unit_charge );
}
sub base_recur {
my($self, $cust_pkg) = @_;
$self->option('base_fee');
}
sub round {
my($number) = shift;
my $roundit= int($number*100 + .5);
return sprintf('%.2f',$roundit/100)
}
1;
--- NEW FILE: residential_elec_generic_var.pm ---
package FS::part_pkg::residential_elec_generic_var;
use strict;
use vars qw(@ISA %info %penalty_fee);
use Date::Format;
use Data::Dumper;
use DBI;
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg::flat;
use FS::usage_elec;
@ISA = qw(FS::part_pkg::flat);
tie %penalty_fee,'Tie::IxHash',
'0'=>0,
'0.05'=>0.05,
;
%info = (
'name' => 'Residential base package var',
'svc_elec_compatible' => 1,
'fields' => {
'setup_fee' => { 'name' => 'Setup fee for this package',
'default' => 0,
},
'base_fee' => { 'name' => 'Base fee for this package',
'default' => 0,
},
'rate' => { 'name' => 'Default Rate for customer',
'default' => '0.12',
},
'vrate' => { 'name' => 'Variable Rate (blank=disable)',
'default' => '2008-01:0.12;2009-01:0.12',
},
'rate1_discount' => { 'name' => 'Discount rate #1 (blank=disable)',
'default' => '',
},
'penalty' => { 'name'=>'Late fee',
'type' =>'select',
'select_options'=> \%penalty_fee,
},
},
'fieldorder' => [ 'setup_fee', 'base_fee','rate', 'vrate', 'rate1_discount', 'penalty' ],
'weight' => '70',
);
sub calc_recur {
my($self, $cust_pkg ) = @_;
my $date =0;
# -cal 7/5/07 added debug comment to those line that tommy use for debugging
# then comment them out
# generate the variable rate hash
my $vrate=$self->option('vrate');
my %var_rate;
if ($vrate) {
foreach my $rate_frame (split(';',$vrate)) {
my ($period, $period_rate) = split(':',$rate_frame);
my ($yr,$mo) = split('-',$period);
$var_rate{$yr}{$mo} = $period_rate;
}
}
my $cust_svc=qsearchs('cust_svc',{'pkgnum' => $cust_pkg->pkgnum});
my $lastdate =$cust_pkg -> last_bill ||0;
my @usage_elecs=qsearch('usage_elec',{'svcnum' => $cust_svc->svcnum,
'_date'=> { op=>'>', value=>$lastdate },
'extra_sql' => 'ORDER BY _date_'});
if(defined($usage_elecs[0])){
my $base=$self->option('base_fee');
my $rate=$self->option('rate');
# usage end date
my $usage_enddate_year = time2str('%Y',$usage_elecs[0]->curr_date);
my $usage_enddate_month = time2str('%m',$usage_elecs[0]->curr_date);
#my $v_rate = $rate;
if ($vrate) {
# if a variable rate
$rate = $var_rate{$usage_enddate_year}{$usage_enddate_month}
if (exists $var_rate{$usage_enddate_year}{$usage_enddate_month});
}
my $sum= $base + ($usage_elecs[0]->getUsage)*$rate+$usage_elecs[0]->tdsp;
return round($sum);
}
return 0;
#$hours -= $self->option('recur_included_hours');
#$hours = 0 if $hours < 0;
#$self->option('recur_flat') + $hours * $self->option('recur_hourly_charge');
#return 99;
}
sub is_free_options {
qw( setup_fee recur_flat recur_unit_charge );
}
sub base_recur {
my($self, $cust_pkg) = @_;
$self->option('base_fee');
}
sub round {
my($number) = shift;
my $roundit= int($number*100 + .5);
return sprintf('%.2f',$roundit/100)
}
1;
--- NEW FILE: business_elec_generic.pm ---
package FS::part_pkg::business_elec_generic;
#test
use strict;
use vars qw(@ISA %info %gr_fee %penalty_fee $DEBUG);
use DBI;
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg::flat;
use FS::usage_elec;
@ISA = qw(FS::part_pkg::flat);
$DEBUG = 0;
tie %penalty_fee,'Tie::IxHash',
'0'=>0,
'0.05'=>0.05,
;
tie %gr_fee, 'Tie::IxHash',
'0.005' => 0.005,
'0.01' => 0.01,
'0.02' => 0.02,
;
%info = (
'name' => 'Business base package',
'svc_elec_compatible' => 1,
'fields' => {
'setup_fee' => { 'name' => 'Setup fee for this package',
'default' => 0,
},
'base_fee' => { 'name' => 'Base fee for this package',
'default' => 0,
},
'rate' => { 'name' => 'Rate for customer',
'default' => 1,
},
'gr_fee' => { 'name' =>'Ground fee',
'type' =>'select',
'select_options' => \%gr_fee,
},
'penalty' => { 'name'=>'Late fee',
'type' =>'select',
'select_options'=> \%penalty_fee,
},
},
'fieldorder' => [ 'setup_fee', 'base_fee','rate','gr_fee','penalty' ],
'weight' => '70',
);
sub calc_recur {
my($self, $cust_pkg ) = @_;
my $date =0;
my $cust_svc=qsearchs('cust_svc',{'pkgnum' => $cust_pkg->pkgnum});
my $lastdate =$cust_pkg -> last_bill ||0;
warn $lastdate if $DEBUG;
my @usage_elecs=qsearch('usage_elec',{'svcnum' => $cust_svc->svcnum,
'_date'=> { op=>'>', value=>$lastdate },
'extra_sql' => 'ORDER BY _date_'});
warn "test". at usage_elecs."\n" if $DEBUG;
if(defined($usage_elecs[0])){
warn "test2".$usage_elecs[0]->id if $DEBUG;
my $base=$self->option('base_fee');
my $rate=$self->option('rate');
my $sum= $base + ($usage_elecs[0]->getUsage)*$rate+$usage_elecs[0]->tdsp;
warn $sum."\n" if $DEBUG;
warn "grfee = ".$sum* $self->option('gr_fee') if $DEBUG;
$sum = $sum + $sum * $self->option('gr_fee');
warn "sum = ".$sum if $DEBUG;
return round($sum);
}
return 0;
#$hours -= $self->option('recur_included_hours');
#$hours = 0 if $hours < 0;
#$self->option('recur_flat') + $hours * $self->option('recur_hourly_charge');
#return 99;
}
sub is_free_options {
qw( setup_fee recur_flat recur_unit_charge );
}
sub base_recur {
my($self, $cust_pkg) = @_;
$self->option('base_fee');
}
sub round {
my($number) = shift;
my $roundit= int($number*100 + .5);
return sprintf('%.2f',$roundit/100)
}
1;
--- NEW FILE: energy_base_discount_tiers.pm ---
package FS::part_pkg::energy_base_discount_tiers;
use strict;
use vars qw(@ISA %info %penalty_fee);
use DBI;
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg::flat;
use FS::usage_elec;
use Date::Format;
use Date::Parse;
use Data::Dumper;
@ISA = qw(FS::part_pkg::flat);
tie %penalty_fee,'Tie::IxHash',
'0'=>0,
'0.05'=>0.05,
;
%info = (
'name' => 'Energy base discount tiers',
'svc_elec_compatible' => 1,
'fields' =>
{
'description' =>
{ 'name' => 'Description printed on bill',
'default' => 'SPECIAL BASE CHARGE DISCOUNT FOR TIERS USAGE',
},
'rate'=>
{ 'name' => 'Tiers Discount Amount',
'default' => '0-499:0.00;500-999:3.00;1000-:7.95',
},
'penalty' =>
{ 'name'=>'Late fee',
'type' =>'select',
'select_options'=> \%penalty_fee,
},
},
'fieldorder' => [ 'description', 'rate' ],
'weight' => '70',
);
sub calc_recur {
my($self, $cust_pkg ) = @_;
my $date =0;
# this fee is dependent on the existence of a base elecusage package existence
# so let check if it exist.
my $custnum = $cust_pkg->custnum;
my $basic_engpkg_exist;
my $usage_svcnum;
my $lastdate;
foreach my $cust_pkg_tmp ( qsearch(
{
'table' => 'cust_pkg',
'hashref'=> { 'custnum' => $custnum },
'extra_sql' => 'ORDER BY pkgnum ASC'
} )
) {
next if $cust_pkg_tmp->getfield('cancel');
# -ctran 06/09/08
# updated liteup
next if $cust_pkg_tmp->getfield('susp');
next if ($cust_pkg_tmp->getfield('pkgnum') == $cust_pkg->pkgnum);
my $pkgnum = $cust_pkg_tmp->getfield('pkgnum');
my $cust_svc_tmp = qsearchs('cust_svc',{'pkgnum' => $pkgnum});
#check for keyword ESIID from svc_external
if ($cust_svc_tmp) {
my $svc_external = qsearchs('svc_external',{'svcnum'=>$cust_svc_tmp->svcnum});
if ($svc_external) {
if (!$basic_engpkg_exist && ($svc_external->title =~ /^ESIID$/i)) {
$basic_engpkg_exist = 1;
$usage_svcnum = $cust_svc_tmp->getfield('svcnum');
$lastdate =$cust_pkg_tmp->last_bill ||0;
}
}
}
}
# now let get the usage if a energy package exist
if ($basic_engpkg_exist) {
my @usage_elecs=qsearch(
{
'table' => 'usage_elec',
'hashref' => { 'svcnum' => $usage_svcnum,
# '_date' => { 'op' => '>',
# 'value' => $lastdate
# }
},
'extra_sql' => 'ORDER BY _date DESC'
});
if(defined($usage_elecs[0])) {
my $usage = $usage_elecs[0]->getUsage;
if ($usage) {
my $rate = $self->option('rate');
foreach my $tier (split(';',$rate)) {
my ($range, $disc_val) = split(':',$tier);
my ($min,$max) = split('-',$range);
#set default value
#$min = 0 unless defined $min;
if ($min) {
if ($min <= $usage) {
if ($max) {
if ($usage <= $max) {
return (round($disc_val) * -1);
}
}
else {
#there no max
return (round($disc_val) * -1);
}
}
}
else {
if ($max) {
if ($usage <= $max) {
return (round($disc_val) * -1);
}
}
else {
#there no max
return (round($disc_val) * -1);
}
}
}#for
}
}
}
return 0;
}
sub is_free_options {
qw( setup_fee recur_flat recur_unit_charge );
}
sub base_recur {
my($self, $cust_pkg) = @_;
$self->option('base_fee');
}
sub round {
my($number) = shift;
my $roundit= int($number*100 + .5);
return sprintf('%.2f',$roundit/100)
}
1;
--- NEW FILE: energy_base_discount_500kwh.pm ---
package FS::part_pkg::energy_base_discount_500kwh;
use strict;
use vars qw(@ISA %info %penalty_fee $DEBUG);
use DBI;
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg::flat;
use FS::usage_elec;
use Date::Format;
use Date::Parse;
use Data::Dumper;
@ISA = qw(FS::part_pkg::flat);
$DEBUG = 0;
tie %penalty_fee,'Tie::IxHash',
'0'=>0,
'0.05'=>0.05,
;
%info = (
'name' => 'Energy base discount 500KWH',
'svc_elec_compatible' => 1,
'fields' =>
{
'description' =>
{ 'name' => 'Description printed on bill',
'default' => 'SPECIAL BASE CHARGE DISCOUNT FOR USAGE > 500KWH',
},
'rate'=>
{ 'name' => 'Discount Amount',
'default' => 4.95,
},
'penalty' =>
{ 'name'=>'Late fee',
'type' =>'select',
'select_options'=> \%penalty_fee,
},
},
'fieldorder' => [ 'description', 'rate' ],
'weight' => '70',
);
sub calc_recur {
my($self, $cust_pkg ) = @_;
my $date =0;
warn "cust_pkg = '\n" .Dumper($cust_pkg). "'\n" if $DEBUG;
#my $cust_svc=qsearchs('cust_svc',{'pkgnum' => $cust_pkg->pkgnum});
#my $lastdate =$cust_pkg -> last_bill ||0;
# this fee is dependent on the existence of a base elecusage package existence
# so let check if it exist.
my $custnum = $cust_pkg->custnum;
my $basic_engpkg_exist;
my $usage_svcnum;
my $lastdate;
foreach my $cust_pkg_tmp ( qsearch(
{
'table' => 'cust_pkg',
'hashref'=> { 'custnum' => $custnum },
'extra_sql' => 'ORDER BY pkgnum ASC'
} )
) {
next if $cust_pkg_tmp->getfield('cancel');
# -ctran 06/09/08
# updated liteup
next if $cust_pkg_tmp->getfield('susp');
next if ($cust_pkg_tmp->getfield('pkgnum') == $cust_pkg->pkgnum);
my $pkgnum = $cust_pkg_tmp->getfield('pkgnum');
warn "\tpkgnum = ". $pkgnum . "\n" if $DEBUG;
my $cust_svc_tmp = qsearchs('cust_svc',{'pkgnum' => $pkgnum});
warn "\t\tcust_svc_tmp = '" . Dumper($cust_pkg_tmp) . "'\n" if $DEBUG;
#check for keyword ESIID from svc_external
if ($cust_svc_tmp) {
my $svc_external = qsearchs('svc_external',{'svcnum'=>$cust_svc_tmp->svcnum});
if ($svc_external) {
warn "\t\t\tsvc_external = '" . Dumper($svc_external) . "'\n" if $DEBUG;
if (!$basic_engpkg_exist && ($svc_external->title =~ /^ESIID$/i)) {
$basic_engpkg_exist = 1;
$usage_svcnum = $cust_svc_tmp->getfield('svcnum');
$lastdate =$cust_pkg_tmp->last_bill ||0;
}
}
}
}
warn "custnum = " . $custnum . "\n" if $DEBUG;
warn "lastdate='".time2str("%C",$lastdate)."'\n" if $DEBUG;
warn "lastdate='".$lastdate."'\n" if $DEBUG;
warn "usage_svcnum=".$usage_svcnum."\n" if $DEBUG;
warn "basic_engpkg_exist = " . $basic_engpkg_exist . "\n" if $DEBUG;
# now let get the usage if a energy package exist
if ($basic_engpkg_exist) {
my @usage_elecs=qsearch(
{
'table' => 'usage_elec',
'hashref' => { 'svcnum' => $usage_svcnum,
# '_date' => { 'op' => '>',
# 'value' => $lastdate
# }
},
'extra_sql' => 'ORDER BY _date DESC'
});
if(defined($usage_elecs[0])) {
#warn "test2". at usage_elecs[0]->id."\n" if $DEBUG;
warn "usage = " . $usage_elecs[0]->getUsage."\n" if $DEBUG;
#my $base=$self->option('base_fee');
#my $rate=$self->option('rate');
#my $sum= $base + (@usage_elecs[0]->getUsage)*$rate+ at usage_elecs[0]->tdsp;
if ($usage_elecs[0]->getUsage >= 500) {
my $discount = $self->option('rate');
return (round($discount) * -1);
}
}
}
return 0;
}
sub is_free_options {
qw( setup_fee recur_flat recur_unit_charge );
}
sub base_recur {
my($self, $cust_pkg) = @_;
$self->option('base_fee');
}
sub round {
my($number) = shift;
my $roundit= int($number*100 + .5);
return sprintf('%.2f',$roundit/100)
}
1;
- Previous message: [freeside-commits] freeside/FS/FS Conf.pm, 1.378, 1.378.2.1 Mason.pm, 1.47, 1.47.2.1 Schema.pm, 1.226, 1.226.2.1 cust_bill.pm, 1.288, 1.288.2.1 cust_bill_pkg.pm, 1.51, 1.51.2.1 cust_bill_pkg_detail.pm, 1.13, 1.13.2.1 cust_main.pm, 1.527, 1.527.2.1 elec_general.pm, NONE, 1.1.2.1 part_pkg.pm, 1.105, 1.105.2.1 svc_elec.pm, NONE, 1.1.2.1 transaction810.pm, NONE, 1.1.2.1 transaction867.pm, NONE, 1.1.2.1 usage_elec.pm, NONE, 1.1.2.1 usage_elec_transaction867.pm, NONE, 1.1.2.1
- Next message: [freeside-commits] freeside/FS/t elec_general.t, NONE, 1.1.2.1 svc_elec.t, NONE, 1.1.2.1 transaction810.t, NONE, 1.1.2.1 transaction867.t, NONE, 1.1.2.1 usage_elec.t, NONE, 1.1.2.1 usage_elec_transaction867.t, NONE, 1.1.2.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list