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_profit.inc.php
<?php

/**
 * included file - draw chart: monthly net oper profit
 */
 
 
    // calculate month labels
    $point_month2 = new DateTime("2012-03-01");
    $point_month2->modify('-' . ($mos_year + 1) . ' months');
    
    
    function monthOut2($point_month2)
    {
        $point_month2->modify('+1 months');
        return $point_month2->format("M");
    }
    
 
    // init
    $grdata2 = array();
    
    $captions2 = array();
    $values2 = array();
    
    for ($i = 0; $i < $mos_year; $i++)
    {
        $captions2[$i] = monthOut2($point_month2);
        $values2[$i] = '';
    }
 
 
    // fetch data
    $query = "SELECT p.per_id, j.jrnl_per, (j.jrnl_in_gross - j.jrnl_in_cogs + j.jrnl_in_0 + j.jrnl_in_1 + j.jrnl_in_2 + j.jrnl_in_3 - 
                (j.jrnl_oh_0 + j.jrnl_oh_1 + j.jrnl_oh_2 + j.jrnl_oh_3 + j.jrnl_oh_4 + j.jrnl_oh_5 + j.jrnl_oh_6 + 
				 j.jrnl_oh_7 + j.jrnl_oh_8 + j.jrnl_la_0 + j.jrnl_la_1 + j.jrnl_la_2 + j.jrnl_la_3 + j.jrnl_la_4 +
				 j.jrnl_la_5 + j.jrnl_la_6 + j.jrnl_la_7 + j.jrnl_op_0 + j.jrnl_op_1 + j.jrnl_op_2 + j.jrnl_op_3 + 
				 j.jrnl_op_4 + j.jrnl_op_5 + j.jrnl_op_6 + j.jrnl_op_7 + j.jrnl_op_8 + j.jrnl_op_9 + j.jrnl_op_10 + 
				 j.jrnl_op_11 + j.jrnl_op_12 + j.jrnl_op_13 + j.jrnl_op_14 + j.jrnl_op_15 + j.jrnl_op_16 +
				 j.jrnl_op_17 + j.jrnl_op_18 + j.jrnl_op_19)) AS nop 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['nop'];
            
            $values2[$i] = $row['nop'];
            $i++;    
        }
    }
    
    // calc average
    $average = round(($total / $ct), 2);
    
    
    // build output array
    for ($i = 0; $i < $mos_year; $i++)
    {
        $grdata2[$i] = array($captions2[$i], $average, $values2[$i]);
    }


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

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

?>