- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / StockUsageGraph.php
blob3a5876634a6ad94b1449cfcca011608db937a2f3
1 <?php
2 $PageSecurity = 2;
3 include('includes/session.inc');
4 $result = DB_query("SELECT description FROM stockmaster WHERE stockid='" . trim(strtoupper($_GET['StockID'])) . "'",$db);
5 $myrow = DB_fetch_row($result);
7 include('includes/phplot/phplot.php');
8 $graph =& new phplot(1000,500);
9 $graph->SetTitle($myrow[0] . ' ' . _('Usage'));
10 $graph->SetXTitle(_('Month'));
11 $graph->SetYTitle(_('Quantity'));
12 $graph->SetBackgroundColor("wheat");
13 $graph->SetTitleColor("blue");
14 $graph->SetPlotType="bars";
15 $graph->SetShading(5);
16 $graph->SetDrawYGrid(TRUE);
17 $graph->SetMarginsPixels(40,40,40,40);
18 $graph->SetDataType('text-data');
20 if($_GET['StockLocation']=='All'){
21 $sql = "SELECT periods.periodno,
22 periods.lastdate_in_period,
23 SUM(-stockmoves.qty) AS qtyused
24 FROM stockmoves INNER JOIN periods
25 ON stockmoves.prd=periods.periodno
26 WHERE (stockmoves.type=10 OR stockmoves.type=11 OR stockmoves.type=28)
27 AND stockmoves.hidemovt=0
28 AND stockmoves.stockid = '" . trim(strtoupper($_GET['StockID'])) . "'
29 GROUP BY periods.periodno,
30 periods.lastdate_in_period
31 ORDER BY periodno LIMIT 24";
32 } else {
33 $sql = "SELECT periods.periodno,
34 periods.lastdate_in_period,
35 SUM(-stockmoves.qty) AS qtyused
36 FROM stockmoves INNER JOIN periods
37 ON stockmoves.prd=periods.periodno
38 WHERE (stockmoves.type=10 Or stockmoves.type=11 OR stockmoves.type=28)
39 AND stockmoves.hidemovt=0
40 AND stockmoves.loccode='" . $_GET['StockLocation'] . "'
41 AND stockmoves.stockid = '" . trim(strtoupper($_GET['StockID'])) . "'
42 GROUP BY periods.periodno,
43 periods.lastdate_in_period
44 ORDER BY periodno LIMIT 24";
46 $MovtsResult = DB_query($sql, $db);
47 if (DB_error_no($db) !=0) {
48 $title = _('Stock Usage Graph Problem');
49 include ('includes/header.inc');
50 echo _('The stock usage for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg($db);
51 if ($debug==1){
52 echo '<BR>' . _('The SQL that failed was') . $sql;
54 include('includes/footer.inc');
55 exit;
57 if (DB_num_rows($MovtsResult)==0){
58 $title = _('Stock Usage Graph Problem');
59 include ('includes/header.inc');
60 prnMsg(_('There are no movements of this item from the selected location to graph'),'info');
61 include('includes/footer.inc');
62 exit;
65 $UsageArray = array();
66 $NumberOfPeriodsUsage = DB_num_rows($MovtsResult);
67 if ($NumberOfPeriodsUsage!=24){
68 $graph->SetDataColors(
69 array("blue"), //Data Colors
70 array("black") //Border Colors
71 );
72 for ($i=1;$i++;$i<=$NumberOfPeriodsUsage){
73 $UsageRow = DB_fetch_array($MovtsResult);
74 if (!$UsageRow){
75 break;
76 } else {
77 $UsageArray[] = array(MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']),$UsageRow['qtyused']);
80 }else {
81 $graph->SetDataColors(
82 array("blue","red"), //Data Colors
83 array("black") //Border Colors
84 );
85 for ($i=1;$i++;$i<=12){
86 $UsageRow = DB_fetch_array($MovtsResult);
87 if (!$UsageRow){
88 break;
90 $UsageArray[] = array(MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']),$UsageRow['qtyused']);
92 for ($i=0,$i++;$i<=11;){
93 $UsageRow = DB_fetch_array($MovtsResult);
94 if (!$UsageRow){
95 break;
97 $UsageArray[$i][0] = MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']);
98 $UsageArray[$i][2] = $UsageRow['qtyused'];
101 //$graph->SetDrawXGrid(TRUE);
102 $graph->SetDataValues($UsageArray);
103 $graph->SetDataColors(
104 array("blue","red"), //Data Colors
105 array("black") //Border Colors
109 //Draw it
110 $graph->DrawGraph();