-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrep_columns.php
159 lines (121 loc) · 5.11 KB
/
rep_columns.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
// $flagNoAuth = true;
require ('common/auth.php');
require ('classes/budget.class.php');
require ('classes/columns.class.php');
require ('classes/reports.class.php');
include ('includes/inc_report_settings.php');
$oBudget = new Budget($budget_scenario);
$oReference = new Budget($reference);
if ($bu_group){
$sql = "SELECT * FROM common_db.tbl_profit WHERE pccParentCode1C='{$bu_group}'";
$rs = $oSQL->q($sql);
while ($rw = $oSQL->f($rs)){
$arrBus[] = $rw['pccID'];
}
}
if(!isset($_GET['pccGUID'])){
$arrJS[]='js/rep_pnl.js';
SetCookie('period_type',$period_type,0,'/budget/');
if(strpos($oBudget->type,'budget')===false){
$arrPeriodType['ytd'] = 'YTD';
$arrPeriodType['cm'] = 'Current month';
$arrPeriodType['nm'] = 'Next month';
$arrPeriodType['roy'] = 'Rest-of-year';
}
if(!$oBudget->offset || $oBudget->length==15){
$arrPeriodType['fye'] = 'FYE';
$arrPeriodType['q1'] = '1<sup>st</sup> quarter';
};
$arrPeriodType['q2'] = '2<sup>nd</sup> quarter';
$arrPeriodType['q3'] = '3<sup>rd</sup> quarter';
$arrPeriodType['q4'] = '4<sup>th</sup> quarter';
if($oBudget->offset || $oBudget->length==15){
$arrPeriodType['q5'] = '5<sup>th</sup> quarter';
$arrPeriodType['am'] = 'Apr-Mar';
}
foreach($arrPeriodType as $id=>$title){
$temp = $_GET;
$temp['period_type'] = $id;
$url = $_SERVER['PHP_SELF'].'?'.http_build_query($temp);
$arrActions[] = Array ('title'=>$title,'action'=>$url);
}
include ('includes/inc-frame_top.php');
echo '<h1>',$arrUsrData["pagTitle$strLocal"],'</h1>';
echo '<h2>',$arrPeriodType[$period_type],'</h2>';
include ('includes/inc_report_selectors.php');
Budget::getProfitTabs('reg_master', !$flagNoAuth, Array('pccID'=>$arrBus));
include ('includes/inc-frame_bottom.php');
} else {
// include ('includes/inc_report_buttons.php');
if ($_GET['pccGUID']=='all'){
if (!$flagNoAuth) {
$strRoles = "'".implode("','",$arrUsrData['roleIDs'])."'";
$sqlPCFilter[] = "pcrRoleID IN ({$strRoles}) AND pcrFlagRead=1";
$sqlRoleFilter[] = "pcrRoleID IN ({$strRoles}) AND pcrFlagRead=1";
};
if ($bu_group){
$strBUs = implode(',',$arrBus);
$sqlPCFilter[] = "pcrProfitID IN ({$strBUs})";
$sql = "SELECT DISTINCT pcrProfitID FROM stbl_profit_role WHERE ".implode(" AND ",$sqlPCFilter);
} else {
$sql = "SELECT DISTINCT pcrProfitID FROM stbl_profit_role WHERE ".implode(" AND ",$sqlRoleFilter);
}
$rs = $oSQL->q($sql);
while ($rw = $oSQL->f($rs)){
$arrPC[] = $rw['pcrProfitID'];
}
$sqlWhere = "WHERE pc in (".implode(',',$arrPC).")";
} else {
$sqlWhere = "WHERE pc in (SELECT pccID FROM vw_profit WHERE pccGUID=".$oSQL->e($_GET['pccGUID']).")";
}
$arrActualRates = $oBudget->getMonthlyRates($currency);
$arrBudgetRates = $oReference->getMonthlyRates($currency);
$sqlActual = "SUM(".$oBudget->getThisYTDSQL($period_type,$arrActualRates).")";
$sqlBudget = "SUM(".$oBudget->getThisYTDSQL($period_type,$arrBudgetRates).")";
// $sql="SELECT sales as optValue,
// usrTitle as optText,
// customer_group_code as optGroupValue,
// customer_group_title as optGroupText,
// {$sqlActual} as Actual,
// 0 as Budget,
// {$sqlActual} as Diff
// FROM vw_master
// {$sqlWhere} AND scenario='{$oBudget->id}' ".Reports::GP_FILTER."
// GROUP BY customer_group_code, sales
// UNION ALL
// SELECT sales as optValue,
// usrTitle as optText,
// customer_group_code as optGroupValue,
// customer_group_title as optGroupText,
// 0 as Actual,
// {$sqlBudget} as Budget, -{$sqlBudget} as Diff
// FROM vw_master
// {$sqlWhere} AND scenario='{$oReference->id}' AND source<>'Estimate' ".Reports::GP_FILTER."
// GROUP BY customer_group_code, sales";
// $oReport = new Columns(Array('sqlBase'=>$sql, 'actual_title'=>$oBudget->title,'budget_title'=>$oReference->title,'xTitle'=>'Gross profit', 'title'=>'Gross profit'));
// $oReport->draw();
$sql="SELECT sales as optValue,
usrTitle as optText,
customer_group_code as optGroupValue,
customer_group_title as optGroupText,
{$sqlActual} as Actual,
0 as Budget,
{$sqlActual} as Diff
FROM vw_master
{$sqlWhere} AND scenario='{$oBudget->id}' AND Group_code=94
GROUP BY customer_group_code, sales
UNION ALL
SELECT sales as optValue,
usrTitle as optText,
customer_group_code as optGroupValue,
customer_group_title as optGroupText,
0 as Actual,
{$sqlBudget} as Budget, -{$sqlBudget} as Diff
FROM vw_master
{$sqlWhere} AND scenario='{$oReference->id}' AND source<>'Estimate' AND Group_code=94
GROUP BY customer_group_code, sales";
$oReport = new Columns(Array('sqlBase'=>$sql, 'actual_title'=>$oBudget->title,'budget_title'=>$oReference->title,'xTitle'=>'Gross margin', 'title'=>'Gross margin'));
$oReport->draw();
}
?>