default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / misc / xmlhttp-reason-hint.html
1 <%doc>
2 Example:
3
4 <& /elements/xmlhttp.html,
5   url => $p . 'misc/xmlhttp-reason-hint.html',
6   subs => [ 'get_hint' ]
7 &>
8 <script>
9 var reasonnum = 101;
10 get_hint( reasonnum, function(stuff) { alert(stuff); } )
11 </script>
12
13 Currently will provide hints for:
14 1. suspension events (new-style reconnection fees, notification)
15 2. unsuspend_pkgpart package info (older reconnection fees)
16 3. crediting for unused time
17 </%doc>
18 <%init>
19 my $sub = $cgi->param('sub');
20 my ($reasonnum) = $cgi->param('arg');
21 # arg is a reasonnum
22 my $conf = FS::Conf->new;
23 my $error = '';
24 my @hints;
25 if ( $reasonnum =~ /^\d+$/ ) {
26   my $reason = FS::reason->by_key($reasonnum);
27   if ( $reason ) {
28     # 1.
29     if ( $reason->feepart ) { # XXX
30       my $part_fee = FS::part_fee->by_key($reason->feepart);
31       my $when = '';
32       if ( $reason->fee_hold ) {
33         $when = 'on the next bill after ';
34       } else {
35         $when = 'upon ';
36       }
37       if ( $reason->fee_on_unsuspend ) {
38         $when .= 'unsuspension';
39       } else {
40         $when .= 'suspension';
41       }
42
43       my $fee_amt = $part_fee->explanation;
44       push @hints, mt('A fee of [_1] will be charged [_2].',
45                       $fee_amt, $when);
46     }
47     # 2.
48     if ( $reason->unsuspend_pkgpart ) {
49       my $part_pkg = FS::part_pkg->by_key($reason->unsuspend_pkgpart);
50       if ( $part_pkg ) {
51         if ( $part_pkg->option('setup_fee',1) > 0 and 
52              $part_pkg->option('recur_fee',1) == 0 ) {
53           # the usual case
54           push @hints,
55             mt('A [_1] unsuspension fee will apply.',
56                ($conf->config('money_char') || '$') .
57                sprintf('%.2f', $part_pkg->option('setup_fee'))
58                );
59         } else {
60           # oddball cases--not really supported
61           push @hints,
62             mt('An unsuspension package will apply: [_1]',
63               $part_pkg->price_info
64               );
65         }
66       } else { #no $part_pkg
67         push @hints,
68           '<FONT COLOR="#ff0000">Unsuspend pkg #'.$reason->unsuspend_pkgpart.
69           ' not found.</FONT>';
70       }
71     }
72     # 3.
73     if ( $reason->unused_credit ) {
74       push @hints, mt('The customer will be credited for unused time.');
75     }
76   } else {
77     warn "reasonnum $reasonnum not found; returning no hints\n";
78   }
79 } else {
80   warn "reason-hint arg '$reasonnum' not a valid reasonnum\n";
81 }
82 </%init>
83 <% join('<BR>', @hints) %>