4 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 );
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
9 use FS::part_pkg_option;
11 getopts('rm:C:p:o:v:t:sSzZe:u:');
13 my $user = shift or &usage;
17 $search{'plan'} = $opt_p if $opt_p;
18 $search{'comment'} = $opt_m if $opt_m;
21 $extra_sql = ( keys(%search) ? 'AND' : 'WHERE' ).
22 " classnum NOT IN ($opt_C)"
25 foreach my $part_pkg ( qsearch({ 'table' => 'part_pkg',
26 'hashref' => \%search,
27 'extra_sql' => $extra_sql,
31 next if ! $part_pkg->freq && $opt_r;
36 'pkgpart' => $part_pkg->pkgpart,
37 'optionname' => $opt_o,
40 my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
42 unless ( defined $opt_v ) {
43 my $error = $part_pkg_option && $part_pkg_option->delete;
48 if ( $part_pkg_option ) {
49 next if $part_pkg_option->optionvalue eq $opt_v;
50 $part_pkg_option->optionvalue($opt_v);
51 my $error = $part_pkg_option->replace;
54 $part_pkg_option = new FS::part_pkg_option { %hash,
55 'optionvalue'=>$opt_v,
57 my $error = $part_pkg_option->insert;
65 'pkgpart' => $part_pkg->pkgpart,
66 'optionname' => 'setup_fee',
69 my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
71 if ( $part_pkg_option ) {
72 $part_pkg_option->optionvalue(
73 sprintf('%.2f', $part_pkg_option->optionvalue * $opt_e)
75 my $error = $part_pkg_option->replace;
82 'pkgpart' => $part_pkg->pkgpart,
83 'optionname' => 'recur_fee',
86 my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
88 if ( $part_pkg_option ) {
89 $part_pkg_option->optionvalue(
90 sprintf('%.2f', $part_pkg_option->optionvalue * $opt_u)
92 my $error = $part_pkg_option->replace;
97 if ( $opt_t || $opt_s || $opt_S || $opt_z || $opt_Z ) {
99 $part_pkg->taxclass($opt_t) if $opt_t;
100 $part_pkg->setup_show_zero('') if $opt_s;
101 $part_pkg->setup_show_zero('Y') if $opt_S;
102 $part_pkg->recur_show_zero('') if $opt_z;
103 $part_pkg->recur_show_zero('Y') if $opt_Z;
105 my $error = $part_pkg->replace;
112 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";
117 cust_main-bulk_change
121 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
125 Command-line tool to change a set of package definitions.
129 -r: recurring package definitions only
131 -p: packages with this price plan only
133 -m: packages with this comment only
135 -C: excluding package classnum or classnums (comma-separated list)
139 -o: part_pkg_option optionname (use without -v to unset)
141 -v: part_pkg_option optionvalue
145 -s: Turn off "Show zero setup"
147 -S: Turn on "Show zero setup"
149 -z: Turn off "Show zero recurring"
151 -Z: Turn on "Show zero recurring"
153 -e: Multiply setup fee by this value (i.e. 1.05 for a 5% price increase)
155 -u: Multiply recurring fee by this value (i.e. 1.05 for a 5% price increase)