summaryrefslogtreecommitdiff
path: root/httemplate/search/customer_accounting_summary.html
blob: 72a00ed957d4deef8adad0cd03a3f366ac75fd76 (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
67
68
69
70
71
72
73
<% include('/graph/elements/monthly.html',
   #Dumper(
                'title'        => $title,
                'graph_type'   => 'none',
                'items'        => \@items,
                'params'       => \@params,
                'labels'       => \@labels,
                'graph_labels' => \@labels,
                'remove_empty' => 1,
                'bottom_total' => 1,
                'agentnum'     => $agentnum,
		'doublemonths' => \@doublemonths,
		'nototal'	=> 1,
             )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');

my @doublemonths = ( 'Billed', 'Paid' );

my ($agentnum,$sel_agent);
if ( $cgi->param('agentnum') eq 'all' ) {
  $agentnum = 0;
}
elsif ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
  $agentnum = $1;
  $sel_agent = qsearchs('agent', { 'agentnum' => $agentnum } );
  die "agentnum $agentnum not found!" unless $sel_agent;
}
my $title = $sel_agent ? $sel_agent->agent.' ' : '';

my ($refnum,$sel_part_referral);
#if ( $cgi->param('refnum') eq 'all' ) {
#  $refnum = 0;
#} els
if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
  $refnum = $1;
  $sel_part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
  die "refnum $refnum not found!" unless $sel_part_referral;
}
$title .=  $sel_part_referral->referral.' '
  if $sel_part_referral;

$title .= 'Customer Accounting Summary Report';

my @custs = ();
@custs = qsearch('cust_main', {} ); 

my @items  = ();
my @params = ();
my @labels = ();

my $status = $cgi->param('status');
die "invalid status" unless $status =~ /^\w+|$/;

foreach my $cust_main ( @custs ) {
  next unless ($status eq '' || $status eq $cust_main->status); 
  next unless ($agentnum == 0 || $cust_main->agentnum eq $agentnum);
  next unless ($refnum   == 0 || $cust_main->refnum eq $refnum);

  push @items, 'netsales', 'cashflow';

  push @labels, $cust_main->name;

  push @params, [ ('custnum' => $cust_main->custnum),
		],
		[ ('custnum' => $cust_main->custnum),
		];
}

</%init>