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;
26 print header("$action Invoice Event Definition", menubar(
27 'Main Menu' => popurl(2),
28 'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
31 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
33 if $cgi->param('error');
35 print '<FORM ACTION="', popurl(1), 'process/part_bill_event.cgi" METHOD=POST>'.
36 '<INPUT TYPE="hidden" NAME="eventpart" VALUE="'.
37 $part_bill_event->eventpart .'">';
38 print "Invoice Event #", $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)";
40 print ntable("#cccccc",2), <<END;
41 <TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
44 for (qw(CARD DCRD CHEK DCHK LECB BILL COMP)) {
45 print qq!<OPTION VALUE="$_"!;
46 if ($part_bill_event->payby eq $_) {
47 print " SELECTED>$_</OPTION>";
53 my $days = $hashref->{seconds}/86400;
57 <TR><TD ALIGN="right">Event</TD><TD><INPUT TYPE="text" NAME="event" VALUE="$hashref->{event}"></TD></TR>
58 <TR><TD ALIGN="right">After</TD><TD><INPUT TYPE="text" NAME="days" VALUE="$days"> days</TD></TR>
61 print '<TR><TD ALIGN="right">Disabled</TD><TD>';
62 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
63 print ' CHECKED' if $hashref->{disabled} eq "Y";
67 print '<TR><TD ALIGN="right">Action</TD><TD>';
74 my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
75 qq(<SELECT NAME="$label" MULTIPLE>).
77 '<OPTION VALUE="'. $_->pkgpart. '"'.
78 ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
79 '>'. $_->pkg. ' - '. $_->comment
80 } qsearch('part_pkg', { 'disabled' => '' } ) ).
86 #my $agentnum = $plandata->{'agentnum'};
87 my %agentnums = map { $_=>1 } split(/,\s*/, $plandata->{'agentnum'});
88 '<SELECT NAME="agentnum" MULTIPLE>'.
90 '<OPTION VALUE="'. $_->agentnum. '"'.
91 ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
93 } qsearch('agent', { 'disabled' => '' } ) ).
97 my $conf = new FS::Conf;
98 my $money_char = $conf->config('money_char') || '$';
100 #this is pretty kludgy right here.
101 tie my %events, 'Tie::IxHash',
104 'name' => 'Late fee',
105 'code' => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
107 'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
108 '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
113 'code' => '$cust_main->suspend();',
117 'name' => 'Suspend if balance (this invoice and previous) over',
118 'code' => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
119 'html' => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
122 'suspend-if-pkgpart' => {
123 'name' => 'Suspend packages',
124 'code' => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
125 'html' => sub { &select_pkgpart('if_pkgpart', @_) },
128 'suspend-unless-pkgpart' => {
129 'name' => 'Suspend packages except',
130 'code' => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
131 'html' => sub { &select_pkgpart('unless_pkgpart', @_) },
136 'code' => '$cust_main->cancel();',
141 'name' => 'Add postal invoicing',
142 'code' => '$cust_main->invoicing_list_addpost(); "";',
147 'name' => 'Pay invoice with a complimentary "payment"',
148 'code' => '$cust_bill->comp();',
153 'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
154 'code' => '$cust_bill->realtime_card();',
158 'realtime-check' => {
159 'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
160 'code' => '$cust_bill->realtime_ach();',
165 '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',
166 'code' => '$cust_bill->realtime_lec();',
171 'name' => 'Add card to the pending credit card batch',
172 'code' => '$cust_bill->batch_card();',
177 'name' => 'Send invoice (email/print)',
178 'code' => '$cust_bill->send();',
182 'send_alternate' => {
183 'name' => 'Send invoice (email/print) with alternate template',
184 'code' => '$cust_bill->send(\'%%%templatename%%%\');',
186 '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
190 'send_if_newest' => {
191 'name' => 'Send invoice (email/print) with alternate template, if it is still the newest invoice (useful for late notices - set to 31 days or later)',
192 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
194 '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
199 'name' => 'Send invoice (email/print) ',
200 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
204 <TD ALIGN="right">only for agent(s) </TD>
205 <TD>'. &select_agentnum(@_). '</TD>
208 <TD ALIGN="right">with template </TD>
210 <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
214 <TD ALIGN="right">email From: </TD>
216 <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
225 'name' => 'Upload CSV invoice data to an FTP server',
226 'code' => '$cust_bill->send_csv( protocol => \'ftp\',
227 server => \'%%%ftpserver%%%\',
228 username => \'%%%ftpusername%%%\',
229 password => \'%%%ftppassword%%%\',
230 dir => \'%%%ftpdir%%%\',
231 \'format\' => \'%%%ftpformat%%%\',
235 '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
238 '<SELECT NAME="ftpformat">'.
239 '<OPTION VALUE="default">Default'.
240 '<OPTION VALUE="billco">Billco'.
243 '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
245 '<TR><TD ALIGN="right">FTP server: </TD>'.
246 '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
248 '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
249 '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
251 '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
252 '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
254 '<TR><TD ALIGN="right">FTP directory: </TD>'.
255 '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
262 'name' => 'Spool CSV invoice data',
263 'code' => '$cust_bill->spool_csv(
264 \'format\' => \'%%%spoolformat%%%\',
265 \'dest\' => \'%%%spooldest%%%\',
266 \'agent_spools\' => \'%%%spoolagent_spools%%%\',
269 my $plandata = shift;
273 '<TR><TD ALIGN="right">Format: </TD>'.
275 '<SELECT NAME="spoolformat">';
277 foreach my $option (qw( default billco )) {
278 $html .= qq(<OPTION VALUE="$option");
279 $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
280 $html .= ">\u$option";
286 '<TR><TD ALIGN="right">For destination: </TD>'.
288 '<SELECT NAME="spooldest">';
290 tie my %dest, 'Tie::IxHash',
292 'POST' => 'Postal Mail',
297 foreach my $dest (keys %dest) {
298 $html .= qq(<OPTION VALUE="$dest");
299 $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
300 $html .= '>'. $dest{$dest};
306 '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
307 '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
308 ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
319 'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
320 'code' => '$cust_main->bill();',
325 'name' => 'Apply unapplied payments and credits',
326 'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
331 'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
332 'code' => '$cust_main->collect();',
338 foreach my $event ( keys %events ) {
339 my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
340 split(/\n/, $part_bill_event->plandata);
341 my $html = $events{$event}{html};
342 if ( ref($html) eq 'CODE' ) {
343 $html = &{$html}(\%plandata);
345 while ( $html =~ /%%%(\w+)%%%/ ) {
347 $html =~ s/%%%$field%%%/$plandata{$field}/;
350 print ntable( "#cccccc", 2).
351 qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
352 print "CHECKED " if $event eq $part_bill_event->plan;
353 print qq!VALUE="!. $event. ":". $events{$event}{weight}. ":".
354 encode_entities($events{$event}{code}).
355 qq!">$events{$event}{name}</TD>!;
356 print '<TD>'. $html. '</TD>' if $html;
368 print qq!<INPUT TYPE="submit" VALUE="!,
369 $hashref->{eventpart} ? "Apply changes" : "Add invoice event",