forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockUsageGraph.php
113 lines (107 loc) · 3.6 KB
/
StockUsageGraph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
include('includes/session.php');
$result = DB_query("SELECT description FROM stockmaster WHERE stockid='" . trim(mb_strtoupper($_GET['StockID'])) . "'");
$myrow = DB_fetch_row($result);
include('includes/phplot/phplot.php');
$graph = new phplot(1000,500);
$graph->SetTitle($myrow[0] . ' ' . _('Usage'));
$graph->SetXTitle(_('Month'));
$graph->SetYTitle(_('Quantity'));
$graph->SetBackgroundColor("wheat");
$graph->SetTitleColor("blue");
$graph->SetPlotType="bars";
$graph->SetShading(5);
$graph->SetDrawYGrid(TRUE);
$graph->SetMarginsPixels(40,40,40,40);
$graph->SetDataType('text-data');
if($_GET['StockLocation']=='All'){
$sql = "SELECT periods.periodno,
periods.lastdate_in_period,
SUM(-stockmoves.qty) AS qtyused
FROM stockmoves INNER JOIN periods
ON stockmoves.prd=periods.periodno
INNER JOIN locationusers ON locationusers.loccode=stockmoves.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE (stockmoves.type=10 OR stockmoves.type=11 OR stockmoves.type=28)
AND stockmoves.hidemovt=0
AND stockmoves.stockid = '" . trim(mb_strtoupper($_GET['StockID'])) . "'
GROUP BY periods.periodno,
periods.lastdate_in_period
ORDER BY periodno LIMIT 24";
} else {
$sql = "SELECT periods.periodno,
periods.lastdate_in_period,
SUM(-stockmoves.qty) AS qtyused
FROM stockmoves INNER JOIN periods
ON stockmoves.prd=periods.periodno
INNER JOIN locationusers ON locationusers.loccode=stockmoves.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE (stockmoves.type=10 Or stockmoves.type=11 OR stockmoves.type=28)
AND stockmoves.hidemovt=0
AND stockmoves.loccode='" . $_GET['StockLocation'] . "'
AND stockmoves.stockid = '" . trim(mb_strtoupper($_GET['StockID'])) . "'
GROUP BY periods.periodno,
periods.lastdate_in_period
ORDER BY periodno LIMIT 24";
}
$MovtsResult = DB_query($sql);
if (DB_error_no() !=0) {
$Title = _('Stock Usage Graph Problem');
include ('includes/header.php');
echo _('The stock usage for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg();
if ($debug==1){
echo '<br />' . _('The SQL that failed was') . $sql;
}
include('includes/footer.php');
exit;
}
if (DB_num_rows($MovtsResult)==0){
$Title = _('Stock Usage Graph Problem');
include ('includes/header.php');
prnMsg(_('There are no movements of this item from the selected location to graph'),'info');
include('includes/footer.php');
exit;
}
$UsageArray = array();
$NumberOfPeriodsUsage = DB_num_rows($MovtsResult);
if ($NumberOfPeriodsUsage!=24){
$graph->SetDataColors(
array("blue"), //Data Colors
array("black") //Border Colors
);
for ($i=1;$i++;$i<=$NumberOfPeriodsUsage){
$UsageRow = DB_fetch_array($MovtsResult);
if (!$UsageRow){
break;
} else {
$UsageArray[] = array(MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']),$UsageRow['qtyused']);
}
}
}else {
$graph->SetDataColors(
array("blue","red"), //Data Colors
array("black") //Border Colors
);
for ($i=1;$i++;$i<=12){
$UsageRow = DB_fetch_array($MovtsResult);
if (!$UsageRow){
break;
}
$UsageArray[] = array(MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']),$UsageRow['qtyused']);
}
for ($i=0,$i++;$i<=11;){
$UsageRow = DB_fetch_array($MovtsResult);
if (!$UsageRow){
break;
}
$UsageArray[$i][0] = MonthAndYearFromSQLDate($UsageRow['lastdate_in_period']);
$UsageArray[$i][2] = $UsageRow['qtyused'];
}
}
//$graph->SetDrawXGrid(TRUE);
$graph->SetDataValues($UsageArray);
$graph->SetDataColors(
array("blue","red"), //Data Colors
array("black") //Border Colors
);
//Draw it
$graph->DrawGraph();
?>