finish up weekly billing
[freeside.git] / httemplate / edit / part_pkg.cgi
1 <!-- mason kludge -->
2 <%
3
4 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
5   $cgi->param('clone', $1);
6 } else {
7   $cgi->param('clone', '');
8 }
9 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
10   $cgi->param('pkgnum', $1);
11 } else {
12   $cgi->param('pkgnum', '');
13 }
14
15 my ($query) = $cgi->keywords;
16 my $action = '';
17 my $part_pkg = '';
18 if ( $cgi->param('error') ) {
19   $part_pkg = new FS::part_pkg ( {
20     map { $_, scalar($cgi->param($_)) } fields('part_pkg')
21   } );
22 }
23 if ( $cgi->param('clone') ) {
24   $action='Custom Pricing';
25   my $old_part_pkg =
26     qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
27   $part_pkg ||= $old_part_pkg->clone;
28   $part_pkg->disabled('Y');
29 } elsif ( $query && $query =~ /^(\d+)$/ ) {
30   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
31 } else {
32   unless ( $part_pkg ) {
33     $part_pkg = new FS::part_pkg {};
34     $part_pkg->plan('flat');
35   }
36 }
37 unless ( $part_pkg->plan ) { #backwards-compat
38   $part_pkg->plan('flat');
39   $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
40                       "recur_fee=". $part_pkg->recur. "\n");
41 }
42 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
43 my $hashref = $part_pkg->hashref;
44
45
46 print header("$action Package Definition", menubar(
47   'Main Menu' => popurl(2),
48   'View all packages' => popurl(2). 'browse/part_pkg.cgi',
49 ));
50 #), ' onLoad="visualize()"');
51
52 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
53       "</FONT>"
54   if $cgi->param('error');
55
56 #print '<FORM ACTION="', popurl(1), 'process/part_pkg.cgi" METHOD=POST>';
57 print '<FORM NAME="dummy">';
58
59 #if ( $cgi->param('clone') ) {
60 #  print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
61 #}
62 #if ( $cgi->param('pkgnum') ) {
63 #  print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
64 #}
65 #
66 #print qq!<INPUT TYPE="hidden" NAME="pkgpart" VALUE="$hashref->{pkgpart}">!,
67 print "Package Part #", $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)";
68
69 #false laziness w/view/cust_main.cgi
70 my %freq;
71 tie %freq, 'Tie::IxHash', 
72   '0'  => '(no recurring fee)',
73   '1d' => 'daily',
74   '1w' => 'weekly',
75   '2w' => 'biweekly (every 2 weeks)',
76   '1'  => 'monthly',
77   '2'  => 'bimonthly (every 2 months)',
78   '3'  => 'quarterly (every 3 months)',
79   '6'  => 'semiannually (every 6 months)',
80   '12' => 'annually',
81   '24' => 'biannually (every 2 years)',
82 ;
83 if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) {
84   delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
85 }
86
87 %>
88 <%= ntable("#cccccc",2) %>
89   <TR>
90     <TD ALIGN="right">Package (customer-visible)</TD>
91     <TD>
92       <INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="<%= $part_pkg->pkg %>">
93     </TD>
94   </TR>
95   <TR>
96     <TD ALIGN="right">Comment (customer-hidden)</TD>
97     <TD>
98       <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%=$part_pkg->comment%>">
99     </TD>
100   </TR>
101   <TR>
102     <TD ALIGN="right">Recurring fee frequency </TD>
103     <TD>
104       <SELECT NAME="freq">
105         <% foreach my $freq ( keys %freq ) { %>
106           <OPTION VALUE="<%= $freq %>"<%= $freq eq $part_pkg->freq ? ' SELECTED' : '' %>><%= $freq{$freq} %>
107         <% } %>
108       </SELECT>
109     </TD>
110   </TR>
111   <TR>
112     <TD ALIGN="right">Setup fee tax exempt</TD>
113     <TD>
114 <%
115
116 print '<INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y"';
117 print ' CHECKED' if $hashref->{setuptax} eq "Y";
118 print '>';
119
120 print <<END;
121 </TD></TR>
122 <TR><TD ALIGN="right">Recurring fee tax exempt</TD><TD>
123 END
124
125 print '<INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y"';
126 print ' CHECKED' if $hashref->{recurtax} eq "Y";
127 print '>';
128
129 print '</TD></TR>';
130
131 my $conf = new FS::Conf;
132 #false laziness w/ view/cust_main.cgi quick order
133 if ( $conf->exists('enable_taxclasses') ) {
134   print '<TR><TD ALIGN="right">Tax class</TD><TD><SELECT NAME="taxclass">';
135   my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
136     or die dbh->errstr;
137   $sth->execute or die $sth->errstr;
138   foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
139     print qq!<OPTION VALUE="$taxclass"!;
140     print ' SELECTED' if $taxclass eq $hashref->{taxclass};
141     print qq!>$taxclass</OPTION>!;
142   }
143   print '</SELECT></TD></TR>';
144 } else {
145   print
146     '<INPUT TYPE="hidden" NAME="taxclass" VALUE="'. $hashref->{taxclass}. '">';
147 }
148
149 print '<TR><TD ALIGN="right">Disable new orders</TD><TD>';
150 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
151 print ' CHECKED' if $hashref->{disabled} eq "Y";
152 print '>';
153 print '</TD></TR></TABLE>';
154
155 my $thead =  "\n\n". ntable('#cccccc', 2). <<END;
156 <TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH><TH BGCOLOR="#dcdcdc">Service</TH></TR>
157 END
158
159 #unless ( $cgi->param('clone') ) {
160 #dunno why...
161 unless ( 0 ) {
162   #print <<END, $thead;
163   print <<END, itable(), '<TR><TD VALIGN="top">', $thead;
164 <BR><BR>Enter the quantity of each service this package includes.<BR><BR>
165 END
166 }
167
168 my @fixups = ();
169 my $count = 0;
170 my $columns = 3;
171 my @part_svc = qsearch( 'part_svc', { 'disabled' => '' } );
172 foreach my $part_svc ( @part_svc ) {
173   my $svcpart = $part_svc->svcpart;
174   my $pkgpart = $cgi->param('clone') || $part_pkg->pkgpart;
175   my $pkg_svc = $pkgpart && qsearchs( 'pkg_svc', {
176     'pkgpart'  => $pkgpart,
177     'svcpart'  => $svcpart,
178   } ) || new FS::pkg_svc ( {
179     'pkgpart'  => $pkgpart,
180     'svcpart'  => $svcpart,
181     'quantity' => 0,
182   });
183   #? #next unless $pkg_svc;
184
185   push @fixups, "pkg_svc$svcpart";
186
187   #unless ( defined ($cgi->param('clone')) && $cgi->param('clone') ) {
188   #dunno why...
189   unless ( 0 ) {
190     print '<TR>'; # if $count == 0 ;
191     print qq!<TD><INPUT TYPE="text" NAME="pkg_svc$svcpart" SIZE=4 MAXLENGTH=3 VALUE="!,
192           $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0,
193           qq!"></TD><TD><A HREF="part_svc.cgi?!,$part_svc->svcpart,
194           qq!">!, $part_svc->getfield('svc'), "</A></TD></TR>";
195 #    print "</TABLE></TD><TD>$thead" if ++$count == int(scalar(@part_svc) / 2);
196     $count+=1;
197     foreach ( 1 .. $columns-1 ) {
198       print "</TABLE></TD><TD VALIGN=\"top\">$thead"
199         if $count == int( $_ * scalar(@part_svc) / $columns );
200     }
201   } else {
202     print qq!<INPUT TYPE="hidden" NAME="pkg_svc$svcpart" VALUE="!,
203           $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0, qq!">\n!;
204   }
205 }
206
207 #unless ( $cgi->param('clone') ) {
208 #dunno why...
209 unless ( 0 ) {
210   print "</TR></TABLE></TD></TR></TABLE>";
211   #print "</TR></TABLE>";
212 }
213
214 foreach my $f ( qw( clone pkgnum ) ) {
215   print qq!<INPUT TYPE="hidden" NAME="$f" VALUE="!. $cgi->param($f). '">';
216 }
217 print '<INPUT TYPE="hidden" NAME="pkgpart" VALUE="'. $part_pkg->pkgpart. '">';
218
219 # prolly should be in database
220 tie my %plans, 'Tie::IxHash',
221   'flat' => {
222     'name' => 'Flat rate (anniversary billing)',
223     'fields' => {
224       'setup_fee' => { 'name' => 'Setup fee for this package',
225                        'default' => 0,
226                      },
227       'recur_fee' => { 'name' => 'Recurring fee for this package',
228                        'default' => 0,
229                       },
230     },
231     'fieldorder' => [ 'setup_fee', 'recur_fee' ],
232     'setup' => 'what.setup_fee.value',
233     'recur' => 'what.recur_fee.value',
234   },
235
236   'flat_delayed' => {
237     'name' => 'Free for X days, then flat rate (anniversary billing)',
238     'fields' =>  {
239       'free_days' => { 'name' => 'Initial free days',
240                        'default' => 0,
241                      },
242       'setup_fee' => { 'name' => 'Setup fee for this package',
243                        'default' => 0,
244                      },
245       'recur_fee' => { 'name' => 'Recurring fee for this package',
246                        'default' => 0,
247                       },
248     },
249     'fieldorder' => [ 'free_days', 'setup_fee', 'recur_fee' ],
250     'setup' => '\'my $d = $cust_pkg->bill || $time; $d += 86400 * \' + what.free_days.value + \'; $cust_pkg->bill($d); $cust_pkg_mod_flag=1; \' + what.setup_fee.value',
251     'recur' => 'what.recur_fee.value',
252   },
253
254   'prorate' => {
255     'name' => 'First partial month pro-rated, then flat-rate (1st of month billing)',
256     'fields' =>  {
257       'setup_fee' => { 'name' => 'Setup fee for this package',
258                        'default' => 0,
259                      },
260       'recur_fee' => { 'name' => 'Recurring fee for this package',
261                        'default' => 0,
262                       },
263     },
264     'fieldorder' => [ 'setup_fee', 'recur_fee' ],
265     'setup' => 'what.setup_fee.value',
266     'recur' => '\'my $mnow = $sdate; my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($sdate) )[0,1,2,3,4,5]; my $mstart = timelocal(0,0,0,1,$mon,$year); my $mend = timelocal(0,0,0,1, $mon == 11 ? 0 : $mon+1, $year+($mon==11)); $sdate = $mstart; ( $part_pkg->freq - 1 ) * \' + what.recur_fee.value + \' / $part_pkg->freq + \' + what.recur_fee.value + \' / $part_pkg->freq * ($mend-$mnow) / ($mend-$mstart) ; \'',
267   },
268
269   'subscription' => {
270     'name' => 'First partial month full charge, then flat-rate (1st of month billing)',
271     'fields' => {
272       'setup_fee' => { 'name' => 'Setup fee for this package',
273                        'default' => 0,
274                      },
275       'recur_fee' => { 'name' => 'Recurring fee for this package',
276                        'default' => 0,
277                       },
278     },
279     'fieldorder' => [ 'setup_fee', 'recur_fee' ],
280     'setup' => 'what.setup_fee.value',
281     'recur' => '\'my $mnow = $sdate; my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($sdate) )[0,1,2,3,4,5]; $sdate = timelocal(0,0,0,1,$mon,$year); \' + what.recur_fee.value',
282   },
283
284   'flat_comission_cust' => {
285     'name' => 'Flat rate with recurring commission per active customer',
286     'fields' => {
287       'setup_fee' => { 'name' => 'Setup fee for this package',
288                        'default' => 0,
289                      },
290       'recur_fee' => { 'name' => 'Recurring fee for this package',
291                        'default' => 0,
292                      },
293       'comission_amount' => { 'name' => 'Commission amount per month (per active customer)',
294                               'default' => 0,
295                             },
296       'comission_depth'  => { 'name' => 'Number of layers',
297                               'default' => 1,
298                             },
299     },
300     'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount' ],
301     'setup' => 'what.setup_fee.value',
302     'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_main_ncancelled(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
303   },
304
305   'flat_comission' => {
306     'name' => 'Flat rate with recurring commission per (any) active package',
307     'fields' => {
308       'setup_fee' => { 'name' => 'Setup fee for this package',
309                        'default' => 0,
310                      },
311       'recur_fee' => { 'name' => 'Recurring fee for this package',
312                        'default' => 0,
313                      },
314       'comission_amount' => { 'name' => 'Commission amount per month (per active package)',
315                               'default' => 0,
316                             },
317       'comission_depth'  => { 'name' => 'Number of layers',
318                               'default' => 1,
319                             },
320     },
321     'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount' ],
322     'setup' => 'what.setup_fee.value',
323     'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
324   },
325
326   'flat_comission_pkg' => {
327     'name' => 'Flat rate with recurring commission per (selected) active package',
328     'fields' => {
329       'setup_fee' => { 'name' => 'Setup fee for this package',
330                        'default' => 0,
331                      },
332       'recur_fee' => { 'name' => 'Recurring fee for this package',
333                        'default' => 0,
334                      },
335       'comission_amount' => { 'name' => 'Commission amount per month (per uncancelled package)',
336                               'default' => 0,
337                             },
338       'comission_depth'  => { 'name' => 'Number of layers',
339                               'default' => 1,
340                             },
341       'comission_pkgpart' => { 'name' => 'Applicable packages<BR><FONT SIZE="-1">(hold <b>ctrl</b> to select multiple packages)</FONT>',
342                                'type' => 'select_multiple',
343                                'select_table' => 'part_pkg',
344                                'select_hash'  => { 'disabled' => '' } ,
345                                'select_key'   => 'pkgpart',
346                                'select_label' => 'pkg',
347                              },
348     },
349     'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount', 'comission_pkgpart' ],
350     'setup' => 'what.setup_fee.value',
351     'recur' => '""; var pkgparts = ""; for ( var c=0; c < document.flat_comission_pkg.comission_pkgpart.options.length; c++ ) { if (document.flat_comission_pkg.comission_pkgpart.options[c].selected) { pkgparts = pkgparts + document.flat_comission_pkg.comission_pkgpart.options[c].value + \', \'; } } what.recur.value = \'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar( grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } ( \' + pkgparts + \'  ) } $cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
352   },
353
354
355
356   'sesmon_hour' => {
357     'name' => 'Base charge plus charge per-hour from the session monitor',
358     'fields' => {
359       'setup_fee' => { 'name' => 'Setup fee for this package',
360                        'default' => 0,
361                      },
362       'recur_flat' => { 'name' => 'Base monthly charge for this package',
363                         'default' => 0,
364                       },
365       'recur_included_hours' => { 'name' => 'Hours included',
366                                   'default' => 0,
367                                 },
368       'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
369                                  'default' => 0,
370                                },
371     },
372     'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_hours', 'recur_hourly_charge' ],
373     'setup' => 'what.setup_fee.value',
374     'recur' => '\'my $hours = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; \' + what.recur_flat.value + \' + \' + what.recur_hourly_charge.value + \' * $hours;\'',
375   },
376
377   'sesmon_minute' => {
378     'name' => 'Base charge plus charge per-minute from the session monitor',
379     'fields' => {
380       'setup_fee' => { 'name' => 'Setup fee for this package',
381                        'default' => 0,
382                      },
383       'recur_flat' => { 'name' => 'Base monthly charge for this package',
384                         'default' => 0,
385                       },
386       'recur_included_min' => { 'name' => 'Minutes included',
387                                 'default' => 0,
388                                 },
389       'recur_minly_charge' => { 'name' => 'Additional charge per minute',
390                                 'default' => 0,
391                               },
392     },
393     'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_min', 'recur_minly_charge' ],
394     'setup' => 'what.setup_fee.value',
395     'recur' => '\'my $min = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 60 - \' + what.recur_included_min.value + \'; $min = 0 if $min < 0; \' + what.recur_flat.value + \' + \' + what.recur_minly_charge.value + \' * $min;\'',
396
397   },
398
399   'sqlradacct_hour' => {
400     'name' => 'Base charge plus charge per-hour (and for data) from an external sqlradius radacct table',
401     'fields' => {
402       'setup_fee' => { 'name' => 'Setup fee for this package',
403                        'default' => 0,
404                      },
405       'recur_flat' => { 'name' => 'Base monthly charge for this package',
406                         'default' => 0,
407                       },
408       'recur_included_hours' => { 'name' => 'Hours included',
409                                   'default' => 0,
410                                 },
411       'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
412                                  'default' => 0,
413                                },
414       'recur_included_input' => { 'name' => 'Input megabytes included',
415                                   'default' => 0,
416                                 },
417       'recur_input_charge' => { 'name' =>
418                                         'Additional charge per input megabyte',
419                                 'default' => 0,
420                               },
421       'recur_included_output' => { 'name' => 'Output megabytes included',
422                                    'default' => 0,
423                                 },
424       'recur_output_charge' => { 'name' =>
425                                        'Additional charge per output megabyte',
426                                 'default' => 0,
427                               },
428       'recur_included_total' => { 'name' =>
429                                        'Total input+output megabytes included',
430                                   'default' => 0,
431                                 },
432       'recur_total_charge' => { 'name' =>
433                                  'Additional charge per input+output megabyte',
434                                 'default' => 0,
435                               },
436     },
437     'fieldorder' => [qw( setup_fee recur_flat recur_included_hours recur_hourly_charge recur_included_input recur_input_charge recur_included_output recur_output_charge recur_included_total recur_total_charge )],
438     'setup' => 'what.setup_fee.value',
439     'recur' => '\'my $last_bill = $cust_pkg->last_bill; my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $sdate ) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; my $input = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctInputOctets\" ) / 1048576; my $output = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctOutputOctets\" ) / 1048576; my $total = $input + $output - \' + what.recur_included_total.value + \'; $total = 0 if $total < 0; my $input = $input - \' + what.recur_included_input.value + \'; $input = 0 if $input < 0; my $output = $output - \' + what.recur_included_output.value + \'; $output = 0 if $output < 0; my $totalcharge = sprintf(\"%.2f\", \' + what.recur_total_charge.value + \' * $total); my $hourscharge = sprintf(\"%.2f\", \' + what.recur_hourly_charge.value + \' * $hours); push @details, \"Last month\\\'s excess data \". sprintf(\"%.1f\", $total). \" megs: \\\$$totalcharge\", \"Last month\\\'s excess time \". sprintf(\"%.1f\", $hours). \" hours: \\\$$hourscharge\"; \' + what.recur_flat.value + \' + $hourscharge + \' + what.recur_input_charge.value + \' * $input + \' + what.recur_output_charge.value + \' * $output + $totalcharge ;\'',
440   },
441
442 ;
443
444 my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
445                     split("\n", $part_pkg->plandata );
446
447 tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
448
449 my @form_select = ();
450 if ( $conf->exists('enable_taxclasses') ) {
451   push @form_select, 'taxclass';
452 } else {
453   push @fixups, 'taxclass'; #hidden
454 }
455
456
457 my $widget = new HTML::Widgets::SelectLayers(
458   'selected_layer' => $part_pkg->plan,
459   'options'        => \%options,
460   'form_name'      => 'dummy',
461   'form_action'    => 'process/part_pkg.cgi',
462   'form_text'      => [ qw(pkg comment freq clone pkgnum pkgpart), @fixups ],
463   'form_checkbox'  => [ qw(setuptax recurtax disabled) ],
464   'form_select'    => [ @form_select ],
465   'fixup_callback' => sub {
466                         #my $ = @_;
467                         my $html = '';
468                         for my $p ( keys %plans ) {
469                           $html .= "if ( what.plan.value == \"$p\" ) {
470                                       what.setup.value = $plans{$p}->{setup} ;
471                                       what.recur.value = $plans{$p}->{recur} ;
472                                     }\n";
473                         }
474                         $html;
475                       },
476   'layer_callback' => sub {
477     my $layer = shift;
478     my $html = qq!<INPUT TYPE="hidden" NAME="plan" VALUE="$layer">!.
479                ntable("#cccccc",2);
480     my $href = $plans{$layer}->{'fields'};
481     foreach my $field ( exists($plans{$layer}->{'fieldorder'})
482                           ? @{$plans{$layer}->{'fieldorder'}}
483                           : keys %{ $href }
484                       ) {
485
486       $html .= '<TR><TD ALIGN="right">'. $href->{$field}{'name'}. '</TD><TD>';
487
488       if ( ! exists($href->{$field}{'type'}) ) {
489         $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
490                  ( exists($plandata{$field})
491                      ? $plandata{$field}
492                      : $href->{$field}{'default'} ).
493                  qq!" onChange="fchanged(this)">!;
494       } elsif ( $href->{$field}{'type'} eq 'select_multiple' ) {
495         $html .= qq!<SELECT MULTIPLE NAME="$field" onChange="fchanged(this)">!;
496         foreach my $record (
497           qsearch( $href->{$field}{'select_table'},
498                    $href->{$field}{'select_hash'}   )
499         ) {
500           my $value = $record->getfield($href->{$field}{'select_key'});
501           $html .= qq!<OPTION VALUE="$value"!.
502                    (  $plandata{$field} =~ /(^|, *)$value *(,|$)/
503                         ? ' SELECTED'
504                         : ''          ).
505                    '>'. $record->getfield($href->{$field}{'select_label'})
506         }
507         $html .= '</SELECT>';
508       }
509
510       $html .= '</TD></TR>';
511     }
512     $html .= '</TABLE>';
513
514     $html .= '<INPUT TYPE="hidden" NAME="plandata" VALUE="'.
515              join(',', keys %{ $href } ). '">'.
516              '<BR><BR>';
517              
518     $html .= '<INPUT TYPE="submit" VALUE="'.
519              ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
520              '" onClick="fchanged(this)">';
521
522     $html .= '<BR><BR>don\'t edit this unless you know what you\'re doing '.
523              '<INPUT TYPE="button" VALUE="refresh expressions" '.
524                'onClick="fchanged(this)">'.
525              ntable("#cccccc",2).
526              '<TR><TD>'.
527              '<FONT SIZE="1">Setup expression<BR>'.
528              '<INPUT TYPE="text" NAME="setup" SIZE="160" VALUE="'.
529                encode_entities($hashref->{setup}). '" onLoad="fchanged(this)">'.
530              '</FONT><BR>'.
531              '<FONT SIZE="1">Recurring espression<BR>'.
532              '<INPUT TYPE="text" NAME="recur" SIZE="160" VALUE="'.
533                encode_entities($hashref->{recur}). '" onLoad="fchanged(this)">'.
534              '</FONT>'.
535              '</TR></TD>'.
536              '</TABLE>';
537
538     $html;
539
540   },
541 );
542
543 %>
544
545 <BR>
546 Price plan <%= $widget->html %>
547   </BODY>
548 </HTML>