1 <% include( 'elements/process.html',
5 'agent_null_right' => \@agent_null_right,
6 'redirect' => $redirect_callback,
7 'viewall_dir' => 'browse',
8 'viewall_ext' => 'cgi',
10 'precheck_callback' => $precheck_callback,
11 'args_callback' => $args_callback,
12 'process_locale' => 'pkg',
13 'process_m2m' => \@process_m2m,
14 'process_o2m' => \@process_o2m,
19 my $customizing = ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') );
21 my $curuser = $FS::CurrentUser::CurrentUser;
23 my $edit_global = 'Edit global package definitions';
24 my $customize = 'Customize customer package';
27 unless $curuser->access_right('Edit package definitions')
28 || $curuser->access_right($edit_global)
29 || ( $customizing && $curuser->access_right($customize) );
31 my @agent_null_right = ( $edit_global );
32 push @agent_null_right, $customize if $customizing;
35 my $precheck_callback = sub {
38 my $conf = new FS::Conf;
40 foreach (qw( setuptax recurtax disabled )) {
41 $cgi->param($_, '') unless defined $cgi->param($_);
44 return 'Must select a tax class'
45 if $cgi->param('taxclass') eq '(select)';
48 foreach ($cgi->param('agent_type')) {
50 push @agents, $1 if $1;
52 return "At least one agent type must be specified."
53 unless scalar(@agents)
54 #wtf? || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
55 || $cgi->param('disabled')
56 || $cgi->param('agentnum');
64 my $args_callback = sub {
65 my( $cgi, $new ) = @_;
67 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
73 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
76 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
77 my $href = $plans{$plan}->{'fields'};
80 my $options = $cgi->param($plan."__OPTIONS");
81 my @options = split(',', $options);
83 map { my $optionname = $_;
84 my $param = $plan."__$optionname";
85 my $parser = exists($href->{$optionname}{parse})
86 ? $href->{$optionname}{parse}
88 my $value = join(', ', &$parser($cgi->param($param)));
89 my $check = $href->{$optionname}{check};
90 if ( $check && ! &$check($value) ) {
91 $value = join(', ', $cgi->param($param));
92 $error ||= "Illegal ".
93 ($href->{$optionname}{name}||$optionname). ": $value";
95 ( $optionname => $value );
97 grep { $_ !~ /^report_option_/ }
100 foreach my $class ( '', split(',', $cgi->param('taxproductnums') ) ) {
101 my $param = "taxproductnum_$class";
102 my $value = $cgi->param($param);
104 if ( $value == -1 ) {
105 my $desc = $cgi->param($param.'_description');
106 # insert a new part_pkg_taxproduct
107 my $engine = FS::TaxEngine->new;
108 my $obj_or_error = $engine->add_taxproduct($desc);
109 if (ref $obj_or_error) {
110 $value = $obj_or_error->taxproductnum;
111 $cgi->param($param, $value); # for error handling
113 die "$obj_or_error (adding tax product)";
117 $error ||= "Illegal $param: $value"
118 unless ( $value =~ /^\d*$/ );
119 if (length($class)) {
120 $options{"usage_taxproductnum_$class"} = $value;
122 $new->set('taxproductnum', $value);
126 foreach ( grep $_, $cgi->param('report_option') ) {
127 $error ||= "Illegal optional report class: $_" unless ( $_ =~ /^\d*$/ );
128 $options{"report_option_$_"} = 1;
131 $options{$_} = scalar( $cgi->param($_) )
132 for (qw( setup_fee recur_fee disable_line_item_date_ranges ));
134 push @args, 'options' => \%options;
140 my %part_pkg_currency = (
141 map { $_ => scalar($cgi->param($_)) }
142 #grep /._[A-Z]{3}$/, #support other options
143 grep /^(setup|recur)_fee_[A-Z]{3}$/,
147 push @args, 'part_pkg_currency' => \%part_pkg_currency;
152 my $fcc_options_string = $cgi->param('fcc_options_string');
153 if ($fcc_options_string) {
154 push @args, 'fcc_options' => decode_json($fcc_options_string);
161 my @svcparts = map { $_->svcpart } qsearch('part_svc', {});
162 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_" )) } @svcparts;
163 my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_" )) } @svcparts;
164 my %provision_hold = map { $_ => scalar($cgi->param("provision_hold$_" )) } @svcparts;
165 my %bulk_skip = map { $_ => ( $cgi->param("no_bulk_skip$_") eq 'Y'
170 push @args, 'pkg_svc' => \%pkg_svc,
171 'hidden_svc' => \%hidden_svc,
172 'provision_hold' => \%provision_hold,
173 'bulk_skip' => \%bulk_skip;
176 # cust_pkg and custnum_ref (inserts only)
178 unless ( $cgi->param('pkgpart') ) {
179 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
180 'custnum_ref' => \$custnum;
184 foreach my $param ( $cgi->param ) {
185 if ( $param =~ /^export(\d+)$/ && length($cgi->param($param)) > 0 ) {
186 $part_pkg_vendor{$1} = $cgi->param($param);
189 if ( keys %part_pkg_vendor > 0 ) {
190 push @args, 'part_pkg_vendor' => \%part_pkg_vendor;
193 push @args, 'part_pkg_restrict_soft_override' => 1
194 if $cgi->param('part_pkg_restrict_soft_override');
196 #warn "args: ".join('/', @args). "\n";
202 my $redirect_callback = sub {
203 #my( $cgi, $new ) = @_;
204 return '' unless $custnum;
205 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
208 #my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
210 #can we link back to the specific customized package? it would be nice...
211 popurl(3). "view/cust_main.cgi?custnum=$custnum$show;dummy=";
214 #these should probably move to @args above and be processed by part_pkg.pm...
216 $cgi->param('tax_override') =~ /^([\d,]+)$/;
217 my (@tax_overrides) = (grep "$_", split (",", $1));
221 'link_table' => 'part_pkg_taxoverride',
222 'target_table' => 'tax_class',
223 'params' => \@tax_overrides,
225 { 'link_table' => 'part_pkg_discount',
226 'target_table' => 'discount',
227 'params' => [ map $cgi->param($_),
228 grep /^discountnum/, $cgi->param
231 { 'link_table' => 'part_pkg_link',
232 'target_table' => 'part_pkg',
233 'base_field' => 'src_pkgpart',
234 'target_field' => 'dst_pkgpart',
235 'hashref' => { 'link_type' => 'svc', 'hidden' => '' },
236 'params' => [ map $cgi->param($_),
237 grep /^svc_dst_pkgpart/, $cgi->param
240 { 'link_table' => 'part_pkg_link',
241 'target_table' => 'part_pkg',
242 'base_field' => 'src_pkgpart',
243 'target_field' => 'dst_pkgpart',
244 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
245 'params' => [ map $cgi->param($_),
246 grep /^supp_dst_pkgpart/, $cgi->param
251 { 'link_table' => 'part_pkg_link',
252 'target_table' => 'part_pkg',
253 'base_field' => 'src_pkgpart',
254 'target_field' => 'dst_pkgpart',
255 'hashref' => { 'link_type' => 'bill', 'hidden' => $hidden },
256 'params' => [ map { $cgi->param($_) }
257 grep { my $param = "bill_dst_pkgpart__hidden";
259 (($digit) = /^bill_dst_pkgpart(\d+)/ ) &&
260 $cgi->param("$param$digit") eq $hidden;
268 foreach my $override_class ($cgi->param) {
269 next unless $override_class =~ /^tax_override_(\w+)$/;
272 my (@tax_overrides) = (grep "$_", split (",", $1))
273 if $cgi->param($override_class) =~ /^([\d,]+)$/;
276 'link_table' => 'part_pkg_taxoverride',
277 'target_table' => 'tax_class',
278 'hashref' => { 'usage_class' => $class },
279 'params' => [ @tax_overrides ],
284 my $conf = new FS::Conf;
287 foreach ($cgi->param('agent_type')) {
289 push @agents, $1 if $1;
292 'link_table' => 'type_pkgs',
293 'target_table' => 'agent_type',
294 'params' => \@agents,
297 my $targets = FS::part_pkg_usageprice->targets;
298 foreach my $amount_param ( grep /^usagepricepart(\d+)_amount$/, $cgi->param ) {
299 $amount_param =~ /^usagepricepart(\d+)_amount$/ or die 'unpossible';
301 my $amount = $cgi->param($amount_param);
302 if ( ! $amount && ! $cgi->param("usagepricepart${num}_price") ) {
303 #don't add empty rows just because the dropdowns have a value
304 $cgi->param("usagepricepart${num}_$_", '') for qw( currency action target );
307 my $target = $cgi->param("usagepricepart${num}_target");
308 $amount *= $targets->{$target}{multiplier} if $targets->{$target}{multiplier};
309 $cgi->param($amount_param, $amount);
314 'table' => 'part_pkg_usageprice',
315 'fields' => [qw( price currency action target amount )],