4 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
5 $cgi->param('eventpart', $1);
7 $cgi->param('eventpart', '');
10 my ($query) = $cgi->keywords;
12 my $part_bill_event = '';
13 if ( $cgi->param('error') ) {
14 $part_bill_event = new FS::part_bill_event ( {
15 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
18 if ( $query && $query =~ /^(\d+)$/ ) {
19 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
21 $part_bill_event ||= new FS::part_bill_event {};
23 $action ||= $part_bill_event->pkgpart ? 'Edit' : 'Add';
24 my $hashref = $part_bill_event->hashref;
26 print header("$action Invoice Event Definition", menubar(
27 'Main Menu' => popurl(2),
28 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
31 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
33 if $cgi->param('error');
35 print '<FORM ACTION="', popurl(1), 'process/part_bill_event.cgi" METHOD=POST>'.
36 '<INPUT TYPE="hidden" NAME="eventpart" VALUE="'.
37 $part_bill_event->eventpart .'">';
38 print "Invoice Event #", $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)";
40 print ntable("#cccccc",2), <<END;
41 <TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
44 for (qw(CARD DCRD CHEK DCHK LECB BILL COMP)) {
45 print qq!<OPTION VALUE="$_"!;
46 if ($part_bill_event->payby eq $_) {
47 print " SELECTED>$_</OPTION>";
53 my $days = $hashref->{seconds}/86400;
57 <TR><TD ALIGN="right">Event</TD><TD><INPUT TYPE="text" NAME="event" VALUE="$hashref->{event}"></TD></TR>
58 <TR><TD ALIGN="right">After</TD><TD><INPUT TYPE="text" NAME="days" VALUE="$days"> days</TD></TR>
61 print '<TR><TD ALIGN="right">Disabled</TD><TD>';
62 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
63 print ' CHECKED' if $hashref->{disabled} eq "Y";
67 print '<TR><TD ALIGN="right">Action</TD><TD>';
71 #this is pretty kludgy right here.
72 tie my %events, 'Tie::IxHash',
76 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
78 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
79 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
84 'code' => '$cust_main->suspend();',
89 'code' => '$cust_main->cancel();',
94 'name' => 'Add postal invoicing',
95 'code' => '$cust_main->invoicing_list_addpost(); "";',
100 'name' => 'Pay invoice with a complimentary "payment"',
101 'code' => '$cust_bill->comp();',
106 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
107 'code' => '$cust_bill->realtime_card();',
111 'realtime-check' => {
112 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
113 'code' => '$cust_bill->realtime_ach();',
118 'name' => 'Run phone bill ("LEC") billing with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
119 'code' => '$cust_bill->realtime_lec();',
124 'name' => 'Add card to the pending credit card batch',
125 'code' => '$cust_bill->batch_card();',
130 'name' => 'Send invoice (email/print)',
131 'code' => '$cust_bill->send();',
135 'send_alternate' => {
136 'name' => 'Send invoice (email/print) with alternate template',
137 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
139 '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
144 'name' => 'Upload CSV invoice data to an FTP server',
145 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
146 server => \'%%%ftpserver%%%\',
147 username => \'%%%ftpusername%%%\',
148 password => \'%%%ftppassword%%%\',
149 dir => \'%%%ftpdir%%%\' );',
151 '<TABLE BORDER=0><TR><TD ALIGN="right">FTP server: </TD>'.
152 '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
154 '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
155 '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
157 '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
158 '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
160 '<TR><TD ALIGN="right">FTP directory: </TD>'.
161 '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
168 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
169 'code' => '$cust_main->bill();',
174 'name' => 'Apply unapplied payments and credits',
175 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
180 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
181 'code' => '$cust_main->collect();',
187 foreach my $event ( keys %events ) {
188 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
189 split(/\n/, $part_bill_event->plandata);
190 my $html = $events{$event}{html};
191 while ( $html =~ /%%%(\w+)%%%/ ) {
193 $html =~ s/%%%$field%%%/$plandata{$field}/;
196 print ntable( "#cccccc", 2).
197 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
198 print "CHECKED " if $event eq $part_bill_event->plan;
199 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
200 encode_entities($events{$event}{code}).
201 qq!">$events{$event}{name}</TD>!;
202 print '<TD>'. $html. '</TD>' if $html;
214 print qq!<INPUT TYPE="submit" VALUE="!,
215 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",