This commit was generated by cvs2svn to compensate for changes in r6255,
[freeside.git] / httemplate / edit / part_bill_event.cgi
1 <% include('/elements/header.html',
2       "$action Invoice Event Definition",
3       menubar(
4         'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
5       )
6     )
7 %>
8
9 <% include('/elements/error.html') %>
10
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)" %>
14
15 <%  ntable("#cccccc",2) %>
16
17   <TR>
18     <TD ALIGN="right">Event name </TD>
19     <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
20   </TR>
21
22   <TR>
23     <TD ALIGN="right">For </TD>
24     <TD>
25       <SELECT NAME="payby">
26 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
27 %           foreach my $payby ( keys %payby ) {
28 %        
29
30
31           <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
32 % } 
33
34
35       </SELECT> customers
36     </TD>
37   </TR>
38 % my $days = $hashref->{seconds}/86400; 
39
40
41   <TR>
42     <TD ALIGN="right">After</TD>
43     <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
44   </TR>
45
46   <TR>
47     <TD ALIGN="right">Test event</TD>
48     <TD>
49       <SELECT NAME="freq">
50 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
51 %           foreach my $freq ( keys %freq ) {
52 %        
53
54
55           <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
56 % } 
57
58
59       </SELECT>
60     </TD>
61   </TR>
62
63
64   <TR>
65     <TD ALIGN="right">Disabled</TD>
66     <TD>
67       <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
68     </TD>
69   </TR>
70
71   <TR>
72     <TD VALIGN="top" ALIGN="right">Action</TD>
73     <TD>
74 %
75 %
76 %#print ntable();
77 %
78 %sub select_pkgpart {
79 %  my $label = shift;
80 %  my $plandata = shift;
81 %  my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
82 %  qq(<SELECT NAME="$label" MULTIPLE>).
83 %  join("\n", map {
84 %    '<OPTION VALUE="'. $_->pkgpart. '"'.
85 %    ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
86 %    '>'. $_->pkg. ' - '. $_->comment
87 %  } qsearch('part_pkg', { 'disabled' => '' } ) ).
88 %  '</SELECT>';
89 %}
90 %
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>'.
96 %  join("\n", map {
97 %    '<OPTION VALUE="'. $_->agentnum. '"'.
98 %    ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
99 %    '>'. $_->agent
100 %  } qsearch('agent', { 'disabled' => '' } ) ).
101 %  '</SELECT>';
102 %}
103 %
104 %my $conf = new FS::Conf;
105 %my $money_char = $conf->config('money_char') || '$';
106 %
107 %my $late_taxclass = '';
108 %my $late_percent_taxclass = '';
109 %if ( $conf->exists('enable_taxclasses') ) {
110 %  $late_taxclass =
111 %    '<BR>Taxclass '.
112 %    include('/elements/select-taxclass.html', '%%%late_taxclass%%%',
113 %              'name' => 'late_taxclass' );
114 %  $late_percent_taxclass =
115 %    '<BR>Taxclass '.
116 %    include('/elements/select-taxclass.html', '%%%late_percent_taxclass%%%',
117 %              'name' => 'late_percent_taxclass' );
118 %}
119 %
120 %#this is pretty kludgy right here.
121 %tie my %events, 'Tie::IxHash',
122 %
123 %  'fee' => {
124 %    'name'   => 'Late fee (flat)',
125 %    'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
126 %    'html'   => 
127 %      'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
128 %      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
129 %      $late_taxclass,
130 %    'weight' => 10,
131 %  },
132 %  'fee_percent' => {
133 %    'name'   => 'Late fee (percentage)',
134 %    'code'   => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
135 %    'html'   => 
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,
139 %    'weight' => 10,
140 %  },
141 %  'suspend' => {
142 %    'name'   => 'Suspend',
143 %    'code'   => '$cust_main->suspend(reason => %%%sreason%%%);',
144 %    'weight' => 10,
145 %    'reason' => 'S',
146 %  },
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%%%">',
151 %    'weight' => 10,
152 %    'reason' => 'S',
153 %  },
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', @_) },
158 %    'weight' => 10,
159 %    'reason' => 'S',
160 %  },
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', @_) },
165 %    'weight' => 10,
166 %    'reason' => 'S',
167 %  },
168 %  'cancel' => {
169 %    'name'   => 'Cancel',
170 %    'code'   => '$cust_main->cancel(reason => %%%creason%%%);',
171 %    'weight' => 10,
172 %    'reason' => 'C',
173 %  },
174 %
175 %  'addpost' => {
176 %    'name' => 'Add postal invoicing',
177 %    'code' => '$cust_main->invoicing_list_addpost(); "";',
178 %    'weight'  => 20,
179 %  },
180 %
181 %  'comp' => {
182 %    'name' => 'Pay invoice with a complimentary "payment"',
183 %    'code' => '$cust_bill->comp();',
184 %    'weight' => 30,
185 %  },
186 %
187 %  'credit' => {
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%%%">',
191 %    'weight' => 30,
192 %  },
193 %
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();',
197 %    'weight' => 30,
198 %  },
199 %
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();',
203 %    'weight' => 30,
204 %  },
205 %
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();',
209 %    'weight' => 30,
210 %  },
211 %
212 %  'batch-card' => {
213 %    'name' => 'Add card or check to a pending batch',
214 %    'code' => '$cust_bill->batch_card(%options);',
215 %    'weight' => 40,
216 %  },
217 %
218 %  
219 %  #'retriable' => {
220 %  #  'name' => 'Mark batched card event as retriable',
221 %  #  'code' => '$cust_pay_batch->retriable();',
222 %  #  'weight' => 60,
223 %  #},
224 %
225 %  'send' => {
226 %    'name' => 'Send invoice (email/print/fax)',
227 %    'code' => '$cust_bill->send();',
228 %    'weight' => 50,
229 %  },
230 %
231 %  'send_email' => {
232 %    'name' => 'Send invoice (email only)',
233 %    'code' => '$cust_bill->email();',
234 %    'weight' => 50,
235 %  },
236 %
237 %  'send_alternate' => {
238 %    'name' => 'Send invoice (email/print/fax) with alternate template',
239 %    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
240 %    'html' =>
241 %        '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
242 %    'weight' => 50,
243 %  },
244 %
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%%%\');',
248 %    'html' =>
249 %        '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
250 %    'weight' => 50,
251 %  },
252 %
253 %  'send_agent' => {
254 %    'name' => 'Send invoice (email/print/fax) ',
255 %    'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
256 %    'html' => sub {
257 %        '<TABLE BORDER=0>
258 %          <TR>
259 %            <TD ALIGN="right">only for agent(s) </TD>
260 %            <TD>'. &select_agentnum(@_). '</TD>
261 %          </TR>
262 %          <TR>
263 %            <TD ALIGN="right">with template </TD>
264 %            <TD>
265 %              <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
266 %            </TD>
267 %          </TR>
268 %          <TR>
269 %            <TD ALIGN="right">email From: </TD>
270 %            <TD>
271 %              <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
272 %            </TD>
273 %          </TR>
274 %        </TABLE>';
275 %    },
276 %    'weight' => 50,
277 %  },
278 %
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%%%\',
287 %                                   );',
288 %    'html' =>
289 %        '<TABLE BORDER=0>'.
290 %        '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
291 %          '<TD>'.
292 %            '<!--'.
293 %            '<SELECT NAME="ftpformat">'.
294 %              '<OPTION VALUE="default">Default'.
295 %              '<OPTION VALUE="billco">Billco'.
296 %            '</SELECT>'.
297 %            '-->'.
298 %            '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
299 %          '</TD></TR>'.
300 %        '<TR><TD ALIGN="right">FTP server: </TD>'.
301 %          '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
302 %          '</TD></TR>'.
303 %        '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
304 %          '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
305 %          '</TD></TR>'.
306 %        '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
307 %          '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
308 %          '</TD></TR>'.
309 %        '<TR><TD ALIGN="right">FTP directory: </TD>'.
310 %          '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
311 %          '</TD></TR>'.
312 %        '</TABLE>',
313 %    'weight' => 50,
314 %  },
315 %
316 %  'spool_csv' => {
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%%%\',
323 %               );',
324 %    'html' => sub {
325 %       my $plandata = shift;
326 %
327 %       my $html =
328 %       '<TABLE BORDER=0>'.
329 %       '<TR><TD ALIGN="right">Format: </TD>'.
330 %         '<TD>'.
331 %           '<SELECT NAME="spoolformat">';
332 %
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";
337 %       }
338 %
339 %       $html .= 
340 %           '</SELECT>'.
341 %         '</TD></TR>'.
342 %       '<TR><TD ALIGN="right">For destination: </TD>'.
343 %         '<TD>'.
344 %           '<SELECT NAME="spooldest">';
345 %
346 %       tie my %dest, 'Tie::IxHash', 
347 %         ''      => '(all)',
348 %         'POST'  => 'Postal Mail',
349 %         'EMAIL' => 'Email',
350 %         'FAX'   => 'Fax',
351 %       ;
352 %
353 %       foreach my $dest (keys %dest) {
354 %         $html .= qq(<OPTION VALUE="$dest");
355 %         $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
356 %         $html .= '>'. $dest{$dest};
357 %       }
358 %
359 %       $html .=
360 %           '</SELECT>'.
361 %         '</TD></TR>'.
362 %
363 %       '<TR>'.
364 %         '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
365 %         '<TD>'.
366 %           "$money_char ".
367 %           '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
368 %         '</TD>'.
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' : '' ).
372 %           '>'.
373 %         '</TD></TR>'.
374 %       '</TABLE>';
375 %
376 %       $html;
377 %    },
378 %    'weight' => 50,
379 %  },
380 %
381 %  'bill' => {
382 %    'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
383 %    'code' => '$cust_main->bill();',
384 %    'weight'  => 60,
385 %  },
386 %
387 %  'apply' => {
388 %    'name' => 'Apply unapplied payments and credits',
389 %    'code' => '$cust_main->apply_payments_and_credits; "";',
390 %    'weight'  => 70,
391 %  },
392 %
393 %  'collect' => {
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();',
396 %    'weight'  => 80,
397 %  },
398 %
399 %;
400 %
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);
408 %  }
409 %  while ( $html =~ /%%%(\w+)%%%/ ) {
410 %    my $field = $1;
411 %    $html =~ s/%%%$field%%%/$plandata{$field}/;
412 %  }
413 %
414 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
415 </SCRIPT>
416 %  if ($event eq $part_bill_event->plan){
417 %    $currentreasonclass=$events{$event}{reason};
418 %  }
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;
427 %  print qq!</TR>!;
428 %  print '</TABLE>';
429 %}
430 %
431 %  if ($currentreasonclass eq 'C'){
432 %    if ($cgi->param('creason') =~ /^(-?\d+)$/){
433 %      $creason =  $1;
434 %    }else{
435 %      $creason = $part_bill_event->reason;
436 %    }
437 %    if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
438 %      $newcreasonT =  $1;
439 %    }
440 %    if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
441 %      $newcreason =  $1;
442 %    }
443 %  }elsif ($currentreasonclass eq 'S'){
444 %    if ($cgi->param('sreason') =~ /^(-?\d+)$/){
445 %      $sreason =  $1;
446 %    }else{
447 %      $sreason = $part_bill_event->reason;
448 %    }
449 %    if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
450 %      $newsreasonT =  $1;
451 %    }
452 %    if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
453 %      $newsreason =  $1;
454 %    }
455 %  }
456 %
457
458 </TD></TR>
459 </TABLE>
460
461 <SCRIPT TYPE="text/javascript">
462   function showhide_table()
463   {
464     for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
465       if (document.editEvent.plan_weight_eventcode[i].checked == true){
466         currentevent=i;
467       }
468     }
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';
475     }else{
476       document.getElementById('Ctable').style.display = 'none';
477       document.getElementById('Stable').style.display = 'none';
478     }
479   }
480 </SCRIPT>
481
482 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
483 <TR><TD>
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
491           )
492 %>
493 </TABLE>
494 </TR></TD>
495 </TABLE>
496
497 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
498 <TR><TD>
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
506           )
507 %>
508 </TABLE>
509 </TR></TD>
510 </TABLE>
511     
512 %
513 %print qq!<INPUT TYPE="submit" VALUE="!,
514 %      $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
515 %      qq!">!;
516 %
517
518
519     </FORM>
520
521 <% include('/elements/footer.html') %>
522
523 <%init>
524
525 die "access denied"
526   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
527
528 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
529   $cgi->param('eventpart', $1);
530 } else {
531   $cgi->param('eventpart', '');
532 }
533
534 my ($creason, $newcreasonT, $newcreason);
535 my ($sreason, $newsreasonT, $newsreason);
536
537 my ($query) = $cgi->keywords;
538 my $action = '';
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')
544   } );
545 }
546 if ( $query && $query =~ /^(\d+)$/ ) {
547   $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
548 } else {
549   $part_bill_event ||= new FS::part_bill_event {};
550 }
551 $action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
552 my $hashref = $part_bill_event->hashref;
553
554 </%init>