summaryrefslogtreecommitdiff
path: root/httemplate/misc/process
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-07-08 22:45:58 -0700
committerIvan Kohler <ivan@freeside.biz>2012-07-08 22:45:58 -0700
commita6fe07e49e3fc12169e801b1ed6874c3a5bd8500 (patch)
treeb87a7e6f37da5c8e13eb4d4653cfc8ce9239d8f0 /httemplate/misc/process
parente27244386c346f459d1569db26344407a0372a05 (diff)
parent005424d0c899aa899f43f583a6c74deb13ea4be1 (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Conflicts: httemplate/misc/process/cancel_pkg.html
Diffstat (limited to 'httemplate/misc/process')
-rw-r--r--httemplate/misc/process/batch-cust_pay.cgi115
-rwxr-xr-xhttemplate/misc/process/cancel_pkg.html40
2 files changed, 93 insertions, 62 deletions
diff --git a/httemplate/misc/process/batch-cust_pay.cgi b/httemplate/misc/process/batch-cust_pay.cgi
index aa371266c..1105af943 100644
--- a/httemplate/misc/process/batch-cust_pay.cgi
+++ b/httemplate/misc/process/batch-cust_pay.cgi
@@ -1,51 +1,69 @@
-% die "access denied"
-% unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch');
-%
-% my $param = $cgi->Vars;
-%
-% #my $paybatch = $param->{'paybatch'};
-% my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
-%
-% my @cust_pay = ();
-% #my $row = 0;
-% #while ( exists($param->{"custnum$row"}) ) {
-% for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
-% my $custnum = $param->{"custnum$row"};
-% my $cust_main;
-% if ( $custnum =~ /^(\d+)$/ and $1 <= 2147483647 ) {
-% $cust_main = qsearchs({
-% 'table' => 'cust_main',
-% 'hashref' => { 'custnum' => $1 },
-% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
-% });
-% }
-% if ( !$cust_main ) { # not found, try agent_custid
-% $cust_main = qsearchs({
-% 'table' => 'cust_main',
-% 'hashref' => { 'agent_custid' => $custnum },
-% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
-% });
-% }
-% $custnum = $cust_main->custnum if $cust_main;
-% # if !$cust_main, then this will throw an error on batch_insert
-%
-% push @cust_pay, new FS::cust_pay {
-% 'custnum' => $custnum,
-% 'paid' => $param->{"paid$row"},
-% 'payby' => 'BILL',
-% 'payinfo' => $param->{"payinfo$row"},
-% 'discount_term' => $param->{"discount_term$row"},
-% 'paybatch' => $paybatch,
-% }
-% if $param->{"custnum$row"}
-% || $param->{"paid$row"}
-% || $param->{"payinfo$row"};
-% #$row++;
-% }
-%
-% my @errors = FS::cust_pay->batch_insert(@cust_pay);
-% my $num_errors = scalar(grep $_, @errors);
-%
+<%init>
+my $DEBUG = 0;
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch');
+
+my $param = $cgi->Vars;
+warn Dumper($param) if $DEBUG;
+
+#my $paybatch = $param->{'paybatch'};
+my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+
+my @cust_pay = ();
+#my $row = 0;
+#while ( exists($param->{"custnum$row"}) ) {
+for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
+ my $custnum = $param->{"custnum$row"};
+ my $cust_main;
+ if ( $custnum =~ /^(\d+)$/ and $1 <= 2147483647 ) {
+ $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => $1 },
+ 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+ });
+ }
+ if ( length($custnum) and !$cust_main ) { # not found, try agent_custid
+ $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'agent_custid' => $custnum },
+ 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+ });
+ }
+ $custnum = $cust_main->custnum if $cust_main;
+ # if !$cust_main, then this will throw an error on batch_insert
+
+ my $cust_pay = new FS::cust_pay {
+ 'custnum' => $custnum,
+ 'paid' => $param->{"paid$row"},
+ 'payby' => 'BILL',
+ 'payinfo' => $param->{"payinfo$row"},
+ 'discount_term' => $param->{"discount_term$row"},
+ 'paybatch' => $paybatch,
+ }
+ if $param->{"custnum$row"}
+ || $param->{"paid$row"}
+ || $param->{"payinfo$row"};
+ next if !$cust_pay;
+ #$row++;
+
+ # payment applications, if any
+ my @cust_bill_pay = ();
+ for ( my $app = 0; exists($param->{"invnum$row.$app"}); $app++ ) {
+ next if !$param->{"invnum$row.$app"};
+ push @cust_bill_pay, new FS::cust_bill_pay {
+ 'invnum' => $param->{"invnum$row.$app"},
+ 'amount' => $param->{"amount$row.$app"}
+ };
+ }
+ $cust_pay->set('apply_to', \@cust_bill_pay) if scalar(@cust_bill_pay) > 0;
+
+ push @cust_pay, $cust_pay;
+
+}
+
+my @errors = FS::cust_pay->batch_insert(@cust_pay);
+my $num_errors = scalar(grep $_, @errors);
+</%init>
% if ( $num_errors ) {
%
% $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
@@ -65,4 +83,3 @@
%
<% $cgi->redirect(popurl(3). "search/cust_pay.html?magic=paybatch;paybatch=$paybatch") %>
% }
-
diff --git a/httemplate/misc/process/cancel_pkg.html b/httemplate/misc/process/cancel_pkg.html
index 4f8e11b7f..79e489c70 100755
--- a/httemplate/misc/process/cancel_pkg.html
+++ b/httemplate/misc/process/cancel_pkg.html
@@ -6,19 +6,21 @@
</HTML>
<%once>
-my %past = ( 'cancel' => 'cancelled',
- 'expire' => 'expired',
- 'suspend' => 'suspended',
- 'adjourn' => 'adjourned',
- 'resume' => 'scheduled to resume',
+my %past = ( 'cancel' => 'cancelled',
+ 'expire' => 'expired',
+ 'suspend' => 'suspended',
+ 'adjourn' => 'adjourned',
+ 'resume' => 'scheduled to resume',
+ 'uncancel' => 'un-cancelled',
);
#i'm sure this is false laziness with somewhere, at least w/misc/cancel_pkg.html
-my %right = ( 'cancel' => 'Cancel customer package immediately',
- 'expire' => 'Cancel customer package later',
- 'suspend' => 'Suspend customer package',
- 'adjourn' => 'Suspend customer package later',
- 'resume' => 'Unsuspend customer package', #later?
+my %right = ( 'cancel' => 'Cancel customer package immediately',
+ 'expire' => 'Cancel customer package later',
+ 'suspend' => 'Suspend customer package',
+ 'adjourn' => 'Suspend customer package later',
+ 'resume' => 'Unsuspend customer package', #later?
+ 'uncancel' => 'Un-cancel customer package',
);
</%once>
@@ -26,7 +28,8 @@ my %right = ( 'cancel' => 'Cancel customer package immediately',
#untaint method
my $method = $cgi->param('method');
-$method =~ /^(cancel|expire|suspend|adjourn|resume)$/ or die "Illegal method";
+$method =~ /^(cancel|expire|suspend|adjourn|resume|uncancel)$/
+ or die "Illegal method";
$method = $1;
my $past_method = $past{$method};
@@ -39,7 +42,7 @@ $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
$pkgnum = $1;
my $date = time;
-if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume'){
+if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
#untaint date
$date = $cgi->param('date'); #huh?
parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
@@ -64,7 +67,7 @@ my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
#untaint reasonnum
my $reasonnum = $cgi->param('reasonnum');
-if ( $method ne 'unsuspend' ) { #i.e. 'resume'
+if ( $method !~ /^(unsuspend|uncancel)$/ ) {
$reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum";
$reasonnum = $1;
@@ -76,9 +79,20 @@ if ( $method ne 'unsuspend' ) { #i.e. 'resume'
}
}
+#for uncancel
+my $last_bill =
+ $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
+my $bill =
+ $cgi->param('bill') ? parse_datetime($cgi->param('bill')) : '';
+
+my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
+
my $error = $cust_pkg->$method( 'reason' => $reasonnum,
'date' => $date,
'resume_date' => $resume_date,
+ 'last_bill' => $last_bill,
+ 'bill' => $bill,
+ 'svc_fatal' => $svc_fatal,
'options' => $options,
);