Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / customer_accounting_summary.html
1 <% include('/graph/elements/monthly.html',
2    #Dumper(
3                 'title'        => $title,
4                 'graph_type'   => 'none',
5                 'items'        => \@items,
6                 'params'       => \@params,
7                 'labels'       => \@labels,
8                 'graph_labels' => \@labels,
9                 'remove_empty' => 1,
10                 'bottom_total' => 1,
11                 'agentnum'     => $agentnum,
12                 'doublemonths' => \@doublemonths,
13                 'nototal'       => 1,
14              )
15 %>
16 <%init>
17
18 die "access denied"
19   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
20
21 my @doublemonths = ( 'Billed', 'Paid' );
22
23 my ($agentnum,$sel_agent);
24 if ( $cgi->param('agentnum') eq 'all' ) {
25   $agentnum = 0;
26 }
27 elsif ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
28   $agentnum = $1;
29   $sel_agent = qsearchs('agent', { 'agentnum' => $agentnum } );
30   die "agentnum $agentnum not found!" unless $sel_agent;
31 }
32 my $title = $sel_agent ? $sel_agent->agent.' ' : '';
33
34 my ($refnum,$sel_part_referral);
35 #if ( $cgi->param('refnum') eq 'all' ) {
36 #  $refnum = 0;
37 #} els
38 if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
39   $refnum = $1;
40   $sel_part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
41   die "refnum $refnum not found!" unless $sel_part_referral;
42 }
43 $title .=  $sel_part_referral->referral.' '
44   if $sel_part_referral;
45
46 $title .= 'Customer Accounting Summary Report';
47
48 my @custs = ();
49 @custs = qsearch('cust_main', {} ); 
50
51 my @items  = ();
52 my @params = ();
53 my @labels = ();
54
55 my $status = $cgi->param('status');
56 die "invalid status" unless $status =~ /^\w+|$/;
57
58 foreach my $cust_main ( @custs ) {
59   next unless ($status eq '' || $status eq $cust_main->status); 
60   next unless ($agentnum == 0 || $cust_main->agentnum eq $agentnum);
61   next unless ($refnum   == 0 || $cust_main->refnum eq $refnum);
62
63   push @items, 'netsales', 'cashflow';
64
65   push @labels, $cust_main->name;
66
67   push @params, [ ('custnum' => $cust_main->custnum),
68                 ],
69                 [ ('custnum' => $cust_main->custnum),
70                 ];
71 }
72
73 </%init>