diff options
| author | Ivan Kohler <ivan@freeside.biz> | 2016-08-03 17:52:34 -0700 |
|---|---|---|
| committer | Ivan Kohler <ivan@freeside.biz> | 2016-08-03 17:52:34 -0700 |
| commit | cf54023e010df76e0c39ac70902877d7c4c94c6e (patch) | |
| tree | 8109fa975ae8ecb4435172f9a990435a734c67b6 /httemplate/misc/process/change_pkg_date.html | |
| parent | d7759b49c2ff3b220ab328767645bfed85d18f31 (diff) | |
| parent | ecf1c9cc0a20be6e489657e005ea771977b9f69c (diff) | |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/misc/process/change_pkg_date.html')
| -rwxr-xr-x | httemplate/misc/process/change_pkg_date.html | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/httemplate/misc/process/change_pkg_date.html b/httemplate/misc/process/change_pkg_date.html new file mode 100755 index 000000000..3084ec538 --- /dev/null +++ b/httemplate/misc/process/change_pkg_date.html @@ -0,0 +1,67 @@ +<& /elements/header-popup.html &> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + </BODY> +</HTML> +<%init> + +my $field = $cgi->param('field'); + +my ($acl, $isstart); +if ($field eq 'start_date') { + $acl = 'Change package start date'; + $isstart = 1; +} elsif ($field eq 'contract_end') { + $acl = 'Change package contract end date'; +} else { + die "Unknown date field"; +} + +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied" + unless $curuser->access_right($acl); + +$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 $date_value; +if ( $cgi->param('when') eq 'now' ) { + # blank start means start it the next time billing runs ("Now") + # blank contract end means it never ends ("Never") + $date_value = ''; +} elsif ( $cgi->param('when') eq 'next_bill_date' ) { + $date_value = $cust_main->next_bill_date; +} elsif ( $cgi->param('when') eq 'date' ) { + $date_value = parse_datetime($cgi->param('date_value')); +} + +if ( $isstart && $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) { + last if $error; + $pkg->set($field, $date_value); + $error ||= $pkg->replace; + } + $error ? dbh->rollback : dbh->commit; +} + +if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect($fsurl.'misc/change_pkg_date.html?', $cgi->query_string); +} +</%init> |
