4 %if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
5 % $cgi->param('eventpart', $1);
7 % $cgi->param('eventpart', '');
10 %my ($creason, $newcreasonT, $newcreason);
11 %my ($sreason, $newsreasonT, $newsreason);
14 %my ($query) = $cgi->keywords;
16 %my $part_bill_event = '';
17 %my $currentreasonclass = '';
18 %if ( $cgi->param('error') ) {
19 % $part_bill_event = new FS::part_bill_event ( {
20 % map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
23 %if ( $query && $query =~ /^(\d+)$/ ) {
24 % $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
26 % $part_bill_event ||= new FS::part_bill_event {};
28 %$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
29 %my $hashref = $part_bill_event->hashref;
34 <% include('/elements/header.html',
35 "$action Invoice Event Definition",
37 'Main Menu' => popurl(2),
38 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
43 <% include('/elements/error.html') %>
45 <FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" NAME="editEvent" METHOD=POST>
46 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
47 Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
49 <% ntable("#cccccc",2) %>
52 <TD ALIGN="right">Event name </TD>
53 <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
57 <TD ALIGN="right">For </TD>
60 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
61 % foreach my $payby ( keys %payby ) {
65 <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
72 % my $days = $hashref->{seconds}/86400;
76 <TD ALIGN="right">After</TD>
77 <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
81 <TD ALIGN="right">Test event</TD>
84 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
85 % foreach my $freq ( keys %freq ) {
89 <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
99 <TD ALIGN="right">Disabled</TD>
101 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
106 <TD VALIGN="top" ALIGN="right">Action</TD>
112 %sub select_pkgpart {
114 % my $plandata = shift;
115 % my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
116 % qq(<SELECT NAME="$label" MULTIPLE>).
118 % '<OPTION VALUE="'. $_->pkgpart. '"'.
119 % ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
120 % '>'. $_->pkg. ' - '. $_->comment
121 % } qsearch('part_pkg', { 'disabled' => '' } ) ).
125 %sub select_agentnum {
126 % my $plandata = shift;
127 % #my $agentnum = $plandata->{'agentnum'};
128 % my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
129 % '<SELECT NAME="agentnum" MULTIPLE>'.
131 % '<OPTION VALUE="'. $_->agentnum. '"'.
132 % ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
134 % } qsearch('agent', { 'disabled' => '' } ) ).
138 %my $conf = new FS::Conf;
139 %my $money_char = $conf->config('money_char') || '$';
141 %#this is pretty kludgy right here.
142 %tie my %events, 'Tie::IxHash',
145 % 'name' => 'Late fee (flat)',
146 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
148 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
149 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
153 % 'name' => 'Late fee (percentage)',
154 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
156 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
157 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
161 % 'name' => 'Suspend',
162 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%);',
166 % 'suspend-if-balance' => {
167 % 'name' => 'Suspend if balance (this invoice and previous) over',
168 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
169 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
173 % 'suspend-if-pkgpart' => {
174 % 'name' => 'Suspend packages',
175 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
176 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
180 % 'suspend-unless-pkgpart' => {
181 % 'name' => 'Suspend packages except',
182 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
183 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
188 % 'name' => 'Cancel',
189 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
195 % 'name' => 'Add postal invoicing',
196 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
201 % 'name' => 'Pay invoice with a complimentary "payment"',
202 % 'code' => '$cust_bill->comp();',
207 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
208 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%reason%%%\' );',
209 % 'html' => '<INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
213 % 'realtime-card' => {
214 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
215 % 'code' => '$cust_bill->realtime_card();',
219 % 'realtime-check' => {
220 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
221 % 'code' => '$cust_bill->realtime_ach();',
225 % 'realtime-lec' => {
226 % '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',
227 % 'code' => '$cust_bill->realtime_lec();',
232 % 'name' => 'Add card or check to a pending batch',
233 % 'code' => '$cust_bill->batch_card(%options);',
239 % # 'name' => 'Mark batched card event as retriable',
240 % # 'code' => '$cust_pay_batch->retriable();',
245 % 'name' => 'Send invoice (email/print/fax)',
246 % 'code' => '$cust_bill->send();',
251 % 'name' => 'Send invoice (email only)',
252 % 'code' => '$cust_bill->email();',
256 % 'send_alternate' => {
257 % 'name' => 'Send invoice (email/print/fax) with alternate template',
258 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
260 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
264 % 'send_if_newest' => {
265 % '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)',
266 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
268 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
273 % 'name' => 'Send invoice (email/print/fax) ',
274 % 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
278 % <TD ALIGN="right">only for agent(s) </TD>
279 % <TD>'. &select_agentnum(@_). '</TD>
282 % <TD ALIGN="right">with template </TD>
284 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
288 % <TD ALIGN="right">email From: </TD>
290 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
298 % 'send_csv_ftp' => {
299 % 'name' => 'Upload CSV invoice data to an FTP server',
300 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
301 % server => \'%%%ftpserver%%%\',
302 % username => \'%%%ftpusername%%%\',
303 % password => \'%%%ftppassword%%%\',
304 % dir => \'%%%ftpdir%%%\',
305 % \'format\' => \'%%%ftpformat%%%\',
308 % '<TABLE BORDER=0>'.
309 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
312 % '<SELECT NAME="ftpformat">'.
313 % '<OPTION VALUE="default">Default'.
314 % '<OPTION VALUE="billco">Billco'.
317 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
319 % '<TR><TD ALIGN="right">FTP server: </TD>'.
320 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
322 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
323 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
325 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
326 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
328 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
329 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
336 % 'name' => 'Spool CSV invoice data',
337 % 'code' => '$cust_bill->spool_csv(
338 % \'format\' => \'%%%spoolformat%%%\',
339 % \'dest\' => \'%%%spooldest%%%\',
340 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
341 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
344 % my $plandata = shift;
347 % '<TABLE BORDER=0>'.
348 % '<TR><TD ALIGN="right">Format: </TD>'.
350 % '<SELECT NAME="spoolformat">';
352 % foreach my $option (qw( default billco )) {
353 % $html .= qq(<OPTION VALUE="$option");
354 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
355 % $html .= ">\u$option";
361 % '<TR><TD ALIGN="right">For destination: </TD>'.
363 % '<SELECT NAME="spooldest">';
365 % tie my %dest, 'Tie::IxHash',
367 % 'POST' => 'Postal Mail',
368 % 'EMAIL' => 'Email',
372 % foreach my $dest (keys %dest) {
373 % $html .= qq(<OPTION VALUE="$dest");
374 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
375 % $html .= '>'. $dest{$dest};
383 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
386 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
388 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
389 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
390 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
401 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
402 % 'code' => '$cust_main->bill();',
407 % 'name' => 'Apply unapplied payments and credits',
408 % 'code' => '$cust_main->apply_payments_and_credits; "";',
413 % 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
414 % 'code' => '$cust_main->collect();',
420 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
421 %foreach my $event ( keys %events ) {
422 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
423 % split(/\n/, $part_bill_event->plandata);
424 % my $html = $events{$event}{html};
425 % if ( ref($html) eq 'CODE' ) {
426 % $html = &{$html}(\%plandata);
428 % while ( $html =~ /%%%(\w+)%%%/ ) {
430 % $html =~ s/%%%$field%%%/$plandata{$field}/;
433 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
435 % if ($event eq $part_bill_event->plan){
436 % $currentreasonclass=$events{$event}{reason};
438 % print ntable( "#cccccc", 2).
439 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
440 % print "CHECKED " if $event eq $part_bill_event->plan;
441 % print qq!onClick="showhide_table()" !;
442 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
443 % encode_entities($events{$event}{code}).
444 % qq!">$events{$event}{name}</TD>!;
445 % print '<TD>'. $html. '</TD>' if $html;
450 % if ($currentreasonclass eq 'C'){
451 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
454 % $creason = $part_bill_event->reason;
456 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
459 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
462 % }elsif ($currentreasonclass eq 'S'){
463 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
466 % $sreason = $part_bill_event->reason;
468 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
471 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
480 <SCRIPT TYPE="text/javascript">
481 function showhide_table()
483 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
484 if (document.editEvent.plan_weight_eventcode[i].checked == true){
488 if(myreasons[currentevent] == 'C'){
489 document.getElementById('Ctable').style.display = 'inline';
490 document.getElementById('Stable').style.display = 'none';
491 }else if(myreasons[currentevent] == 'S'){
492 document.getElementById('Ctable').style.display = 'none';
493 document.getElementById('Stable').style.display = 'inline';
495 document.getElementById('Ctable').style.display = 'none';
496 document.getElementById('Stable').style.display = 'none';
501 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
503 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
504 <% include('/elements/tr-select-reason.html',
505 'field' => 'creason',
506 'reason_class' => 'C',
507 'curr_value' => $creason,
508 'init_type' => $newcreasonT,
509 'init_newreason' => $newcreason
516 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
518 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
519 <% include('/elements/tr-select-reason.html',
520 'field' => 'sreason',
521 'reason_class' => 'S',
522 'curr_value' => $sreason,
523 'init_type' => $newsreasonT,
524 'init_newreason' => $newsreason
532 %print qq!<INPUT TYPE="submit" VALUE="!,
533 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",