1 <% include('/elements/header.html',
2 "$action Invoice Event Definition",
4 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
9 <% include('/elements/error.html') %>
11 <FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" NAME="editEvent" METHOD=POST>
12 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
13 Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
15 <% ntable("#cccccc",2) %>
18 <TD ALIGN="right">Event name </TD>
19 <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
23 <TD ALIGN="right">For </TD>
26 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
27 % foreach my $payby ( keys %payby ) {
31 <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
38 % my $days = $hashref->{seconds}/86400;
42 <TD ALIGN="right">After</TD>
43 <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
47 <TD ALIGN="right">Test event</TD>
50 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
51 % foreach my $freq ( keys %freq ) {
55 <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
65 <TD ALIGN="right">Disabled</TD>
67 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
72 <TD VALIGN="top" ALIGN="right">Action</TD>
80 % my $plandata = shift;
81 % my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
82 % qq(<SELECT NAME="$label" MULTIPLE>).
84 % '<OPTION VALUE="'. $_->pkgpart. '"'.
85 % ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
86 % '>'. $_->pkg. ' - '. $_->comment
87 % } qsearch('part_pkg', { 'disabled' => '' } ) ).
91 %sub select_agentnum {
92 % my $plandata = shift;
93 % #my $agentnum = $plandata->{'agentnum'};
94 % my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
95 % '<SELECT NAME="agentnum" MULTIPLE>'.
97 % '<OPTION VALUE="'. $_->agentnum. '"'.
98 % ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
100 % } qsearch('agent', { 'disabled' => '' } ) ).
104 %my $conf = new FS::Conf;
105 %my $money_char = $conf->config('money_char') || '$';
107 %#this is pretty kludgy right here.
108 %tie my %events, 'Tie::IxHash',
111 % 'name' => 'Late fee (flat)',
112 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
114 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
115 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
119 % 'name' => 'Late fee (percentage)',
120 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
122 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
123 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
127 % 'name' => 'Suspend',
128 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%);',
132 % 'suspend-if-balance' => {
133 % 'name' => 'Suspend if balance (this invoice and previous) over',
134 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
135 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
139 % 'suspend-if-pkgpart' => {
140 % 'name' => 'Suspend packages',
141 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
142 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
146 % 'suspend-unless-pkgpart' => {
147 % 'name' => 'Suspend packages except',
148 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
149 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
154 % 'name' => 'Cancel',
155 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
161 % 'name' => 'Add postal invoicing',
162 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
167 % 'name' => 'Pay invoice with a complimentary "payment"',
168 % 'code' => '$cust_bill->comp();',
173 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
174 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%reason%%%\' );',
175 % 'html' => '<INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
179 % 'realtime-card' => {
180 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
181 % 'code' => '$cust_bill->realtime_card();',
185 % 'realtime-check' => {
186 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
187 % 'code' => '$cust_bill->realtime_ach();',
191 % 'realtime-lec' => {
192 % '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',
193 % 'code' => '$cust_bill->realtime_lec();',
198 % 'name' => 'Add card or check to a pending batch',
199 % 'code' => '$cust_bill->batch_card(%options);',
205 % # 'name' => 'Mark batched card event as retriable',
206 % # 'code' => '$cust_pay_batch->retriable();',
211 % 'name' => 'Send invoice (email/print/fax)',
212 % 'code' => '$cust_bill->send();',
217 % 'name' => 'Send invoice (email only)',
218 % 'code' => '$cust_bill->email();',
222 % 'send_alternate' => {
223 % 'name' => 'Send invoice (email/print/fax) with alternate template',
224 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
226 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
230 % 'send_if_newest' => {
231 % '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)',
232 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
234 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
239 % 'name' => 'Send invoice (email/print/fax) ',
240 % 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
244 % <TD ALIGN="right">only for agent(s) </TD>
245 % <TD>'. &select_agentnum(@_). '</TD>
248 % <TD ALIGN="right">with template </TD>
250 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
254 % <TD ALIGN="right">email From: </TD>
256 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
264 % 'send_csv_ftp' => {
265 % 'name' => 'Upload CSV invoice data to an FTP server',
266 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
267 % server => \'%%%ftpserver%%%\',
268 % username => \'%%%ftpusername%%%\',
269 % password => \'%%%ftppassword%%%\',
270 % dir => \'%%%ftpdir%%%\',
271 % \'format\' => \'%%%ftpformat%%%\',
274 % '<TABLE BORDER=0>'.
275 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
278 % '<SELECT NAME="ftpformat">'.
279 % '<OPTION VALUE="default">Default'.
280 % '<OPTION VALUE="billco">Billco'.
283 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
285 % '<TR><TD ALIGN="right">FTP server: </TD>'.
286 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
288 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
289 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
291 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
292 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
294 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
295 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
302 % 'name' => 'Spool CSV invoice data',
303 % 'code' => '$cust_bill->spool_csv(
304 % \'format\' => \'%%%spoolformat%%%\',
305 % \'dest\' => \'%%%spooldest%%%\',
306 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
307 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
310 % my $plandata = shift;
313 % '<TABLE BORDER=0>'.
314 % '<TR><TD ALIGN="right">Format: </TD>'.
316 % '<SELECT NAME="spoolformat">';
318 % foreach my $option (qw( default billco )) {
319 % $html .= qq(<OPTION VALUE="$option");
320 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
321 % $html .= ">\u$option";
327 % '<TR><TD ALIGN="right">For destination: </TD>'.
329 % '<SELECT NAME="spooldest">';
331 % tie my %dest, 'Tie::IxHash',
333 % 'POST' => 'Postal Mail',
334 % 'EMAIL' => 'Email',
338 % foreach my $dest (keys %dest) {
339 % $html .= qq(<OPTION VALUE="$dest");
340 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
341 % $html .= '>'. $dest{$dest};
349 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
352 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
354 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
355 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
356 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
367 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
368 % 'code' => '$cust_main->bill();',
373 % 'name' => 'Apply unapplied payments and credits',
374 % 'code' => '$cust_main->apply_payments_and_credits; "";',
379 % 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
380 % 'code' => '$cust_main->collect();',
386 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
387 %foreach my $event ( keys %events ) {
388 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
389 % split(/\n/, $part_bill_event->plandata);
390 % my $html = $events{$event}{html};
391 % if ( ref($html) eq 'CODE' ) {
392 % $html = &{$html}(\%plandata);
394 % while ( $html =~ /%%%(\w+)%%%/ ) {
396 % $html =~ s/%%%$field%%%/$plandata{$field}/;
399 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
401 % if ($event eq $part_bill_event->plan){
402 % $currentreasonclass=$events{$event}{reason};
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!onClick="showhide_table()" !;
408 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
409 % encode_entities($events{$event}{code}).
410 % qq!">$events{$event}{name}</TD>!;
411 % print '<TD>'. $html. '</TD>' if $html;
416 % if ($currentreasonclass eq 'C'){
417 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
420 % $creason = $part_bill_event->reason;
422 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
425 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
428 % }elsif ($currentreasonclass eq 'S'){
429 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
432 % $sreason = $part_bill_event->reason;
434 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
437 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
446 <SCRIPT TYPE="text/javascript">
447 function showhide_table()
449 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
450 if (document.editEvent.plan_weight_eventcode[i].checked == true){
454 if(myreasons[currentevent] == 'C'){
455 document.getElementById('Ctable').style.display = 'inline';
456 document.getElementById('Stable').style.display = 'none';
457 }else if(myreasons[currentevent] == 'S'){
458 document.getElementById('Ctable').style.display = 'none';
459 document.getElementById('Stable').style.display = 'inline';
461 document.getElementById('Ctable').style.display = 'none';
462 document.getElementById('Stable').style.display = 'none';
467 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
469 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
470 <% include('/elements/tr-select-reason.html',
471 'field' => 'creason',
472 'reason_class' => 'C',
473 'curr_value' => $creason,
474 'init_type' => $newcreasonT,
475 'init_newreason' => $newcreason
482 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
484 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
485 <% include('/elements/tr-select-reason.html',
486 'field' => 'sreason',
487 'reason_class' => 'S',
488 'curr_value' => $sreason,
489 'init_type' => $newsreasonT,
490 'init_newreason' => $newsreason
498 %print qq!<INPUT TYPE="submit" VALUE="!,
499 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
506 <% include('/elements/footer.html') %>
511 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
513 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
514 $cgi->param('eventpart', $1);
516 $cgi->param('eventpart', '');
519 my ($creason, $newcreasonT, $newcreason);
520 my ($sreason, $newsreasonT, $newsreason);
522 my ($query) = $cgi->keywords;
524 my $part_bill_event = '';
525 my $currentreasonclass = '';
526 if ( $cgi->param('error') ) {
527 $part_bill_event = new FS::part_bill_event ( {
528 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
531 if ( $query && $query =~ /^(\d+)$/ ) {
532 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
534 $part_bill_event ||= new FS::part_bill_event {};
536 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
537 my $hashref = $part_bill_event->hashref;