add lec billing event
[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->pkgpart ? 'Edit' : 'Add';
24 my $hashref = $part_bill_event->hashref;
25
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',
29 ));
30
31 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
32       "</FONT>"
33   if $cgi->param('error');
34
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)";
39
40 print ntable("#cccccc",2), <<END;
41 <TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
42 END
43
44 for (qw(CARD CHEK LECB BILL COMP)) {
45   print qq!<OPTION VALUE="$_"!;
46   if ($part_bill_event->payby eq $_) {
47     print " SELECTED>$_</OPTION>";
48   } else {
49     print ">$_</OPTION>";
50   }
51 }
52
53 my $days = $hashref->{seconds}/86400;
54
55 print <<END;
56 </SELECT></TD></TR>
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>
59 END
60
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";
64 print '>';
65 print '</TD></TR>';
66
67 print '<TR><TD ALIGN="right">Action</TD><TD>';
68
69 #print ntable();
70
71 #this is pretty kludgy right here.
72 tie my %events, 'Tie::IxHash',
73
74   'fee' => {
75     'name'   => 'Late fee',
76     'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
77     'html'   => 
78       'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
79       '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
80     'weight' => 10,
81   },
82   'suspend' => {
83     'name'   => 'Suspend',
84     'code'   => '$cust_main->suspend();',
85     'weight' => 10,
86   },
87   'cancel' => {
88     'name'   => 'Cancel',
89     'code'   => '$cust_main->cancel();',
90     'weight' => 10,
91   },
92
93   'addpost' => {
94     'name' => 'Add postal invoicing',
95     'code' => '$cust_main->invoicing_list_addpost(); "";',
96     'weight'  => 20,
97   },
98
99   'comp' => {
100     'name' => 'Pay invoice with a complimentary "payment"',
101     'code' => '$cust_bill->comp();',
102     'weight' => 30,
103   },
104
105   'realtime-card' => {
106     'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
107     'code' => '$cust_bill->realtime_card();',
108     'weight' => 30,
109   },
110
111   'realtime-check' => {
112     'name' => 'Run check with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
113     'code' => '$cust_bill->realtime_ach();',
114     'weight' => 30,
115   },
116
117   'realtime-card-cybercash' => {
118     'name' => '(<b>deprecated</b>) Run card with <a href="http://www.cybercash.com/cashregister">CyberCash CashRegister</a> realtime gateway',
119     'code' => '$cust_bill->realtime_card_cybercash();',
120     'weight' => 30,
121   },
122
123   'realtime-lec' => {
124     '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',
125     'code' => '$cust_bill->realtime_lec();',
126     'weight' => 30,
127   },
128
129   'batch-card' => {
130     'name' => 'Add card to the pending credit card batch',
131     'code' => '$cust_bill->batch_card();',
132     'weight' => 40,
133   },
134
135   'send' => {
136     'name' => 'Send invoice (email/print)',
137     'code' => '$cust_bill->send();',
138     'weight' => 50,
139   },
140
141   'send_alternate' => {
142     'name' => 'Send invoice (email/print) with alternate template',
143     'code' => '$cust_bill->send(\'%%%templatename%%%\');',
144     'html' =>
145         '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
146     'weight' => 50,
147   },
148
149   'send_csv_ftp' => {
150     'name' => 'Upload CSV invoice data to an FTP server',
151     'code' => '$cust_bill->send_csv( protocol => \'ftp\',
152                                      server   => \'%%%ftpserver%%%\',
153                                      username => \'%%%ftpusername%%%\',
154                                      password => \'%%%ftppassword%%%\',
155                                      dir      => \'%%%ftpdir%%%\'       );',
156     'html' =>
157         '<TABLE BORDER=0><TR><TD ALIGN="right">FTP server: </TD>'.
158           '<TD><INPUT TYPE="text" NAME="ftpserver" VALUE="%%%ftpserver%%%">'.
159           '</TD></TR>'.
160         '<TR><TD ALIGN="right">FTP username: </TD><TD>'.
161           '<INPUT TYPE="text" NAME="ftpusername" VALUE="%%%ftpusername%%%">'.
162           '</TD></TR>'.
163         '<TR><TD ALIGN="right">FTP password: </TD><TD>'.
164           '<INPUT TYPE="text" NAME="ftppassword" VALUE="%%%ftppassword%%%">'.
165           '</TD></TR>'.
166         '<TR><TD ALIGN="right">FTP directory: </TD>'.
167           '<TD><INPUT TYPE="text" NAME="ftpdir" VALUE="%%%ftpdir%%%">'.
168           '</TD></TR>'.
169         '</TABLE>',
170     'weight' => 50,
171   },
172
173   'bill' => {
174     'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
175     'code' => '$cust_main->bill();',
176     'weight'  => 60,
177   },
178
179   'apply' => {
180     'name' => 'Apply unapplied payments and credits',
181     'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
182     'weight'  => 70,
183   },
184
185   'collect' => {
186     'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
187     'code' => '$cust_main->collect();',
188     'weight'  => 80,
189   },
190
191 ;
192
193 foreach my $event ( keys %events ) {
194   my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
195                    split(/\n/, $part_bill_event->plandata);
196   my $html = $events{$event}{html};
197   while ( $html =~ /%%%(\w+)%%%/ ) {
198     my $field = $1;
199     $html =~ s/%%%$field%%%/$plandata{$field}/;
200   }
201
202   print ntable( "#cccccc", 2).
203         qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
204   print "CHECKED " if $event eq $part_bill_event->plan;
205   print qq!VALUE="!.  $event. ":". $events{$event}{weight}. ":".
206         encode_entities($events{$event}{code}).
207         qq!">$events{$event}{name}</TD>!;
208   print '<TD>'. $html. '</TD>' if $html;
209   print qq!</TR>!;
210   print '</TABLE>';
211 }
212
213 #print '</TABLE>';
214
215 print <<END;
216 </TD></TR>
217 </TABLE>
218 END
219
220 print qq!<INPUT TYPE="submit" VALUE="!,
221       $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
222       qq!">!;
223 %>
224
225     </FORM>
226   </BODY>
227 </HTML>
228