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 %my $late_taxclass = '';
108 %my $late_percent_taxclass = '';
109 %if ( $conf->exists('enable_taxclasses') ) {
112 % include('/elements/select-taxclass.html', '%%%late_taxclass%%%',
113 % 'name' => 'late_taxclass' );
114 % $late_percent_taxclass =
116 % include('/elements/select-taxclass.html', '%%%late_percent_taxclass%%%',
117 % 'name' => 'late_percent_taxclass' );
120 %#this is pretty kludgy right here.
121 %tie my %events, 'Tie::IxHash',
124 % 'name' => 'Late fee (flat)',
125 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
127 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
128 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
133 % 'name' => 'Late fee (percentage)',
134 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
136 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
137 % '<BR>Reason <INPUT TYPE="text" NAME="percent_reason" VALUE="%%%percent_reason%%%">'.
138 % $late_percent_taxclass,
142 % 'name' => 'Suspend',
143 % 'code' => '$cust_main->suspend(reason => %%%sreason%%%);',
147 % 'suspend-if-balance' => {
148 % 'name' => 'Suspend if balance (this invoice and previous) over',
149 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
150 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
154 % 'suspend-if-pkgpart' => {
155 % 'name' => 'Suspend packages',
156 % 'code' => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
157 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
161 % 'suspend-unless-pkgpart' => {
162 % 'name' => 'Suspend packages except',
163 % 'code' => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
164 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
169 % 'name' => 'Cancel',
170 % 'code' => '$cust_main->cancel(reason => %%%creason%%%);',
176 % 'name' => 'Add postal invoicing',
177 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
182 % 'name' => 'Pay invoice with a complimentary "payment"',
183 % 'code' => '$cust_bill->comp();',
188 % 'name' => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
189 % 'code' => '$cust_main->credit( $cust_main->balance, \'%%%credit_reason%%%\' );',
190 % 'html' => '<INPUT TYPE="text" NAME="credit_reason" VALUE="%%%credit_reason%%%">',
194 % 'realtime-card' => {
195 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
196 % 'code' => '$cust_bill->realtime_card();',
200 % 'realtime-check' => {
201 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
202 % 'code' => '$cust_bill->realtime_ach();',
206 % 'realtime-lec' => {
207 % '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',
208 % 'code' => '$cust_bill->realtime_lec();',
213 % 'name' => 'Add card or check to a pending batch',
214 % 'code' => '$cust_bill->batch_card(%options);',
220 % # 'name' => 'Mark batched card event as retriable',
221 % # 'code' => '$cust_pay_batch->retriable();',
226 % 'name' => 'Send invoice (email/print/fax)',
227 % 'code' => '$cust_bill->send();',
232 % 'name' => 'Send invoice (email only)',
233 % 'code' => '$cust_bill->email();',
237 % 'send_alternate' => {
238 % 'name' => 'Send invoice (email/print/fax) with alternate template',
239 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
241 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
245 % 'send_if_newest' => {
246 % '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)',
247 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
249 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
254 % 'name' => 'Send invoice (email/print/fax) ',
255 % 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
259 % <TD ALIGN="right">only for agent(s) </TD>
260 % <TD>'. &select_agentnum(@_). '</TD>
263 % <TD ALIGN="right">with template </TD>
265 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
269 % <TD ALIGN="right">email From: </TD>
271 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
279 % 'send_csv_ftp' => {
280 % 'name' => 'Upload CSV invoice data to an FTP server',
281 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
282 % server => \'%%%ftpserver%%%\',
283 % username => \'%%%ftpusername%%%\',
284 % password => \'%%%ftppassword%%%\',
285 % dir => \'%%%ftpdir%%%\',
286 % \'format\' => \'%%%ftpformat%%%\',
289 % '<TABLE BORDER=0>'.
290 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
293 % '<SELECT NAME="ftpformat">'.
294 % '<OPTION VALUE="default">Default'.
295 % '<OPTION VALUE="billco">Billco'.
298 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
300 % '<TR><TD ALIGN="right">FTP server: </TD>'.
301 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
303 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
304 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
306 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
307 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
309 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
310 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
317 % 'name' => 'Spool CSV invoice data',
318 % 'code' => '$cust_bill->spool_csv(
319 % \'format\' => \'%%%spoolformat%%%\',
320 % \'dest\' => \'%%%spooldest%%%\',
321 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
322 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
325 % my $plandata = shift;
328 % '<TABLE BORDER=0>'.
329 % '<TR><TD ALIGN="right">Format: </TD>'.
331 % '<SELECT NAME="spoolformat">';
333 % foreach my $option (qw( default billco )) {
334 % $html .= qq(<OPTION VALUE="$option");
335 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
336 % $html .= ">\u$option";
342 % '<TR><TD ALIGN="right">For destination: </TD>'.
344 % '<SELECT NAME="spooldest">';
346 % tie my %dest, 'Tie::IxHash',
348 % 'POST' => 'Postal Mail',
349 % 'EMAIL' => 'Email',
353 % foreach my $dest (keys %dest) {
354 % $html .= qq(<OPTION VALUE="$dest");
355 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
356 % $html .= '>'. $dest{$dest};
364 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
367 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
369 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
370 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
371 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
382 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
383 % 'code' => '$cust_main->bill();',
388 % 'name' => 'Apply unapplied payments and credits',
389 % 'code' => '$cust_main->apply_payments_and_credits; "";',
394 % 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
395 % 'code' => '$cust_main->collect();',
401 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
402 %foreach my $event ( keys %events ) {
403 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
404 % split(/\n/, $part_bill_event->plandata);
405 % my $html = $events{$event}{html};
406 % if ( ref($html) eq 'CODE' ) {
407 % $html = &{$html}(\%plandata);
409 % while ( $html =~ /%%%(\w+)%%%/ ) {
411 % $html =~ s/%%%$field%%%/$plandata{$field}/;
414 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
416 % if ($event eq $part_bill_event->plan){
417 % $currentreasonclass=$events{$event}{reason};
419 % print ntable( "#cccccc", 2).
420 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
421 % print "CHECKED " if $event eq $part_bill_event->plan;
422 % print qq!onClick="showhide_table()" !;
423 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
424 % encode_entities($events{$event}{code}).
425 % qq!">$events{$event}{name}</TD>!;
426 % print '<TD>'. $html. '</TD>' if $html;
431 % if ($currentreasonclass eq 'C'){
432 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
435 % $creason = $part_bill_event->reason;
437 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
440 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
443 % }elsif ($currentreasonclass eq 'S'){
444 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
447 % $sreason = $part_bill_event->reason;
449 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
452 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
461 <SCRIPT TYPE="text/javascript">
462 function showhide_table()
464 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
465 if (document.editEvent.plan_weight_eventcode[i].checked == true){
469 if(myreasons[currentevent] == 'C'){
470 document.getElementById('Ctable').style.display = 'inline';
471 document.getElementById('Stable').style.display = 'none';
472 }else if(myreasons[currentevent] == 'S'){
473 document.getElementById('Ctable').style.display = 'none';
474 document.getElementById('Stable').style.display = 'inline';
476 document.getElementById('Ctable').style.display = 'none';
477 document.getElementById('Stable').style.display = 'none';
482 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
484 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
485 <% include('/elements/tr-select-reason.html',
486 'field' => 'creason',
487 'reason_class' => 'C',
488 'curr_value' => $creason,
489 'init_type' => $newcreasonT,
490 'init_newreason' => $newcreason
497 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
499 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
500 <% include('/elements/tr-select-reason.html',
501 'field' => 'sreason',
502 'reason_class' => 'S',
503 'curr_value' => $sreason,
504 'init_type' => $newsreasonT,
505 'init_newreason' => $newsreason
513 %print qq!<INPUT TYPE="submit" VALUE="!,
514 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
521 <% include('/elements/footer.html') %>
526 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
528 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
529 $cgi->param('eventpart', $1);
531 $cgi->param('eventpart', '');
534 my ($creason, $newcreasonT, $newcreason);
535 my ($sreason, $newsreasonT, $newsreason);
537 my ($query) = $cgi->keywords;
539 my $part_bill_event = '';
540 my $currentreasonclass = '';
541 if ( $cgi->param('error') ) {
542 $part_bill_event = new FS::part_bill_event ( {
543 map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
546 if ( $query && $query =~ /^(\d+)$/ ) {
547 $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
549 $part_bill_event ||= new FS::part_bill_event {};
551 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
552 my $hashref = $part_bill_event->hashref;