14 while ( $syear < $eyear || ( $syear == $eyear && $smonth < $emonth ) ) {
15 push @labels, "$smonth/$syear";
17 my $speriod = timelocal(0,0,0,1,$smonth-1,$syear);
18 if ( ++$smonth == 13 ) { $syear++; $smonth=1; }
19 my $eperiod = timelocal(0,0,0,1,$smonth-1,$syear);
21 my $where = "WHERE _date >= $speriod AND _date < $eperiod";
24 my $charged_sql = "SELECT SUM(charged) FROM cust_bill $where";
25 my $charged_sth = dbh->prepare($charged_sql) or die dbh->errstr;
26 $charged_sth->execute or die $charged_sth->errstr;
27 my $charged = $charged_sth->fetchrow_arrayref->[0] || 0;
29 push @{$data{charged}}, $charged;
32 # my $ar_sql2 = "SELECT SUM(amount) FROM cust_credit $where";
33 my $credited_sql = "SELECT SUM(cust_credit_bill.amount) FROM cust_credit_bill, cust_bill WHERE cust_bill.invnum = cust_credit_bill.invnum AND cust_bill._date >= $speriod AND cust_bill._date < $eperiod";
34 my $credited_sth = dbh->prepare($credited_sql) or die dbh->errstr;
35 $credited_sth->execute or die $credited_sth->errstr;
36 my $credited = $credited_sth->fetchrow_arrayref->[0] || 0;
38 #horrible local kludge
39 my $expenses_sql = "SELECT SUM(cust_bill_pkg.setup) FROM cust_bill_pkg, cust_bill, cust_pkg, part_pkg WHERE cust_bill.invnum = cust_bill_pkg.invnum AND cust_bill._date >= $speriod AND cust_bill._date < $eperiod AND cust_pkg.pkgnum = cust_bill_pkg.pkgnum AND cust_pkg.pkgpart = part_pkg.pkgpart AND LOWER(part_pkg.pkg) LIKE 'expense _%'";
40 my $expenses_sth = dbh->prepare($expenses_sql) or die dbh->errstr;
41 $expenses_sth->execute or die $expenses_sth->errstr;
42 my $expenses = $expenses_sth->fetchrow_arrayref->[0] || 0;
44 push @{$data{ar}}, $charged-$credited-$expenses;
47 # push @{$data{defer}}, '0';
50 my $paid_sql = "SELECT SUM(paid) FROM cust_pay $where";
51 my $paid_sth = dbh->prepare($paid_sql) or die dbh->errstr;
52 $paid_sth->execute or die $paid_sth->errstr;
53 my $paid = $paid_sth->fetchrow_arrayref->[0] || 0;
55 my $refunded_sql = "SELECT SUM(refund) FROM cust_refund $where";
56 my $refunded_sth = dbh->prepare($refunded_sql) or die dbh->errstr;
57 $refunded_sth->execute or die $refunded_sth->errstr;
58 my $refunded = $refunded_sth->fetchrow_arrayref->[0] || 0;
60 push @{$data{cash}}, $paid-$refunded;
64 #my $chart = Chart::LinesPoints->new(1024,480);
65 my $chart = Chart::LinesPoints->new(768,480);
70 'legend_labels' => [ #'Invoiced (cust_bill)',
71 'Accounts receivable (invoices - applied credits)',
73 'Actual cashflow (payments - refunds)' ],
76 my @data = ( \@labels,
77 #map $data{$_}, qw( ar defer cash )
78 #map $data{$_}, qw( charged ar cash )
79 map $data{$_}, qw( ar cash )
82 #my $gd = $chart->plot(\@data);
83 #open (IMG, ">i_r_c.png");
87 #$chart->png("i_r_c.png", \@data);
89 #$chart->cgi_png(\@data);
91 http_header('Content-Type' => 'image/png' );
92 $Response->{ContentType} = 'image/png';
94 $chart->_set_colors();
96 %><%= $chart->scalar_png(\@data) %>