1 <% include('/elements/header.html', "$action Package Definition", menubar(
2 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
4 % #), ' onLoad="visualize()"');
6 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
7 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
8 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_draggable.js"></SCRIPT>
9 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/iframecontentmws.js"></SCRIPT>
11 <% include('/elements/error.html') %>
15 <% itable('',8,1) %><TR><TD VALIGN="top">
19 <% ntable("#cccccc",2) %>
21 <TD ALIGN="right">Package Definition #</TD>
22 <TD BGCOLOR="#ffffff">
23 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
27 <TD ALIGN="right">Package (customer-visible)</TD>
29 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
33 <TD ALIGN="right">Comment (customer-hidden)</TD>
35 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
38 <% include( '/elements/tr-select-pkg_class.html',
39 'curr_value' => $part_pkg->classnum,
43 <TD ALIGN="right">Promotional code</TD>
45 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
49 <TD ALIGN="right">Disable new orders</TD>
51 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
57 </TD><TD VALIGN="top">
60 <% ntable("#cccccc", 2) %>
62 <TD ALIGN="right">Setup fee tax exempt</TD>
64 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
68 <TD ALIGN="right">Recurring fee tax exempt</TD>
70 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
74 % if ( $conf->exists('enable_taxclasses') ) {
77 <TD align="right">Tax class</TD>
79 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
85 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
89 % if ( $conf->exists('enable_taxproducts') ) {
92 <% ntable("#cccccc", 2) %>
94 <TD align="right">Tax product</TD>
96 <INPUT name="part_pkg_taxproduct_taxproductnum" id="taxproductnum" type="hidden" value="<% $hashref->{'taxproductnum'}%>">
97 <INPUT name="part_pkg_taxproduct_description" id="taxproductnum_description" type="text" value="<% $taxproduct_description %>" size="12" onclick="overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
101 <TD colspan="2" align="right">
102 <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $tax_override %>">
103 <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
104 <% $tax_override ? 'Edit tax overrides' : 'Override taxes' %>
113 <INPUT TYPE="hidden" NAME="taxproductnum" VALUE="<% $hashref->{taxproductnum} %>">
114 <INPUT TYPE="hidden" NAME="tax_override" VALUE="<% $tax_override %>">
121 Line-item revenue recognition
122 <% ntable("#cccccc", 2) %>
123 % tie my %weight, 'Tie::IxHash',
124 % 'pay_weight' => 'Payment',
125 % 'credit_weight' => 'Credit'
127 % foreach my $weight (keys %weight) {
129 <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
131 <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
137 </TD><TD VALIGN="top">
139 % if ( $cgi->param('clone') ) {
141 <INPUT TYPE="hidden" NAME="agent_type" VALUE="">
143 % } elsif ( scalar(@all_agent_types) == 1) {
145 <INPUT TYPE="hidden" NAME="agent_type" VALUE="<% $all_agent_types[0] %>">
150 <% ntable("#cccccc", 2) %>
152 <TD ALIGN="right"><% 'Agent Types' %></TD>
154 <% include( '/elements/select-table.html',
155 'element_name' => 'agent_type',
156 'table' => 'agent_type',
157 'name_col' => 'atype',
158 'value' => \@agent_type,
160 'element_etc' => 'size="10"',
171 %my $thead = "\n\n". ntable('#cccccc', 2).
172 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>'.
173 % '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'.
174 % '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
176 <BR><BR>Services included
177 <% itable('', 4, 1) %><TR><TD VALIGN="top">
181 %my $where = "WHERE disabled IS NULL OR disabled = ''";
183 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
184 % WHERE pkg_svc.svcpart = part_svc.svcpart
185 % AND pkgpart = $pkgpart
188 %my @part_svc = qsearch('part_svc', {}, '', $where);
189 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
190 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
195 %foreach my $part_svc ( @part_svc ) {
196 % my $svcpart = $part_svc->svcpart;
197 % my $pkg_svc = $pkg_svc{$svcpart}
198 % || new FS::pkg_svc ( {
199 % 'pkgpart' => $pkgpart,
200 % 'svcpart' => $svcpart,
202 % 'primary_svc' => '',
204 % if ( $cgi->param('error') ) {
205 % my $primary_svc = ( $pkg_svc->primary_svc =~ /^Y/i );
206 % my $pkg_svc_primary = scalar($cgi->param('pkg_svc_primary'));
207 % $pkg_svc->primary_svc('')
208 % if $primary_svc && $pkg_svc_primary != $svcpart;
209 % $pkg_svc->primary_svc('Y')
210 % if ! $primary_svc && $pkg_svc_primary == $svcpart;
213 % push @fixups, "pkg_svc$svcpart";
216 % if ( $cgi->param("pkg_svc$svcpart") =~ /^\s*(\d+)\s*$/ ) {
218 % } elsif ( $pkg_svc->quantity ) {
219 % $quan = $pkg_svc->quantity;
225 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $quan %>">
229 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
233 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
236 % foreach ( 1 .. $columns-1 ) {
237 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
240 </TABLE></TD><TD VALIGN="top"><% $thead %>
248 </TR></TABLE></TD></TR></TABLE>
249 % foreach my $f ( qw( clone pkgnum ) ) { #safe, these were untained in %init
250 <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
253 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
256 %# prolly should be in database
257 %tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
259 %my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
260 % split("\n", ($clone_part_pkg||$part_pkg)->plandata );
261 %#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
263 %tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
265 %#my @form_select = ('classnum');
266 %#if ( $conf->exists('enable_taxclasses') ) {
267 %# push @form_select, 'taxclass';
269 %# push @fixups, 'taxclass'; #hidden
271 %my @form_elements = ( 'classnum', 'taxclass', 'agent_type', 'tax_override' );
273 %my @form_radio = ( 'pkg_svc_primary' );
275 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
276 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
277 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
280 %#this should be replaced by /elements/selectlayers.html
281 %my $widget = new HTML::Widgets::SelectLayers(
282 % 'selected_layer' => $part_pkg->plan,
283 % 'options' => \%options,
284 % 'form_name' => 'dummy',
285 % 'form_action' => 'process/part_pkg.cgi',
286 % 'form_elements' => \@form_elements,
287 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
288 % qw(pay_weight credit_weight), #keys(%weight),
292 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
293 % 'form_radio' => \@form_radio,
294 % 'layer_callback' => sub {
296 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
297 % ntable("#cccccc",2);
300 % <TD ALIGN="right">Recurring fee frequency </TD>
301 % <TD><SELECT NAME="freq">
304 % my @freq = keys %freq;
305 % @freq = grep { /^\d+$/ } @freq
306 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
307 % foreach my $freq ( @freq ) {
308 % $html .= qq(<OPTION VALUE="$freq");
309 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
310 % $html .= ">$freq{$freq}";
312 % $html .= '</SELECT></TD></TR>';
314 % my $href = $plans{$layer}->{'fields'};
315 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
316 % ? @{$plans{$layer}->{'fieldorder'}}
320 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
322 % my $format = sub { shift };
323 % $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
325 % if ( ! exists($href->{$field}{'type'}) ) {
327 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
328 % ( exists($plandata{$field})
329 % ? &$format($plandata{$field})
330 % : $href->{$field}{'default'} ).
331 % qq!" onChange="fchanged(this)">!;
333 % } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
335 % $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
336 % ( exists($plandata{$field}) && $plandata{$field}
341 % } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
343 % $html .= '<SELECT';
344 % $html .= ' MULTIPLE'
345 % if $href->{$field}{'type'} eq 'select_multiple';
346 % $html .= qq! NAME="$field" onChange="fchanged(this)">!;
348 % if ( $href->{$field}{'select_table'} ) {
349 % foreach my $record (
350 % qsearch( $href->{$field}{'select_table'},
351 % $href->{$field}{'select_hash'} )
353 % my $value = $record->getfield($href->{$field}{'select_key'});
354 % $html .= qq!<OPTION VALUE="$value"!.
355 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
359 % '>'. $record->getfield($href->{$field}{'select_label'});
361 % } elsif ( $href->{$field}{'select_options'} ) {
362 % foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
363 % my $label = $href->{$field}{'select_options'}{$key};
364 % $html .= qq!<OPTION VALUE="$key"!.
365 % ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
373 % $html .= '<font color="#ff0000">warning: '.
374 % "don't know how to retreive options for $field select field".
377 % $html .= '</SELECT>';
379 % } elsif ( $href->{$field}{'type'} eq 'radio' ) {
382 % qq!<INPUT TYPE="radio" NAME="$field" onChange="fchanged(this)"!;
384 % foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
385 % my $label = $href->{$field}{'options'}{$key};
386 % $html .= qq!$radio VALUE="$key"!.
387 % ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
396 % $html .= '</TD></TR>';
398 % $html .= '</TABLE>';
400 % $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
401 % join(',', keys %{ $href } ). '">'.
404 % $html .= '<INPUT TYPE="submit" VALUE="'.
405 % ( $action eq 'Custom'
406 % ? 'Customize package'
407 % : ( $hashref->{pkgpart} ? "Apply changes" : "Add package" )
409 % '" onClick="fchanged(this)">';
419 <BR><BR>Price plan <% $widget->html %>
421 <% include('/elements/footer.html') %>
424 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
425 $cgi->param('clone', $1);
427 $cgi->param('clone', '');
429 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
430 $cgi->param('pkgnum', $1);
432 $cgi->param('pkgnum', '');
435 my $curuser = $FS::CurrentUser::CurrentUser;
438 unless $curuser->access_right('Edit package definitions')
439 || $curuser->access_right('Edit global package definitions')
440 || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
442 my ($query) = $cgi->keywords;
444 my $conf = new FS::Conf;
448 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
449 if ( $cgi->param('error') ) {
450 $part_pkg = new FS::part_pkg ( {
451 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
453 (@agent_type) = $cgi->param('agent_type');
454 $tax_override = $cgi->param('tax_override');
458 my $clone_part_pkg = '';
460 if ( $cgi->param('clone') ) {
461 $pkgpart = $cgi->param('clone');
462 #$action = 'Custom Pricing';
464 $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
465 $part_pkg ||= $clone_part_pkg->clone;
466 $part_pkg->disabled('Y') unless $cgi->param('error');
467 } elsif ( $query && $query =~ /^(\d+)$/ ) {
468 (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
472 join (",", map {$_->taxclassnum}
473 qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} )
475 # join (",", map {$_->taxclassnum}
476 # $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc')
478 # unless $tax_override;
480 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
481 $pkgpart = $part_pkg->pkgpart;
483 unless ( $part_pkg ) {
484 $part_pkg = new FS::part_pkg {};
485 $part_pkg->plan('flat');
486 @agent_type = @all_agent_types if $conf->exists('agent_defaultpkg');
490 unless ( $part_pkg->plan ) { #backwards-compat
491 $part_pkg->plan('flat');
492 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
493 "recur_fee=". $part_pkg->recur. "\n");
495 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
496 my $hashref = $part_pkg->hashref;
497 my $taxproduct_description = $part_pkg->taxproduct_description;