-Price plan <SELECT NAME="plan" SIZE=1 onChange="changed(this);">
-<OPTION>
-<% foreach my $layer (keys %plans ) { %>
-<OPTION VALUE="<%= $layer %>"<%= ' SELECTED'x($layer eq $part_pkg->plan) %>><%= $plans{$layer}->{'name'} %>
-<% } %>
-</SELECT></FORM>
-
-<SCRIPT>
-function fchanged(what) {
- fixup(what.form);
-}
-
-function fixup(what) {
-<% foreach my $f ( qw( pkg comment freq ), @fixups ) { %>
- what.<%= $f %>.value = document.dummy.<%= $f %>.value;
-<% } %>
- what.plan.value = document.dummy.plan.options[document.dummy.plan.selectedIndex].value;
-<% foreach my $p ( keys %plans ) { %>
- if ( what.plan.value == "<%= $p %>" ) {
- what.setup.value = <%= $plans{$p}->{setup} %>;
- what.recur.value = <%= $plans{$p}->{recur} %>;
- }
-<% } %>
-}
-</SCRIPT>
-
-<% my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
- split("\n", $part_pkg->plandata );
- #foreach my $layer ( 'konq_kludge', keys %plans ) {
- foreach my $layer ( 'konq_kludge', keys %plans ) {
- my $visibility = "hidden";
-%>
-<SCRIPT>
-if (document.getElementById) {
- document.write("<DIV ID=\"d<%= $layer %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
-} else {
-<% $visibility="show" if $visibility eq "visible"; %>
- document.write("<LAYER ID=\"l<%= $layer %>\" VISIBILITY=\"<%= $visibility %>\">");
-}
-</SCRIPT>
-
-<FORM NAME="<%= $layer %>" ACTION="process/part_pkg.cgi" METHOD=POST onSubmit="fixup(this)">
-<INPUT TYPE="hidden" NAME="plan" VALUE="<%= $part_pkg->plan %>">
-<INPUT TYPE="hidden" NAME="pkg" VALUE="<%= $hashref->{pkg} %>">
-<INPUT TYPE="hidden" NAME="comment" VALUE="$<%= $hashref->{comment} %>">
-<INPUT TYPE="hidden" NAME="freq" VALUE="<%= $hashref->{freq} %>">
-<% foreach my $f ( @fixups ) { %>
-<INPUT TYPE="hidden" NAME="<%= $f %>" VALUE="">
-<% } %>
-
-<%
-if ( $cgi->param('clone') ) {
- print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
-}
-if ( $cgi->param('pkgnum') ) {
- print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
-}
-print qq!<INPUT TYPE="hidden" NAME="pkgpart" VALUE="$hashref->{pkgpart}">!,
-%>
-
-<% my $href = $plans{$layer}->{'fields'};
- foreach my $field ( keys %{ $href } ) { %>
-<%= $href->{$field}{'name'} %>:
-<INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= exists($plandata{$field}) ? $plandata{$field} : $href->{$field}{'default'} %>" onChange="fchanged(this)"><BR>
-<% } %>
-<INPUT TYPE="hidden" NAME="plandata" VALUE="<%= join(',', keys %{ $href } ) %>">
-
-<FONT SIZE="1">
-Setup expression<BR><INPUT TYPE="text" NAME="setup" SIZE="160" VALUE="<%= $hashref->{setup} %>" onLoad="fchanged(this)"><BR>
-Recurring espression<BR><INPUT TYPE="text" NAME="recur" SIZE="160" VALUE="<%= $hashref->{recur} %>" onLoad="fchanged(this)"><BR>
-</FONT>
-
-<%
-print qq!<BR><INPUT TYPE="submit" VALUE="!,
- $hashref->{pkgpart} ? "Apply changes" : "Add package",
- qq!" onClick="fchanged(this)">!;
-%>
-
-</FORM>
-
-<SCRIPT>
-if (document.getElementById) {
- document.write("</DIV>");
-} else {
- document.write("</LAYER>");
-}
-</SCRIPT>
-
-<% } %>
-
-<TAG onLoad="
- if (document.getElementById) {
- document.getElementById('d<%= $part_pkg->plan %>').style.visibility = 'visible';
- } else {
- document.l<%= $part_pkg->plan %>.visibility = 'visible';
- }
-">
+
+Line-item revenue recognition
+<% ntable("#cccccc", 2) %>
+% tie my %weight, 'Tie::IxHash',
+% 'pay_weight' => 'Payment',
+% 'credit_weight' => 'Credit'
+% ;
+% foreach my $weight (keys %weight) {
+ <TR>
+ <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
+ <TD>
+ <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
+ </TD>
+ </TR>
+% }
+</TABLE>
+
+</TD><TD VALIGN="top">
+
+% if ( $cgi->param('clone') || $conf->exists('agent_defaultpkg') ) {
+
+ <INPUT TYPE="hidden" NAME="agent_type" VALUE="">
+
+% } else {
+
+ Reseller information
+ <% ntable("#cccccc", 2) %>
+ <TR>
+ <TD ALIGN="right"><% 'Agent Types' %></TD>
+ <TD>
+ <% include( '/elements/select-table.html',
+ 'element_name' => 'agent_type',
+ 'table' => 'agent_type',
+ 'name_col' => 'atype',
+ 'value' => \@agent_type,
+ 'empty_label' => 'select agent types',
+ 'element_etc' => 'multiple size="10"',
+ )
+ %>
+ </TD>
+ </TR>
+ </TABLE>
+
+% }
+
+</TD></TR></TABLE>
+
+%
+%my $thead = "\n\n". ntable('#cccccc', 2).
+% '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>';
+%$thead .= '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'
+% if dbdef->table('pkg_svc')->column('primary_svc');
+%$thead .= '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
+%
+%
+
+
+<BR><BR>Services included
+<% itable('', 4, 1) %><TR><TD VALIGN="top">
+<% $thead %>
+%
+%
+%my $where = "WHERE disabled IS NULL OR disabled = ''";
+%if ( $pkgpart ) {
+% $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
+% WHERE pkg_svc.svcpart = part_svc.svcpart
+% AND pkgpart = $pkgpart
+% )";
+%}
+%my @part_svc = qsearch('part_svc', {}, '', $where);
+%my $q_part_pkg = $clone_part_pkg || $part_pkg;
+%my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
+%
+%my @fixups = ();
+%my $count = 0;
+%my $columns = 3;
+%foreach my $part_svc ( @part_svc ) {
+% my $svcpart = $part_svc->svcpart;
+% my $pkg_svc = $pkg_svc{$svcpart}
+% || new FS::pkg_svc ( {
+% 'pkgpart' => $pkgpart,
+% 'svcpart' => $svcpart,
+% 'quantity' => 0,
+% 'primary_svc' => '',
+% } );
+%
+% push @fixups, "pkg_svc$svcpart";
+%
+%
+
+
+ <TR>
+ <TD>
+ <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0 %>">
+ </TD>
+
+ <TD>
+ <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
+ </TD>
+
+ <TD>
+ <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
+ </TD>
+ </TR>
+% foreach ( 1 .. $columns-1 ) {
+% if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
+%
+
+ </TABLE></TD><TD VALIGN="top"><% $thead %>
+% }
+% }
+% $count++;
+%
+% }
+
+
+</TR></TABLE></TD></TR></TABLE>
+% foreach my $f ( qw( clone pkgnum ) ) {
+
+ <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
+% }
+
+<INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
+%
+%
+%# prolly should be in database
+%tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
+%
+%my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
+% split("\n", ($clone_part_pkg||$part_pkg)->plandata );
+%#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
+%
+%tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
+%
+%#my @form_select = ('classnum');
+%#if ( $conf->exists('enable_taxclasses') ) {
+%# push @form_select, 'taxclass';
+%#} else {
+%# push @fixups, 'taxclass'; #hidden
+%#}
+%my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
+%
+%my @form_radio = ();
+%if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
+% push @form_radio, 'pkg_svc_primary';
+%}
+%
+%tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
+%if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
+% delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
+%}
+%
+%my $widget = new HTML::Widgets::SelectLayers(
+% 'selected_layer' => $part_pkg->plan,
+% 'options' => \%options,
+% 'form_name' => 'dummy',
+% 'form_action' => 'process/part_pkg.cgi',
+% 'form_elements' => \@form_elements,
+% 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
+% qw(pay_weight credit_weight), #keys(%weight),
+% @fixups,
+% ],
+% 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
+% 'form_radio' => \@form_radio,
+% 'layer_callback' => sub {
+% my $layer = shift;
+% my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
+% ntable("#cccccc",2);
+% $html .= '
+% <TR>
+% <TD ALIGN="right">Recurring fee frequency </TD>
+% <TD><SELECT NAME="freq">
+% ';
+%
+% my @freq = keys %freq;
+% @freq = grep { /^\d+$/ } @freq
+% if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
+% foreach my $freq ( @freq ) {
+% $html .= qq(<OPTION VALUE="$freq");
+% $html .= ' SELECTED' if $freq eq $part_pkg->freq;
+% $html .= ">$freq{$freq}";
+% }
+% $html .= '</SELECT></TD></TR>';
+%
+% my $href = $plans{$layer}->{'fields'};
+% foreach my $field ( exists($plans{$layer}->{'fieldorder'})
+% ? @{$plans{$layer}->{'fieldorder'}}
+% : keys %{ $href }
+% ) {
+%
+% $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
+%
+% my $format = sub { shift };
+% $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
+% if ( ! exists($href->{$field}{'type'}) ) {
+% $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
+% ( exists($plandata{$field})
+% ? &$format($plandata{$field})
+% : $href->{$field}{'default'} ).
+% qq!">!;
+% } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
+% $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
+% ( exists($plandata{$field}) && $plandata{$field}
+% ? ' CHECKED'
+% : ''
+% ). '>';
+% } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
+% $html .= '<SELECT';
+% $html .= ' MULTIPLE'
+% if $href->{$field}{'type'} eq 'select_multiple';
+% $html .= qq! NAME="$field">!;
+%
+% if ( $href->{$field}{'select_table'} ) {
+% foreach my $record (
+% qsearch( $href->{$field}{'select_table'},
+% $href->{$field}{'select_hash'} )
+% ) {
+% my $value = $record->getfield($href->{$field}{'select_key'});
+% $html .= qq!<OPTION VALUE="$value"!.
+% ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
+% ? ' SELECTED'
+% : ''
+% ).
+% '>'. $record->getfield($href->{$field}{'select_label'});
+% }
+% } elsif ( $href->{$field}{'select_options'} ) {
+% foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
+% my $value = $href->{$field}{'select_options'}{$key};
+% $html .= qq!<OPTION VALUE="$key"!.
+% ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
+% ? ' SELECTED'
+% : ''
+% ).
+% '>'. $value;
+% }
+%
+% } else {
+% $html .= '<font color="#ff0000">warning: '.
+% "don't know how to retreive options for $field select field".
+% '</font>';
+% }
+% $html .= '</SELECT>';
+% }
+%
+% $html .= '</TD></TR>';
+% }
+% $html .= '</TABLE>';
+%
+% $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
+% join(',', keys %{ $href } ). '">'.
+% '<BR><BR>';
+%
+% $html .= '<INPUT TYPE="submit" VALUE="'.
+% ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
+% '">';
+%
+% $html;
+%
+% },
+%);
+%
+%
+
+
+<BR><BR>Price plan <% $widget->html %>