my $amount = sprintf( "%.2f", $part_pkg->base_recur / $part_pkg->freq );
my $error =
- $referring_cust_main->credit( $amount,
- 'Referral credit for '. $cust_main->name
- );
+ $referring_cust_main->
+ credit( $amount,
+ 'Referral credit for '.$cust_main->name,
+ 'reason_type' => $conf->config('referral_credit_type')
+ );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error crediting customer ". $cust_main->referral_custnum.
}
$self->otaker(getotaker) unless $self->otaker;
- $self->otaker =~ /^([\w\.\-]{0,16})$/ or return "Illegal otaker";
+ $self->otaker =~ /^(\w{1,32})$/ or return "Illegal otaker";
$self->otaker($1);
if ( $self->dbdef_table->column('manual_flag') ) {
# Add a credit for remaining service
my $remaining_value = $self->calc_remain(time=>$cancel_time);
if ( $remaining_value > 0 && !$options{'no_credit'} ) {
+ my $conf = new FS::Conf;
my $error = $self->cust_main->credit(
- $remaining_value,
- 'Credit for unused time on '. $self->part_pkg->pkg,
- );
+ $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".
my $error = send_email(
'from' => $conf->config('invoice_from'),
'to' => \@invoicing_list,
- 'subject' => $conf->config('cancelsubject'),
+ 'subject' => ( $conf->config('cancelsubject') || 'Cancellation Notice' ),
'body' => [ map "$_\n", $conf->config('cancelmessage') ],
);
#should this do something on errors?
: qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
}
+=item old_cust_pkg
+
+Returns the cancelled package this package was changed from, if any.
+
+=cut
+
+sub old_cust_pkg {
+ my $self = shift;
+ return '' unless $self->change_pkgnum;
+ qsearchs('cust_pkg', { 'pkgnum' => $self->change_pkgnum } );
+}
+
=item calc_setup
Calls the I<calc_setup> of the FS::part_pkg object associated with this billing
my $change = scalar(@old_cust_pkg) != 0;
my %hash = ();
- if ( scalar(@old_cust_pkg) == 1 ) {
+ if ( scalar(@old_cust_pkg) == 1 && scalar(@$pkgparts) == 1 ) {
+
+ my $time = time;
+
#$hash{$_} = $old_cust_pkg[0]->$_() foreach qw( last_bill bill );
- $hash{'setup'} = time;
+
+ #$hash{$_} = $old_cust_pkg[0]->$_() foreach qw( setup );
+ $hash{'setup'} = $time if $old_cust_pkg[0]->setup;
+
+ $hash{'change_date'} = $time;
+ $hash{"change_$_"} = $old_cust_pkg[0]->$_() foreach qw( pkgnum pkgpart );
}
# Create the new packages.
my $cust_pkg_reason =
new FS::cust_pkg_reason({ 'pkgnum' => $self->pkgnum,
- 'reasonnum' => $options{'reason'},
+ 'reasonnum' => $reasonnum,
'otaker' => $otaker,
'date' => $options{'date'}
? $options{'date'}
}
}
+=item recharge USAGE_VALUE_HASHREF
+
+USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts
+to which they should be set (see L<FS::svc_acct>). Currently seconds,
+upbytes, downbytes, and totalbytes are appropriate keys.
+
+All svc_accts which are part of this package have their values incremented.
+
+=cut
+
+sub recharge {
+ my ($self, $valueref) = @_;
+
+ foreach my $cust_svc ($self->cust_svc){
+ my $svc_x = $cust_svc->svc_x;
+ $svc_x->recharge($valueref)
+ if $svc_x->can("recharge");
+ }
+}
+
=back
=head1 BUGS