1 <!-- $Id: part_pkg.cgi,v 1.9 2002-01-29 16:33:16 ivan Exp $ -->
5 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
6 $cgi->param('clone', $1);
8 $cgi->param('clone', '');
10 if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
11 $cgi->param('pkgnum', $1);
13 $cgi->param('pkgnum', '');
16 my ($query) = $cgi->keywords;
19 if ( $cgi->param('error') ) {
20 $part_pkg = new FS::part_pkg ( {
21 map { $_, scalar($cgi->param($_)) } fields('part_pkg')
24 if ( $cgi->param('clone') ) {
25 $action='Custom Pricing';
27 qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
28 $part_pkg ||= $old_part_pkg->clone;
29 $part_pkg->disabled('Y');
30 } elsif ( $query && $query =~ /^(\d+)$/ ) {
31 $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
33 $part_pkg ||= new FS::part_pkg {};
34 $part_pkg->plan('flat');
36 unless ( $part_pkg->plan ) { #backwards-compat
37 $part_pkg->plan('flat');
38 $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
39 "recur_fee=". $part_pkg->recur. "\n");
41 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
42 my $hashref = $part_pkg->hashref;
47 function visualize(what) {
48 if (document.getElementById) {
49 document.getElementById('d<%= $part_pkg->plan %>').style.visibility = "visible";
51 document.l<%= $part_pkg->plan %>.visibility = "visible";
58 print header("$action Package Definition", menubar(
59 'Main Menu' => popurl(2),
60 'View all packages' => popurl(2). 'browse/part_pkg.cgi',
61 ), ' onLoad="visualize()"');
63 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
65 if $cgi->param('error');
67 #print '<FORM ACTION="', popurl(1), 'process/part_pkg.cgi" METHOD=POST>';
68 print '<FORM NAME="dummy">';
70 #if ( $cgi->param('clone') ) {
71 # print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
73 #if ( $cgi->param('pkgnum') ) {
74 # print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
77 #print qq!<INPUT TYPE="hidden" NAME="pkgpart" VALUE="$hashref->{pkgpart}">!,
78 print "Package Part #", $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)";
80 print ntable("#cccccc",2), <<END;
81 <TR><TD ALIGN="right">Package (customer-visable)</TD><TD><INPUT TYPE="text" NAME="pkg" SIZE=32 VALUE="$hashref->{pkg}"></TD></TR>
82 <TR><TD ALIGN="right">Comment (customer-hidden)</TD><TD><INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="$hashref->{comment}"></TD></TR>
83 <TR><TD ALIGN="right">Frequency (months) of recurring fee</TD><TD><INPUT TYPE="text" NAME="freq" VALUE="$hashref->{freq}" SIZE=3></TD></TR>
84 <TR><TD ALIGN="right">Setup fee tax exempt</TD><TD>
87 print '<INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y"';
88 print ' CHECKED' if $hashref->{setuptax} eq "Y";
93 <TR><TD ALIGN="right">Recurring fee tax exempt</TD><TD>
96 print '<INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y"';
97 print ' CHECKED' if $hashref->{recurtax} eq "Y";
102 print '<TR><TD ALIGN="right">Disable new orders</TD><TD>';
103 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
104 print ' CHECKED' if $hashref->{disabled} eq "Y";
106 print '</TD></TR></TABLE>';
108 my $thead = "\n\n". ntable('#cccccc', 2). <<END;
109 <TR><TH BGCOLOR="#dcdcdc"><FONT SIZE=-1>Quan.</FONT></TH><TH BGCOLOR="#dcdcdc">Service</TH></TR>
112 unless ( $cgi->param('clone') ) {
113 #print <<END, $thead;
114 print <<END, itable(), '<TR><TD VALIGN="top">', $thead;
115 <BR><BR>Enter the quantity of each service this package includes.<BR><BR>
122 my @part_svc = qsearch( 'part_svc', { 'disabled' => '' } );
123 foreach my $part_svc ( @part_svc ) {
124 my $svcpart = $part_svc->svcpart;
125 my $pkg_svc = qsearchs( 'pkg_svc', {
126 'pkgpart' => $cgi->param('clone') || $part_pkg->pkgpart,
127 'svcpart' => $svcpart,
128 } ) || new FS::pkg_svc ( {
129 'pkgpart' => $cgi->param('clone') || $part_pkg->pkgpart,
130 'svcpart' => $svcpart,
133 #? #next unless $pkg_svc;
135 push @fixups, "pkg_svc$svcpart";
137 unless ( defined ($cgi->param('clone')) && $cgi->param('clone') ) {
138 print '<TR>'; # if $count == 0 ;
139 print qq!<TD><INPUT TYPE="text" NAME="pkg_svc$svcpart" SIZE=4 MAXLENGTH=3 VALUE="!,
140 $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0,
141 qq!"></TD><TD><A HREF="part_svc.cgi?!,$part_svc->svcpart,
142 qq!">!, $part_svc->getfield('svc'), "</A></TD></TR>";
143 # print "</TABLE></TD><TD>$thead" if ++$count == int(scalar(@part_svc) / 2);
145 foreach ( 1 .. $columns-1 ) {
146 print "</TABLE></TD><TD VALIGN=\"top\">$thead"
147 if $count == int( $_ * scalar(@part_svc) / $columns );
150 print qq!<INPUT TYPE="hidden" NAME="pkg_svc$svcpart" VALUE="!,
151 $cgi->param("pkg_svc$svcpart") || $pkg_svc->quantity || 0, qq!">\n!;
155 unless ( $cgi->param('clone') ) {
156 print "</TR></TABLE></TD></TR></TABLE>";
157 #print "</TR></TABLE>";
160 # prolly should be in database
162 tie my %plans, 'Tie::IxHash',
164 'name' => 'Flat rate',
166 'setup_fee' => { 'name' => 'Setup fee for this package',
169 'recur_fee' => { 'name' => 'Recurring fee for this package',
173 'fieldorder' => [ 'setup_fee', 'recur_fee' ],
174 'setup' => 'what.setup_fee.value',
175 'recur' => 'what.recur_fee.value',
178 'flat_comission' => {
179 'name' => 'Flat rate with recurring referral comission as credit',
181 'setup_fee' => { 'name' => 'Setup fee for this package',
184 'recur_fee' => { 'name' => 'Recurring fee for this package',
187 'comission_amount' => { 'name' => 'Comission amount',
190 'comission_depth' => { 'name' => 'Number of layers',
194 'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount' ],
195 'setup' => 'what.setup_fee.value',
196 '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 + \';\'',
200 'name' => 'Base charge plus charge per-hour from the session monitor',
202 'setup_fee' => { 'name' => 'Setup fee for this package',
205 'recur_flat' => { 'name' => 'Base monthly charge for this package',
208 'recur_included_hours' => { 'name' => 'Hours included',
211 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
215 'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_hours', 'recur_hourly_charge' ],
216 'setup' => 'what.setup_fee.value',
217 'recur' => '\'my $hours = $cust_pkg->seconds_since($cust_bkg->bill || 0) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; \' + what.recur_flat.value + \' + \' + what.recur_hourly_charge.value + \' * $hours;\'',
221 'name' => 'Base charge plus charge per-minute from the session monitor',
223 'setup_fee' => { 'name' => 'Setup fee for this package',
226 'recur_flat' => { 'name' => 'Base monthly charge for this package',
229 'recur_included_min' => { 'name' => 'Minutes included',
232 'recur_minly_charge' => { 'name' => 'Additional charge per minute',
236 'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_min', 'recur_minly_charge' ],
237 'setup' => 'what.setup_fee.value',
238 'recur' => '\'my $min = $cust_pkg->seconds_since($cust_bkg->bill || 0) / 60 - \' + what.recur_included_min.value + \'; $min = 0 if $min < 0; \' + what.recur_flat.value + \' + \' + what.recur_minly_charge.value + \' * $min;\'',
249 function changed(what) {
250 layer = what.options[what.selectedIndex].value;
251 <% foreach my $layer ( keys %plans ) { %>
252 if (layer == "<%= $layer %>" ) {
253 <% foreach my $not ( grep { $_ ne $layer } keys %plans ) { %>
254 if (document.getElementById) {
255 document.getElementById('d<%= $not %>').style.visibility = "hidden";
257 document.l<%= $not %>.visibility = "hidden";
260 if (document.getElementById) {
261 document.getElementById('d<%= $layer %>').style.visibility = "visible";
263 document.l<%= $layer %>.visibility = "visible";
271 Price plan <SELECT NAME="plan" SIZE=1 onChange="changed(this);">
273 <% foreach my $layer (keys %plans ) { %>
274 <OPTION VALUE="<%= $layer %>"<%= ' SELECTED'x($layer eq $part_pkg->plan) %>><%= $plans{$layer}->{'name'} %>
279 function fchanged(what) {
283 function fixup(what) {
284 <% foreach my $f ( qw( pkg comment freq ), @fixups ) { %>
285 what.<%= $f %>.value = document.dummy.<%= $f %>.value;
287 <% foreach my $f ( qw( setuptax recurtax disabled ) ) { %>
288 if (document.dummy.<%= $f %>.checked)
289 what.<%= $f %>.value = 'Y';
291 what.<%= $f %>.value = '';
293 what.plan.value = document.dummy.plan.options[document.dummy.plan.selectedIndex].value;
294 <% foreach my $p ( keys %plans ) { %>
295 if ( what.plan.value == "<%= $p %>" ) {
296 what.setup.value = <%= $plans{$p}->{setup} %>;
297 what.recur.value = <%= $plans{$p}->{recur} %>;
303 <% my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
304 split("\n", $part_pkg->plandata );
305 #foreach my $layer ( 'konq_kludge', keys %plans ) {
306 foreach my $layer ( 'konq_kludge', keys %plans ) {
307 my $visibility = "hidden";
310 if (document.getElementById) {
311 document.write("<DIV ID=\"d<%= $layer %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
313 <% $visibility="show" if $visibility eq "visible"; %>
314 document.write("<LAYER ID=\"l<%= $layer %>\" VISIBILITY=\"<%= $visibility %>\">");
318 <FORM NAME="<%= $layer %>" ACTION="process/part_pkg.cgi" METHOD=POST onSubmit="fixup(this)">
319 <INPUT TYPE="hidden" NAME="plan" VALUE="<%= $part_pkg->plan %>">
320 <INPUT TYPE="hidden" NAME="pkg" VALUE="<%= $hashref->{pkg} %>">
321 <INPUT TYPE="hidden" NAME="comment" VALUE="$<%= $hashref->{comment} %>">
322 <INPUT TYPE="hidden" NAME="freq" VALUE="<%= $hashref->{freq} %>">
323 <INPUT TYPE="hidden" NAME="setuptax" VALUE="<%= $hashref->{setuptax} %>">
324 <INPUT TYPE="hidden" NAME="recurtax" VALUE="<%= $hashref->{recurtax} %>">
325 <INPUT TYPE="hidden" NAME="disabled" VALUE="<%= $hashref->{disabled} %>">
326 <% foreach my $f ( @fixups ) { %>
327 <INPUT TYPE="hidden" NAME="<%= $f %>" VALUE="">
331 if ( $cgi->param('clone') ) {
332 print qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $cgi->param('clone'), qq!">!;
334 if ( $cgi->param('pkgnum') ) {
335 print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $cgi->param('pkgnum'), qq!">!;
339 <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<%= $hashref->{pkgpart} %>">
340 <%= ntable("#cccccc",2) %>
342 <% my $href = $plans{$layer}->{'fields'};
343 foreach my $field ( exists($plans{$layer}->{'fieldorder'})
344 ? @{$plans{$layer}->{'fieldorder'}}
348 <TR><TD ALIGN="right"><%= $href->{$field}{'name'} %></TD>
349 <TD><INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= exists($plandata{$field}) ? $plandata{$field} : $href->{$field}{'default'} %>" onChange="fchanged(this)"></TD></TR>
352 <INPUT TYPE="hidden" NAME="plandata" VALUE="<%= join(',', keys %{ $href } ) %>">
356 print qq!<INPUT TYPE="submit" VALUE="!,
357 $hashref->{pkgpart} ? "Apply changes" : "Add package",
358 qq!" onClick="fchanged(this)">!;
361 <BR><BR>don't edit this unless you know what you're doing <INPUT TYPE="button" VALUE="refresh expressions" onClick="fchanged(this)"><%= ntable("#cccccc",2) %><TR><TD>
362 <FONT SIZE="1">Setup expression<BR><INPUT TYPE="text" NAME="setup" SIZE="160" VALUE="<%= $hashref->{setup} %>" onLoad="fchanged(this)"></FONT><BR>
363 <FONT SIZE="1">Recurring espression<BR><INPUT TYPE="text" NAME="recur" SIZE="160" VALUE="<%= $hashref->{recur} %>" onLoad="fchanged(this)"></FONT>
370 if (document.getElementById) {
371 document.write("</DIV>");
373 document.write("</LAYER>");
380 if (document.getElementById) {
381 document.getElementById('d<%= $part_pkg->plan %>').style.visibility = 'visible';
383 document.l<%= $part_pkg->plan %>.visibility = 'visible';