RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / bulk-part_pkg.html
1 <& /elements/popup-topreload.html, emt($message) &>
2
3 <%init>
4 die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Bulk edit package definitions');
5
6 my @pkgparts = $cgi->param('pkgpart')
7   or die "no package definitions selected";
8
9 my $error;
10
11 if ($cgi->param('report_class')) {
12   my %delete = map { 'report_option_'.($_->num) => 1 }
13     qsearch('part_pkg_report_option', {});
14   my %insert;
15
16   foreach my $param (grep { /^report_option_\d+$/ } $cgi->param) {
17     if ( $cgi->param($param) == 1 ) {
18       $insert{$param} = 1;
19       delete $delete{$param};
20     } elsif ( $cgi->param($param) == -1 ) {
21       # leave it alone
22       delete $delete{$param};
23     } # else it's empty, so leave it on the delete list
24   }
25
26   foreach my $pkgpart (@pkgparts) {
27     my $part_pkg = FS::part_pkg->by_key($pkgpart);
28     my %options = ( $part_pkg->options, %insert );
29     delete $options{$_} foreach keys(%delete);
30     $error ||= $part_pkg->replace( options => \%options );
31   }
32 }
33
34 if ($cgi->param('pricing')) {
35   my $setup_fee_increase = $cgi->param('setup_fee_increase');
36   my $recurring_fee_increase = $cgi->param('recurring_fee_increase');
37
38   foreach my $pkgpart (@pkgparts) {
39     my $part_pkg = FS::part_pkg->by_key($pkgpart);
40     my %options = $part_pkg->options;
41     if ($recurring_fee_increase) {
42       $options{'recur_fee'} = $options{'recur_fee'} + ($options{'recur_fee'} * ($recurring_fee_increase / 100));
43     }
44     if ($setup_fee_increase) {
45       $options{'setup_fee'} = $options{'setup_fee'} + ($options{'setup_fee'} * ($setup_fee_increase / 100));
46     }
47     $error ||= $part_pkg->replace( options => \%options );
48   }
49 }
50
51 my $message = "Packages updated successfully";
52 $message = $error."=error" if $error;
53
54 </%init>