MOON
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 PHP/5.4.10
System: Linux vps.presagepowered.net 2.6.18-398.el5 #1 SMP Tue Sep 16 20:51:48 EDT 2014 i686
User: mckernan (512)
PHP: 5.4.10
Disabled: NONE
Upload Files
File: /home/mckernan/public_html/iJournal/includes/journal/chart_mo_income.inc.php
<?php

/**
 * included file - draw chart: monthly income
 */
 
 
    // calculate month labels
    $point_month = new DateTime("2012-03-01");
    $point_month->modify('-' . ($mos_year + 1) . ' months');

    function monthOut($point_month)
    {
        $point_month->modify('+1 months');
        return $point_month->format("M");
    }
    
 
    // init
    $grdata = array();
    
    $captions = array();
    $values = array();
    
    for ($i = 0; $i < $mos_year; $i++)
    {
        $captions[$i] = monthOut($point_month);
        $values[$i] = '';
    }
 
 
    // fetch data
    $query = "SELECT p.per_id, j.jrnl_per, (j.jrnl_in_gross + j.jrnl_in_0 + j.jrnl_in_1 + j.jrnl_in_2 + j.jrnl_in_3) AS income
                 FROM journal j LEFT JOIN periods p ON p.per_id = j.jrnl_per
				 WHERE j.jrnl_per IN (SELECT per_id FROM periods WHERE per_yr = (SELECT per_yr FROM periods WHERE per_id = " . $pid . ")) 
                 ORDER BY j.jrnl_id ASC";

    
    if ($result = $db->query($query))
    {
        $ct = 0;
        $total = 0.00;
        $i = 0;
        
        while ($row = $result->fetch_assoc())
        {
            $ct++;
            $total += $row['income'];
            
            $values[$i] = $row['income'];
            $i++;    
        }
    }
    
    // calc average
    $average = round(($total / $ct), 2);
    
    
    // build output array
    for ($i = 0; $i < $mos_year; $i++)
    {
        $grdata[$i] = array($captions[$i], $average, $values[$i]);
    }


    // create graph / save as jpg
    include_once(includePath() . "phplot.php");
    
    $file = clientPath() . $dbn . '/tmp_income.jpg';

    $graph = new PHPlot(400, 200, $file);
    $graph->y_precision = 2;
    $graph->SetXLabelFontSize(5);
    $graph->SetYLabelFontSize(5);
    $graph->SetXLabel('Months');
    $graph->SetYLabel('Total Income');
    $graph->SetAxisFontSize(2);
    $graph->SetDataColors(array('gray', 'blue'));
        
    // set data
    $graph->SetDataValues($grdata);
        
    // draw graph
    $graph->DrawGraph();

?>