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>
25 <SELECT NAME="payby" <% $hashref->{eventpart} ? '' : 'MULTIPLE SIZE=7'%>>
26 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
27 % foreach my $payby ( keys %payby ) {
28 <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
33 % my $days = $hashref->{seconds}/86400;
37 <TD ALIGN="right">After</TD>
38 <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
42 <TD ALIGN="right">Test event</TD>
45 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
46 % foreach my $freq ( keys %freq ) {
50 <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
60 <TD ALIGN="right">Disabled</TD>
62 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
67 <TD VALIGN="top" ALIGN="right">Action</TD>
75 % my $plandata = shift;
76 % my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
77 % qq(<SELECT NAME="$label" MULTIPLE>).
79 % '<OPTION VALUE="'. $_->pkgpart. '"'.
80 % ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
81 % '>'. $_->pkg. ' - '. $_->comment
82 % } qsearch('part_pkg', { 'disabled' => '' } ) ).
86 %sub select_agentnum {
87 % my $plandata = shift;
88 % #my $agentnum = $plandata->{'agentnum'};
89 % my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
90 % '<SELECT NAME="agentnum" MULTIPLE>'.
92 % '<OPTION VALUE="'. $_->agentnum. '"'.
93 % ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
95 % } qsearch('agent', { 'disabled' => '' } ) ).
99 %my $conf = new FS::Conf;
100 %my $money_char = $conf->config('money_char') || '$';
102 %my $late_taxclass = '';
103 %my $late_percent_taxclass = '';
104 %if ( $conf->exists('enable_taxclasses') ) {
107 % include('/elements/select-taxclass.html',
108 % 'curr_value' => '%%%late_taxclass%%%',
109 % 'name' => 'late_taxclass' );
110 % $late_percent_taxclass =
112 % include('/elements/select-taxclass.html',
113 % 'curr_value' => '%%%late_percent_taxclass%%%',
114 % 'name' => 'late_percent_taxclass' );
117 %#this is pretty kludgy right here.
118 %tie my %events, 'Tie::IxHash',
121 % 'name' => 'Late fee (flat)',
122 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
124 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
125 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
130 % 'name' => 'Late fee (percentage)',
131 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
133 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
134 % '<BR>Reason <INPUT TYPE="text" NAME="percent_reason" VALUE="%%%percent_reason%%%">'.
135 % $late_percent_taxclass,
139 % 'name' => 'Suspend',
140 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%);',
144 % 'suspend-if-balance' => {
145 % 'name' => 'Suspend if balance (this invoice and previous) over',
146 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
147 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
151 % 'suspend-if-pkgpart' => {
152 % 'name' => 'Suspend packages',
153 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
154 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
158 % 'suspend-unless-pkgpart' => {
159 % 'name' => 'Suspend packages except',
160 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
161 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
166 % 'name' => 'Cancel',
167 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
173 % 'name' => 'Add postal invoicing',
174 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
179 % 'name' => 'Pay invoice with a complimentary "payment"',
180 % 'code' => '$cust_bill->comp();',
185 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
186 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%credit_reason%%%\' );',
187 % 'html' => '<INPUT TYPE="text" NAME="credit_reason" VALUE="%%%credit_reason%%%">',
191 % 'realtime-card' => {
192 % 'name' => 'Run card 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_card();',
197 % 'realtime-check' => {
198 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
199 % 'code' => '$cust_bill->realtime_ach();',
203 % 'realtime-lec' => {
204 % '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',
205 % 'code' => '$cust_bill->realtime_lec();',
210 % 'name' => 'Add card or check to a pending batch',
211 % 'code' => '$cust_bill->batch_card(%options);',
217 % # 'name' => 'Mark batched card event as retriable',
218 % # 'code' => '$cust_pay_batch->retriable();',
223 % 'name' => 'Send invoice (email/print/fax)',
224 % 'code' => '$cust_bill->send();',
229 % 'name' => 'Send invoice (email only)',
230 % 'code' => '$cust_bill->email();',
234 % 'send_alternate' => {
235 % 'name' => 'Send invoice (email/print/fax) with alternate template',
236 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
238 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
242 % 'send_if_newest' => {
243 % '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)',
244 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
246 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
251 % 'name' => 'Send invoice (email/print/fax) ',
252 % 'code' => '$cust_bill->send( \'%%%agent_templatename%%%\',
253 % [ %%%agentnum%%% ],
254 % \'%%%agent_invoice_from%%%\',
255 % %%%agent_balanceover%%%
260 % <TD ALIGN="right">only for agent(s) </TD>
261 % <TD>'. &select_agentnum(@_). '</TD>
264 % <TD ALIGN="right">with template </TD>
266 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
270 % <TD ALIGN="right">email From: </TD>
272 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
276 % <TD ALIGN="right">if balance (this invoice and previous) over
279 % '. $money_char. '<INPUT TYPE="text" SIZE="7" NAME="agent_balanceover" VALUE="%%%agent_balanceover%%%">
287 % 'send_csv_ftp' => {
288 % 'name' => 'Upload CSV invoice data to an FTP server',
289 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
290 % server => \'%%%ftpserver%%%\',
291 % username => \'%%%ftpusername%%%\',
292 % password => \'%%%ftppassword%%%\',
293 % dir => \'%%%ftpdir%%%\',
294 % \'format\' => \'%%%ftpformat%%%\',
297 % '<TABLE BORDER=0>'.
298 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
301 % '<SELECT NAME="ftpformat">'.
302 % '<OPTION VALUE="default">Default'.
303 % '<OPTION VALUE="billco">Billco'.
306 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
308 % '<TR><TD ALIGN="right">FTP server: </TD>'.
309 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
311 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
312 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
314 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
315 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
317 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
318 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
325 % 'name' => 'Spool CSV invoice data',
326 % 'code' => '$cust_bill->spool_csv(
327 % \'format\' => \'%%%spoolformat%%%\',
328 % \'dest\' => \'%%%spooldest%%%\',
329 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
330 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
333 % my $plandata = shift;
336 % '<TABLE BORDER=0>'.
337 % '<TR><TD ALIGN="right">Format: </TD>'.
339 % '<SELECT NAME="spoolformat">';
341 % foreach my $option (qw( default billco )) {
342 % $html .= qq(<OPTION VALUE="$option");
343 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
344 % $html .= ">\u$option";
350 % '<TR><TD ALIGN="right">For destination: </TD>'.
352 % '<SELECT NAME="spooldest">';
354 % tie my %dest, 'Tie::IxHash',
356 % 'POST' => 'Postal Mail',
357 % 'EMAIL' => 'Email',
361 % foreach my $dest (keys %dest) {
362 % $html .= qq(<OPTION VALUE="$dest");
363 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
364 % $html .= '>'. $dest{$dest};
372 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
375 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
377 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
378 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
379 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
390 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
391 % 'code' => '$cust_main->bill();',
396 % 'name' => 'Apply unapplied payments and credits',
397 % 'code' => '$cust_main->apply_payments_and_credits; "";',
403 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
404 %foreach my $event ( keys %events ) {
405 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
406 % split(/\n/, $part_bill_event->plandata);
407 % my $html = $events{$event}{html};
408 % if ( ref($html) eq 'CODE' ) {
409 % $html = &{$html}(\%plandata);
411 % while ( $html =~ /%%%(\w+)%%%/ ) {
413 % $html =~ s/%%%$field%%%/$plandata{$field}/;
416 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
418 % if ($event eq $part_bill_event->plan){
419 % $currentreasonclass=$events{$event}{reason};
421 % print ntable( "#cccccc", 2).
422 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
423 % print "CHECKED " if $event eq $part_bill_event->plan;
424 % print qq!onClick="showhide_table()" !;
425 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
426 % encode_entities($events{$event}{code}).
427 % qq!">$events{$event}{name}</TD>!;
428 % print '<TD>'. $html. '</TD>' if $html;
431 % print qq!<HR WIDTH="90%">!;
434 % if ($currentreasonclass eq 'C'){
435 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
438 % $creason = $part_bill_event->reason;
440 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
443 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
446 % }elsif ($currentreasonclass eq 'S'){
447 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
450 % $sreason = $part_bill_event->reason;
452 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
455 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
464 <SCRIPT TYPE="text/javascript">
465 function showhide_table()
467 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
468 if (document.editEvent.plan_weight_eventcode[i].checked == true){
472 if(myreasons[currentevent] == 'C'){
473 document.getElementById('Ctable').style.display = 'inline';
474 document.getElementById('Stable').style.display = 'none';
475 }else if(myreasons[currentevent] == 'S'){
476 document.getElementById('Ctable').style.display = 'none';
477 document.getElementById('Stable').style.display = 'inline';
479 document.getElementById('Ctable').style.display = 'none';
480 document.getElementById('Stable').style.display = 'none';
485 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
487 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
488 <% include('/elements/tr-select-reason.html',
489 'field' => 'creason',
490 'reason_class' => 'C',
491 'curr_value' => $creason,
492 'init_type' => $newcreasonT,
493 'init_newreason' => $newcreason
500 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
502 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
503 <% include('/elements/tr-select-reason.html',
504 'field' => 'sreason',
505 'reason_class' => 'S',
506 'curr_value' => $sreason,
507 'init_type' => $newsreasonT,
508 'init_newreason' => $newsreason
516 %print qq!<INPUT TYPE="submit" VALUE="!,
517 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
524 <% include('/elements/footer.html') %>
529 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
531 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
532 $cgi->param('eventpart', $1);
534 $cgi->param('eventpart', '');
537 my ($creason, $newcreasonT, $newcreason);
538 my ($sreason, $newsreasonT, $newsreason);
540 my ($query) = $cgi->keywords;
542 my $part_bill_event = '';
543 my $currentreasonclass = '';
544 if ( $cgi->param('error') ) {
545 $part_bill_event = new FS::part_bill_event ( {
546 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
549 if ( $query && $query =~ /^(\d+)$/ ) {
550 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
552 $part_bill_event ||= new FS::part_bill_event {};
554 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
555 my $hashref = $part_bill_event->hashref;