summaryrefslogtreecommitdiff
path: root/httemplate/misc/process/change_pkg_date.html
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/misc/process/change_pkg_date.html')
-rwxr-xr-xhttemplate/misc/process/change_pkg_date.html67
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>