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' => '' } ) ).
101 % my $plandata = shift;
103 % '<TR><TD ALIGN="right">Allow delay until dun date? </TD>'.
104 % qq(<TD><INPUT TYPE="checkbox" NAME="$label" VALUE="$label => 1," ).
105 % ( $plandata->{$label} eq "$label => 1," ? 'CHECKED' : '' ).
111 %my $conf = new FS::Conf;
112 %my $money_char = $conf->config('money_char') || '$';
114 %my $late_taxclass = '';
115 %my $late_percent_taxclass = '';
116 %if ( $conf->exists('enable_taxclasses') ) {
119 % include('/elements/select-taxclass.html',
120 % 'curr_value' => '%%%late_taxclass%%%',
121 % 'name' => 'late_taxclass' );
122 % $late_percent_taxclass =
124 % include('/elements/select-taxclass.html',
125 % 'curr_value' => '%%%late_percent_taxclass%%%',
126 % 'name' => 'late_percent_taxclass' );
129 %#this is pretty kludgy right here.
130 %tie my %events, 'Tie::IxHash',
133 % 'name' => 'Late fee (flat)',
134 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
136 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
137 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
142 % 'name' => 'Late fee (percentage)',
143 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
145 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
146 % '<BR>Reason <INPUT TYPE="text" NAME="percent_reason" VALUE="%%%percent_reason%%%">'.
147 % $late_percent_taxclass,
151 % 'name' => 'Suspend',
152 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%, %%%honor_dundate%%% );',
153 % 'html' => sub { &honor_dundate('honor_dundate', @_) },
157 % 'suspend-if-balance' => {
158 % 'name' => 'Suspend if balance (this invoice and previous) over',
159 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, %%%balance_honor_dundate%%% );',
160 % 'html' => sub { " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%"> '. &honor_dundate('balance_honor_dundate', @_) },
164 % 'suspend-if-pkgpart' => {
165 % 'name' => 'Suspend packages',
166 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%, %%%if_pkgpart_honor_dundate%%% });',
167 % 'html' => sub { &select_pkgpart('if_pkgpart', @_). &honor_dundate('if_pkgpart_honor_dundate', @_) },
171 % 'suspend-unless-pkgpart' => {
172 % 'name' => 'Suspend packages except',
173 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%, %%%unless_pkgpart_honor_dundate%%% });',
174 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_). &honor_dundate('unless_pkgpart_honor_dundate' => @_) },
179 % 'name' => 'Cancel',
180 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
181 % 'weight' => 80, #10,
186 % 'name' => 'Add postal invoicing',
187 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
192 % 'name' => 'Pay invoice with a complimentary "payment"',
193 % 'code' => '$cust_bill->comp();',
194 % 'weight' => 90, #30,
198 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
199 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%credit_reason%%%\' );',
200 % 'html' => '<INPUT TYPE="text" NAME="credit_reason" VALUE="%%%credit_reason%%%">',
204 % 'realtime-card' => {
205 % 'name' => 'Run card 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_card();',
210 % 'realtime-check' => {
211 % 'name' => 'Run check 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_ach();',
216 % 'realtime-lec' => {
217 % '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',
218 % 'code' => '$cust_bill->realtime_lec();',
223 % 'name' => 'Add card or check to a pending batch',
224 % 'code' => '$cust_bill->batch_card(%options);',
230 % # 'name' => 'Mark batched card event as retriable',
231 % # 'code' => '$cust_pay_batch->retriable();',
236 % 'name' => 'Send invoice (email/print/fax)',
237 % 'code' => '$cust_bill->send();',
242 % 'name' => 'Send invoice (email only)',
243 % 'code' => '$cust_bill->email();',
247 % 'send_alternate' => {
248 % 'name' => 'Send invoice (email/print/fax) with alternate template',
249 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
251 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
255 % 'send_if_newest' => {
256 % '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)',
257 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
259 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
264 % 'name' => 'Send invoice (email/print/fax) ',
265 % 'code' => '$cust_bill->send( \'%%%agent_templatename%%%\',
266 % [ %%%agentnum%%% ],
267 % \'%%%agent_invoice_from%%%\',
268 % %%%agent_balanceover%%%
273 % <TD ALIGN="right">only for agent(s) </TD>
274 % <TD>'. &select_agentnum(@_). '</TD>
277 % <TD ALIGN="right">with template </TD>
279 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
283 % <TD ALIGN="right">email From: </TD>
285 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
289 % <TD ALIGN="right">if balance (this invoice and previous) over
292 % '. $money_char. '<INPUT TYPE="text" SIZE="7" NAME="agent_balanceover" VALUE="%%%agent_balanceover%%%">
300 % 'send_csv_ftp' => {
301 % 'name' => 'Upload CSV invoice data to an FTP server',
302 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
303 % server => \'%%%ftpserver%%%\',
304 % username => \'%%%ftpusername%%%\',
305 % password => \'%%%ftppassword%%%\',
306 % dir => \'%%%ftpdir%%%\',
307 % \'format\' => \'%%%ftpformat%%%\',
310 % '<TABLE BORDER=0>'.
311 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
314 % '<SELECT NAME="ftpformat">'.
315 % '<OPTION VALUE="default">Default'.
316 % '<OPTION VALUE="billco">Billco'.
319 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
321 % '<TR><TD ALIGN="right">FTP server: </TD>'.
322 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
324 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
325 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
327 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
328 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
330 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
331 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
338 % 'name' => 'Spool CSV invoice data',
339 % 'code' => '$cust_bill->spool_csv(
340 % \'format\' => \'%%%spoolformat%%%\',
341 % \'dest\' => \'%%%spooldest%%%\',
342 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
343 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
346 % my $plandata = shift;
349 % '<TABLE BORDER=0>'.
350 % '<TR><TD ALIGN="right">Format: </TD>'.
352 % '<SELECT NAME="spoolformat">';
354 % foreach my $option (qw( default billco )) {
355 % $html .= qq(<OPTION VALUE="$option");
356 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
357 % $html .= ">\u$option";
363 % '<TR><TD ALIGN="right">For destination: </TD>'.
365 % '<SELECT NAME="spooldest">';
367 % tie my %dest, 'Tie::IxHash',
369 % 'POST' => 'Postal Mail',
370 % 'EMAIL' => 'Email',
374 % foreach my $dest (keys %dest) {
375 % $html .= qq(<OPTION VALUE="$dest");
376 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
377 % $html .= '>'. $dest{$dest};
385 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
388 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
390 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
391 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
392 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
403 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
404 % 'code' => '$cust_main->bill();',
409 % 'name' => 'Apply unapplied payments and credits',
410 % 'code' => '$cust_main->apply_payments_and_credits; "";',
416 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
417 %foreach my $event ( keys %events ) {
418 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
419 % split(/\n/, $part_bill_event->plandata);
420 % my $html = $events{$event}{html};
421 % if ( ref($html) eq 'CODE' ) {
422 % $html = &{$html}(\%plandata);
424 % while ( $html =~ /%%%(\w+)%%%/ ) {
426 % $html =~ s/%%%$field%%%/$plandata{$field}/;
429 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
431 % if ($event eq $part_bill_event->plan){
432 % $currentreasonclass=$events{$event}{reason};
434 % print ntable( "#cccccc", 2).
435 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
436 % print "CHECKED " if $event eq $part_bill_event->plan;
437 % print qq!onClick="showhide_table()" !;
438 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
439 % encode_entities($events{$event}{code}).
440 % qq!">$events{$event}{name}</TD>!;
441 % print '<TD>'. $html. '</TD>' if $html;
444 % print qq!<HR WIDTH="90%">!;
447 % if ($currentreasonclass eq 'C'){
448 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
451 % $creason = $part_bill_event->reason;
453 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
456 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
459 % }elsif ($currentreasonclass eq 'S'){
460 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
463 % $sreason = $part_bill_event->reason;
465 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
468 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
477 <SCRIPT TYPE="text/javascript">
478 function showhide_table()
480 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
481 if (document.editEvent.plan_weight_eventcode[i].checked == true){
485 if(myreasons[currentevent] == 'C'){
486 document.getElementById('Ctable').style.display = 'inline';
487 document.getElementById('Stable').style.display = 'none';
488 }else if(myreasons[currentevent] == 'S'){
489 document.getElementById('Ctable').style.display = 'none';
490 document.getElementById('Stable').style.display = 'inline';
492 document.getElementById('Ctable').style.display = 'none';
493 document.getElementById('Stable').style.display = 'none';
498 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
500 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
501 <% include('/elements/tr-select-reason.html',
502 'field' => 'creason',
503 'reason_class' => 'C',
504 'curr_value' => $creason,
505 'init_type' => $newcreasonT,
506 'init_newreason' => $newcreason
513 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
515 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
516 <% include('/elements/tr-select-reason.html',
517 'field' => 'sreason',
518 'reason_class' => 'S',
519 'curr_value' => $sreason,
520 'init_type' => $newsreasonT,
521 'init_newreason' => $newsreason
529 %print qq!<INPUT TYPE="submit" VALUE="!,
530 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
537 <% include('/elements/footer.html') %>
542 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
544 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
545 $cgi->param('eventpart', $1);
547 $cgi->param('eventpart', '');
550 my ($creason, $newcreasonT, $newcreason);
551 my ($sreason, $newsreasonT, $newsreason);
553 my ($query) = $cgi->keywords;
555 my $part_bill_event = '';
556 my $currentreasonclass = '';
557 if ( $cgi->param('error') ) {
558 $part_bill_event = new FS::part_bill_event ( {
559 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
562 if ( $query && $query =~ /^(\d+)$/ ) {
563 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
565 $part_bill_event ||= new FS::part_bill_event {};
567 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
568 my $hashref = $part_bill_event->hashref;