%init> my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right('Edit customer package dates') or $curuser->access_right('Change package contract end date'); my %arg = $cgi->Vars; my $contract_only = $curuser->access_right('Edit customer package dates') ? 0 : 1; $contract_only = 1 if $arg{'contract_only'}; my $pkgnum = $arg{'pkgnum'}; $pkgnum =~ /^\d+$/ or die "bad pkgnum '$pkgnum'"; my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); my %hash = $cust_pkg->hash; foreach ( $contract_only ? qw( contract_end ) : qw( start_date setup bill last_bill contract_end )) { # adjourn, expire, resume not editable this way if( $arg{$_} =~ /^\d+$/ ) { $hash{$_} = $arg{$_}; } elsif ( $arg{$_} ) { $hash{$_} = parse_datetime($arg{$_}); } else { $hash{$_} = ''; } } my (@changes, @confirm, @errors); my $part_pkg = $cust_pkg->part_pkg; my @supp_pkgs = $cust_pkg->supplemental_pkgs; my $main_pkg = $cust_pkg->main_pkg; my $conf = FS::Conf->new; my $date_format = $conf->config('date_format') || '%b %o, %Y'; # Start date if ( $hash{'start_date'} != $cust_pkg->get('start_date') and !$hash{'setup'} ) { my $start = ''; $start = time2str($date_format, $hash{'start_date'}) if $hash{'start_date'}; my $text = 'Set this package'; if ( @supp_pkgs ) { $text .= ' and all its supplemental packages'; } $text .= ' to start billing'; if ( $start ) { $text .= ' on [_1].'; push @changes, mt($text, $start); } else { $text .= ' immediately.'; push @changes, mt($text); } push @confirm, ''; } # Setup date changes if ( $hash{'setup'} != $cust_pkg->get('setup') ) { my $setup = time2str($date_format, $hash{'setup'}); my $has_setup_fee = grep { $_->part_pkg->option('setup_fee',1) > 0 } $cust_pkg, @supp_pkgs; if ( !$hash{'setup'} ) { my $text = 'Remove the setup date'; $text .= ' from this and all its supplemental packages' if @supp_pkgs; $text .= '.'; push @changes, mt($text); if ( $has_setup_fee ) { push @confirm, mt('This will re-charge the customer for the setup fee.'); } else { push @confirm, ''; } } elsif ( $hash{'setup'} and !$cust_pkg->get('setup') ) { my $text = 'Add a setup date of [_1]'; $text .= ' to this and all its supplemental packages' if @supp_pkgs; $text .= '.'; push @changes, mt($text, $setup); if ( $has_setup_fee ) { push @confirm, mt('This will prevent charging the setup fee.'); } else { push @confirm, ''; } } else { my $text = 'Set the setup date to [_1]'; $text .= ' on this and all its supplemental packages' if @supp_pkgs; $text .= '.'; push @changes, mt($text, $setup); push @confirm, ''; } } # Check for start date + setup date if ( $hash{'start_date'} and $hash{'setup'} ) { if ( $cust_pkg->get('setup') ) { push @errors, mt('Since the package has already started billing, it '. 'cannot have a start date.'); } else { push @errors, mt('You cannot set both a start date and a setup date on '. 'the same package.'); } } # Last bill date change if ( $hash{'last_bill'} != $cust_pkg->get('last_bill') ) { my $last_bill = time2str($date_format, $hash{'last_bill'}); my $name = 'last bill date'; $name = 'last renewal date' if $part_pkg->is_prepaid; if ( $hash{'last_bill'} ) { push @changes, mt('Set the [_1] to [_2].', $name, $last_bill); } else { push @changes, mt('Remove the [_1].', $name); } push @confirm, ''; # I don't think we want to adjust this on supplemental packages. } # Bill date change if ( $hash{'bill'} != $cust_pkg->get('bill') ) { my $bill = time2str($date_format, $hash{'bill'}); $bill = 'today' if !$hash{'bill'}; # or 'the end of today'?... my $name = 'next bill date'; $name = 'end of the prepaid period' if $part_pkg->is_prepaid; push @changes, mt('Set the [_1] to [_2].', $name, $bill); if ( $hash{'bill'} < time and $hash{'bill'} ) { push @confirm, mt('The customer will be charged for the interval from [_1] until now.', $bill); } elsif ( !$hash{'bill'} and ($hash{'last_bill'} or $hash{'setup'}) ) { my $last_bill = time2str($date_format, $hash{'last_bill'} || $hash{'setup'}); push @confirm, mt('The customer will be charged for the interval from [_1] until now.', $last_bill); } else { push @confirm, ''; } if ( @supp_pkgs ) { push @changes, ''; if ( $cust_pkg->get('bill') and $hash{'bill'} ) { # the package already has a bill date, so adjust the dates # of supplementals by the same interval my $diff = $hash{'bill'} - $cust_pkg->get('bill'); my $sign = $diff < 0 ? -1 : 1; $diff = $diff * $sign / 86400; if ( $diff < 1 ) { $diff = mt('[quant,_1,hour]', int($diff * 24)); } else { $diff = mt('[quant,_1,day]', int($diff)); } push @confirm, mt('[_1] supplemental package will also be billed [_2] [_3].', (@supp_pkgs > 1 ? 'Each' : 'The'), $diff, ($sign > 0 ? 'later' : 'earlier') ); } else { # the package hasn't been billed yet, or you've set bill = null push @confirm, mt('[_1] supplemental package will also be billed on [_2].', (@supp_pkgs > 1 ? 'Each' : 'The'), $bill ); } } #if @supp_pkgs if ( $main_pkg ) { push @changes, ''; push @confirm, mt('This package is a supplemental package. The bill date of its '. 'main package will not be adjusted.'); } } # Contract end change if ( $hash{'contract_end'} != $cust_pkg->get('contract_end') ) { if ( $hash{'contract_end'} ) { my $contract_end = time2str($date_format, $hash{'contract_end'}); push @changes, mt('Set this package\'s contract end date to [_1]', $contract_end); } else { push @changes, mt('Remove this package\'s contract end date.'); } if ( @supp_pkgs ) { my $text = 'This change will also apply to ' . (@supp_pkgs > 1 ? 'all supplemental packages.': 'the supplemental package.'); push @confirm, mt($text); } else { push @confirm, ''; } } my $title = ''; if ( @errors ) { $title = 'Error changing package dates'; } else { $title = 'Confirm date changes'; } %init> <& /elements/header-popup.html, { title => $title, etc => 'BGCOLOR=""' } &>
<% $error %> | |
<% $text %> | |
<% $text %> |