summaryrefslogtreecommitdiff
path: root/httemplate/search/cust_main_credit_limit.html
blob: 902dbbc0a29a69a548434483a1e93c29bfe3d753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<& elements/search.html,
     'title'         => 'Credit limit incidents',
     'name_singular' => 'incident',
     'query'         => $query,
     'count_query'   => "SELECT COUNT(*) FROM cust_main_credit_limit",
     'header'        => [ 'Date',

                          #XXX should use cust_fields etc.
                          '#',
                          'Customer',

                          'Amount',
                          'Limit',
                        ],
     'fields'        => [ sub { time2str($date_format, shift->_date); },

                          #XXX should use cust_fields etc.
                          sub { shift->cust_main->display_custnum },
                          sub { shift->cust_main->name },

                          sub { $money_char. shift->amount },
                          sub { $money_char. shift->credit_limit },
                        ],

     'links'         => [ '',

                          #XXX should use cust_fields etc.
                          $cust_link,
                          $cust_link,

                          '',
                          '',
                        ],
&>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('List rating data');

my $conf = new FS::Conf;

my $date_format = $conf->config('date_format') || '%m/%d/%Y';

my $money_char = $conf->config('money_char') || '$';

my $cust_link = [ "${p}view/cust_main.cgi?", 'custnum' ];

my ($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
my $dates_sql = "_date >= $begin AND _date < $end";

my $count_query= "SELECT COUNT(*) FROM cust_main_credit_limit WHERE $dates_sql";

my %hash = ();
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
  $hash{custnum} = $1;
  $count_query .= " AND custnum = $1";
}

my $query = {
  table     => 'cust_main_credit_limit',
  hashref   => \%hash,
  extra_sql => ( keys(%hash) ? ' AND ' : ' WHERE ' ). $dates_sql,
  order_by  => 'ORDER BY _date ASC',
};

</%init>