|| $self->ut_numbern('adjourn')
|| $self->ut_numbern('expire')
|| $self->ut_enum('no_auto', [ '', 'Y' ])
+ || $self->ut_numbern('agent_pkgid')
;
return $error if $error;
}
}
- my %svc;
- if ( $date ) {
-# copied from below
- foreach my $cust_svc (
- #schwartz
- map { $_->[0] }
- sort { $a->[1] <=> $b->[1] }
- map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
- qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
- ) {
- my $error = $cust_svc->cancel( ('date' => $date) );
+ my %svc_cancel_opt = ();
+ $svc_cancel_opt{'date'} = $date if $date;
+ foreach my $cust_svc (
+ #schwartz
+ map { $_->[0] }
+ sort { $a->[1] <=> $b->[1] }
+ map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
+ qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
+ ) {
+ my $error = $cust_svc->cancel( %svc_cancel_opt );
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "Error expiring cust_svc: $error";
- }
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return 'Error '. ($svc_cancel_opt{'date'} ? 'expiring' : 'canceling' ).
+ " cust_svc: $error";
}
- } else { #!date
- foreach my $cust_svc (
- #schwartz
- map { $_->[0] }
- sort { $a->[1] <=> $b->[1] }
- map { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
- qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
- ) {
- my $error = $cust_svc->cancel;
+ }
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "Error cancelling cust_svc: $error";
- }
+ unless ($date) {
+
+ # Add a credit for remaining service
+ 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 $date
+ 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 ) {
+ my $error = $self->cust_main->credit(
+ $remaining_value,
+ 'Credit for unused time on '. $self->part_pkg->pkg,
+ 'reason_type' => $conf->config('cancel_credit_type'),
+ );
+ if ($error) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error crediting customer \$$remaining_value for unused time".
+ " on ". $self->part_pkg->pkg. ": $error";
+ }
+ } #if $remaining_value
+ } #if $do_credit
- # Add a credit for remaining service
- 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,
- 'reason_type' => $conf->config('cancel_credit_type'),
- );
- if ($error) {
- $dbh->rollback if $oldAutoCommit;
- return "Error crediting customer \$$remaining_value for unused time on".
- $self->part_pkg->pkg. ": $error";
- }
- } #if $remaining_value
- } #if $do_credit
+ } #unless $date
my %hash = $self->hash;
$date ? ($hash{'expire'} = $date) : ($hash{'cancel'} = $cancel_time);
sub h_cust_svc {
my $self = shift;
+ warn "$me _h_cust_svc called on $self\n"
+ if $DEBUG;
+
my ($end, $start, $mode) = @_;
my @cust_svc = $self->_sort_cust_svc(
[ qsearch( 'h_cust_svc',
if ( $mode eq 'I' ) {
my %hidden_svcpart = map { $_->svcpart => $_->hidden } $self->part_svc;
return grep { !$hidden_svcpart{$_->svcpart} } @cust_svc;
- }
- else {
+ } else {
return @cust_svc;
}
}
sub h_labels {
my $self = shift;
+ warn "$me _h_labels called on $self\n"
+ if $DEBUG;
map { [ $_->label(@_) ] } $self->h_cust_svc(@_);
}
sub _labels_short {
my( $self, $method ) = ( shift, shift );
+ warn "$me _labels_short called on $self with $method method\n"
+ if $DEBUG;
+
my $conf = new FS::Conf;
my $max_same_services = $conf->config('cust_bill-max_same_services') || 5;
+ warn "$me _labels_short populating \%labels\n"
+ if $DEBUG;
+
my %labels;
#tie %labels, 'Tie::IxHash';
push @{ $labels{$_->[0]} }, $_->[1]
foreach $self->$method(@_);
+
+ warn "$me _labels_short populating \@labels\n"
+ if $DEBUG;
+
my @labels;
foreach my $label ( keys %labels ) {
my %seen = ();
my @values = grep { ! $seen{$_}++ } @{ $labels{$label} };
my $num = scalar(@values);
+ warn "$me _labels_short $num items for $label\n"
+ if $DEBUG;
+
if ( $num > $max_same_services ) {
+ warn "$me _labels_short more than $max_same_services, so summarizing\n"
+ if $DEBUG;
push @labels, "$label ($num)";
} else {
if ( $conf->exists('cust_bill-consolidate_services') ) {
+ warn "$me _labels_short consolidating services\n"
+ if $DEBUG;
# push @labels, "$label: ". join(', ', @values);
while ( @values ) {
my $detail = "$label: ";
$detail .= shift(@values). ', '
- while @values && length($detail.$values[0]) < 78;
+ while @values
+ && ( length($detail.$values[0]) < 78 || $detail eq "$label: " );
$detail =~ s/, $//;
push @labels, $detail;
}
+ warn "$me _labels_short done consolidating services\n"
+ if $DEBUG;
} else {
+ warn "$me _labels_short adding service data\n"
+ if $DEBUG;
push @labels, map { "$label: $_" } @values;
}
}