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->eventpart ? '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 CHEK 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>';
74 my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
75 qq(<SELECT NAME="$label" MULTIPLE>).
77 '<OPTION VALUE="'. $_->pkgpart. '"'.
78 ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
79 '>'. $_->pkg. ' - '. $_->comment
80 } qsearch('part_pkg', { 'disabled' => '' } ) ).
86 my $agentnum = $plandata->{'agentnum'};
87 '<SELECT NAME="agentnum">'.
89 '<OPTION VALUE="'. $_->agentnum. '"'.
90 ( $_->agentnum == $agentnum ? ' SELECTED' : '' ).
92 } qsearch('agent', { 'disabled' => '' } ) ).
96 #this is pretty kludgy right here.
97 tie my %events, 'Tie::IxHash',
100 'name' => 'Late fee',
101 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
103 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
104 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
109 'code' => '$cust_main->suspend();',
112 'suspend-if-pkgpart' => {
113 'name' => 'Suspend packages',
114 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
115 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
118 'suspend-unless-pkgpart' => {
119 'name' => 'Suspend packages except',
120 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
121 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
126 'code' => '$cust_main->cancel();',
131 'name' => 'Add postal invoicing',
132 'code' => '$cust_main->invoicing_list_addpost(); "";',
137 'name' => 'Pay invoice with a complimentary "payment"',
138 'code' => '$cust_bill->comp();',
143 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
144 'code' => '$cust_bill->realtime_card();',
148 'realtime-check' => {
149 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
150 'code' => '$cust_bill->realtime_ach();',
154 'realtime-card-cybercash' => {
155 'name' => '(<b>deprecated</b>) Run card with <a href="http://www.cybercash.com/cashregister">CyberCash CashRegister</a> realtime gateway',
156 'code' => '$cust_bill->realtime_card_cybercash();',
161 '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',
162 'code' => '$cust_bill->realtime_lec();',
167 'name' => 'Add card to the pending credit card batch',
168 'code' => '$cust_bill->batch_card();',
173 'name' => 'Send invoice (email/print)',
174 'code' => '$cust_bill->send();',
178 'send_alternate' => {
179 'name' => 'Send invoice (email/print) with alternate template',
180 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
182 '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
187 'name' => 'Send invoice (email/print) ',
188 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', %%%agentnum%%%);',
192 <TD ALIGN="right">only for agent </TD>
193 <TD>'. &select_agentnum(@_). '</TD>
196 <TD ALIGN="right">with template </TD>
198 <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
207 'name' => 'Upload CSV invoice data to an FTP server',
208 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
209 server => \'%%%ftpserver%%%\',
210 username => \'%%%ftpusername%%%\',
211 password => \'%%%ftppassword%%%\',
212 dir => \'%%%ftpdir%%%\' );',
214 '<TABLE BORDER=0><TR><TD ALIGN="right">FTP server: </TD>'.
215 '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
217 '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
218 '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
220 '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
221 '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
223 '<TR><TD ALIGN="right">FTP directory: </TD>'.
224 '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
231 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
232 'code' => '$cust_main->bill();',
237 'name' => 'Apply unapplied payments and credits',
238 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
243 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
244 'code' => '$cust_main->collect();',
250 foreach my $event ( keys %events ) {
251 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
252 split(/\n/, $part_bill_event->plandata);
253 my $html = $events{$event}{html};
254 if ( ref($html) eq 'CODE' ) {
255 $html = &{$html}(\%plandata);
257 while ( $html =~ /%%%(\w+)%%%/ ) {
259 $html =~ s/%%%$field%%%/$plandata{$field}/;
262 print ntable( "#cccccc", 2).
263 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
264 print "CHECKED " if $event eq $part_bill_event->plan;
265 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
266 encode_entities($events{$event}{code}).
267 qq!">$events{$event}{name}</TD>!;
268 print '<TD>'. $html. '</TD>' if $html;
280 print qq!<INPUT TYPE="submit" VALUE="!,
281 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",