3 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
4 $cgi->param('eventpart', $1);
6 $cgi->param('eventpart', '');
9 my ($query) = $cgi->keywords;
11 my $part_bill_event = '';
12 if ( $cgi->param('error') ) {
13 $part_bill_event = new FS::part_bill_event ( {
14 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
17 if ( $query && $query =~ /^(\d+)$/ ) {
18 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
20 $part_bill_event ||= new FS::part_bill_event {};
22 $action ||= $part_bill_event->pkgpart ? 'Edit' : 'Add';
23 my $hashref = $part_bill_event->hashref;
25 print header("$action Invoice Event Definition", menubar(
26 'Main Menu' => popurl(2),
27 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
30 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
32 if $cgi->param('error');
34 print '<FORM ACTION="', popurl(1), 'process/part_bill_event.cgi" METHOD=POST>'.
35 '<INPUT TYPE="hidden" NAME="eventpart" VALUE="'.
36 $part_bill_event->eventpart .'">';
37 print "Invoice Event #", $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)";
39 print ntable("#cccccc",2), <<END;
40 <TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
43 for (qw(CARD BILL COMP)) {
44 print qq!<OPTION VALUE="$_"!;
45 if ($part_bill_event->payby eq $_) {
46 print " SELECTED>$_</OPTION>";
52 my $days = $hashref->{seconds}/86400;
56 <TR><TD ALIGN="right">Event</TD><TD><INPUT TYPE="text" NAME="event" VALUE="$hashref->{event}"></TD></TR>
57 <TR><TD ALIGN="right">After</TD><TD><INPUT TYPE="text" NAME="days" VALUE="$days"> days</TD></TR>
60 print '<TR><TD ALIGN="right">Disabled</TD><TD>';
61 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
62 print ' CHECKED' if $hashref->{disabled} eq "Y";
66 print '<TR><TD ALIGN="right">Action</TD><TD>';
70 #this is pretty kludgy right here.
71 tie my %events, 'Tie::IxHash',
75 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
77 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
78 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
83 'code' => '$cust_main->suspend();',
88 'code' => '$cust_main->cancel();',
93 'name' => 'Add postal invoicing',
94 'code' => '$cust_main->invoicing_list_addpost(); "";',
99 'name' => 'Pay invoice with a complimentary "payment"',
100 'code' => '$cust_bill->comp();',
105 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
106 'code' => '$cust_bill->realtime_card();',
110 'realtime-card-cybercash' => {
111 'name' => '(<b>deprecated</b>) Run card with <a href="http://www.cybercash.com/cashregister">CyberCash CashRegister</a> realtime gateway',
112 'code' => '$cust_bill->realtime_card_cybercash();',
117 'name' => 'Add card to the pending credit card batch',
118 'code' => '$cust_bill->batch_card();',
123 'name' => 'Send invoice (email/print)',
124 'code' => '$cust_bill->send();',
129 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
130 'code' => '$cust_main->bill();',
135 'name' => 'Apply unapplied payments and credits',
136 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
141 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
142 'code' => '$cust_main->collect();',
148 foreach my $event ( keys %events ) {
149 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
150 split(/\n/, $part_bill_event->plandata);
151 my $html = $events{$event}{html};
152 while ( $html =~ /%%%(\w+)%%%/ ) {
154 $html =~ s/%%%$field%%%/$plandata{$field}/;
157 print ntable( "#cccccc", 2).
158 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
159 print "CHECKED " if $event eq $part_bill_event->plan;
160 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
161 encode_entities($events{$event}{code}).
162 qq!">$events{$event}{name}</TD>!;
163 print '<TD>'. $html. '</TD>' if $html;
175 print qq!<INPUT TYPE="submit" VALUE="!,
176 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",