4 %if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
5 % $cgi->param('eventpart', $1);
7 % $cgi->param('eventpart', '');
10 %my ($query) = $cgi->keywords;
12 %my $part_bill_event = '';
13 %if ( $cgi->param('error') ) {
14 % $part_bill_event = new FS::part_bill_event ( {
15 % map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
18 %if ( $query && $query =~ /^(\d+)$/ ) {
19 % $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
21 % $part_bill_event ||= new FS::part_bill_event {};
23 %$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
24 %my $hashref = $part_bill_event->hashref;
29 <% include('/elements/header.html',
30 "$action Invoice Event Definition",
32 'Main Menu' => popurl(2),
33 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
37 % if ( $cgi->param('error') ) {
39 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
43 <FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" METHOD=POST>
44 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
45 Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
47 <% ntable("#cccccc",2) %>
50 <TD ALIGN="right">Event name </TD>
51 <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
55 <TD ALIGN="right">For </TD>
58 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
59 % foreach my $payby ( keys %payby ) {
63 <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
70 % my $days = $hashref->{seconds}/86400;
74 <TD ALIGN="right">After</TD>
75 <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
79 <TD ALIGN="right">Test event</TD>
82 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
83 % foreach my $freq ( keys %freq ) {
87 <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
97 <TD ALIGN="right">Disabled</TD>
99 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
104 <TD VALIGN="top" ALIGN="right">Action</TD>
110 %sub select_pkgpart {
112 % my $plandata = shift;
113 % my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
114 % qq(<SELECT NAME="$label" MULTIPLE>).
116 % '<OPTION VALUE="'. $_->pkgpart. '"'.
117 % ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
118 % '>'. $_->pkg. ' - '. $_->comment
119 % } qsearch('part_pkg', { 'disabled' => '' } ) ).
123 %sub select_agentnum {
124 % my $plandata = shift;
125 % #my $agentnum = $plandata->{'agentnum'};
126 % my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
127 % '<SELECT NAME="agentnum" MULTIPLE>'.
129 % '<OPTION VALUE="'. $_->agentnum. '"'.
130 % ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
132 % } qsearch('agent', { 'disabled' => '' } ) ).
136 %my $conf = new FS::Conf;
137 %my $money_char = $conf->config('money_char') || '$';
139 %#this is pretty kludgy right here.
140 %tie my %events, 'Tie::IxHash',
143 % 'name' => 'Late fee (flat)',
144 % 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
146 % 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
147 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
151 % 'name' => 'Late fee (percentage)',
152 % 'code' => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
154 % 'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
155 % '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
159 % 'name' => 'Suspend',
160 % 'code' => '$cust_main->suspend();',
163 % 'suspend-if-balance' => {
164 % 'name' => 'Suspend if balance (this invoice and previous) over',
165 % 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
166 % 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
169 % 'suspend-if-pkgpart' => {
170 % 'name' => 'Suspend packages',
171 % 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
172 % 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
175 % 'suspend-unless-pkgpart' => {
176 % 'name' => 'Suspend packages except',
177 % 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
178 % 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
182 % 'name' => 'Cancel',
183 % 'code' => '$cust_main->cancel();',
188 % 'name' => 'Add postal invoicing',
189 % 'code' => '$cust_main->invoicing_list_addpost(); "";',
194 % 'name' => 'Pay invoice with a complimentary "payment"',
195 % 'code' => '$cust_bill->comp();',
199 % 'realtime-card' => {
200 % 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
201 % 'code' => '$cust_bill->realtime_card();',
205 % 'realtime-check' => {
206 % 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
207 % 'code' => '$cust_bill->realtime_ach();',
211 % 'realtime-lec' => {
212 % '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',
213 % 'code' => '$cust_bill->realtime_lec();',
218 % 'name' => 'Add card or check to a pending batch',
219 % 'code' => '$cust_bill->batch_card(%options);',
225 % # 'name' => 'Mark batched card event as retriable',
226 % # 'code' => '$cust_pay_batch->retriable();',
231 % 'name' => 'Send invoice (email/print/fax)',
232 % 'code' => '$cust_bill->send();',
236 % 'send_alternate' => {
237 % 'name' => 'Send invoice (email/print/fax) with alternate template',
238 % 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
240 % '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
244 % 'send_if_newest' => {
245 % '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)',
246 % 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
248 % '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
253 % 'name' => 'Send invoice (email/print/fax) ',
254 % 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
258 % <TD ALIGN="right">only for agent(s) </TD>
259 % <TD>'. &select_agentnum(@_). '</TD>
262 % <TD ALIGN="right">with template </TD>
264 % <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
268 % <TD ALIGN="right">email From: </TD>
270 % <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
278 % 'send_csv_ftp' => {
279 % 'name' => 'Upload CSV invoice data to an FTP server',
280 % 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
281 % server => \'%%%ftpserver%%%\',
282 % username => \'%%%ftpusername%%%\',
283 % password => \'%%%ftppassword%%%\',
284 % dir => \'%%%ftpdir%%%\',
285 % \'format\' => \'%%%ftpformat%%%\',
288 % '<TABLE BORDER=0>'.
289 % '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
292 % '<SELECT NAME="ftpformat">'.
293 % '<OPTION VALUE="default">Default'.
294 % '<OPTION VALUE="billco">Billco'.
297 % '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
299 % '<TR><TD ALIGN="right">FTP server: </TD>'.
300 % '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
302 % '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
303 % '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
305 % '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
306 % '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
308 % '<TR><TD ALIGN="right">FTP directory: </TD>'.
309 % '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
316 % 'name' => 'Spool CSV invoice data',
317 % 'code' => '$cust_bill->spool_csv(
318 % \'format\' => \'%%%spoolformat%%%\',
319 % \'dest\' => \'%%%spooldest%%%\',
320 % \'balanceover\' => \'%%%spoolbalanceover%%%\',
321 % \'agent_spools\' => \'%%%spoolagent_spools%%%\',
324 % my $plandata = shift;
327 % '<TABLE BORDER=0>'.
328 % '<TR><TD ALIGN="right">Format: </TD>'.
330 % '<SELECT NAME="spoolformat">';
332 % foreach my $option (qw( default billco )) {
333 % $html .= qq(<OPTION VALUE="$option");
334 % $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
335 % $html .= ">\u$option";
341 % '<TR><TD ALIGN="right">For destination: </TD>'.
343 % '<SELECT NAME="spooldest">';
345 % tie my %dest, 'Tie::IxHash',
347 % 'POST' => 'Postal Mail',
348 % 'EMAIL' => 'Email',
352 % foreach my $dest (keys %dest) {
353 % $html .= qq(<OPTION VALUE="$dest");
354 % $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
355 % $html .= '>'. $dest{$dest};
363 % '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
366 % '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
368 % '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
369 % '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
370 % ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
381 % 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
382 % 'code' => '$cust_main->bill();',
387 % 'name' => 'Apply unapplied payments and credits',
388 % 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
393 % 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
394 % 'code' => '$cust_main->collect();',
400 %foreach my $event ( keys %events ) {
401 % my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
402 % split(/\n/, $part_bill_event->plandata);
403 % my $html = $events{$event}{html};
404 % if ( ref($html) eq 'CODE' ) {
405 % $html = &{$html}(\%plandata);
407 % while ( $html =~ /%%%(\w+)%%%/ ) {
409 % $html =~ s/%%%$field%%%/$plandata{$field}/;
412 % print ntable( "#cccccc", 2).
413 % qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
414 % print "CHECKED " if $event eq $part_bill_event->plan;
415 % print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
416 % encode_entities($events{$event}{code}).
417 % qq!">$events{$event}{name}</TD>!;
418 % print '<TD>'. $html. '</TD>' if $html;
430 %print qq!<INPUT TYPE="submit" VALUE="!,
431 % $hashref->{eventpart} ? "Apply changes" : "Add invoice event",