<?php
require_once("../ChartDirector/lib/phpchartdir.php");
if ($CH_type=="Body"){$CH_title="Shk-diff_Final";$CH_matNo="652141300006"; }
else if ($CH_type=="Soft"){$CH_title="Shk-diff_Soft";$CH_matNo="652141300007"; }
else if ($CH_type=="Hard"){$CH_title="Shk-diff_Hard";$CH_matNo="652141300008"; }
else{}
//echo $CH_type."<br>";
//$CH_matNo="652141300006";
//$CH_dateST="2018-05-11";
//$CH_dateFI="2018-05-30";
//$CH_plant="6511";
//$CH_host="localhost";
//$CH_user="root";
//$CH_password="036316324";
####################################BATCH NO######################################################
$selecttype=1;
$database ="tn_general";
$table ="ft_body_eirich_pd";
$criteria_sql ="(IDNO != '' )and(LOT_DATE between '$CH_dateST' and '$CH_dateFI' )";
$orderby="ORDER BY $table.LOT_DATE ASC LIMIT 0,1000";
$objConnect1 = mysql_connect("$CH_host","$CH_user","$CH_password") or die("Error Connect to Database");
//mysql_connect($host,$user,$password);
mysql_select_db("$database");
mysql_query('SET CHARACTER SET tis620');
mysql_query('SET collation_connection="tis620_thai_ci"');
$sql1="select * from $table where ($criteria_sql) $orderby ";
$db_query1=@mysql_db_query("$database",$sql1);
$total1=@mysql_num_rows($db_query1);
$body_count=0;
$soft_count=0;
$hard_count=0;
for($i=1;$i<=$total1;$i++)
{$rc1=mysql_fetch_array($db_query1);
if ($CH_type=="Body")
{
if ($rc1[LOT_FINAL]!=""){$no_batch[$body_count]=$rc1[LOT_FINAL];$batch_date[$body_count]=$rc1[LOT_DATE];$body_count=$body_count+1;}else{}
}
else if ($CH_type=="Hard")
{
if ($rc1[LOT_HARD1]!=""){$no_batch[$hard_count]=$rc1[LOT_HARD1];$batch_date[$hard_count]=$rc1[LOT_DATE];$hard_count=$hard_count+1;}else{}
if ($rc1[LOT_HARD2]!=""){$no_batch[$hard_count]=$rc1[LOT_HARD2];$batch_date[$hard_count]=$rc1[LOT_DATE];$hard_count=$hard_count+1;}else{}
}
else if ($CH_type=="Soft")
{
if ($rc1[LOT_SOFT1]!=""){$no_batch[$soft_count]=$rc1[LOT_SOFT1];$batch_date[$soft_count]=$rc1[LOT_DATE];$soft_count=$soft_count+1;}else{}
if ($rc1[LOT_SOFT2]!=""){$no_batch[$soft_count]=$rc1[LOT_SOFT2];$batch_date[$soft_count]=$rc1[LOT_DATE];$soft_count=$soft_count+1;}else{}
}
else {}
}
$row_batch=count($no_batch);
for($hh=1;$hh<=$row_batch;$hh++)
{ $batch_se=$no_batch[$hh-1];
if ($CH_type=="Body")
{$daten_comp= date("Y-m-d",strtotime("+7 days",strtotime($batch_date[$hh-1])));
$date_st_batch=$batch_date[$hh-1];
$date_fi_batch=$daten_comp;
}
else if ($CH_type=="Hard")
{ $daten_comn= date("Y-m-d",strtotime("-30 days",strtotime($batch_date[$hh-1])));
$date_st_batch=$daten_comn;
$date_fi_batch=$batch_date[$hh-1];
}
else if ($CH_type=="Soft")
{ $daten_comn= date("Y-m-d",strtotime("-45 days",strtotime($batch_date[$hh-1])));
$date_st_batch=$daten_comn;
$date_fi_batch=$batch_date[$hh-1];
}
else{}
$selecttype2=1;
$database2 ="tn_general";
$table2 ="ft_body";
$criteria_sql2 ="(IDNO != '' )and(LOT_DATE between '$date_st_batch' and '$date_fi_batch')and(BATCH_NO ='$batch_se')";
$orderby2="ORDER BY ft_body.IDNO ASC";
$objConnect2 = mysql_connect("$CH_host","$CH_user","$CH_password") or die("Error Connect to Database");
//mysql_connect($host,$user,$password);
mysql_select_db("$database2");
mysql_query('SET CHARACTER SET tis620');
mysql_query('SET collation_connection="tis620_thai_ci"');
$sql2="select * from $table2 where ($criteria_sql2) $orderby2 ";
$db_query2=@mysql_db_query("$database2",$sql2);
$total2=@mysql_num_rows($db_query2);
if ($rc2[SHRINK_SPEC]!="")
{
$spec_expl=explode(" .. ",$rc2[SHRINK_SPEC]);
if ($spec_expl[0]!=""){$data0[$nn-1]=$spec_expl[0];}else{$data0[$nn-1]=NoValue;}
if ($spec_expl[1]!=""){$max_expl=explode(" %",$spec_expl[1]);$data1[$nn-1]=$max_expl[0];}else{$data1[$nn-1]=NoValue;}
}
else{$data0[$nn-1]=NoValue;$data1[$nn-1]=NoValue;}
# Create a XYChart object of size 600 x 375 pixels
$c = new XYChart(950, 450);
# Add a title to the chart using 18 pts Times Bold Italic font
$c->addTitle("$CH_title", "timesbi.ttf", 15);
# Set the plotarea at (50, 55) and of 500 x 280 pixels in size. Use a vertical
# gradient color from light blue (f9f9ff) to sky blue (aaccff) as background. Set
# border to transparent and grid lines to white (ffffff).
$c->setPlotArea(55, 45, 880, 320, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
# Add a legend box at (50, 28) using horizontal layout. Use 10pts Arial Bold as font,
# with transparent background.
$legendObj = $c->addLegend(50, 15, false, "arialbd.ttf", 12);
$legendObj->setBackground(Transparent);
# Set the x axis labels
$c->xAxis->setLabels($labels);
# Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this as
# the guideline when putting ticks on the y-axis.
$c->yAxis->setTickDensity(30);
# Set axis label style to 8pts Arial Bold
$c->xAxis->setLabelStyle("arialbd.ttf", 8);
$c->yAxis->setLabelStyle("arialbd.ttf", 8);
# Set axis line width to 2 pixels
$c->xAxis->setWidth(1);
$c->yAxis->setWidth(1);
# Add axis title using 10pts Arial Bold Italic font
$c->yAxis->setTitle("% Shrinkage (%)", "arialbi.ttf", 10);
$c->xAxis->setTitle("Batch No.", "arialbi.ttf", 10);
# Add a line layer to the chart
$layer = $c->addLineLayer2();
# Set the line width to 3 pixels
$layer->setLineWidth(2);
# Add the three data sets to the line layer, using circles, diamands and X shapes as
# symbols
$dataSetObj = $layer->addDataSet($data0, $c->dashLineColor(0xff0000, DashLine), "Lower");
$dataSetObj = $layer->addDataSet($data1, $c->dashLineColor(0xff0000, DashLine), "Upper");
$dataSetObj = $layer->addDataSet($data2, 0x0000ff, "% Shrink");
$dataSetObj->setDataSymbol(CircleSymbol, 5);
/*
////////////////$dataSetObj = $layer->addDataSet($data3, 0x0000ff, "CV2");
////////////////$dataSetObj->setDataSymbol(CircleSymbol, 5);
////////////////$dataSetObj = $layer->addDataSet($data4, 0xff3300, "CV3");
////////////////$dataSetObj->setDataSymbol(CircleSymbol, 5);
////////////////$dataSetObj = $layer->addDataSet($data5, 0x00ffff, "CV4");
////////////////$dataSetObj->setDataSymbol(CircleSymbol, 5);
////////////////$dataSetObj = $layer->addDataSet($data6, 0x9900ff, "CV5");
////////////////$dataSetObj->setDataSymbol(CircleSymbol, 5);
////////////////$dataSetObj = $layer->addDataSet($data7, 0x000000, "CV6");
////////////////$dataSetObj->setDataSymbol(CircleSymbol, 5);
*/
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));