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