3 %if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
4 % $cgi->param('clone', $1);
6 % $cgi->param('clone', '');
8 %if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
9 % $cgi->param('pkgnum', $1);
11 % $cgi->param('pkgnum', '');
14 %my ($query) = $cgi->keywords;
18 %if ( $cgi->param('error') ) {
19 % $part_pkg = new FS::part_pkg ( {
20 % map { $_, scalar($cgi->param($_)) } fields('part_pkg')
22 % (@agent_type) = $cgi->param('agent_type');
26 %my $clone_part_pkg = '';
28 %if ( $cgi->param('clone') ) {
29 % $pkgpart = $cgi->param('clone');
30 % $action = 'Custom Pricing';
31 % $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
32 % $part_pkg ||= $clone_part_pkg->clone;
33 % $part_pkg->disabled('Y'); #isn't sticky on errors
34 %} elsif ( $query && $query =~ /^(\d+)$/ ) {
35 % (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
37 % $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
38 % $pkgpart = $part_pkg->pkgpart;
40 % unless ( $part_pkg ) {
41 % $part_pkg = new FS::part_pkg {};
42 % $part_pkg->plan('flat');
45 %unless ( $part_pkg->plan ) { #backwards-compat
46 % $part_pkg->plan('flat');
47 % $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
48 % "recur_fee=". $part_pkg->recur. "\n");
50 %$action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
51 %my $hashref = $part_pkg->hashref;
56 <% include("/elements/header.html","$action Package Definition", menubar(
57 'Main Menu' => popurl(2),
58 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
60 % #), ' onLoad="visualize()"');
61 % if ( $cgi->param('error') ) {
63 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
69 <% itable('',8,1) %><TR><TD VALIGN="top">
73 <% ntable("#cccccc",2) %>
75 <TD ALIGN="right">Package Definition #</TD>
76 <TD BGCOLOR="#ffffff">
77 <% $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)" %>
81 <TD ALIGN="right">Package (customer-visible)</TD>
83 <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<% $part_pkg->pkg %>">
87 <TD ALIGN="right">Comment (customer-hidden)</TD>
89 <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%$part_pkg->comment%>">
92 <% include( '/elements/tr-select-pkg_class.html', $part_pkg->classnum ) %>
94 <TD ALIGN="right">Promotional code</TD>
96 <INPUT TYPE="text" NAME="promo_code" SIZE=32 VALUE="<%$part_pkg->promo_code%>">
100 <TD ALIGN="right">Disable new orders</TD>
102 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>
108 </TD><TD VALIGN="top">
111 <% ntable("#cccccc", 2) %>
113 <TD ALIGN="right">Setup fee tax exempt</TD>
115 <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
119 <TD ALIGN="right">Recurring fee tax exempt</TD>
121 <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <% $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
125 % my $conf = new FS::Conf;
126 % if ( $conf->exists('enable_taxclasses') ) {
129 <TD align="right">Tax class</TD>
131 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
137 <% include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
144 Line-item revenue recognition
145 <% ntable("#cccccc", 2) %>
146 % tie my %weight, 'Tie::IxHash',
147 % 'pay_weight' => 'Payment',
148 % 'credit_weight' => 'Credit'
150 % foreach my $weight (keys %weight) {
152 <TD ALIGN="right"><% $weight{$weight} %> weight</TD>
154 <INPUT TYPE="text" NAME="<% $weight %>" SIZE=6 VALUE=<% $hashref->{$weight} || 0 %>>
160 </TD><TD VALIGN="top">
162 %#Reseller information # after 1.7.2
163 %#<% ntable("#cccccc", 2) %>
165 %# <TD ALIGN="right"><% 'Agent Types' %></TD>
167 %# <% include( '/elements/select-table.html',
168 %# 'element_name' => 'agent_type',
169 %# 'table' => 'agent_type',
170 %# 'name_col' => 'atype',
171 %# 'value' => \@agent_type,
172 %# 'empty_label' => '(none)',
173 %# 'element_etc' => 'multiple size="10"',
182 %my $thead = "\n\n". ntable('#cccccc', 2).
183 % '<TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH>';
184 %$thead .= '<TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Primary</FONT></TH>'
185 % if dbdef->table('pkg_svc')->column('primary_svc');
186 %$thead .= '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
191 <BR><BR>Services included
192 <% itable('', 4, 1) %><TR><TD VALIGN="top">
196 %my $where = "WHERE disabled IS NULL OR disabled = ''";
198 % $where .= " OR 0 < ( SELECT quantity FROM pkg_svc
199 % WHERE pkg_svc.svcpart = part_svc.svcpart
200 % AND pkgpart = $pkgpart
203 %my @part_svc = qsearch('part_svc', {}, '', $where);
204 %my $q_part_pkg = $clone_part_pkg || $part_pkg;
205 %my %pkg_svc = map { $_->svcpart => $_ } $q_part_pkg->pkg_svc;
210 %foreach my $part_svc ( @part_svc ) {
211 % my $svcpart = $part_svc->svcpart;
212 % my $pkg_svc = $pkg_svc{$svcpart}
213 % || new FS::pkg_svc ( {
214 % 'pkgpart' => $pkgpart,
215 % 'svcpart' => $svcpart,
217 % 'primary_svc' => '',
220 % push @fixups, "pkg_svc$svcpart";
227 <INPUT TYPE="text" NAME="pkg_svc<% $svcpart %>" SIZE=4 MAXLENGTH=3 VALUE="<% $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0 %>">
231 <INPUT TYPE="radio" NAME="pkg_svc_primary" VALUE="<% $svcpart %>" <% $pkg_svc->primary_svc =~ /^Y/i ? ' CHECKED' : '' %>>
235 <A HREF="part_svc.cgi?<% $part_svc->svcpart %>"><% $part_svc->svc %></A> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %>
238 % foreach ( 1 .. $columns-1 ) {
239 % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) {
242 </TABLE></TD><TD VALIGN="top"><% $thead %>
250 </TR></TABLE></TD></TR></TABLE>
251 % foreach my $f ( qw( clone pkgnum ) ) {
253 <INPUT TYPE="hidden" NAME="<% $f %>" VALUE="<% $cgi->param($f) %>">
256 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
259 %# prolly should be in database
260 %tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
262 %my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
263 % split("\n", ($clone_part_pkg||$part_pkg)->plandata );
264 %#warn join("\n", map { "$_: $plandata{$_}" } keys %plandata ). "\n";
266 %tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
268 %#my @form_select = ('classnum');
269 %#if ( $conf->exists('enable_taxclasses') ) {
270 %# push @form_select, 'taxclass';
272 %# push @fixups, 'taxclass'; #hidden
274 %my @form_elements = ( 'classnum', 'taxclass' );
275 %# copying non-existant elements is probably harmless, but after 1.7.2
276 %#my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
278 %my @form_radio = ();
279 %if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
280 % push @form_radio, 'pkg_svc_primary';
283 %tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()};
284 %if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
285 % delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
288 %my $widget = new HTML::Widgets::SelectLayers(
289 % 'selected_layer' => $part_pkg->plan,
290 % 'options' => \%options,
291 % 'form_name' => 'dummy',
292 % 'form_action' => 'process/part_pkg.cgi',
293 % 'form_elements' => \@form_elements,
294 % 'form_text' => [ qw(pkg comment promo_code clone pkgnum pkgpart),
295 % qw(pay_weight credit_weight),
298 % 'form_checkbox' => [ qw(setuptax recurtax disabled) ],
299 % 'form_radio' => \@form_radio,
300 % 'layer_callback' => sub {
302 % my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
303 % ntable("#cccccc",2);
306 % <TD ALIGN="right">Recurring fee frequency </TD>
307 % <TD><SELECT NAME="freq">
310 % my @freq = keys %freq;
311 % @freq = grep { /^\d+$/ } @freq
312 % if exists($plans{$layer}->{'freq'}) && $plans{$layer}->{'freq'} eq 'm';
313 % foreach my $freq ( @freq ) {
314 % $html .= qq(<OPTION VALUE="$freq");
315 % $html .= ' SELECTED' if $freq eq $part_pkg->freq;
316 % $html .= ">$freq{$freq}";
318 % $html .= '</SELECT></TD></TR>';
320 % my $href = $plans{$layer}->{'fields'};
321 % foreach my $field ( exists($plans{$layer}->{'fieldorder'})
322 % ? @{$plans{$layer}->{'fieldorder'}}
326 % $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
328 % if ( ! exists($href->{$field}{'type'}) ) {
329 % $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
330 % ( exists($plandata{$field})
331 % ? $plandata{$field}
332 % : $href->{$field}{'default'} ).
333 % qq!" onChange="fchanged(this)">!; #after 1.7.2
334 % } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
335 % $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
336 % ( exists($plandata{$field}) && $plandata{$field}
340 % } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
341 % $html .= '<SELECT';
342 % $html .= ' MULTIPLE'
343 % if $href->{$field}{'type'} eq 'select_multiple';
344 % $html .= qq! NAME="$field" onChange="fchanged(this)">!; # after 1.7.2
346 % if ( $href->{$field}{'select_table'} ) {
347 % foreach my $record (
348 % qsearch( $href->{$field}{'select_table'},
349 % $href->{$field}{'select_hash'} )
351 % my $value = $record->getfield($href->{$field}{'select_key'});
352 % $html .= qq!<OPTION VALUE="$value"!.
353 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
357 % '>'. $record->getfield($href->{$field}{'select_label'});
359 % } elsif ( $href->{$field}{'select_options'} ) {
360 % foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
361 % my $value = $href->{$field}{'select_options'}{$key};
362 % $html .= qq!<OPTION VALUE="$key"!.
363 % ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
371 % $html .= '<font color="#ff0000">warning: '.
372 % "don't know how to retreive options for $field select field".
375 % $html .= '</SELECT>';
378 % $html .= '</TD></TR>';
380 % $html .= '</TABLE>';
382 % $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
383 % join(',', keys %{ $href } ). '">'.
386 % $html .= '<INPUT TYPE="submit" VALUE="'.
387 % ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
388 % '" onClick="fchanged(this)">'; #after 1.7.2
398 <BR><BR>Price plan <% $widget->html %>