2 % $cgi->param('error', $error);
3 % $cgi->redirect(popurl(3). 'misc/change_pkg.cgi?'. $cgi->query_string );
6 <% header(emt("Package changed")) %>
7 <SCRIPT TYPE="text/javascript">
8 window.top.location.reload();
16 my $curuser = $FS::CurrentUser::CurrentUser;
19 unless $curuser->access_right('Change customer package');
21 my $cust_pkg = qsearchs({
22 'table' => 'cust_pkg',
23 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
24 'hashref' => { 'pkgnum' => scalar($cgi->param('pkgnum')), },
25 'extra_sql' => ' AND '. $curuser->agentnums_sql,
27 die 'unknown pkgnum' unless $cust_pkg;
29 my %change = map { $_ => scalar($cgi->param($_)) }
30 qw( locationnum pkgpart quantity );
32 $change{'keep_dates'} = 1;
34 if ( $cgi->param('locationnum') == -1 ) {
35 my $cust_location = FS::cust_location->new({
36 'custnum' => $cust_pkg->custnum,
37 map { $_ => scalar($cgi->param($_)) }
38 FS::cust_main->location_fields
40 $change{'cust_location'} = $cust_location;
44 if ( $cgi->param('delay') ) {
45 my $date = parse_datetime($cgi->param('start_date'));
47 $error = "Invalid change date '".$cgi->param('start_date')."'.";
48 } elsif ( $date < time ) {
49 $error = "Change date ".$cgi->param('start_date')." is in the past.";
52 $change{'start_date'} = $date;
53 $error = $cust_pkg->change_later(\%change);
56 # special case: if there's a package change scheduled, and it matches
57 # the parameters the user requested this time, then change to the existing
59 if ( $cust_pkg->change_to_pkgnum ) {
60 my $change_to = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
61 if ( $change_to->pkgpart == $change{'pkgpart'} and
62 $change_to->locationnum == $change{'locationnum'} ) {
64 %change = ( 'cust_pkg' => $change_to );
69 # do a package change right now
70 my $pkg_or_error = $cust_pkg->change( \%change );
71 $error = ref($pkg_or_error) ? '' : $pkg_or_error;