fix -C, RT#82943
[freeside.git] / bin / part_pkg-bulk_change
index 21a6c5a..5347da6 100755 (executable)
@@ -1,19 +1,33 @@
 #!/usr/bin/perl
 
 use strict;
 #!/usr/bin/perl
 
 use strict;
-use vars qw( $opt_r $opt_o $opt_v $opt_t );
+use vars qw( $opt_r $opt_m $opt_C $opt_p $opt_o $opt_v $opt_t $opt_s $opt_S $opt_z $opt_Z $opt_e $opt_u );
 use Getopt::Std;
 use FS::UID qw(adminsuidsetup);
 use FS::Record qw(qsearch qsearchs);
 use FS::part_pkg;
 use FS::part_pkg_option;
 
 use Getopt::Std;
 use FS::UID qw(adminsuidsetup);
 use FS::Record qw(qsearch qsearchs);
 use FS::part_pkg;
 use FS::part_pkg_option;
 
-getopts('ro:v:t:');
+getopts('rm:C:p:o:v:t:sSzZe:u:');
 
 my $user = shift or &usage;
 adminsuidsetup $user;
 
 
 my $user = shift or &usage;
 adminsuidsetup $user;
 
-foreach my $part_pkg ( qsearch('part_pkg', {}) ) {
+my %search = ();
+$search{'plan'} = $opt_p if $opt_p;
+$search{'comment'} = $opt_m if $opt_m;
+
+my $extra_sql = '';
+$extra_sql = ( keys(%search) ? 'AND' : 'WHERE' ).
+             " classnum NOT IN ($opt_C)"
+  if $opt_C;
+
+foreach my $part_pkg ( qsearch({ 'table'     => 'part_pkg',
+                                 'hashref'   => \%search,
+                                 'extra_sql' => $extra_sql,
+                              })
+                     )
+{
   next if ! $part_pkg->freq && $opt_r;
 
   if ( $opt_o ) {
   next if ! $part_pkg->freq && $opt_r;
 
   if ( $opt_o ) {
@@ -40,9 +54,48 @@ foreach my $part_pkg ( qsearch('part_pkg', {}) ) {
 
   }
 
 
   }
 
-  if ( $opt_t ) {
+  if ( $opt_e ) {
+    my %hash = (
+      'pkgpart'    => $part_pkg->pkgpart,
+      'optionname' => 'setup_fee',
+    );
+
+    my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
+
+    if ( $part_pkg_option ) {
+      $part_pkg_option->optionvalue(
+        sprintf('%.2f', $part_pkg_option->optionvalue * $opt_e)
+      );
+      my $error = $part_pkg_option->replace;
+      die $error if $error;
+    }
+  }
+
+  if ( $opt_u ) {
+    my %hash = (
+      'pkgpart'    => $part_pkg->pkgpart,
+      'optionname' => 'recur_fee',
+    );
+
+    my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
+
+    if ( $part_pkg_option ) {
+      $part_pkg_option->optionvalue(
+        sprintf('%.2f', $part_pkg_option->optionvalue * $opt_u)
+      );
+      my $error = $part_pkg_option->replace;
+      die $error if $error;
+    }
+  }
+
+  if ( $opt_t || $opt_s || $opt_S || $opt_z || $opt_Z ) {
+
+    $part_pkg->taxclass($opt_t) if $opt_t;
+    $part_pkg->setup_show_zero('') if $opt_s;
+    $part_pkg->setup_show_zero('Y') if $opt_S;
+    $part_pkg->recur_show_zero('') if $opt_z;
+    $part_pkg->recur_show_zero('Y') if $opt_Z;
 
 
-    $part_pkg->taxclass($opt_t);
     my $error = $part_pkg->replace;
 
   }
     my $error = $part_pkg->replace;
 
   }
@@ -50,7 +103,7 @@ foreach my $part_pkg ( qsearch('part_pkg', {}) ) {
 }
 
 sub usage {
 }
 
 sub usage {
-  die "usage: part_pkg-bulk_change [ -r ] [ -o option_name -v option_value ] [ -t new_taxclass ] employee_username\n";
+  die "usage: part_pkg-bulk_change [ -r ] [ -p plan ] [ -m comment ] [ -C classnum,classnum ] [ -o option_name -v option_value ] [ -t new_taxclass ] [ -s | -S ] [ -z | -Z ]  [ -e multiplier ] [ -u multiplier ] employee_username\n";
 }
 
 =head1 NAME
 }
 
 =head1 NAME
@@ -59,7 +112,7 @@ cust_main-bulk_change
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
-  part_pkg-bulk_change [ -r ] [ -o option_name -v option_value ] [ -t new_taxclass ] employee_username
+  part_pkg-bulk_change [ -r ] [ -p plan ] [ -m comment ] [ -C classnum,classnum ] [ -o option_name -v option_value ] [ -t new_taxclass ] [ -s | -S ] [ -z | -Z ] [ -e multiplier ] [ -u multiplier ] employee_username
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -69,6 +122,12 @@ Search options:
 
 -r: recurring package definitions only
 
 
 -r: recurring package definitions only
 
+-p: packages with this price plan only
+
+-m: packages with this comment only
+
+-C: excluding package classnum or classnums (comma-separated list)
+
 Change options:
 
 -o: part_pkg_option optionname
 Change options:
 
 -o: part_pkg_option optionname
@@ -77,6 +136,18 @@ Change options:
 
 -t: new taxclass
 
 
 -t: new taxclass
 
+-s: Turn off "Show zero setup"
+
+-S: Turn on "Show zero setup"
+
+-z: Turn off "Show zero recurring"
+
+-Z: Turn on "Show zero recurring"
+
+-e: Multiply setup fee by this value (i.e. 1.05 for a 5% price increase)
+
+-u: Multiply recurring fee by this value (i.e. 1.05 for a 5% price increase)
+
 employee_username
 
 =head1 BUGS
 employee_username
 
 =head1 BUGS