8e5dcd1fc11660ee0bbf1df92c4a51d4f4791978
[freeside.git] / httemplate / edit / part_bill_event.cgi
1 <!--mason kludge-->
2 %
3 %
4 %if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
5 %  $cgi->param('eventpart', $1);
6 %} else {
7 %  $cgi->param('eventpart', '');
8 %}
9 %
10 %my ($creason, $newcreasonT, $newcreason);
11 %my ($sreason, $newsreasonT, $newsreason);
12 %
13 %
14 %my ($query) = $cgi->keywords;
15 %my $action = '';
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')
21 %  } );
22 %}
23 %if ( $query && $query =~ /^(\d+)$/ ) {
24 %  $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
25 %} else {
26 %  $part_bill_event ||= new FS::part_bill_event {};
27 %}
28 %$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
29 %my $hashref = $part_bill_event->hashref;
30 %
31 %
32
33
34 <% include('/elements/header.html',
35       "$action Invoice Event Definition",
36       menubar(
37         'Main Menu' => popurl(2),
38         'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
39       )
40     )
41 %>
42 % if ( $cgi->param('error') ) { 
43
44   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
45 % } 
46
47
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)" %>
51
52 <%  ntable("#cccccc",2) %>
53
54   <TR>
55     <TD ALIGN="right">Event name </TD>
56     <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
57   </TR>
58
59   <TR>
60     <TD ALIGN="right">For </TD>
61     <TD>
62       <SELECT NAME="payby">
63 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
64 %           foreach my $payby ( keys %payby ) {
65 %        
66
67
68           <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
69 % } 
70
71
72       </SELECT> customers
73     </TD>
74   </TR>
75 % my $days = $hashref->{seconds}/86400; 
76
77
78   <TR>
79     <TD ALIGN="right">After</TD>
80     <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
81   </TR>
82
83   <TR>
84     <TD ALIGN="right">Test event</TD>
85     <TD>
86       <SELECT NAME="freq">
87 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
88 %           foreach my $freq ( keys %freq ) {
89 %        
90
91
92           <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
93 % } 
94
95
96       </SELECT>
97     </TD>
98   </TR>
99
100
101   <TR>
102     <TD ALIGN="right">Disabled</TD>
103     <TD>
104       <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
105     </TD>
106   </TR>
107
108   <TR>
109     <TD VALIGN="top" ALIGN="right">Action</TD>
110     <TD>
111 %
112 %
113 %#print ntable();
114 %
115 %sub select_pkgpart {
116 %  my $label = shift;
117 %  my $plandata = shift;
118 %  my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
119 %  qq(<SELECT NAME="$label" MULTIPLE>).
120 %  join("\n", map {
121 %    '<OPTION VALUE="'. $_->pkgpart. '"'.
122 %    ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
123 %    '>'. $_->pkg. ' - '. $_->comment
124 %  } qsearch('part_pkg', { 'disabled' => '' } ) ).
125 %  '</SELECT>';
126 %}
127 %
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>'.
133 %  join("\n", map {
134 %    '<OPTION VALUE="'. $_->agentnum. '"'.
135 %    ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
136 %    '>'. $_->agent
137 %  } qsearch('agent', { 'disabled' => '' } ) ).
138 %  '</SELECT>';
139 %}
140 %
141 %my $conf = new FS::Conf;
142 %my $money_char = $conf->config('money_char') || '$';
143 %
144 %#this is pretty kludgy right here.
145 %tie my %events, 'Tie::IxHash',
146 %
147 %  'fee' => {
148 %    'name'   => 'Late fee (flat)',
149 %    'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
150 %    'html'   => 
151 %      'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
152 %      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
153 %    'weight' => 10,
154 %  },
155 %  'fee_percent' => {
156 %    'name'   => 'Late fee (percentage)',
157 %    'code'   => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
158 %    'html'   => 
159 %      'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
160 %      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
161 %    'weight' => 10,
162 %  },
163 %  'suspend' => {
164 %    'name'   => 'Suspend',
165 %    'code'   => '$cust_main->suspend(reason => %%%sreason%%%);',
166 %    'weight' => 10,
167 %    'reason' => 'S',
168 %  },
169 %  'suspend-if-balance' => {
170 %    'name'   => 'Suspend if balance (this invoice and previous) over',
171 %    'code'   => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
172 %    'html'   => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
173 %    'weight' => 10,
174 %    'reason' => 'S',
175 %  },
176 %  'suspend-if-pkgpart' => {
177 %    'name'   => 'Suspend packages',
178 %    'code'   => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
179 %    'html'   => sub { &select_pkgpart('if_pkgpart', @_) },
180 %    'weight' => 10,
181 %    'reason' => 'S',
182 %  },
183 %  'suspend-unless-pkgpart' => {
184 %    'name'   => 'Suspend packages except',
185 %    'code'   => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
186 %    'html'   => sub { &select_pkgpart('unless_pkgpart', @_) },
187 %    'weight' => 10,
188 %    'reason' => 'S',
189 %  },
190 %  'cancel' => {
191 %    'name'   => 'Cancel',
192 %    'code'   => '$cust_main->cancel(reason => %%%creason%%%);',
193 %    'weight' => 10,
194 %    'reason' => 'C',
195 %  },
196 %
197 %  'addpost' => {
198 %    'name' => 'Add postal invoicing',
199 %    'code' => '$cust_main->invoicing_list_addpost(); "";',
200 %    'weight'  => 20,
201 %  },
202 %
203 %  'comp' => {
204 %    'name' => 'Pay invoice with a complimentary "payment"',
205 %    'code' => '$cust_bill->comp();',
206 %    'weight' => 30,
207 %  },
208 %
209 %  'credit' => {
210 %    'name'   => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
211 %    'code'   => '$cust_main->credit( $cust_main->balance, \'%%%reason%%%\' );',
212 %    'html'   => '<INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
213 %    'weight' => 30,
214 %  },
215 %
216 %  'realtime-card' => {
217 %    'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
218 %    'code' => '$cust_bill->realtime_card();',
219 %    'weight' => 30,
220 %  },
221 %
222 %  'realtime-check' => {
223 %    'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
224 %    'code' => '$cust_bill->realtime_ach();',
225 %    'weight' => 30,
226 %  },
227 %
228 %  'realtime-lec' => {
229 %    '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',
230 %    'code' => '$cust_bill->realtime_lec();',
231 %    'weight' => 30,
232 %  },
233 %
234 %  'batch-card' => {
235 %    'name' => 'Add card or check to a pending batch',
236 %    'code' => '$cust_bill->batch_card(%options);',
237 %    'weight' => 40,
238 %  },
239 %
240 %  
241 %  #'retriable' => {
242 %  #  'name' => 'Mark batched card event as retriable',
243 %  #  'code' => '$cust_pay_batch->retriable();',
244 %  #  'weight' => 60,
245 %  #},
246 %
247 %  'send' => {
248 %    'name' => 'Send invoice (email/print/fax)',
249 %    'code' => '$cust_bill->send();',
250 %    'weight' => 50,
251 %  },
252 %
253 %  'send_alternate' => {
254 %    'name' => 'Send invoice (email/print/fax) with alternate template',
255 %    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
256 %    'html' =>
257 %        '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
258 %    'weight' => 50,
259 %  },
260 %
261 %  'send_if_newest' => {
262 %    '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)',
263 %    'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
264 %    'html' =>
265 %        '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
266 %    'weight' => 50,
267 %  },
268 %
269 %  'send_agent' => {
270 %    'name' => 'Send invoice (email/print/fax) ',
271 %    'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
272 %    'html' => sub {
273 %        '<TABLE BORDER=0>
274 %          <TR>
275 %            <TD ALIGN="right">only for agent(s) </TD>
276 %            <TD>'. &select_agentnum(@_). '</TD>
277 %          </TR>
278 %          <TR>
279 %            <TD ALIGN="right">with template </TD>
280 %            <TD>
281 %              <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
282 %            </TD>
283 %          </TR>
284 %          <TR>
285 %            <TD ALIGN="right">email From: </TD>
286 %            <TD>
287 %              <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
288 %            </TD>
289 %          </TR>
290 %        </TABLE>';
291 %    },
292 %    'weight' => 50,
293 %  },
294 %
295 %  'send_csv_ftp' => {
296 %    'name' => 'Upload CSV invoice data to an FTP server',
297 %    'code' => '$cust_bill->send_csv( protocol   => \'ftp\',
298 %                                     server     => \'%%%ftpserver%%%\',
299 %                                     username   => \'%%%ftpusername%%%\',
300 %                                     password   => \'%%%ftppassword%%%\',
301 %                                     dir        => \'%%%ftpdir%%%\',
302 %                                     \'format\' => \'%%%ftpformat%%%\',
303 %                                   );',
304 %    'html' =>
305 %        '<TABLE BORDER=0>'.
306 %        '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
307 %          '<TD>'.
308 %            '<!--'.
309 %            '<SELECT NAME="ftpformat">'.
310 %              '<OPTION VALUE="default">Default'.
311 %              '<OPTION VALUE="billco">Billco'.
312 %            '</SELECT>'.
313 %            '-->'.
314 %            '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
315 %          '</TD></TR>'.
316 %        '<TR><TD ALIGN="right">FTP server: </TD>'.
317 %          '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
318 %          '</TD></TR>'.
319 %        '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
320 %          '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
321 %          '</TD></TR>'.
322 %        '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
323 %          '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
324 %          '</TD></TR>'.
325 %        '<TR><TD ALIGN="right">FTP directory: </TD>'.
326 %          '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
327 %          '</TD></TR>'.
328 %        '</TABLE>',
329 %    'weight' => 50,
330 %  },
331 %
332 %  'spool_csv' => {
333 %    'name' => 'Spool CSV invoice data',
334 %    'code' => '$cust_bill->spool_csv(
335 %                 \'format\' => \'%%%spoolformat%%%\',
336 %                 \'dest\'   => \'%%%spooldest%%%\',
337 %                 \'balanceover\' => \'%%%spoolbalanceover%%%\',
338 %                 \'agent_spools\' => \'%%%spoolagent_spools%%%\',
339 %               );',
340 %    'html' => sub {
341 %       my $plandata = shift;
342 %
343 %       my $html =
344 %       '<TABLE BORDER=0>'.
345 %       '<TR><TD ALIGN="right">Format: </TD>'.
346 %         '<TD>'.
347 %           '<SELECT NAME="spoolformat">';
348 %
349 %       foreach my $option (qw( default billco )) {
350 %         $html .= qq(<OPTION VALUE="$option");
351 %         $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
352 %         $html .= ">\u$option";
353 %       }
354 %
355 %       $html .= 
356 %           '</SELECT>'.
357 %         '</TD></TR>'.
358 %       '<TR><TD ALIGN="right">For destination: </TD>'.
359 %         '<TD>'.
360 %           '<SELECT NAME="spooldest">';
361 %
362 %       tie my %dest, 'Tie::IxHash', 
363 %         ''      => '(all)',
364 %         'POST'  => 'Postal Mail',
365 %         'EMAIL' => 'Email',
366 %         'FAX'   => 'Fax',
367 %       ;
368 %
369 %       foreach my $dest (keys %dest) {
370 %         $html .= qq(<OPTION VALUE="$dest");
371 %         $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
372 %         $html .= '>'. $dest{$dest};
373 %       }
374 %
375 %       $html .=
376 %           '</SELECT>'.
377 %         '</TD></TR>'.
378 %
379 %       '<TR>'.
380 %         '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
381 %         '<TD>'.
382 %           "$money_char ".
383 %           '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
384 %         '</TD>'.
385 %       '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
386 %         '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
387 %           ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
388 %           '>'.
389 %         '</TD></TR>'.
390 %       '</TABLE>';
391 %
392 %       $html;
393 %    },
394 %    'weight' => 50,
395 %  },
396 %
397 %  'bill' => {
398 %    'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
399 %    'code' => '$cust_main->bill();',
400 %    'weight'  => 60,
401 %  },
402 %
403 %  'apply' => {
404 %    'name' => 'Apply unapplied payments and credits',
405 %    'code' => '$cust_main->apply_payments_and_credits; "";',
406 %    'weight'  => 70,
407 %  },
408 %
409 %  'collect' => {
410 %    'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
411 %    'code' => '$cust_main->collect();',
412 %    'weight'  => 80,
413 %  },
414 %
415 %;
416 %
417 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
418 %foreach my $event ( keys %events ) {
419 %  my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
420 %                   split(/\n/, $part_bill_event->plandata);
421 %  my $html = $events{$event}{html};
422 %  if ( ref($html) eq 'CODE' ) {
423 %    $html = &{$html}(\%plandata);
424 %  }
425 %  while ( $html =~ /%%%(\w+)%%%/ ) {
426 %    my $field = $1;
427 %    $html =~ s/%%%$field%%%/$plandata{$field}/;
428 %  }
429 %
430 <SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
431 </SCRIPT>
432 %  if ($event eq $part_bill_event->plan){
433 %    $currentreasonclass=$events{$event}{reason};
434 %  }
435 %  print ntable( "#cccccc", 2).
436 %        qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
437 %  print "CHECKED " if $event eq $part_bill_event->plan;
438 %  print qq!onClick="showhide_table()" !;
439 %  print qq!VALUE="!.  $event. ":". $events{$event}{weight}. ":".
440 %        encode_entities($events{$event}{code}).
441 %        qq!">$events{$event}{name}</TD>!;
442 %  print '<TD>'. $html. '</TD>' if $html;
443 %  print qq!</TR>!;
444 %  print '</TABLE>';
445 %}
446 %
447 %  if ($currentreasonclass eq 'C'){
448 %    if ($cgi->param('creason') =~ /^(-?\d+)$/){
449 %      $creason =  $1;
450 %    }else{
451 %      $creason = $part_bill_event->reason;
452 %    }
453 %    if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
454 %      $newcreasonT =  $1;
455 %    }
456 %    if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
457 %      $newcreason =  $1;
458 %    }
459 %  }elsif ($currentreasonclass eq 'S'){
460 %    if ($cgi->param('sreason') =~ /^(-?\d+)$/){
461 %      $sreason =  $1;
462 %    }else{
463 %      $sreason = $part_bill_event->reason;
464 %    }
465 %    if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
466 %      $newsreasonT =  $1;
467 %    }
468 %    if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
469 %      $newsreason =  $1;
470 %    }
471 %  }
472 %
473
474 </TD></TR>
475 </TABLE>
476
477 <SCRIPT TYPE="text/javascript">
478   function showhide_table()
479   {
480     for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
481       if (document.editEvent.plan_weight_eventcode[i].checked == true){
482         currentevent=i;
483       }
484     }
485     if(myreasons[currentevent] == 'C'){
486       document.getElementById('Ctable').style.display = 'inline';
487       document.getElementById('Stable').style.display = 'none';
488     }else if(myreasons[currentevent] == 'S'){
489       document.getElementById('Ctable').style.display = 'none';
490       document.getElementById('Stable').style.display = 'inline';
491     }else{
492       document.getElementById('Ctable').style.display = 'none';
493       document.getElementById('Stable').style.display = 'none';
494     }
495   }
496 </SCRIPT>
497
498 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
499 <TR><TD>
500 <TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
501 <% include('/elements/tr-select-reason.html', 'creason', 'C', $creason, $newcreasonT, $newcreason) %>
502 </TABLE>
503 </TR></TD>
504 </TABLE>
505
506 <TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
507 <TR><TD>
508 <TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
509 <% include('/elements/tr-select-reason.html', 'sreason', 'S', $sreason, $newsreasonT, $newsreason) %>
510 </TABLE>
511 </TR></TD>
512 </TABLE>
513     
514 %
515 %print qq!<INPUT TYPE="submit" VALUE="!,
516 %      $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
517 %      qq!">!;
518 %
519
520
521     </FORM>
522   </BODY>
523 </HTML>
524
525