This commit was generated by cvs2svn to compensate for changes in r4888,
[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 ($query) = $cgi->keywords;
11 %my $action = '';
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')
16 %  } );
17 %}
18 %if ( $query && $query =~ /^(\d+)$/ ) {
19 %  $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
20 %} else {
21 %  $part_bill_event ||= new FS::part_bill_event {};
22 %}
23 %$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
24 %my $hashref = $part_bill_event->hashref;
25 %
26 %
27
28
29 <% include('/elements/header.html',
30       "$action Invoice Event Definition",
31       menubar(
32         'Main Menu' => popurl(2),
33         'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
34       )
35     )
36 %>
37 % if ( $cgi->param('error') ) { 
38
39   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
40 % } 
41
42
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)" %>
46
47 <%  ntable("#cccccc",2) %>
48
49   <TR>
50     <TD ALIGN="right">Event name </TD>
51     <TD><INPUT TYPE="text" NAME="event" VALUE="<% $hashref->{event} %>"></TD>
52   </TR>
53
54   <TR>
55     <TD ALIGN="right">For </TD>
56     <TD>
57       <SELECT NAME="payby">
58 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
59 %           foreach my $payby ( keys %payby ) {
60 %        
61
62
63           <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
64 % } 
65
66
67       </SELECT> customers
68     </TD>
69   </TR>
70 % my $days = $hashref->{seconds}/86400; 
71
72
73   <TR>
74     <TD ALIGN="right">After</TD>
75     <TD><INPUT TYPE="text" NAME="days" VALUE="<% $days %>"> days</TD>
76   </TR>
77
78   <TR>
79     <TD ALIGN="right">Test event</TD>
80     <TD>
81       <SELECT NAME="freq">
82 % tie my %freq, 'Tie::IxHash', '1d' => 'daily', '1m' => 'monthly';
83 %           foreach my $freq ( keys %freq ) {
84 %        
85
86
87           <OPTION VALUE="<% $freq %>"<% ($part_bill_event->freq eq $freq) ? ' SELECTED' : '' %>><% $freq{$freq} %></OPTION>
88 % } 
89
90
91       </SELECT>
92     </TD>
93   </TR>
94
95
96   <TR>
97     <TD ALIGN="right">Disabled</TD>
98     <TD>
99       <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>>
100     </TD>
101   </TR>
102
103   <TR>
104     <TD VALIGN="top" ALIGN="right">Action</TD>
105     <TD>
106 %
107 %
108 %#print ntable();
109 %
110 %sub select_pkgpart {
111 %  my $label = shift;
112 %  my $plandata = shift;
113 %  my %selected = map { $_=>1 } split(/,\s*/, $plandata->{$label});
114 %  qq(<SELECT NAME="$label" MULTIPLE>).
115 %  join("\n", map {
116 %    '<OPTION VALUE="'. $_->pkgpart. '"'.
117 %    ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
118 %    '>'. $_->pkg. ' - '. $_->comment
119 %  } qsearch('part_pkg', { 'disabled' => '' } ) ).
120 %  '</SELECT>';
121 %}
122 %
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>'.
128 %  join("\n", map {
129 %    '<OPTION VALUE="'. $_->agentnum. '"'.
130 %    ( $agentnums{$_->agentnum} ? ' SELECTED' : '' ).
131 %    '>'. $_->agent
132 %  } qsearch('agent', { 'disabled' => '' } ) ).
133 %  '</SELECT>';
134 %}
135 %
136 %my $conf = new FS::Conf;
137 %my $money_char = $conf->config('money_char') || '$';
138 %
139 %#this is pretty kludgy right here.
140 %tie my %events, 'Tie::IxHash',
141 %
142 %  'fee' => {
143 %    'name'   => 'Late fee (flat)',
144 %    'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
145 %    'html'   => 
146 %      'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
147 %      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
148 %    'weight' => 10,
149 %  },
150 %  'fee_percent' => {
151 %    'name'   => 'Late fee (percentage)',
152 %    'code'   => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
153 %    'html'   => 
154 %      'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
155 %      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
156 %    'weight' => 10,
157 %  },
158 %  'suspend' => {
159 %    'name'   => 'Suspend',
160 %    'code'   => '$cust_main->suspend();',
161 %    'weight' => 10,
162 %  },
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%%%">',
167 %    'weight' => 10,
168 %  },
169 %  'suspend-if-pkgpart' => {
170 %    'name'   => 'Suspend packages',
171 %    'code'   => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
172 %    'html'   => sub { &select_pkgpart('if_pkgpart', @_) },
173 %    'weight' => 10,
174 %  },
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', @_) },
179 %    'weight' => 10,
180 %  },
181 %  'cancel' => {
182 %    'name'   => 'Cancel',
183 %    'code'   => '$cust_main->cancel();',
184 %    'weight' => 10,
185 %  },
186 %
187 %  'addpost' => {
188 %    'name' => 'Add postal invoicing',
189 %    'code' => '$cust_main->invoicing_list_addpost(); "";',
190 %    'weight'  => 20,
191 %  },
192 %
193 %  'comp' => {
194 %    'name' => 'Pay invoice with a complimentary "payment"',
195 %    'code' => '$cust_bill->comp();',
196 %    'weight' => 30,
197 %  },
198 %
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();',
202 %    'weight' => 30,
203 %  },
204 %
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();',
208 %    'weight' => 30,
209 %  },
210 %
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();',
214 %    'weight' => 30,
215 %  },
216 %
217 %  'batch-card' => {
218 %    'name' => 'Add card or check to a pending batch',
219 %    'code' => '$cust_bill->batch_card(%options);',
220 %    'weight' => 40,
221 %  },
222 %
223 %  
224 %  #'retriable' => {
225 %  #  'name' => 'Mark batched card event as retriable',
226 %  #  'code' => '$cust_pay_batch->retriable();',
227 %  #  'weight' => 60,
228 %  #},
229 %
230 %  'send' => {
231 %    'name' => 'Send invoice (email/print/fax)',
232 %    'code' => '$cust_bill->send();',
233 %    'weight' => 50,
234 %  },
235 %
236 %  'send_alternate' => {
237 %    'name' => 'Send invoice (email/print/fax) with alternate template',
238 %    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
239 %    'html' =>
240 %        '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
241 %    'weight' => 50,
242 %  },
243 %
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%%%\');',
247 %    'html' =>
248 %        '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
249 %    'weight' => 50,
250 %  },
251 %
252 %  'send_agent' => {
253 %    'name' => 'Send invoice (email/print/fax) ',
254 %    'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
255 %    'html' => sub {
256 %        '<TABLE BORDER=0>
257 %          <TR>
258 %            <TD ALIGN="right">only for agent(s) </TD>
259 %            <TD>'. &select_agentnum(@_). '</TD>
260 %          </TR>
261 %          <TR>
262 %            <TD ALIGN="right">with template </TD>
263 %            <TD>
264 %              <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
265 %            </TD>
266 %          </TR>
267 %          <TR>
268 %            <TD ALIGN="right">email From: </TD>
269 %            <TD>
270 %              <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
271 %            </TD>
272 %          </TR>
273 %        </TABLE>';
274 %    },
275 %    'weight' => 50,
276 %  },
277 %
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%%%\',
286 %                                   );',
287 %    'html' =>
288 %        '<TABLE BORDER=0>'.
289 %        '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
290 %          '<TD>'.
291 %            '<!--'.
292 %            '<SELECT NAME="ftpformat">'.
293 %              '<OPTION VALUE="default">Default'.
294 %              '<OPTION VALUE="billco">Billco'.
295 %            '</SELECT>'.
296 %            '-->'.
297 %            '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
298 %          '</TD></TR>'.
299 %        '<TR><TD ALIGN="right">FTP server: </TD>'.
300 %          '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
301 %          '</TD></TR>'.
302 %        '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
303 %          '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
304 %          '</TD></TR>'.
305 %        '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
306 %          '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
307 %          '</TD></TR>'.
308 %        '<TR><TD ALIGN="right">FTP directory: </TD>'.
309 %          '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
310 %          '</TD></TR>'.
311 %        '</TABLE>',
312 %    'weight' => 50,
313 %  },
314 %
315 %  'spool_csv' => {
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%%%\',
322 %               );',
323 %    'html' => sub {
324 %       my $plandata = shift;
325 %
326 %       my $html =
327 %       '<TABLE BORDER=0>'.
328 %       '<TR><TD ALIGN="right">Format: </TD>'.
329 %         '<TD>'.
330 %           '<SELECT NAME="spoolformat">';
331 %
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";
336 %       }
337 %
338 %       $html .= 
339 %           '</SELECT>'.
340 %         '</TD></TR>'.
341 %       '<TR><TD ALIGN="right">For destination: </TD>'.
342 %         '<TD>'.
343 %           '<SELECT NAME="spooldest">';
344 %
345 %       tie my %dest, 'Tie::IxHash', 
346 %         ''      => '(all)',
347 %         'POST'  => 'Postal Mail',
348 %         'EMAIL' => 'Email',
349 %         'FAX'   => 'Fax',
350 %       ;
351 %
352 %       foreach my $dest (keys %dest) {
353 %         $html .= qq(<OPTION VALUE="$dest");
354 %         $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
355 %         $html .= '>'. $dest{$dest};
356 %       }
357 %
358 %       $html .=
359 %           '</SELECT>'.
360 %         '</TD></TR>'.
361 %
362 %       '<TR>'.
363 %         '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
364 %         '<TD>'.
365 %           "$money_char ".
366 %           '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
367 %         '</TD>'.
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' : '' ).
371 %           '>'.
372 %         '</TD></TR>'.
373 %       '</TABLE>';
374 %
375 %       $html;
376 %    },
377 %    'weight' => 50,
378 %  },
379 %
380 %  'bill' => {
381 %    'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
382 %    'code' => '$cust_main->bill();',
383 %    'weight'  => 60,
384 %  },
385 %
386 %  'apply' => {
387 %    'name' => 'Apply unapplied payments and credits',
388 %    'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
389 %    'weight'  => 70,
390 %  },
391 %
392 %  'collect' => {
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();',
395 %    'weight'  => 80,
396 %  },
397 %
398 %;
399 %
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);
406 %  }
407 %  while ( $html =~ /%%%(\w+)%%%/ ) {
408 %    my $field = $1;
409 %    $html =~ s/%%%$field%%%/$plandata{$field}/;
410 %  }
411 %
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;
419 %  print qq!</TR>!;
420 %  print '</TABLE>';
421 %}
422 %
423 %#print '</TABLE>';
424 %
425 %print <<END;
426 %</TD></TR>
427 %</TABLE>
428 %END
429 %
430 %print qq!<INPUT TYPE="submit" VALUE="!,
431 %      $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
432 %      qq!">!;
433 %
434
435
436     </FORM>
437   </BODY>
438 </HTML>
439
440