summaryrefslogtreecommitdiff
path: root/httemplate/misc/process
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-12-31 17:44:04 -0800
committerMark Wells <mark@freeside.biz>2015-12-31 17:44:31 -0800
commit0070abc9190436fc6cc6ff908345bb24e19e388a (patch)
tree0b3ada6ca1babe0ad841862ede2271314403f8ee /httemplate/misc/process
parent3e14859be9589167b7d1dd4ab25457bca55e53b9 (diff)
allow back-billing by changing start dates, #38883
Diffstat (limited to 'httemplate/misc/process')
-rwxr-xr-xhttemplate/misc/process/change_pkg_start.html53
1 files changed, 53 insertions, 0 deletions
diff --git a/httemplate/misc/process/change_pkg_start.html b/httemplate/misc/process/change_pkg_start.html
new file mode 100755
index 000000000..17a8518f9
--- /dev/null
+++ b/httemplate/misc/process/change_pkg_start.html
@@ -0,0 +1,53 @@
+<& /elements/header-popup.html &>
+ <SCRIPT TYPE="text/javascript">
+ window.top.location.reload();
+ </SCRIPT>
+ </BODY>
+</HTML>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied"
+ unless $curuser->access_right('Change package start date');
+
+$cgi->param('pkgnum') =~ /^(\d+)$/
+ or die "illegal pkgnum";
+my $pkgnum = $1;
+
+my $cust_pkg = qsearchs({
+ table => 'cust_pkg',
+ addl_from => ' JOIN cust_main USING (custnum) ',
+ hashref => { 'pkgnum' => $pkgnum },
+ extra_sql => ' AND '. $curuser->agentnums_sql,
+}) or die "Unknown pkgnum: $pkgnum";
+
+my $cust_main = $cust_pkg->cust_main;
+
+my $error;
+my $start_date;
+if ( $cgi->param('when') eq 'now' ) {
+ # start it the next time billing runs
+ $start_date = '';
+} elsif ( $cgi->param('when') eq 'next_bill_date' ) {
+ $start_date = $cust_main->next_bill_date;
+} elsif ( $cgi->param('when') eq 'date' ) {
+ $start_date = parse_datetime($cgi->param('start_date'));
+}
+
+if ( $cust_pkg->setup ) {
+ # shouldn't happen
+ $error = 'This package has already started billing.';
+} else {
+ local $FS::UID::AutoCommit = 0;
+ foreach my $pkg ($cust_pkg, $cust_pkg->supplemental_pkgs) {
+ $pkg->set('start_date', $start_date);
+ $error ||= $pkg->replace;
+ }
+ $error ? dbh->rollback : dbh->commit;
+}
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ print $cgi->redirect($fsurl.'misc/change_pkg_start.html?', $cgi->query_string);
+}
+</%init>