return "Unable to transfer all services from package ". $self->pkgnum;
}
+ #reset usage if changing pkgpart
+ if ($self->pkgpart != $cust_pkg->pkgpart) {
+ my $part_pkg = $cust_pkg->part_pkg;
+ $error = $part_pkg->reset_usage($cust_pkg, $part_pkg->is_prepaid
+ ? ()
+ : ( 'null' => 1 )
+ )
+ if $part_pkg->can('reset_usage');
+
+ if ($error) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error setting usage values: $error";
+ }
+ }
+
#Good to go, cancel old package.
$error = $self->cancel( quiet=>1 );
if ($error) {
=cut
sub set_usage {
- my ($self, $valueref) = @_;
+ my ($self, $valueref, %opt) = @_;
foreach my $cust_svc ($self->cust_svc){
my $svc_x = $cust_svc->svc_x;
- $svc_x->set_usage($valueref)
+ $svc_x->set_usage($valueref, %opt)
if $svc_x->can("set_usage");
}
}
if ($self->option('usage_rollover', 1)) {
$cust_pkg->recharge(\%values);
}else{
- $cust_pkg->set_usage(\%values);
+ $cust_pkg->set_usage(\%values, %opt);
}
}
}
sub set_usage {
- my( $self, $valueref ) = @_;
+ my( $self, $valueref, %options ) = @_;
warn "$me set_usage called for svcnum ". $self->svcnum.
' ('. $self->email. "): ".
my $reset = 0;
my %handyhash = ();
+ if ( $options{null} ) {
+ %handyhash = ( map { ( $_ => 'NULL', $_."_threshold" => 'NULL' ) }
+ qw( seconds upbytes downbytes totalbytes )
+ );
+ }
foreach my $field (keys %$valueref){
$reset = 1 if $valueref->{$field};
$self->setfield($field, $valueref->{$field});
#die $error if $error; #services not explicity changed via the UI
my $sql = "UPDATE svc_acct SET " .
- join (',', map { "$_ = ?" } (keys %handyhash) ).
- " WHERE svcnum = ?";
+ join (',', map { "$_ = $handyhash{$_}" } (keys %handyhash) ).
+ " WHERE svcnum = ". $self->svcnum;
warn "$me $sql\n"
if $DEBUG;
if (scalar(keys %handyhash)) {
my $sth = $dbh->prepare( $sql )
or die "Error preparing $sql: ". $dbh->errstr;
- my $rv = $sth->execute((values %handyhash), $self->svcnum);
+ my $rv = $sth->execute();
die "Error executing $sql: ". $sth->errstr
unless defined($rv);
die "Can't update usage for svcnum ". $self->svcnum
%if ($error) {
% $cgi->param('error', $error);
-<% cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string ) %>
+<% $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string ) %>
%} else {
<% header("Package recharged") %>
<SCRIPT TYPE="text/javascript">
$error = $cust_main->recharge_prepay( $prepaid );
} elsif ( $payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP)$/ ) {
my $part_pkg = $svc_acct->cust_svc->cust_pkg->part_pkg;
- $amount = $part_pkg->option('recharge_amount', 1);
+ my $amount = $part_pkg->option('recharge_amount', 1);
my %rhash = map { $_ =~ /^recharge_(.*)$/; $1, $part_pkg->option($_) }
grep { $part_pkg->option($_, 1) }
qw ( recharge_seconds recharge_upbytes recharge_downbytes
$description, $part_pkg->taxclass);
if ($part_pkg->option('recharge_reset', 1)) {
- $error ||= $svc_acct->set_usage(\%rhash);
+ $error ||= $svc_acct->set_usage(\%rhash, 'null' => 1);
}else{
$error ||= $svc_acct->recharge(\%rhash);
}