1 <% include( 'elements/edit.html',
2 'post_url' => popurl(1).'process/part_pkg.cgi',
3 'name' => "Package definition",
5 #'viewall_dir' => 'browse',
6 'viewall_url' => $p.'browse/part_pkg.cgi',
7 'html_init' => include('/elements/init_overlib.html').
9 'html_bottom' => $html_bottom,
10 'new_hashref_callback' => $new_hashref_callback,
11 'new_object_callback' => $new_object_callback,
12 'new_callback' => $new_callback,
13 'edit_callback' => $edit_callback,
14 'error_callback' => $error_callback,
17 'pkgpart' => 'Package Definition',
18 'pkg' => 'Package (customer-visible)',
19 'comment' => 'Comment (customer-hidden)',
20 'classnum' => 'Package class',
21 'promo_code' => 'Promotional code',
22 'freq' => 'Recurring fee frequency',
23 'setuptax' => 'Setup fee tax exempt',
24 'recurtax' => 'Recurring fee tax exempt',
25 'taxclass' => 'Tax class',
26 'plan' => 'Price plan',
27 'disabled' => 'Disable new orders',
28 'pay_weight' => 'Payment weight',
29 'credit_weight' => 'Credit weight',
31 'setup_fee' => 'Setup fee',
32 'recur_fee' => 'Recurring fee',
33 'bill_dst_pkgpart' => 'Include line item(s) from package',
34 'svc_dst_pkgpart' => 'Include services of package',
38 { field=>'clone', type=>'hidden' },
39 { field=>'pkgnum', type=>'hidden' },
41 { type => 'columnstart' },
43 {field=>'pkg', type=>'text', size=>40 }, #32
44 {field=>'comment', type=>'text', size=>40 }, #32
45 {field=>'classnum', type=>'select-pkg_class' },
46 {field=>'disabled', type=>'checkbox', value=>'Y'},
48 { type => 'tablebreak-tr-title',
49 value => 'Pricing', #better name?
52 type => 'selectlayers-select',
53 options => [ keys %plan_labels ],
54 labels => \%plan_labels,
56 { field => 'setup_fee',
60 type => 'part_pkg_freq',
61 onchange => 'freq_changed', #XXX enable recurring fee
63 { field => 'recur_fee',
65 disabled => sub { $recur_disabled },
71 #recurring fee (auto-disable)
73 { type => 'columnnext' },
75 {type=>'justtitle', value=>'Taxation' },
76 {field=>'setuptax', type=>'checkbox', value=>'Y'},
77 {field=>'recurtax', type=>'checkbox', value=>'Y'},
78 {field=>'classnum', type=>'select-taxclass' },
79 {field=>'taxproductnum', type=>'select-taxproduct' },
81 { type => 'tablebreak-tr-title',
82 value => 'Promotions', #XXX better name?
84 { field=>'promo_code', type=>'text', size=>15 },
86 { type => 'tablebreak-tr-title',
87 value => 'Line-item revenue recogition', #XXX better name?
89 { field=>'pay_weight', type=>'text', size=>6 },
90 { field=>'credit_weight', type=>'text', size=>6 },
92 { type => 'columnnext' },
94 { field=>'agent_type',
95 type => 'select-agent_types',
96 curr_value_callback => sub {
97 my($cgi, $object, $field) = @_;
98 #in the other callbacks..? hmm.
103 { type => 'columnend' },
105 { 'type' => 'tablebreak-tr-title',
106 'value' => 'Pricing add-ons',
108 { 'field' => 'bill_dst_pkgpart',
109 'type' => 'select-part_pkg',
110 'm2_label' => 'Include line item(s) from package',
111 'm2m_table' => 'part_pkg_link',
112 'm2m_target_table' => 'part_pkg', #XXX actually just the method name...
113 'm2m_dstcol' => 'dst_pkgpart',
114 'm2m_static_or_something' => { 'link_type' => 'bill' }, #XXX
115 'm2_error_callback' => sub { (); }, #XXX existing!
118 { type => 'tablebreak-tr-title',
121 { type => 'pkg_svc', },
123 { 'field' => 'svc_dst_pkgpart',
124 'label' => 'Also include services from package: ',
125 'type' => 'select-part_pkg',
126 'm2_label' => 'Include services of package: ',
127 'm2m_table' => 'part_pkg_link',
128 'm2m_target_table' => 'part_pkg', #XXX actually just the method name...
129 'm2m_dstcol' => 'dst_pkgpart',
130 'm2m_static_or_something' => { 'link_type' => 'svc' }, #XXX
131 'm2_error_callback' => sub { (); }, #XXX existing!
134 { type => 'tablebreak-tr-title',
135 value => 'Price plan options',
144 my $curuser = $FS::CurrentUser::CurrentUser;
147 unless $curuser->access_right('Edit package definitions')
148 || $curuser->access_right('Edit global package definitions')
149 || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
152 # - part_pkg.pm bits (need separate access methods not just part_pkg_link)
153 # - tr-part_pkg_freq: month_increments_only (from price plans)
155 # - write edit bits for m2ms
156 # - display add-ons in browse... yeah
157 # -QIS- thank goodness
159 # - test custom pricing
160 #recur_flat->recur_fee migration, ugh
161 # - move the selectlayer divs away from lame layer_callback
163 #my ($query) = $cgi->keywords;
170 my $clone_part_pkg = '';
173 my $recur_disabled = 1;
174 my $error_callback = sub {
175 my($cgi, $object, $fields) = @_;
176 (@agent_type) = $cgi->param('agent_type');
177 $tax_override = $cgi->param('tax_override');
178 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
180 $recur_disabled = $cgi->param('freq') ? 0 : 1;
182 #some false laziness w/process
183 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
185 my $options = $cgi->param($plan."__OPTIONS");
186 my @options = split(',', $options);
188 map { my $optionname = $_;
189 my $param = $plan."__$optionname";
190 my $value = join(', ', $cgi->param($param));
191 ( $optionname => $value );
195 $cgi->param($_, $options{$_}) foreach (qw( setup_fee recur_fee ));
199 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
201 my $new_object_callback = sub {
202 my( $cgi, $hashref, $fields, $opt ) = @_;
204 if ( $cgi->param('clone') ) {
205 $opt->{action} = 'Custom';
206 $clone_part_pkg = qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
207 my $part_pkg = $clone_part_pkg->clone;
208 $part_pkg->disabled('Y');
209 %options = $clone_part_pkg->options;
212 FS::part_pkg->new( $hashref );
217 my $edit_callback = sub {
218 my( $cgi, $object, $fields ) = @_;
220 $recur_disabled = $object->freq ? 0 : 1;
222 (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1});
224 join (",", map {$_->taxclassnum}
225 qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} )
228 # join (",", map {$_->taxclassnum}
229 # $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc')
231 # unless $tax_override;
233 %options = $object->options;
237 my $new_callback = sub {
238 my( $cgi, $object, $fields ) = @_;
240 my $conf = new FS::Conf;
241 if ( $conf->exists('agent_defaultpkg') ) {
242 #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
243 @agent_type = map {$_->typenum} qsearch('agent_type',{});
248 my $freq_changed = <<'END';
249 <SCRIPT TYPE="text/javascript">
251 function freq_changed(what) {
252 var freq = what.options[what.selectedIndex].value;
255 what.form.recur_fee.disabled = true;
256 what.form.recur_fee.style.backgroundColor = '#dddddd';
258 what.form.recur_fee.disabled = false;
259 what.form.recur_fee.style.backgroundColor = '#ffffff';
267 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
269 tie my %plan_labels, 'Tie::IxHash',
270 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
273 my $html_bottom = sub {
276 #warn join("\n", map { "$_: $options{$_}" } keys %options ). "\n";
278 my $layer_callback = sub {
281 my $html = ntable("#cccccc",2);
285 # <TD ALIGN="right">Recurring fee frequency </TD>
286 # <TD><SELECT NAME="freq">
289 #my @freq = keys %freq;
290 #@freq = grep { /^\d+$/ } @freq
291 #XXX this bit# # if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
292 #foreach my $freq ( @freq ) {
293 # $html .= qq(<OPTION VALUE="$freq");
294 # $html .= ' SELECTED' if $freq eq $part_pkg->freq;
295 # $html .= ">$freq{$freq}";
297 #$html .= '</SELECT></TD></TR>';
299 my $href = $plans{$layer}->{'fields'};
300 my @fields = exists($plans{$layer}->{'fieldorder'})
301 ? @{$plans{$layer}->{'fieldorder'}}
304 foreach my $field ( grep $_ !~ /^(setup|recur)_fee$/, @fields ) {
306 $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
308 my $format = sub { shift };
309 $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
311 #XXX these should use elements/ fields... (or this whole thing should
312 #just use layer_fields instead of layer_callback)
314 if ( ! exists($href->{$field}{'type'}) ) {
316 $html .= qq!<INPUT TYPE="text" NAME="${layer}__$field" VALUE="!.
317 ( exists($options{$field})
318 ? &$format($options{$field})
319 : $href->{$field}{'default'} ).
322 } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
324 $html .= qq!<INPUT TYPE="checkbox" NAME="${layer}__$field" VALUE=1 !.
325 ( exists($options{$field}) && $options{$field}
330 } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
334 if $href->{$field}{'type'} eq 'select_multiple';
335 $html .= qq! NAME="${layer}__$field">!;
337 if ( $href->{$field}{'select_table'} ) {
339 qsearch( $href->{$field}{'select_table'},
340 $href->{$field}{'select_hash'} )
342 my $value = $record->getfield($href->{$field}{'select_key'});
343 $html .= qq!<OPTION VALUE="$value"!.
344 ( $options{$field} =~ /(^|, *)$value *(,|$)/ #XXX fix?
348 '>'. $record->getfield($href->{$field}{'select_label'});
350 } elsif ( $href->{$field}{'select_options'} ) {
351 foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
352 my $label = $href->{$field}{'select_options'}{$key};
353 $html .= qq!<OPTION VALUE="$key"!.
354 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix?
362 $html .= '<font color="#ff0000">warning: '.
363 "don't know how to retreive options for $field select field".
366 $html .= '</SELECT>';
368 } elsif ( $href->{$field}{'type'} eq 'radio' ) {
371 qq!<INPUT TYPE="radio" NAME="${layer}__$field"!;
373 foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
374 my $label = $href->{$field}{'options'}{$key};
375 $html .= qq!$radio VALUE="$key"!.
376 ( $options{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix?
385 $html .= '</TD></TR>';
389 $html .= qq(<INPUT TYPE="hidden" NAME="${layer}__OPTIONS" VALUE=").
390 join(',', keys %{ $href } ). '">';
398 options => [ keys %plan_labels ],
399 labels => \%plan_labels,
400 curr_value => $object->plan,
401 layer_callback => $layer_callback,
404 include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
405 '<SCRIPT TYPE="text/javascript">'.
406 include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 ).