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_m2m' => \@process_m2m,
13 'process_o2m' => \@process_o2m,
18 my $customizing = ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') );
20 my $curuser = $FS::CurrentUser::CurrentUser;
22 my $edit_global = 'Edit global package definitions';
23 my $customize = 'Customize customer package';
26 unless $curuser->access_right('Edit package definitions')
27 || $curuser->access_right($edit_global)
28 || ( $customizing && $curuser->access_right($customize) );
30 my @agent_null_right = ( $edit_global );
31 push @agent_null_right, $customize if $customizing;
34 my $precheck_callback = sub {
37 my $conf = new FS::Conf;
39 foreach (qw( setuptax recurtax disabled )) {
40 $cgi->param($_, '') unless defined $cgi->param($_);
43 return 'Must select a tax class'
44 if $cgi->param('taxclass') eq '(select)';
47 foreach ($cgi->param('agent_type')) {
49 push @agents, $1 if $1;
51 return "At least one agent type must be specified."
52 unless scalar(@agents)
53 #wtf? || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
54 || $cgi->param('disabled')
55 || $cgi->param('agentnum');
63 my $args_callback = sub {
64 my( $cgi, $new ) = @_;
66 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
72 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
75 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
76 my $href = $plans{$plan}->{'fields'};
79 my $options = $cgi->param($plan."__OPTIONS");
80 my @options = split(',', $options);
82 map { my $optionname = $_;
83 my $param = $plan."__$optionname";
84 my $parser = exists($href->{$optionname}{parse})
85 ? $href->{$optionname}{parse}
87 my $value = join(', ', &$parser($cgi->param($param)));
88 my $check = $href->{$optionname}{check};
89 if ( $check && ! &$check($value) ) {
90 $value = join(', ', $cgi->param($param));
91 $error ||= "Illegal ".
92 ($href->{$optionname}{name}||$optionname). ": $value";
94 ( $optionname => $value );
96 grep { $_ !~ /^report_option_/ }
99 foreach my $class ( '', split(',', $cgi->param('taxproductnums') ) ) {
100 my $param = "taxproductnum_$class";
101 my $value = $cgi->param($param);
103 if ( $value == -1 ) {
104 my $desc = $cgi->param($param.'_description');
105 # insert a new part_pkg_taxproduct
106 my $engine = FS::TaxEngine->new;
107 my $obj_or_error = $engine->add_taxproduct($desc);
108 if (ref $obj_or_error) {
109 $value = $obj_or_error->taxproductnum;
110 $cgi->param($param, $value); # for error handling
112 die "$obj_or_error (adding tax product)";
116 $error ||= "Illegal $param: $value"
117 unless ( $value =~ /^\d*$/ );
118 if (length($class)) {
119 $options{"usage_taxproductnum_$class"} = $value;
121 $new->set('taxproductnum', $value);
125 foreach ( grep $_, $cgi->param('report_option') ) {
126 $error ||= "Illegal optional report class: $_" unless ( $_ =~ /^\d*$/ );
127 $options{"report_option_$_"} = 1;
130 $options{$_} = scalar( $cgi->param($_) )
131 for (qw( setup_fee recur_fee disable_line_item_date_ranges ));
133 push @args, 'options' => \%options;
139 my %part_pkg_currency = (
140 map { $_ => scalar($cgi->param($_)) }
141 #grep /._[A-Z]{3}$/, #support other options
142 grep /^(setup|recur)_fee_[A-Z]{3}$/,
146 push @args, 'part_pkg_currency' => \%part_pkg_currency;
151 my $fcc_options_string = $cgi->param('fcc_options_string');
152 if ($fcc_options_string) {
153 push @args, 'fcc_options' => decode_json($fcc_options_string);
160 my @svcparts = map { $_->svcpart } qsearch('part_svc', {});
161 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_" )) } @svcparts;
162 my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_" )) } @svcparts;
163 my %bulk_skip = map { $_ => ( $cgi->param("no_bulk_skip$_") eq 'Y'
168 push @args, 'pkg_svc' => \%pkg_svc,
169 'hidden_svc' => \%hidden_svc,
170 'bulk_skip' => \%bulk_skip;
173 # cust_pkg and custnum_ref (inserts only)
175 unless ( $cgi->param('pkgpart') ) {
176 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
177 'custnum_ref' => \$custnum;
181 foreach my $param ( $cgi->param ) {
182 if ( $param =~ /^export(\d+)$/ && length($cgi->param($param)) > 0 ) {
183 $part_pkg_vendor{$1} = $cgi->param($param);
186 if ( keys %part_pkg_vendor > 0 ) {
187 push @args, 'part_pkg_vendor' => \%part_pkg_vendor;
190 push @args, 'part_pkg_restrict_soft_override' => 1
191 if $cgi->param('part_pkg_restrict_soft_override');
193 #warn "args: ".join('/', @args). "\n";
199 my $redirect_callback = sub {
200 #my( $cgi, $new ) = @_;
201 return '' unless $custnum;
202 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
205 #my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
207 #can we link back to the specific customized package? it would be nice...
208 popurl(3). "view/cust_main.cgi?custnum=$custnum$show;dummy=";
211 #these should probably move to @args above and be processed by part_pkg.pm...
213 $cgi->param('tax_override') =~ /^([\d,]+)$/;
214 my (@tax_overrides) = (grep "$_", split (",", $1));
218 'link_table' => 'part_pkg_taxoverride',
219 'target_table' => 'tax_class',
220 'params' => \@tax_overrides,
222 { 'link_table' => 'part_pkg_discount',
223 'target_table' => 'discount',
224 'params' => [ map $cgi->param($_),
225 grep /^discountnum/, $cgi->param
228 { 'link_table' => 'part_pkg_link',
229 'target_table' => 'part_pkg',
230 'base_field' => 'src_pkgpart',
231 'target_field' => 'dst_pkgpart',
232 'hashref' => { 'link_type' => 'svc', 'hidden' => '' },
233 'params' => [ map $cgi->param($_),
234 grep /^svc_dst_pkgpart/, $cgi->param
237 { 'link_table' => 'part_pkg_link',
238 'target_table' => 'part_pkg',
239 'base_field' => 'src_pkgpart',
240 'target_field' => 'dst_pkgpart',
241 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
242 'params' => [ map $cgi->param($_),
243 grep /^supp_dst_pkgpart/, $cgi->param
248 { 'link_table' => 'part_pkg_link',
249 'target_table' => 'part_pkg',
250 'base_field' => 'src_pkgpart',
251 'target_field' => 'dst_pkgpart',
252 'hashref' => { 'link_type' => 'bill', 'hidden' => $hidden },
253 'params' => [ map { $cgi->param($_) }
254 grep { my $param = "bill_dst_pkgpart__hidden";
256 (($digit) = /^bill_dst_pkgpart(\d+)/ ) &&
257 $cgi->param("$param$digit") eq $hidden;
265 foreach my $override_class ($cgi->param) {
266 next unless $override_class =~ /^tax_override_(\w+)$/;
269 my (@tax_overrides) = (grep "$_", split (",", $1))
270 if $cgi->param($override_class) =~ /^([\d,]+)$/;
273 'link_table' => 'part_pkg_taxoverride',
274 'target_table' => 'tax_class',
275 'hashref' => { 'usage_class' => $class },
276 'params' => [ @tax_overrides ],
281 my $conf = new FS::Conf;
284 foreach ($cgi->param('agent_type')) {
286 push @agents, $1 if $1;
289 'link_table' => 'type_pkgs',
290 'target_table' => 'agent_type',
291 'params' => \@agents,
294 my $targets = FS::part_pkg_usageprice->targets;
295 foreach my $amount_param ( grep /^usagepricepart(\d+)_amount$/, $cgi->param ) {
296 $amount_param =~ /^usagepricepart(\d+)_amount$/ or die 'unpossible';
298 my $amount = $cgi->param($amount_param);
299 if ( ! $amount && ! $cgi->param("usagepricepart${num}_price") ) {
300 #don't add empty rows just because the dropdowns have a value
301 $cgi->param("usagepricepart${num}_$_", '') for qw( currency action target );
304 my $target = $cgi->param("usagepricepart${num}_target");
305 $amount *= $targets->{$target}{multiplier} if $targets->{$target}{multiplier};
306 $cgi->param($amount_param, $amount);
311 'table' => 'part_pkg_msgcat',
312 'fields' => [qw( locale pkg )],
315 'table' => 'part_pkg_usageprice',
316 'fields' => [qw( price currency action target amount )],