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 ) {
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' => '' } ) ).
106 % my $plandata = shift;
108 % '<TR><TD ALIGN="right">Allow delay until dun date? </TD>'.
109 % qq(<TD><INPUT TYPE="checkbox" NAME="$label" VALUE="$label => 1," ).
110 % ( $plandata->{$label} eq "$label => 1," ? 'CHECKED' : '' ).
116 %my $conf = new FS::Conf;
117 %my $money_char = $conf->config('money_char') || '$';
119 %my $late_taxclass = '';
120 %my $late_percent_taxclass = '';
121 %if ( $conf->exists('enable_taxclasses') ) {
124 % include('/elements/select-taxclass.html', '%%%late_taxclass%%%',
125 % 'name' => 'late_taxclass' );
126 % $late_percent_taxclass =
128 % include('/elements/select-taxclass.html', '%%%late_percent_taxclass%%%',
129 % 'name' => 'late_percent_taxclass' );
132 %#this is pretty kludgy right here.
133 %tie my %events, 'Tie::IxHash',
136 % 'name' => 'Late fee (flat)',
137 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
139 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
140 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
145 % 'name' => 'Late fee (percentage)',
146 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
148 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
149 % '<BR>Reason <INPUT TYPE="text" NAME="percent_reason" VALUE="%%%percent_reason%%%">'.
150 % $late_percent_taxclass,
154 % 'name' => 'Suspend',
155 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%, %%%honor_dundate%%% );',
156 % 'html' => sub { &honor_dundate('honor_dundate', @_) },
160 % 'suspend-if-balance' => {
161 % 'name' => 'Suspend if balance (this invoice and previous) over',
162 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, %%%balance_honor_dundate%%% );',
163 % 'html' => sub { " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%"> '. &honor_dundate('balance_honor_dundate', @_) },
167 % 'suspend-if-pkgpart' => {
168 % 'name' => 'Suspend packages',
169 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%, %%%if_pkgpart_honor_dundate%%% });',
170 % 'html' => sub { &select_pkgpart('if_pkgpart', @_). &honor_dundate('if_pkgpart_honor_dundate', @_) },
174 % 'suspend-unless-pkgpart' => {
175 % 'name' => 'Suspend packages except',
176 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%, %%%unless_pkgpart_honor_dundate%%% });',
177 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_). &honor_dundate('unless_pkgpart_honor_dundate' => @_) },
182 % 'name' => 'Cancel',
183 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
189 % 'name' => 'Add postal invoicing',
190 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
195 % 'name' => 'Pay invoice with a complimentary "payment"',
196 % 'code' => '$cust_bill->comp();',
201 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
202 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%credit_reason%%%\' );',
203 % 'html' => '<INPUT TYPE="text" NAME="credit_reason" VALUE="%%%credit_reason%%%">',
207 % 'realtime-card' => {
208 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
209 % 'code' => '$cust_bill->realtime_card();',
213 % 'realtime-check' => {
214 % 'name' => 'Run check 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_ach();',
219 % 'realtime-lec' => {
220 % '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',
221 % 'code' => '$cust_bill->realtime_lec();',
226 % 'name' => 'Add card or check to a pending batch',
227 % 'code' => '$cust_bill->batch_card(%options);',
233 % # 'name' => 'Mark batched card event as retriable',
234 % # 'code' => '$cust_pay_batch->retriable();',
239 % 'name' => 'Send invoice (email/print/fax)',
240 % 'code' => '$cust_bill->send();',
245 % 'name' => 'Send invoice (email only)',
246 % 'code' => '$cust_bill->email();',
250 % 'send_alternate' => {
251 % 'name' => 'Send invoice (email/print/fax) with alternate template',
252 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
254 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
258 % 'send_if_newest' => {
259 % '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)',
260 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
262 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
267 % 'name' => 'Send invoice (email/print/fax) ',
268 % 'code' => '$cust_bill->send( \'%%%agent_templatename%%%\',
269 % [ %%%agentnum%%% ],
270 % \'%%%agent_invoice_from%%%\',
271 % %%%agent_balanceover%%%
276 % <TD ALIGN="right">only for agent(s) </TD>
277 % <TD>'. &select_agentnum(@_). '</TD>
280 % <TD ALIGN="right">with template </TD>
282 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
286 % <TD ALIGN="right">email From: </TD>
288 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
292 % <TD ALIGN="right">if balance (this invoice and previous) over
295 % '. $money_char. '<INPUT TYPE="text" SIZE="7" NAME="agent_balanceover" VALUE="%%%agent_balanceover%%%">
303 % 'send_csv_ftp' => {
304 % 'name' => 'Upload CSV invoice data to an FTP server',
305 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
306 % server => \'%%%ftpserver%%%\',
307 % username => \'%%%ftpusername%%%\',
308 % password => \'%%%ftppassword%%%\',
309 % dir => \'%%%ftpdir%%%\',
310 % \'format\' => \'%%%ftpformat%%%\',
313 % '<TABLE BORDER=0>'.
314 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
317 % '<SELECT NAME="ftpformat">'.
318 % '<OPTION VALUE="default">Default'.
319 % '<OPTION VALUE="billco">Billco'.
322 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
324 % '<TR><TD ALIGN="right">FTP server: </TD>'.
325 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
327 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
328 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
330 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
331 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
333 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
334 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
341 % 'name' => 'Spool CSV invoice data',
342 % 'code' => '$cust_bill->spool_csv(
343 % \'format\' => \'%%%spoolformat%%%\',
344 % \'dest\' => \'%%%spooldest%%%\',
345 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
346 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
349 % my $plandata = shift;
352 % '<TABLE BORDER=0>'.
353 % '<TR><TD ALIGN="right">Format: </TD>'.
355 % '<SELECT NAME="spoolformat">';
357 % foreach my $option (qw( default billco )) {
358 % $html .= qq(<OPTION VALUE="$option");
359 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
360 % $html .= ">\u$option";
366 % '<TR><TD ALIGN="right">For destination: </TD>'.
368 % '<SELECT NAME="spooldest">';
370 % tie my %dest, 'Tie::IxHash',
372 % 'POST' => 'Postal Mail',
373 % 'EMAIL' => 'Email',
377 % foreach my $dest (keys %dest) {
378 % $html .= qq(<OPTION VALUE="$dest");
379 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
380 % $html .= '>'. $dest{$dest};
388 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
391 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
393 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
394 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
395 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
406 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
407 % 'code' => '$cust_main->bill();',
412 % 'name' => 'Apply unapplied payments and credits',
413 % 'code' => '$cust_main->apply_payments_and_credits; "";',
419 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
420 %foreach my $event ( keys %events ) {
421 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
422 % split(/\n/, $part_bill_event->plandata);
423 % my $html = $events{$event}{html};
424 % if ( ref($html) eq 'CODE' ) {
425 % $html = &{$html}(\%plandata);
427 % while ( $html =~ /%%%(\w+)%%%/ ) {
429 % $html =~ s/%%%$field%%%/$plandata{$field}/;
432 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
434 % if ($event eq $part_bill_event->plan){
435 % $currentreasonclass=$events{$event}{reason};
437 % print ntable( "#cccccc", 2).
438 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
439 % print "CHECKED " if $event eq $part_bill_event->plan;
440 % print qq!onClick="showhide_table()" !;
441 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
442 % encode_entities($events{$event}{code}).
443 % qq!">$events{$event}{name}</TD>!;
444 % print '<TD>'. $html. '</TD>' if $html;
447 % print qq!<HR WIDTH="90%">!;
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', 'creason', 'C', $creason, $newcreasonT, $newcreason) %>
509 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
511 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
512 <% include('/elements/tr-select-reason.html', 'sreason', 'S', $sreason, $newsreasonT, $newsreason) %>
518 %print qq!<INPUT TYPE="submit" VALUE="!,
519 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
526 <% include('/elements/footer.html') %>
531 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
533 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
534 $cgi->param('eventpart', $1);
536 $cgi->param('eventpart', '');
539 my ($creason, $newcreasonT, $newcreason);
540 my ($sreason, $newsreasonT, $newsreason);
542 my ($query) = $cgi->keywords;
544 my $part_bill_event = '';
545 my $currentreasonclass = '';
546 if ( $cgi->param('error') ) {
547 $part_bill_event = new FS::part_bill_event ( {
548 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
551 if ( $query && $query =~ /^(\d+)$/ ) {
552 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
554 $part_bill_event ||= new FS::part_bill_event {};
556 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
557 my $hashref = $part_bill_event->hashref;