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 (flat)',
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%%%">',
150 'name' => 'Late fee (percentage)',
151 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
153 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
154 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
159 'code' => '$cust_main->suspend();',
162 'suspend-if-balance' => {
163 'name' => 'Suspend if balance (this invoice and previous) over',
164 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
165 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
168 'suspend-if-pkgpart' => {
169 'name' => 'Suspend packages',
170 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
171 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
174 'suspend-unless-pkgpart' => {
175 'name' => 'Suspend packages except',
176 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
177 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
182 'code' => '$cust_main->cancel();',
187 'name' => 'Add postal invoicing',
188 'code' => '$cust_main->invoicing_list_addpost(); "";',
193 'name' => 'Pay invoice with a complimentary "payment"',
194 'code' => '$cust_bill->comp();',
199 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
200 'code' => '$cust_bill->realtime_card();',
204 'realtime-check' => {
205 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
206 'code' => '$cust_bill->realtime_ach();',
211 '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',
212 'code' => '$cust_bill->realtime_lec();',
217 'name' => 'Add card to the pending credit card batch',
218 'code' => '$cust_bill->batch_card();',
223 'name' => 'Send invoice (email/print/fax)',
224 'code' => '$cust_bill->send();',
228 'send_alternate' => {
229 'name' => 'Send invoice (email/print/fax) with alternate template',
230 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
232 '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
236 'send_if_newest' => {
237 '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)',
238 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
240 '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
245 'name' => 'Send invoice (email/print/fax) ',
246 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
250 <TD ALIGN="right">only for agent(s) </TD>
251 <TD>'. &select_agentnum(@_). '</TD>
254 <TD ALIGN="right">with template </TD>
256 <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
260 <TD ALIGN="right">email From: </TD>
262 <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
271 'name' => 'Upload CSV invoice data to an FTP server',
272 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
273 server => \'%%%ftpserver%%%\',
274 username => \'%%%ftpusername%%%\',
275 password => \'%%%ftppassword%%%\',
276 dir => \'%%%ftpdir%%%\',
277 \'format\' => \'%%%ftpformat%%%\',
281 '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
284 '<SELECT NAME="ftpformat">'.
285 '<OPTION VALUE="default">Default'.
286 '<OPTION VALUE="billco">Billco'.
289 '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
291 '<TR><TD ALIGN="right">FTP server: </TD>'.
292 '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
294 '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
295 '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
297 '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
298 '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
300 '<TR><TD ALIGN="right">FTP directory: </TD>'.
301 '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
308 'name' => 'Spool CSV invoice data',
309 'code' => '$cust_bill->spool_csv(
310 \'format\' => \'%%%spoolformat%%%\',
311 \'dest\' => \'%%%spooldest%%%\',
312 \'balanceover\' => \'%%%spoolbalanceover%%%\',
313 \'agent_spools\' => \'%%%spoolagent_spools%%%\',
316 my $plandata = shift;
320 '<TR><TD ALIGN="right">Format: </TD>'.
322 '<SELECT NAME="spoolformat">';
324 foreach my $option (qw( default billco )) {
325 $html .= qq(<OPTION VALUE="$option");
326 $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
327 $html .= ">\u$option";
333 '<TR><TD ALIGN="right">For destination: </TD>'.
335 '<SELECT NAME="spooldest">';
337 tie my %dest, 'Tie::IxHash',
339 'POST' => 'Postal Mail',
344 foreach my $dest (keys %dest) {
345 $html .= qq(<OPTION VALUE="$dest");
346 $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
347 $html .= '>'. $dest{$dest};
355 '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
358 '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
360 '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
361 '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
362 ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
373 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
374 'code' => '$cust_main->bill();',
379 'name' => 'Apply unapplied payments and credits',
380 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
385 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
386 'code' => '$cust_main->collect();',
392 foreach my $event ( keys %events ) {
393 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
394 split(/\n/, $part_bill_event->plandata);
395 my $html = $events{$event}{html};
396 if ( ref($html) eq 'CODE' ) {
397 $html = &{$html}(\%plandata);
399 while ( $html =~ /%%%(\w+)%%%/ ) {
401 $html =~ s/%%%$field%%%/$plandata{$field}/;
404 print ntable( "#cccccc", 2).
405 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
406 print "CHECKED " if $event eq $part_bill_event->plan;
407 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
408 encode_entities($events{$event}{code}).
409 qq!">$events{$event}{name}</TD>!;
410 print '<TD>'. $html. '</TD>' if $html;
422 print qq!<INPUT TYPE="submit" VALUE="!,
423 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",