if ( $cust_main->total_owed_date($self->_date) < $amount ) {
return ();
} else {
- $cust_main->suspend;
+ $cust_main->suspend(@_);
}
}
sub suspend {
my $self = shift;
- grep { $_->suspend } $self->unsuspended_pkgs;
+ grep { $_->suspend(@_) } $self->unsuspended_pkgs;
}
=item suspend_if_pkgpart PKGPART [ , PKGPART ... ]
sub suspend_if_pkgpart {
my $self = shift;
- my @pkgparts = @_;
- grep { $_->suspend }
+ my (@pkgparts, %opt);
+ if (ref($_[0]) eq 'HASH'){
+ @pkgparts = @{$_[0]{pkgparts}};
+ %opt = %{$_[0]};
+ }else{
+ @pkgparts = @_;
+ }
+ grep { $_->suspend(%opt) }
grep { my $pkgpart = $_->pkgpart; grep { $pkgpart eq $_ } @pkgparts }
$self->unsuspended_pkgs;
}
sub suspend_unless_pkgpart {
my $self = shift;
- my @pkgparts = @_;
- grep { $_->suspend }
+ my (@pkgparts, %opt);
+ if (ref($_[0]) eq 'HASH'){
+ @pkgparts = @{$_[0]{pkgparts}};
+ %opt = %{$_[0]};
+ }else{
+ @pkgparts = @_;
+ }
+ grep { $_->suspend(%opt) }
grep { my $pkgpart = $_->pkgpart; ! grep { $pkgpart eq $_ } @pkgparts }
$self->unsuspended_pkgs;
}
use FS::cust_bill_pkg;
use FS::h_cust_svc;
use FS::reg_code;
+use FS::cust_pkg_reason;
# need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
# setup }
=cut
sub replace {
- my( $new, $old ) = ( shift, shift );
+ my( $new, $old, %options ) = @_;
#return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
return "Can't change otaker!" if $old->otaker ne $new->otaker;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ if ($options{'reason'} && $new->expire && $old->expire ne $new->expire) {
+ my $error = $new->insert_reason( 'reason' => $options{'reason'},
+ 'date' => $new->expire,
+ );
+ if ( $error ) {
+ dbh->rollback if $oldAutoCommit;
+ return "Error inserting cust_pkg_reason: $error";
+ }
+ }
+
#save off and freeze RADIUS attributes for any associated svc_acct records
my @svc_acct = ();
if ( $old->part_pkg->is_prepaid || $new->part_pkg->is_prepaid ) {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ if ($options{'reason'}) {
+ $error = $self->insert_reason( 'reason' => $options{'reason'} );
+ if ( $error ) {
+ dbh->rollback if $oldAutoCommit;
+ return "Error inserting cust_pkg_reason: $error";
+ }
+ }
+
my %svc;
foreach my $cust_svc (
qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
=cut
sub suspend {
- my $self = shift;
+ my( $self, %options ) = @_;
my $error ;
local $SIG{HUP} = 'IGNORE';
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ if ($options{'reason'}) {
+ $error = $self->insert_reason( 'reason' => $options{'reason'} );
+ if ( $error ) {
+ dbh->rollback if $oldAutoCommit;
+ return "Error inserting cust_pkg_reason: $error";
+ }
+ }
+
foreach my $cust_svc (
qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
) {
$cust_bill_pkg ? $cust_bill_pkg->sdate : $self->setup || 0;
}
+=item last_reason
+
+Returns the most recent FS::reason associated with the package.
+
+=cut
+
+sub last_reason {
+ my $self = shift;
+ my $cust_pkg_reason = qsearchs( {
+ 'table' => 'cust_pkg_reason',
+ 'hashref' => { 'pkgnum' => $self->pkgnum, },
+ 'extra_sql'=> 'ORDER BY date DESC',
+ } );
+ qsearchs ( 'reason', { 'reasonnum' => $cust_pkg_reason->reasonnum } )
+ if $cust_pkg_reason;
+}
+
=item part_pkg
Returns the definition for this billing item, as an FS::part_pkg object (see
'';
}
+sub insert_reason {
+ my ($self, %options) = @_;
+
+ my $otaker = $FS::CurrentUser::CurrentUser->name;
+ $otaker = $FS::CurrentUser::CurrentUser->username
+ if (($otaker) eq "User, Legacy");
+
+ my $cust_pkg_reason =
+ new FS::cust_pkg_reason({ 'pkgnum' => $self->pkgnum,
+ 'reasonnum' => $options{'reason'},
+ 'otaker' => $otaker,
+ 'date' => $options{'date'}
+ ? $options{'date'}
+ : time,
+ });
+ return $cust_pkg_reason->insert;
+}
+
=back
=head1 BUGS
}
}
- my $reasonr = qsearchs('reason', {'reasonnum' => $self->reason});
- return "Unknown reason" unless $reasonr;
+ if ($self->reason){
+ my $reasonr = qsearchs('reason', {'reasonnum' => $self->reason});
+ return "Unknown reason" unless $reasonr;
+ }
$self->SUPER::check;
}
% },
% 'suspend' => {
% 'name' => 'Suspend',
-% 'code' => '$cust_main->suspend();',
+% 'code' => '$cust_main->suspend(reason => %%%sreason%%%);',
% 'weight' => 10,
% 'reason' => 'S',
% },
% 'suspend-if-balance' => {
% 'name' => 'Suspend if balance (this invoice and previous) over',
-% 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
+% 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
% 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
% 'weight' => 10,
% 'reason' => 'S',
% },
% 'suspend-if-pkgpart' => {
% 'name' => 'Suspend packages',
-% 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
+% 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
% 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
% 'weight' => 10,
% 'reason' => 'S',
% },
% 'suspend-unless-pkgpart' => {
% 'name' => 'Suspend packages except',
-% 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
+% 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
% 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
% 'weight' => 10,
% 'reason' => 'S',
% },
% 'cancel' => {
% 'name' => 'Cancel',
-% 'code' => '$cust_main->cancel();',
+% 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
% 'weight' => 10,
% 'reason' => 'C',
% },
% my $rnum;
% my $rtype;
% my $reasonm;
-% if ($eventcode =~ /cancel/) {
-% $cgi->param('creason') =~ /^(-?\d+)$/ || die "Invalid creason";
+% my $class = '';
+% $class='c' if ($eventcode =~ /cancel/);
+% $class='s' if ($eventcode =~ /suspend/);
+% if ($class) {
+% $cgi->param("${class}reason") =~ /^(-?\d+)$/
+% or $error = "Invalid ${class}reason";
% $rnum = $1;
% if ($rnum == -1) {
-% $cgi->param('newcreasonT') =~ /^(\d+)$/ || die "Invalid newcreasonT";
+% $cgi->param("new${class}reasonT") =~ /^(\d+)$/
+% or $error = "Invalid new${class}reasonT";
% $rtype = $1;
-% $cgi->param('newcreason') =~ /^([\s\w]+)$/ || die "Invalid newcreasonT";
-% $reasonm = $1;
-% }
-% }
-% if ($eventcode =~ /suspend/) {
-% $cgi->param('sreason') =~ /^(-?\d+)$/ || die "Invalid sreason";
-% $rnum = $1;
-% if ($rnum == -1) {
-% $cgi->param('newsreasonT') =~ /^(\d+)$/ || die "Invalid newsreasonT";
-% $rtype = $1;
-% $cgi->param('newsreason') =~ /^([\s\w]+)$/ || die "Invalid newsreasonT";
+% $cgi->param("new${class}reason") =~ /^([\s\w]+)$/
+% or $error = "Invalid new${class}reason";
% $reasonm = $1;
% }
% }
% 'reason_type' => $rtype,
% });
% $error = $reason->insert or $rnum = $reason->reasonnum;
+% unless ($error) {
+% $cgi->param("${class}reason", $rnum);
+% $cgi->param("new${class}reason", '');
+% $cgi->param("new${class}reasonT", '');
+% }
% }
%
% unless($error){
%}
%
%
-
-
%
% my (@types) = qsearch( 'reason_type', { 'class' => $class } );
%
+% unless (scalar(@types)) {
+% print $cgi->redirect( "reason_type.html?class=$class" );
+% }
<% include( 'elements/edit.html',
'name' => ucfirst($classname) . ' Reason',
'table' => 'reason',
{
%if ($curuser->access_right($access_right)){
+ if (document.getElementById('<% $name %>').selectedIndex == 0){
+ <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
+ }else{
+ <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
+ }
if (document.getElementById('<% $name %>').selectedIndex ==
(document.getElementById('<% $name %>').length - 1)) {
% extra_sql => $extra_sql,
% addl_from => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type',
% });
+ <OPTION VALUE="" <% ($init_reason eq "") ? 'SELECTED' : '' %>>Select Reason...</OPTION>
% foreach my $reason (@reasons) {
<OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reason %></OPTION>
% }
</TR>
<%init>
-my($name, $class, $init_reason, $init_type, $init_newreason) = @_;
+my($name, $class, $init_reason, $init_type, $init_newreason, $controlledbutton) = @_;
my($extra_sql, $curuser, $access_right, $display, $disabled);
if ($class eq 'C') {
%}
%
-<% include('/elements/tr-select-reason.html', 'reasonnum', $class) %>
+<% include('/elements/tr-select-reason.html', 'reasonnum', $class, '', '', '', 'document.sc_popup.submit' ) %>
</TABLE>
<BR>
-<INPUT TYPE="submit" VALUE="<% $submit %>">
+<INPUT TYPE="submit" NAME="submit" VALUE="<% $submit %>" disabled='true'>
</FORM>
</BODY>
%}
%
%unless ($error) {
-% my $cust_pkg_reason = new FS::cust_pkg_reason({ 'pkgnum' => $pkgnum,
-% 'reasonnum' => $reasonnum,
-% 'otaker' => $otaker,
-% 'date' => $date,
-% });
-% $error = $cust_pkg_reason->insert;
-%}
-%
-%unless ($error) {
% if ($method eq 'expire'){
% my %hash = $cust_pkg->hash;
% $hash{'expire'}=$date;
% my $new = new FS::cust_pkg (\%hash);
-% $error = $new->replace($cust_pkg);
+% $error = $new->replace($cust_pkg, 'reason' => $reasonnum);
% }else{
-% $error = $cust_pkg->$method
+% $error = $cust_pkg->$method( 'reason' => $reasonnum );
% }
%}
%