summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authorivan <ivan>2002-01-29 16:33:16 +0000
committerivan <ivan>2002-01-29 16:33:16 +0000
commit6991d4986df7fb3a6c7c49b5ae1b3713e87a16c4 (patch)
tree40efa15fb918ceb4e065160a4257349322658b6c /httemplate/edit
parentf02dd9b0e5042ef000d9338089eed50988d48914 (diff)
- web interface for hourly account charges!
(FS::cust_pkg, FS::cust_svc and FS::svc_acct seconds_since methods) - Makefile target to regenerate HTML manpages on install - FS.pm doc update - $FS::Record::Debug now dumps all SQL - new FS::cust_main methods: ->cancel, ->invoicing_list_addpost - start of a billing event web interface - cust_pay::upgrade_replace doesn't error out if history includes overapplied payments
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-xhttemplate/edit/part_bill_event.cgi131
-rwxr-xr-xhttemplate/edit/part_pkg.cgi71
-rwxr-xr-xhttemplate/edit/process/part_bill_event.cgi32
3 files changed, 224 insertions, 10 deletions
diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi
new file mode 100755
index 000000000..41d6666dc
--- /dev/null
+++ b/httemplate/edit/part_bill_event.cgi
@@ -0,0 +1,131 @@
+<!-- $Id: part_bill_event.cgi,v 1.1 2002-01-29 16:33:16 ivan Exp $ -->
+
+<%
+
+if ( $cgi->param('eventnum') && $cgi->param('eventnum') =~ /^(\d+)$/ ) {
+ $cgi->param('eventnum', $1);
+} else {
+ $cgi->param('eventnum', '');
+}
+
+my ($query) = $cgi->keywords;
+my $action = '';
+my $part_bill_event = '';
+if ( $cgi->param('error') ) {
+ $part_bill_event = new FS::part_bill_event ( {
+ map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
+ } );
+}
+if ( $query && $query =~ /^(\d+)$/ ) {
+ $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
+} else {
+ $part_bill_event ||= new FS::part_bill_event {};
+}
+$action ||= $part_bill_event->pkgpart ? 'Edit' : 'Add';
+my $hashref = $part_bill_event->hashref;
+
+print header("$action Invoice Event Definition", menubar(
+ 'Main Menu' => popurl(2),
+ 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
+));
+
+print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
+ "</FONT>"
+ if $cgi->param('error');
+
+print '<FORM ACTION="', popurl(1), 'process/part_bill_event.cgi" METHOD=POST>';
+
+print "Invoice Event #", $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)";
+
+print ntable("#cccccc",2), <<END;
+<TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
+END
+
+for (qw(CARD BILL COMP)) {
+ print qq!<OPTION VALUE="$_"!;
+ if ($part_bill_event->payby eq $_) {
+ print " SELECTED> $_</OPTION>";
+ } else {
+ print ">$_</OPTION>";
+ }
+}
+
+my $days = $hashref->{seconds}/3600;
+
+print <<END;
+</SELECT></TD></TR>
+<TR><TD ALIGN="right">Event</TD><TD><INPUT TYPE="text" NAME="event" VALUE="$hashref->{event}"></TD></TR>
+<TR><TD ALIGN="right">After</TD><TD><INPUT TYPE="text" NAME="days" VALUE="$days"> days</TD></TR>
+END
+
+print '<TR><TD ALIGN="right">Disabled</TD><TD>';
+print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
+print ' CHECKED' if $hashref->{disabled} eq "Y";
+print '>';
+print '</TD></TR>';
+
+print '<TR><TD ALIGN="right">Action</TD><TD>';
+
+#print ntable();
+
+#this is pretty kludgy right here.
+tie my %events, 'Tie::IxHash',
+
+ 'Charge a fee' => {
+ 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
+ 'html' => 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge"><BR>'.
+ 'Reason <INPUT TYPE="text" NAME="reason">',
+ },
+ 'Suspend accounts' => {
+ 'code' => '$cust_main->suspend();',
+ },
+ 'Cancel accounts' => {
+ 'code' => '$cust_main->cancel();',
+ },
+
+ 'Add postal invoicing' => {
+ 'code' => '$cust_main->invoicing_list_addpost();',
+ 'pad' => 10,
+ },
+
+ 'Generate invoices' => {
+ 'code' => '$cust_main->bill();',
+ 'pad' => 20,
+ },
+
+ 'Apply unapplied payments and credits' => {
+ 'code' => '$cust_main->apply_payments; $cust_main->apply_credits;',
+ 'pad' => 30,
+ },
+
+ 'Collect on invoices' => {
+ 'code' => '$cust_main->collect();',
+ 'pad' => 40,
+ },
+
+;
+
+foreach my $event ( keys %events ) {
+ print ntable( "#cccccc", 2). qq!<TR><TD><INPUT TYPE="radio" NAME="eventcode" VALUE="!.
+ encode_entities($events{$event}{code}). qq!">$event</TD>!;
+ print '<TD>'. $events{$event}{html}. '</TD>' if exists $events{$event}{html};
+ print qq!</TR>!;
+ print '</TABLE>';
+}
+
+#print '</TABLE>';
+
+print <<END;
+</TD></TR>
+</TABLE>
+END
+
+print qq!<INPUT TYPE="submit" VALUE="!,
+ $hashref->{pkgpart} ? "Apply changes" : "Add invoice event",
+ qq!">!;
+%>
+
+ </FORM>
+ </BODY>
+</HTML>
+
diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
index 735f4f269..ea3f62aa2 100755
--- a/httemplate/edit/part_pkg.cgi
+++ b/httemplate/edit/part_pkg.cgi
@@ -1,4 +1,4 @@
-<!-- $Id: part_pkg.cgi,v 1.8 2001-12-28 14:40:35 ivan Exp $ -->
+<!-- $Id: part_pkg.cgi,v 1.9 2002-01-29 16:33:16 ivan Exp $ -->
<%
@@ -158,8 +158,8 @@ unless ( $cgi->param('clone') ) {
}
# prolly should be in database
-my %plans = (
-
+use Tie::IxHash;
+tie my %plans, 'Tie::IxHash',
'flat' => {
'name' => 'Flat rate',
'fields' => {
@@ -170,6 +170,7 @@ my %plans = (
'default' => 0,
},
},
+ 'fieldorder' => [ 'setup_fee', 'recur_fee' ],
'setup' => 'what.setup_fee.value',
'recur' => 'what.recur_fee.value',
},
@@ -190,11 +191,55 @@ my %plans = (
'default' => 1,
},
},
+ 'fieldorder' => [ 'setup_fee', 'recur_fee', 'comission_depth', 'comission_amount' ],
'setup' => 'what.setup_fee.value',
'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 + \';\'',
},
-);
+ 'sesmon_hour' => {
+ 'name' => 'Base charge plus charge per-hour from the session monitor',
+ 'fields' => {
+ 'setup_fee' => { 'name' => 'Setup fee for this package',
+ 'default' => 0,
+ },
+ 'recur_flat' => { 'name' => 'Base monthly charge for this package',
+ 'default' => 0,
+ },
+ 'recur_included_hours' => { 'name' => 'Hours included',
+ 'default' => 0,
+ },
+ 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
+ 'default' => 0,
+ },
+ },
+ 'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_hours', 'recur_hourly_charge' ],
+ 'setup' => 'what.setup_fee.value',
+ '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;\'',
+ },
+
+ 'sesmon_minute' => {
+ 'name' => 'Base charge plus charge per-minute from the session monitor',
+ 'fields' => {
+ 'setup_fee' => { 'name' => 'Setup fee for this package',
+ 'default' => 0,
+ },
+ 'recur_flat' => { 'name' => 'Base monthly charge for this package',
+ 'default' => 0,
+ },
+ 'recur_included_min' => { 'name' => 'Minutes included',
+ 'default' => 0,
+ },
+ 'recur_minly_charge' => { 'name' => 'Additional charge per minute',
+ 'default' => 0,
+ },
+ },
+ 'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_min', 'recur_minly_charge' ],
+ 'setup' => 'what.setup_fee.value',
+ '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;\'',
+
+ },
+
+;
%>
@@ -295,24 +340,30 @@ if ( $cgi->param('pkgnum') ) {
<%= ntable("#cccccc",2) %>
<% my $href = $plans{$layer}->{'fields'};
- foreach my $field ( keys %{ $href } ) { %>
+ foreach my $field ( exists($plans{$layer}->{'fieldorder'})
+ ? @{$plans{$layer}->{'fieldorder'}}
+ : keys %{ $href }
+ ) {
+%>
<TR><TD ALIGN="right"><%= $href->{$field}{'name'} %></TD>
<TD><INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= exists($plandata{$field}) ? $plandata{$field} : $href->{$field}{'default'} %>" onChange="fchanged(this)"></TD></TR>
<% } %>
</TABLE>
<INPUT TYPE="hidden" NAME="plandata" VALUE="<%= join(',', keys %{ $href } ) %>">
-<FONT SIZE="1">
<BR><BR>
-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="!,
+print qq!<INPUT TYPE="submit" VALUE="!,
$hashref->{pkgpart} ? "Apply changes" : "Add package",
qq!" onClick="fchanged(this)">!;
%>
+<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>
+<FONT SIZE="1">Setup expression<BR><INPUT TYPE="text" NAME="setup" SIZE="160" VALUE="<%= $hashref->{setup} %>" onLoad="fchanged(this)"></FONT><BR>
+<FONT SIZE="1">Recurring espression<BR><INPUT TYPE="text" NAME="recur" SIZE="160" VALUE="<%= $hashref->{recur} %>" onLoad="fchanged(this)"></FONT>
+</TR></TD>
+</TABLE>
+
</FORM>
<SCRIPT>
diff --git a/httemplate/edit/process/part_bill_event.cgi b/httemplate/edit/process/part_bill_event.cgi
new file mode 100755
index 000000000..eb7c53e5d
--- /dev/null
+++ b/httemplate/edit/process/part_bill_event.cgi
@@ -0,0 +1,32 @@
+<%
+
+my $eventpart = $cgi->param('eventpart');
+
+my $old = qsearchs('part_bill_event',{'eventpart'=>$eventpart}) if $eventpart;
+
+#s/days/seconds/
+$cgi->param('seconds', $cgi->param('days') * 3600 );
+
+my $new = new FS::part_bill_event ( {
+ map {
+ $_, scalar($cgi->param($_));
+ } fields('part_bill_event'),
+} );
+
+my $error;
+if ( $eventpart ) {
+ $error = $new->replace($old);
+} else {
+ $error = $new->insert;
+ $eventpart = $new->getfield('eventpart');
+}
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ print $cgi->redirect(popurl(2). "part_bill_event.cgi?". $cgi->query_string );
+} else {
+ print $cgi->redirect(popurl(3)."browse/part_bill_event.cgi");
+}
+
+%>
+