This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / search / cust_credit_refund.html
1 <% include( 'elements/search.html',
2                 'title'       => $title,
3                 'name'        => 'net refunds',
4                 'query'       => $sql_query,
5                 'count_query' => $count_query,
6                 'count_addl'  => [ '$%.2f total refunded (net)', ],
7                 'header'      => [ 'Net applied',
8                                    'to Credit',
9                                    'Refund',
10                                    'By',
11                                    FS::UI::Web::cust_header(),
12                                  ],
13                'fields'      => [
14                    sub { $money_char. sprintf('%.2f', shift->amount ) },
15                    sub { my $ccr = shift;
16                          '#'.$ccr->crednum. ' '.
17                          time2str('%b %d %Y', $ccr->cust_credit_date ).
18                          " ($money_char".
19                            sprintf('%.2f', $ccr->cust_credit_amount).
20                          ")" 
21                        },
22                    sub { my $ccr = shift;
23                          time2str('%b %d %Y', $ccr->_date ).
24                          " ($money_char".
25                          sprintf('%.2f', $ccr->cust_refund_refund ).
26                          ")"
27                        },
28                    sub { shift->cust_refund->otaker },
29                    \&FS::UI::Web::cust_fields,
30                 ],
31                 'align' => 'rrrl'.FS::UI::Web::cust_aligns(),
32                 'links' => [
33                              '',
34                              '',
35                              '',
36                              '',
37                              ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
38                                    FS::UI::Web::cust_header()
39                              ),
40                            ],
41                 'color' => [ 
42                              '',
43                              '',
44                              '',
45                              '',
46                              FS::UI::Web::cust_colors(),
47                            ],
48                 'style' => [ 
49                              '',
50                              '',
51                              '',
52                              '',
53                              FS::UI::Web::cust_styles(),
54                            ],
55           )
56 %>
57 <%init>
58
59 die "access denied"
60   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
61
62 my $conf = new FS::Conf;
63 my $money_char = $conf->config('money_char') || '$';
64
65 my $title = 'Net Refund Search Results';
66
67 my @search = ();
68
69 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
70   push @search, "agentnum = $1";
71   my $agent = qsearchs('agent', { 'agentnum' => $1 } );
72   die "unknown agentnum $1" unless $agent;
73   $title = $agent->agent. " $title";
74 }
75
76 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
77 push @search, "cust_credit._date >= $beginning ",
78               "cust_credit._date <= $ending";
79
80 #here is the agent virtualization
81 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
82
83 my $where = 'WHERE '. join(' AND ', @search);
84 #
85 my $count_query = 'SELECT COUNT(*), SUM(cust_credit_refund.amount)
86                    FROM cust_credit_refund
87                      LEFT JOIN cust_credit USING ( crednum )
88                      LEFT JOIN cust_main   USING ( custnum ) '.
89                   $where;
90
91 my $sql_query   = {
92   'table'     => 'cust_credit_refund',
93   'select'    => join(', ',
94                    'cust_credit_refund.*',
95                    'cust_refund.refund  AS cust_refund_refund',
96                    'cust_credit._date   AS cust_credit_date',
97                    'cust_credit.amount  AS cust_credit_amnount',
98                    'cust_refund.custnum AS custnum',
99                    'cust_main.custnum   AS cust_main_custnum',
100                    FS::UI::Web::cust_sql_fields(),
101                  ),
102   'hashref'   => {},
103   'extra_sql' => $where,
104   'addl_from' => 'LEFT JOIN cust_credit USING ( crednum   )
105                   LEFT JOIN cust_refund USING ( refundnum )
106                   LEFT JOIN cust_main ON ( cust_credit.custnum = cust_main.custnum )',
107 };
108
109 #my $cust_credit_link = sub {
110 #  my $cust_credit_refund = shift;
111 #  $cust_credit_refund->crednum
112 #    ? [ "${p}view/cust_credit.cgi?", 'credum' ]
113 #    : '';
114 #};
115
116 #my $cust_refund_link = sub {
117 #  my $cust_credit_refund = shift;
118 #  $cust_credit_refund->refundnum
119 #    ? [ "${p}view/cust_refund.cgi?", 'refundnum' ]
120 #    : '';
121 #};
122
123 my $cust_link = sub {
124   my $cust_credit_refund = shift;
125   $cust_credit_refund->cust_main_custnum
126     ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]
127     : '';
128 };
129
130 </%init>