580e46734795910f6f29401b1ad9a09bc8056d25
[freeside.git] / httemplate / edit / part_bill_event.cgi
1 <!-- $Id: part_bill_event.cgi,v 1.5 2002-02-04 17:04:33 ivan Exp $ -->
2
3 <%
4
5 if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
6   $cgi->param('eventpart', $1);
7 } else {
8   $cgi->param('eventpart', '');
9 }
10
11 my ($query) = $cgi->keywords;
12 my $action = '';
13 my $part_bill_event = '';
14 if ( $cgi->param('error') ) {
15   $part_bill_event = new FS::part_bill_event ( {
16     map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
17   } );
18 }
19 if ( $query && $query =~ /^(\d+)$/ ) {
20   $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
21 } else {
22   $part_bill_event ||= new FS::part_bill_event {};
23 }
24 $action ||= $part_bill_event->pkgpart ? 'Edit' : 'Add';
25 my $hashref = $part_bill_event->hashref;
26
27 print header("$action Invoice Event Definition", menubar(
28   'Main Menu' => popurl(2),
29   'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
30 ));
31
32 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
33       "</FONT>"
34   if $cgi->param('error');
35
36 print '<FORM ACTION="', popurl(1), 'process/part_bill_event.cgi" METHOD=POST>'.
37       '<INPUT TYPE="hidden" NAME="eventpart" VALUE="'.
38       $part_bill_event->eventpart  .'">';
39 print "Invoice Event #", $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)";
40
41 print ntable("#cccccc",2), <<END;
42 <TR><TD ALIGN="right">Payby</TD><TD><SELECT NAME="payby">
43 END
44
45 for (qw(CARD BILL COMP)) {
46   print qq!<OPTION VALUE="$_"!;
47   if ($part_bill_event->payby eq $_) {
48     print " SELECTED>$_</OPTION>";
49   } else {
50     print ">$_</OPTION>";
51   }
52 }
53
54 my $days = $hashref->{seconds}/86400;
55
56 print <<END;
57 </SELECT></TD></TR>
58 <TR><TD ALIGN="right">Event</TD><TD><INPUT TYPE="text" NAME="event" VALUE="$hashref->{event}"></TD></TR>
59 <TR><TD ALIGN="right">After</TD><TD><INPUT TYPE="text" NAME="days" VALUE="$days"> days</TD></TR>
60 END
61
62 print '<TR><TD ALIGN="right">Disabled</TD><TD>';
63 print '<INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"';
64 print ' CHECKED' if $hashref->{disabled} eq "Y";
65 print '>';
66 print '</TD></TR>';
67
68 print '<TR><TD ALIGN="right">Action</TD><TD>';
69
70 #print ntable();
71
72 #this is pretty kludgy right here.
73 tie my %events, 'Tie::IxHash',
74
75   'fee' => {
76     'name'   => 'Late fee',
77     'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
78     'html'   => 
79       'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
80       '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
81     'weight' => 10,
82   },
83   'suspend' => {
84     'name'   => 'Suspend',
85     'code'   => '$cust_main->suspend();',
86     'weight' => 10,
87   },
88   'cancel' => {
89     'name'   => 'Cancel',
90     'code'   => '$cust_main->cancel();',
91     'weight' => 10,
92   },
93
94   'addpost' => {
95     'name' => 'Add postal invoicing',
96     'code' => '$cust_main->invoicing_list_addpost(); "";',
97     'pad'  => 20,
98   },
99
100   'comp' => {
101     'name' => 'Pay invoice with a complimentary "payment"',
102     'code' => '$cust_bill->comp();',
103     'weight' => 30,
104   },
105
106   'realtime-card' => {
107     'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
108     'code' => '$cust_bill->realtime_card();',
109     'weight' => 30,
110   },
111
112   'realtime-card-cybercash' => {
113     'name' => '(<b>deprecated</b>) Run card with <a href="http://www.cybercash.com/cashregister">CyberCash CashRegister</a> realtime gateway',
114     'code' => '$cust_bill->realtime_card_cybercash();',
115     'weight' => 30,
116   },
117
118   'batch-card' => {
119     'name' => 'Add card to the pending credit card batch',
120     'code' => '$cust_bill->batch_card();',
121     'weight' => 40,
122   },
123
124   'send' => {
125     'name' => 'Send invoice (email/print)',
126     'code' => '$cust_bill->send();',
127     'weight' => 50,
128   },
129
130   'bill' => {
131     'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
132     'code' => '$cust_main->bill();',
133     'weight'  => 60,
134   },
135
136   'apply' => {
137     'name' => 'Apply unapplied payments and credits',
138     'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
139     'weight'  => 70,
140   },
141
142   'collect' => {
143     'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
144     'code' => '$cust_main->collect();',
145     'weight'  => 80,
146   },
147
148 ;
149
150 foreach my $event ( keys %events ) {
151   my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
152                    split(/\n/, $part_bill_event->plandata);
153   my $html = $events{$event}{html};
154   while ( $html =~ /%%%(\w+)%%%/ ) {
155     my $field = $1;
156     $html =~ s/%%%$field%%%/$plandata{$field}/;
157   }
158
159   print ntable( "#cccccc", 2).
160         qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
161   print "CHECKED " if $event eq $part_bill_event->plan;
162   print qq!VALUE="!.  $event. ":". $events{$event}{weight}. ":".
163         encode_entities($events{$event}{code}).
164         qq!">$events{$event}{name}</TD>!;
165   print '<TD>'. $html. '</TD>' if $html;
166   print qq!</TR>!;
167   print '</TABLE>';
168 }
169
170 #print '</TABLE>';
171
172 print <<END;
173 </TD></TR>
174 </TABLE>
175 END
176
177 print qq!<INPUT TYPE="submit" VALUE="!,
178       $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
179       qq!">!;
180 %>
181
182     </FORM>
183   </BODY>
184 </HTML>
185