[freeside-commits] freeside/FS/FS cust_pkg.pm,1.185,1.186
Mark Wells
mark at wavetail.420.am
Fri Dec 24 01:56:40 PST 2010
- Previous message: [freeside-commits] freeside/FS/FS/part_pkg agent.pm, 1.7, 1.7.2.1 base_delayed.pm, 1.4, 1.4.8.1 base_rate.pm, 1.4, 1.4.6.1 bulk.pm, 1.10, 1.10.2.1 cdr_termination.pm, 1.7, 1.7.2.1 flat_comission_cust.pm, 1.8, 1.8.4.1 flat_comission_pkg.pm, 1.7, 1.7.4.1 flat_comission.pm, 1.8, 1.8.4.1 flat_delayed.pm, 1.9, 1.9.6.1 flat_introrate.pm, 1.3, 1.3.6.1 flat.pm, 1.53.2.1, 1.53.2.2 global_Mixin.pm, NONE, 1.1.2.2 prepaid.pm, 1.6, 1.6.6.1 prorate_delayed.pm, 1.4, 1.4.6.1 prorate.pm, 1.23, 1.23.2.1 rt_time.pm, 1.3, 1.3.4.1 sesmon_hour.pm, 1.9, 1.9.4.1 sesmon_minute.pm, 1.10, 1.10.4.1 sql_external.pm, 1.11, 1.11.2.1 sql_generic.pm, 1.9, 1.9.4.1 sqlradacct_hour.pm, 1.10, 1.10.4.1 subscription.pm, 1.18, 1.18.2.1 usage_Mixin.pm, NONE, 1.1.2.2 voip_cdr.pm, 1.108, 1.108.2.1 voip_inbound.pm, 1.4, 1.4.2.1 voip_sqlradacct.pm, 1.22, 1.22.4.1
- Next message: [freeside-commits] freeside/FS/FS cust_pkg.pm,1.179.2.5,1.179.2.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv18804
Modified Files:
cust_pkg.pm
Log Message:
option to credit unused time on package change, RT#10670
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.185
retrieving revision 1.186
diff -u -w -d -r1.185 -r1.186
--- cust_pkg.pm 21 Dec 2010 06:26:11 -0000 1.185
+++ cust_pkg.pm 24 Dec 2010 09:56:38 -0000 1.186
@@ -595,6 +595,12 @@
=item nobill - can be set true to skip billing if it might otherwise be done.
+=item unused_credit - can be set to 1 to credit the remaining time, or 0 to
+not credit it. This must be set (by change()) when changing the package
+to a different pkgpart or location, and probably shouldn't be in any other
+case. If it's not set, the 'unused_credit_cancel' part_pkg option will
+be used.
+
=back
If there is an error, returns the error, otherwise returns false.
@@ -645,7 +651,6 @@
if $error;
}
-
my $cancel_time = $options{'time'} || time;
if ( $options{'reason'} ) {
@@ -670,7 +675,6 @@
map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
) {
-
my $error = $cust_svc->cancel( ('date' => $date) );
if ( $error ) {
@@ -678,8 +682,7 @@
return "Error expiring cust_svc: $error";
}
}
-
- } else {
+ } else { #!date
foreach my $cust_svc (
#schwartz
map { $_->[0] }
@@ -687,7 +690,6 @@
map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
) {
-
my $error = $cust_svc->cancel;
if ( $error ) {
@@ -695,10 +697,28 @@
return "Error cancelling cust_svc: $error";
}
}
+ } #if $date
# Add a credit for remaining service
- my $remaining_value = $self->calc_remain(time=>$cancel_time);
- if ( $remaining_value > 0 && !$options{'no_credit'} ) {
+ my $last_bill = $self->getfield('last_bill') || 0;
+ my $next_bill = $self->getfield('bill') || 0;
+ my $do_credit;
+ if ( exists($options{'unused_credit'}) ) {
+ $do_credit = $options{'unused_credit'};
+ }
+ else {
+ $do_credit = $self->part_pkg->option('unused_credit_cancel', 1);
+ }
+ if ( $do_credit
+ and $last_bill > 0 # the package has been billed
+ and $next_bill > 0 # the package has a next bill date
+ and $next_bill >= $cancel_time # which is in the future
+ ) {
+ my $remaining_value = $self->calc_remain('time' => $cancel_time);
+ if ( $remaining_value > 0 ) {
+ # && !$options{'no_credit'} ) {
+ # Undocumented, unused option.
+ # part_pkg configuration should decide this anyway.
my $error = $self->cust_main->credit(
$remaining_value,
'Credit for unused time on '. $self->part_pkg->pkg,
@@ -709,8 +729,8 @@
return "Error crediting customer \$$remaining_value for unused time on".
$self->part_pkg->pkg. ": $error";
}
- }
- }
+ } #if $remaining_value
+ } #if $do_credit
my %hash = $self->hash;
$date ? ($hash{'expire'} = $date) : ($hash{'cancel'} = $cancel_time);
@@ -1221,12 +1241,23 @@
$opt->{'locationnum'} = $opt->{'cust_location'}->locationnum;
}
+ my $unused_credit = 0;
if ( $opt->{'keep_dates'} ) {
foreach my $date ( qw(setup bill last_bill susp adjourn cancel expire
start_date contract_end ) ) {
$hash{$date} = $self->getfield($date);
}
}
+ # Special case. If the pkgpart is changing, and the customer is
+ # going to be credited for remaining time, don't keep setup, bill,
+ # or last_bill dates, and DO pass the flag to cancel() to credit
+ # the customer.
+ if ( $opt->{'pkgpart'}
+ and $opt->{'pkgpart'} != $self->pkgpart
+ and $self->part_pkg->option('unused_credit_change', 1) ) {
+ $unused_credit = 1;
+ $hash{$_} = '' foreach qw(setup bill last_bill);
+ }
# Create the new package.
my $cust_pkg = new FS::cust_pkg {
@@ -1285,8 +1316,9 @@
}
}
- #Good to go, cancel old package.
- $error = $self->cancel( quiet=>1 );
+ #Good to go, cancel old package. Notify 'cancel' of whether to credit
+ #remaining time.
+ $error = $self->cancel( quiet=>1, unused_credit => $unused_credit );
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
- Previous message: [freeside-commits] freeside/FS/FS/part_pkg agent.pm, 1.7, 1.7.2.1 base_delayed.pm, 1.4, 1.4.8.1 base_rate.pm, 1.4, 1.4.6.1 bulk.pm, 1.10, 1.10.2.1 cdr_termination.pm, 1.7, 1.7.2.1 flat_comission_cust.pm, 1.8, 1.8.4.1 flat_comission_pkg.pm, 1.7, 1.7.4.1 flat_comission.pm, 1.8, 1.8.4.1 flat_delayed.pm, 1.9, 1.9.6.1 flat_introrate.pm, 1.3, 1.3.6.1 flat.pm, 1.53.2.1, 1.53.2.2 global_Mixin.pm, NONE, 1.1.2.2 prepaid.pm, 1.6, 1.6.6.1 prorate_delayed.pm, 1.4, 1.4.6.1 prorate.pm, 1.23, 1.23.2.1 rt_time.pm, 1.3, 1.3.4.1 sesmon_hour.pm, 1.9, 1.9.4.1 sesmon_minute.pm, 1.10, 1.10.4.1 sql_external.pm, 1.11, 1.11.2.1 sql_generic.pm, 1.9, 1.9.4.1 sqlradacct_hour.pm, 1.10, 1.10.4.1 subscription.pm, 1.18, 1.18.2.1 usage_Mixin.pm, NONE, 1.1.2.2 voip_cdr.pm, 1.108, 1.108.2.1 voip_inbound.pm, 1.4, 1.4.2.1 voip_sqlradacct.pm, 1.22, 1.22.4.1
- Next message: [freeside-commits] freeside/FS/FS cust_pkg.pm,1.179.2.5,1.179.2.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list