RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
1 % if ($error) {
2 %   $cgi->param('error', $error);
3 %   $cgi->redirect(popurl(3). 'edit/cust_pkg.cgi?'. $cgi->query_string );
4 % } else {
5 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
6 % }
7 <%init>
8 use Data::Dumper;
9 my $DEBUG = 0;
10 my $curuser = $FS::CurrentUser::CurrentUser;
11
12 die "access denied"
13   unless $curuser->access_right('Bulk change customer packages');
14
15 my $error = '';
16 my %param = $cgi->Vars;
17
18 my $custnum = $param{custnum};
19 $error = "Invalid custnum ($custnum)" if $custnum =~ /\D/;
20
21 my $locationnum = $param{locationnum};
22 $error = "Invalid locationnum ($locationnum)" if $locationnum =~ /\D/;
23
24 my @remove_pkgnum =
25   map { $_ =~ /remove_cust_pkg\[(\d+)\]/ ? $1 : () }
26   keys %param;
27
28 my @pkgparts;
29 for my $k ( keys %param ) {
30   next unless $k =~ /qty_part_pkg\[(\d+)\]/;
31   my $pkgpart = $1;
32   my $qty     = $param{$k};
33   $qty =~ s/(^\s+|\s+$)//g;
34
35   warn "k($k) param{k}($param{$k}) pkgpart($pkgpart) qty($qty)\n"
36     if $DEBUG;
37
38   if ( $qty =~ /\D/ ) {
39     $error = "Invalid quantity $qty for pkgpart $pkgpart - please use a number";
40     last;
41   }
42
43   next if $qty == 0;
44
45   push ( @pkgparts, $pkgpart ) for ( 1..$qty );
46 }
47
48 if ( $DEBUG ) {
49   warn Dumper({
50     custnum       => $custnum,
51     locationnum   => $locationnum,
52     remove_pkgnum => \@remove_pkgnum,
53     pkgparts      => \@pkgparts,
54     param         => \%param,
55   });
56 }
57
58 $error ||= FS::cust_pkg::order({
59   custnum       => $custnum,
60   pkgparts      => \@pkgparts,
61   remove_pkgnum => \@remove_pkgnum,
62   locationnum   => $locationnum,
63 });
64
65 </%init>