1 <& /elements/header-popup.html &>
2 <SCRIPT TYPE="text/javascript">
3 window.top.location.reload();
9 my $field = $cgi->param('field');
12 if ($field eq 'start_date') {
13 $acl = 'Change package start date';
15 } elsif ($field eq 'contract_end') {
16 $acl = 'Change package contract end date';
18 die "Unknown date field";
21 my $curuser = $FS::CurrentUser::CurrentUser;
23 unless $curuser->access_right($acl);
25 $cgi->param('pkgnum') =~ /^(\d+)$/
26 or die "illegal pkgnum";
29 my $cust_pkg = qsearchs({
31 addl_from => ' JOIN cust_main USING (custnum) ',
32 hashref => { 'pkgnum' => $pkgnum },
33 extra_sql => ' AND '. $curuser->agentnums_sql,
34 }) or die "Unknown pkgnum: $pkgnum";
36 my $cust_main = $cust_pkg->cust_main;
40 if ( $cgi->param('when') eq 'now' ) {
41 # blank start means start it the next time billing runs ("Now")
42 # blank contract end means it never ends ("Never")
44 } elsif ( $cgi->param('when') eq 'next_bill_date' ) {
45 $date_value = $cust_main->next_bill_date;
46 } elsif ( $cgi->param('when') eq 'date' ) {
47 $date_value = parse_datetime($cgi->param('date_value'));
50 if ( $isstart && $cust_pkg->setup ) {
52 $error = 'This package has already started billing.';
54 local $FS::UID::AutoCommit = 0;
55 foreach my $pkg ($cust_pkg, $cust_pkg->supplemental_pkgs) {
57 $pkg->set($field, $date_value);
58 $error ||= $pkg->replace;
60 $error ? dbh->rollback : dbh->commit;
64 $cgi->param('error', $error);
65 print $cgi->redirect($fsurl.'misc/change_pkg_date.html?', $cgi->query_string);