This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / httemplate / search / cust_pay_batch.cgi
1 <% include('elements/search.html',
2               'title'       => 'Batch payment details',
3               'name'        => 'batch details',
4               'query'       => $sql_query,
5               'count_query' => $count_query,
6               'html_init'   => $pay_batch ? 
7                                   include('elements/cust_pay_batch_top.html',
8                                           'pay_batch' => $pay_batch
9                                   ) : '',
10               'header'      => [ '#',
11                                  'Inv #',
12                                  'Customer',
13                                  'Customer',
14                                  'Card Name',
15                                  'Card',
16                                  'Exp',
17                                  'Amount',
18                                  'Status',
19                                ],
20               'fields'      => [ sub {
21                                    shift->[0];
22                                  },
23                                  sub {
24                                    shift->[1];
25                                  },
26                                  sub {
27                                    shift->[2];
28                                  },
29                                  sub {
30                                    my $cpb = shift;
31                                    $cpb->[3] . ', ' . $cpb->[4];
32                                  },
33                                  sub {
34                                    shift->[5];
35                                  },
36                                  sub {
37                                    my $cardnum = shift->[6];
38                                    'x'x(length($cardnum)-4). substr($cardnum,(length($cardnum)-4));
39                                  },
40                                  sub {
41                                    shift->[7] =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
42                                    my( $mon, $year ) = ( $2, $1 );
43                                    $mon = "0$mon" if length($mon) == 1;
44                                    "$mon/$year";
45                                  },
46                                  sub {
47                                    shift->[8];
48                                  },
49                                  sub {
50                                    shift->[9];
51                                  },
52                                ],
53               'align'       => 'lllllllrl',
54               'links'       => [ ['', sub{'#';}],
55                                  ["${p}view/cust_bill.cgi?", sub{shift->[1];},],
56                                  ["${p}view/cust_main.cgi?", sub{shift->[2];},],
57                                  ["${p}view/cust_main.cgi?", sub{shift->[2];},],
58                                ],
59       )
60 %>
61 <%init>
62
63 my $conf = new FS::Conf;
64
65 die "access denied"
66   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
67       || $FS::CurrentUser::CurrentUser->access_right('Process batches')
68       || ( $cgi->param('custnum') 
69            && (    $conf->exists('batch-enable')
70                 || $conf->config('batch-enable_payby')
71               )
72          );
73
74 my( $count_query, $sql_query );
75 my $hashref = {};
76 my @search = ();
77 my $orderby = 'paybatchnum';
78
79 my( $pay_batch, $batchnum ) = ( '', '');
80 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
81   push @search, "batchnum = $1";
82   $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
83   die "Batch $1 not found!" unless $pay_batch;
84   $batchnum = $pay_batch->batchnum;
85 }
86
87 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
88   push @search, "custnum = $1";
89 }
90
91 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
92   push @search, "pay_batch.status = '$1'";
93 }
94
95 if ( $cgi->param('payby') ) {
96   $cgi->param('payby') =~ /^(CARD|CHEK)$/
97     or die "illegal payby " . $cgi->param('payby');
98
99   push @search, "cust_pay_batch.payby = '$1'";
100 }
101
102 if ( not $cgi->param('dcln') ) {
103   push @search, "cpb.status IS DISTINCT FROM 'Approved'";
104 }
105
106 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
107 unless ($pay_batch){
108   push @search, "pay_batch.upload >= $beginning" if ($beginning);
109   push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
110   $orderby = "pay_batch.download,paybatchnum";
111 }
112
113 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
114 my $search = ' WHERE ' . join(' AND ', @search);
115
116 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch AS cpb ' .
117                   'LEFT JOIN cust_main USING ( custnum ) ' .
118                   'LEFT JOIN pay_batch USING ( batchnum )' .
119                   $search;
120
121 #grr
122 $sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," .
123              "cpb.payname,cpb.payinfo,cpb.exp,amount,cpb.status " .
124              "FROM cust_pay_batch AS cpb " .
125              'LEFT JOIN cust_main USING ( custnum ) ' .
126              'LEFT JOIN pay_batch USING ( batchnum ) ' .
127              "$search ORDER BY $orderby";
128
129 my $html_init = '';
130 if ( $pay_batch ) {
131   $html_init = include('elements/cust_pay_batch_top.html', 
132                     'pay_batch' => $pay_batch);
133 }
134 </%init>