4 %if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
5 % $cgi->param('eventpart', $1);
7 % $cgi->param('eventpart', '');
10 %my ($creason, $newcreasonT, $newcreason);
11 %my ($sreason, $newsreasonT, $newsreason);
14 %my ($query) = $cgi->keywords;
16 %my $part_bill_event = '';
17 %my $currentreasonclass = '';
18 %if ( $cgi->param('error') ) {
19 % $part_bill_event = new FS::part_bill_event ( {
20 % map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
23 %if ( $query && $query =~ /^(\d+)$/ ) {
24 % $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
26 % $part_bill_event ||= new FS::part_bill_event {};
28 %$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
29 %my $hashref = $part_bill_event->hashref;
34 <% include('/elements/header.html',
35 "$action Invoice Event Definition",
37 'Main Menu' => popurl(2),
38 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
42 % if ( $cgi->param('error') ) {
44 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
48 <FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" NAME="editEvent" METHOD=POST>
49 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
50 Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
52 <% ntable("#cccccc",2) %>
55 <TD ALIGN="right">Event name </TD>
56 <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
60 <TD ALIGN="right">For </TD>
63 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
64 % foreach my $payby ( keys %payby ) {
68 <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
75 % my $days = $hashref->{seconds}/86400;
79 <TD ALIGN="right">After</TD>
80 <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
84 <TD ALIGN="right">Test event</TD>
87 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
88 % foreach my $freq ( keys %freq ) {
92 <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
102 <TD ALIGN="right">Disabled</TD>
104 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
109 <TD VALIGN="top" ALIGN="right">Action</TD>
115 %sub select_pkgpart {
117 % my $plandata = shift;
118 % my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
119 % qq(<SELECT NAME="$label" MULTIPLE>).
121 % '<OPTION VALUE="'. $_->pkgpart. '"'.
122 % ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
123 % '>'. $_->pkg. ' - '. $_->comment
124 % } qsearch('part_pkg', { 'disabled' => '' } ) ).
128 %sub select_agentnum {
129 % my $plandata = shift;
130 % #my $agentnum = $plandata->{'agentnum'};
131 % my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
132 % '<SELECT NAME="agentnum" MULTIPLE>'.
134 % '<OPTION VALUE="'. $_->agentnum. '"'.
135 % ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
137 % } qsearch('agent', { 'disabled' => '' } ) ).
141 %my $conf = new FS::Conf;
142 %my $money_char = $conf->config('money_char') || '$';
144 %#this is pretty kludgy right here.
145 %tie my %events, 'Tie::IxHash',
148 % 'name' => 'Late fee (flat)',
149 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
151 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
152 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
156 % 'name' => 'Late fee (percentage)',
157 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
159 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
160 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
164 % 'name' => 'Suspend',
165 % 'code' => '$cust_main->suspend();',
169 % 'suspend-if-balance' => {
170 % 'name' => 'Suspend if balance (this invoice and previous) over',
171 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
172 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
176 % 'suspend-if-pkgpart' => {
177 % 'name' => 'Suspend packages',
178 % 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
179 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
183 % 'suspend-unless-pkgpart' => {
184 % 'name' => 'Suspend packages except',
185 % 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
186 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
191 % 'name' => 'Cancel',
192 % 'code' => '$cust_main->cancel();',
198 % 'name' => 'Add postal invoicing',
199 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
204 % 'name' => 'Pay invoice with a complimentary "payment"',
205 % 'code' => '$cust_bill->comp();',
209 % 'realtime-card' => {
210 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
211 % 'code' => '$cust_bill->realtime_card();',
215 % 'realtime-check' => {
216 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
217 % 'code' => '$cust_bill->realtime_ach();',
221 % 'realtime-lec' => {
222 % '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',
223 % 'code' => '$cust_bill->realtime_lec();',
228 % 'name' => 'Add card or check to a pending batch',
229 % 'code' => '$cust_bill->batch_card(%options);',
235 % # 'name' => 'Mark batched card event as retriable',
236 % # 'code' => '$cust_pay_batch->retriable();',
241 % 'name' => 'Send invoice (email/print/fax)',
242 % 'code' => '$cust_bill->send();',
246 % 'send_alternate' => {
247 % 'name' => 'Send invoice (email/print/fax) with alternate template',
248 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
250 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
254 % 'send_if_newest' => {
255 % '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)',
256 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
258 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
263 % 'name' => 'Send invoice (email/print/fax) ',
264 % 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
268 % <TD ALIGN="right">only for agent(s) </TD>
269 % <TD>'. &select_agentnum(@_). '</TD>
272 % <TD ALIGN="right">with template </TD>
274 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
278 % <TD ALIGN="right">email From: </TD>
280 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
288 % 'send_csv_ftp' => {
289 % 'name' => 'Upload CSV invoice data to an FTP server',
290 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
291 % server => \'%%%ftpserver%%%\',
292 % username => \'%%%ftpusername%%%\',
293 % password => \'%%%ftppassword%%%\',
294 % dir => \'%%%ftpdir%%%\',
295 % \'format\' => \'%%%ftpformat%%%\',
298 % '<TABLE BORDER=0>'.
299 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
302 % '<SELECT NAME="ftpformat">'.
303 % '<OPTION VALUE="default">Default'.
304 % '<OPTION VALUE="billco">Billco'.
307 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
309 % '<TR><TD ALIGN="right">FTP server: </TD>'.
310 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
312 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
313 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
315 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
316 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
318 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
319 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
326 % 'name' => 'Spool CSV invoice data',
327 % 'code' => '$cust_bill->spool_csv(
328 % \'format\' => \'%%%spoolformat%%%\',
329 % \'dest\' => \'%%%spooldest%%%\',
330 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
331 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
334 % my $plandata = shift;
337 % '<TABLE BORDER=0>'.
338 % '<TR><TD ALIGN="right">Format: </TD>'.
340 % '<SELECT NAME="spoolformat">';
342 % foreach my $option (qw( default billco )) {
343 % $html .= qq(<OPTION VALUE="$option");
344 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
345 % $html .= ">\u$option";
351 % '<TR><TD ALIGN="right">For destination: </TD>'.
353 % '<SELECT NAME="spooldest">';
355 % tie my %dest, 'Tie::IxHash',
357 % 'POST' => 'Postal Mail',
358 % 'EMAIL' => 'Email',
362 % foreach my $dest (keys %dest) {
363 % $html .= qq(<OPTION VALUE="$dest");
364 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
365 % $html .= '>'. $dest{$dest};
373 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
376 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
378 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
379 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
380 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
391 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
392 % 'code' => '$cust_main->bill();',
397 % 'name' => 'Apply unapplied payments and credits',
398 % 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
403 % 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
404 % 'code' => '$cust_main->collect();',
410 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
411 %foreach my $event ( keys %events ) {
412 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
413 % split(/\n/, $part_bill_event->plandata);
414 % my $html = $events{$event}{html};
415 % if ( ref($html) eq 'CODE' ) {
416 % $html = &{$html}(\%plandata);
418 % while ( $html =~ /%%%(\w+)%%%/ ) {
420 % $html =~ s/%%%$field%%%/$plandata{$field}/;
423 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
425 % if ($event eq $part_bill_event->plan){
426 % $currentreasonclass=$events{$event}{reason};
428 % print ntable( "#cccccc", 2).
429 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
430 % print "CHECKED " if $event eq $part_bill_event->plan;
431 % print qq!onClick="showhide_table()" !;
432 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
433 % encode_entities($events{$event}{code}).
434 % qq!">$events{$event}{name}</TD>!;
435 % print '<TD>'. $html. '</TD>' if $html;
440 % if ($currentreasonclass eq 'C'){
441 % if ($cgi->param('creason') =~ /^(-?\d+)$/){
444 % $creason = $part_bill_event->reason;
446 % if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
449 % if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
452 % }elsif ($currentreasonclass eq 'S'){
453 % if ($cgi->param('sreason') =~ /^(-?\d+)$/){
456 % $sreason = $part_bill_event->reason;
458 % if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
461 % if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
470 <SCRIPT TYPE="text/javascript">
471 function showhide_table()
473 for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
474 if (document.editEvent.plan_weight_eventcode[i].checked == true){
478 if(myreasons[currentevent] == 'C'){
479 document.getElementById('Ctable').style.display = 'inline';
480 document.getElementById('Stable').style.display = 'none';
481 }else if(myreasons[currentevent] == 'S'){
482 document.getElementById('Ctable').style.display = 'none';
483 document.getElementById('Stable').style.display = 'inline';
485 document.getElementById('Ctable').style.display = 'none';
486 document.getElementById('Stable').style.display = 'none';
491 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
493 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
494 <% include('/elements/tr-select-reason.html', 'creason', 'C', $creason, $newcreasonT, $newcreason) %>
499 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
501 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
502 <% include('/elements/tr-select-reason.html', 'sreason', 'S', $sreason, $newsreasonT, $newsreason) %>
508 %print qq!<INPUT TYPE="submit" VALUE="!,
509 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",