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;
28 <%= include('/elements/header.html',
29 "$action Invoice Event Definition",
31 'Main Menu' => popurl(2),
32 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
37 <% if ( $cgi->param('error') ) { %>
38 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
41 <FORM ACTION="<%= popurl(1) %>process/part_bill_event.cgi" METHOD=POST>
42 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<%= $part_bill_event->eventpart %>">
43 Invoice Event #<%= $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
45 <%= ntable("#cccccc",2) %>
48 <TD ALIGN="right">Event name </TD>
49 <TD><INPUT TYPE="text" NAME="event" VALUE="<%= $hashref->{event} %>"></TD>
53 <TD ALIGN="right">For </TD>
57 <% tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
58 foreach my $payby ( keys %payby ) {
61 <OPTION VALUE="<%= $payby %>"<%= ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><%= $payby{$payby} %></OPTION>
69 <% my $days = $hashref->{seconds}/86400; %>
72 <TD ALIGN="right">After</TD>
73 <TD><INPUT TYPE="text" NAME="days" VALUE="<%= $days %>"> days</TD>
77 <TD ALIGN="right">Test event</TD>
81 <% tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
82 foreach my $freq ( keys %freq ) {
85 <OPTION VALUE="<%= $freq %>"<%= ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><%= $freq{$freq} %></OPTION>
95 <TD ALIGN="right">Disabled</TD>
97 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<%= $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
102 <TD VALIGN="top" ALIGN="right">Action</TD>
111 my $plandata = shift;
112 my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
113 qq(<SELECT NAME="$label" MULTIPLE>).
115 '<OPTION VALUE="'. $_->pkgpart. '"'.
116 ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
117 '>'. $_->pkg. ' - '. $_->comment
118 } qsearch('part_pkg', { 'disabled' => '' } ) ).
122 sub select_agentnum {
123 my $plandata = shift;
124 #my $agentnum = $plandata->{'agentnum'};
125 my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
126 '<SELECT NAME="agentnum" MULTIPLE>'.
128 '<OPTION VALUE="'. $_->agentnum. '"'.
129 ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
131 } qsearch('agent', { 'disabled' => '' } ) ).
135 my $conf = new FS::Conf;
136 my $money_char = $conf->config('money_char') || '$';
138 #this is pretty kludgy right here.
139 tie my %events, 'Tie::IxHash',
142 'name' => 'Late fee',
143 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
145 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
146 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
151 'code' => '$cust_main->suspend();',
154 'suspend-if-balance' => {
155 'name' => 'Suspend if balance (this invoice and previous) over',
156 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
157 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
160 'suspend-if-pkgpart' => {
161 'name' => 'Suspend packages',
162 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
163 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
166 'suspend-unless-pkgpart' => {
167 'name' => 'Suspend packages except',
168 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
169 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
174 'code' => '$cust_main->cancel();',
179 'name' => 'Add postal invoicing',
180 'code' => '$cust_main->invoicing_list_addpost(); "";',
185 'name' => 'Pay invoice with a complimentary "payment"',
186 'code' => '$cust_bill->comp();',
191 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
192 'code' => '$cust_bill->realtime_card();',
196 'realtime-check' => {
197 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
198 'code' => '$cust_bill->realtime_ach();',
203 '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',
204 'code' => '$cust_bill->realtime_lec();',
209 'name' => 'Add card to the pending credit card batch',
210 'code' => '$cust_bill->batch_card();',
215 'name' => 'Send invoice (email/print/fax)',
216 'code' => '$cust_bill->send();',
220 'send_alternate' => {
221 'name' => 'Send invoice (email/print/fax) with alternate template',
222 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
224 '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
228 'send_if_newest' => {
229 'name' => 'Send invoice (email/print/fax) with alternate template, if it is still the newest invoice (useful for late notices - set to 31 days or later)',
230 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
232 '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
237 'name' => 'Send invoice (email/print/fax) ',
238 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
242 <TD ALIGN="right">only for agent(s) </TD>
243 <TD>'. &select_agentnum(@_). '</TD>
246 <TD ALIGN="right">with template </TD>
248 <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
252 <TD ALIGN="right">email From: </TD>
254 <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
263 'name' => 'Upload CSV invoice data to an FTP server',
264 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
265 server => \'%%%ftpserver%%%\',
266 username => \'%%%ftpusername%%%\',
267 password => \'%%%ftppassword%%%\',
268 dir => \'%%%ftpdir%%%\',
269 \'format\' => \'%%%ftpformat%%%\',
273 '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
276 '<SELECT NAME="ftpformat">'.
277 '<OPTION VALUE="default">Default'.
278 '<OPTION VALUE="billco">Billco'.
281 '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
283 '<TR><TD ALIGN="right">FTP server: </TD>'.
284 '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
286 '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
287 '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
289 '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
290 '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
292 '<TR><TD ALIGN="right">FTP directory: </TD>'.
293 '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
300 'name' => 'Spool CSV invoice data',
301 'code' => '$cust_bill->spool_csv(
302 \'format\' => \'%%%spoolformat%%%\',
303 \'dest\' => \'%%%spooldest%%%\',
304 \'balanceover\' => \'%%%spoolbalanceover%%%\',
305 \'agent_spools\' => \'%%%spoolagent_spools%%%\',
308 my $plandata = shift;
312 '<TR><TD ALIGN="right">Format: </TD>'.
314 '<SELECT NAME="spoolformat">';
316 foreach my $option (qw( default billco )) {
317 $html .= qq(<OPTION VALUE="$option");
318 $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
319 $html .= ">\u$option";
325 '<TR><TD ALIGN="right">For destination: </TD>'.
327 '<SELECT NAME="spooldest">';
329 tie my %dest, 'Tie::IxHash',
331 'POST' => 'Postal Mail',
336 foreach my $dest (keys %dest) {
337 $html .= qq(<OPTION VALUE="$dest");
338 $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
339 $html .= '>'. $dest{$dest};
347 '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
350 '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
352 '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
353 '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
354 ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
365 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
366 'code' => '$cust_main->bill();',
371 'name' => 'Apply unapplied payments and credits',
372 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
377 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
378 'code' => '$cust_main->collect();',
384 foreach my $event ( keys %events ) {
385 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
386 split(/\n/, $part_bill_event->plandata);
387 my $html = $events{$event}{html};
388 if ( ref($html) eq 'CODE' ) {
389 $html = &{$html}(\%plandata);
391 while ( $html =~ /%%%(\w+)%%%/ ) {
393 $html =~ s/%%%$field%%%/$plandata{$field}/;
396 print ntable( "#cccccc", 2).
397 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
398 print "CHECKED " if $event eq $part_bill_event->plan;
399 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
400 encode_entities($events{$event}{code}).
401 qq!">$events{$event}{name}</TD>!;
402 print '<TD>'. $html. '</TD>' if $html;
414 print qq!<INPUT TYPE="submit" VALUE="!,
415 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",