Will things ever be the same again?
[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 to the pending credit card batch',
219 %    'code' => '$cust_bill->batch_card();',
220 %    'weight' => 40,
221 %  },
222 %
223 %  'send' => {
224 %    'name' => 'Send invoice (email/print/fax)',
225 %    'code' => '$cust_bill->send();',
226 %    'weight' => 50,
227 %  },
228 %
229 %  'send_alternate' => {
230 %    'name' => 'Send invoice (email/print/fax) with alternate template',
231 %    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
232 %    'html' =>
233 %        '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
234 %    'weight' => 50,
235 %  },
236 %
237 %  'send_if_newest' => {
238 %    '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)',
239 %    'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');',
240 %    'html' =>
241 %        '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
242 %    'weight' => 50,
243 %  },
244 %
245 %  'send_agent' => {
246 %    'name' => 'Send invoice (email/print/fax) ',
247 %    'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
248 %    'html' => sub {
249 %        '<TABLE BORDER=0>
250 %          <TR>
251 %            <TD ALIGN="right">only for agent(s) </TD>
252 %            <TD>'. &select_agentnum(@_). '</TD>
253 %          </TR>
254 %          <TR>
255 %            <TD ALIGN="right">with template </TD>
256 %            <TD>
257 %              <INPUT TYPE="text" NAME="agent_templatename" VALUE="%%%agent_templatename%%%">
258 %            </TD>
259 %          </TR>
260 %          <TR>
261 %            <TD ALIGN="right">email From: </TD>
262 %            <TD>
263 %              <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
264 %            </TD>
265 %          </TR>
266 %        </TABLE>';
267 %    },
268 %    'weight' => 50,
269 %  },
270 %
271 %  'send_csv_ftp' => {
272 %    'name' => 'Upload CSV invoice data to an FTP server',
273 %    'code' => '$cust_bill->send_csv( protocol   => \'ftp\',
274 %                                     server     => \'%%%ftpserver%%%\',
275 %                                     username   => \'%%%ftpusername%%%\',
276 %                                     password   => \'%%%ftppassword%%%\',
277 %                                     dir        => \'%%%ftpdir%%%\',
278 %                                     \'format\' => \'%%%ftpformat%%%\',
279 %                                   );',
280 %    'html' =>
281 %        '<TABLE BORDER=0>'.
282 %        '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
283 %          '<TD>'.
284 %            '<!--'.
285 %            '<SELECT NAME="ftpformat">'.
286 %              '<OPTION VALUE="default">Default'.
287 %              '<OPTION VALUE="billco">Billco'.
288 %            '</SELECT>'.
289 %            '-->'.
290 %            '<INPUT TYPE="text" NAME="ftpformat" VALUE="%%%ftpformat%%%">'.
291 %          '</TD></TR>'.
292 %        '<TR><TD ALIGN="right">FTP server: </TD>'.
293 %          '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
294 %          '</TD></TR>'.
295 %        '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
296 %          '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
297 %          '</TD></TR>'.
298 %        '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
299 %          '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
300 %          '</TD></TR>'.
301 %        '<TR><TD ALIGN="right">FTP directory: </TD>'.
302 %          '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
303 %          '</TD></TR>'.
304 %        '</TABLE>',
305 %    'weight' => 50,
306 %  },
307 %
308 %  'spool_csv' => {
309 %    'name' => 'Spool CSV invoice data',
310 %    'code' => '$cust_bill->spool_csv(
311 %                 \'format\' => \'%%%spoolformat%%%\',
312 %                 \'dest\'   => \'%%%spooldest%%%\',
313 %                 \'balanceover\' => \'%%%spoolbalanceover%%%\',
314 %                 \'agent_spools\' => \'%%%spoolagent_spools%%%\',
315 %               );',
316 %    'html' => sub {
317 %       my $plandata = shift;
318 %
319 %       my $html =
320 %       '<TABLE BORDER=0>'.
321 %       '<TR><TD ALIGN="right">Format: </TD>'.
322 %         '<TD>'.
323 %           '<SELECT NAME="spoolformat">';
324 %
325 %       foreach my $option (qw( default billco )) {
326 %         $html .= qq(<OPTION VALUE="$option");
327 %         $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
328 %         $html .= ">\u$option";
329 %       }
330 %
331 %       $html .= 
332 %           '</SELECT>'.
333 %         '</TD></TR>'.
334 %       '<TR><TD ALIGN="right">For destination: </TD>'.
335 %         '<TD>'.
336 %           '<SELECT NAME="spooldest">';
337 %
338 %       tie my %dest, 'Tie::IxHash', 
339 %         ''      => '(all)',
340 %         'POST'  => 'Postal Mail',
341 %         'EMAIL' => 'Email',
342 %         'FAX'   => 'Fax',
343 %       ;
344 %
345 %       foreach my $dest (keys %dest) {
346 %         $html .= qq(<OPTION VALUE="$dest");
347 %         $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
348 %         $html .= '>'. $dest{$dest};
349 %       }
350 %
351 %       $html .=
352 %           '</SELECT>'.
353 %         '</TD></TR>'.
354 %
355 %       '<TR>'.
356 %         '<TD ALIGN="right">if balance (this invoice and previous) over </TD>'.
357 %         '<TD>'.
358 %           "$money_char ".
359 %           '<INPUT TYPE="text" SIZE="7" NAME="spoolbalanceover" VALUE="%%%spoolbalanceover%%%">'.
360 %         '</TD>'.
361 %       '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
362 %         '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
363 %           ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
364 %           '>'.
365 %         '</TD></TR>'.
366 %       '</TABLE>';
367 %
368 %       $html;
369 %    },
370 %    'weight' => 50,
371 %  },
372 %
373 %  'bill' => {
374 %    'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
375 %    'code' => '$cust_main->bill();',
376 %    'weight'  => 60,
377 %  },
378 %
379 %  'apply' => {
380 %    'name' => 'Apply unapplied payments and credits',
381 %    'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
382 %    'weight'  => 70,
383 %  },
384 %
385 %  'collect' => {
386 %    'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
387 %    'code' => '$cust_main->collect();',
388 %    'weight'  => 80,
389 %  },
390 %
391 %;
392 %
393 %foreach my $event ( keys %events ) {
394 %  my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
395 %                   split(/\n/, $part_bill_event->plandata);
396 %  my $html = $events{$event}{html};
397 %  if ( ref($html) eq 'CODE' ) {
398 %    $html = &{$html}(\%plandata);
399 %  }
400 %  while ( $html =~ /%%%(\w+)%%%/ ) {
401 %    my $field = $1;
402 %    $html =~ s/%%%$field%%%/$plandata{$field}/;
403 %  }
404 %
405 %  print ntable( "#cccccc", 2).
406 %        qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
407 %  print "CHECKED " if $event eq $part_bill_event->plan;
408 %  print qq!VALUE="!.  $event. ":". $events{$event}{weight}. ":".
409 %        encode_entities($events{$event}{code}).
410 %        qq!">$events{$event}{name}</TD>!;
411 %  print '<TD>'. $html. '</TD>' if $html;
412 %  print qq!</TR>!;
413 %  print '</TABLE>';
414 %}
415 %
416 %#print '</TABLE>';
417 %
418 %print <<END;
419 %</TD></TR>
420 %</TABLE>
421 %END
422 %
423 %print qq!<INPUT TYPE="submit" VALUE="!,
424 %      $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
425 %      qq!">!;
426 %
427
428
429     </FORM>
430   </BODY>
431 </HTML>
432