-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrep_my_bu.php
136 lines (108 loc) · 4.15 KB
/
rep_my_bu.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
<?php
require ('common/auth.php');
require_once ('classes/budget.class.php');
require_once ('classes/reports.class.php');
require_once ('classes/waterfall.class.php');
$bdv = isset($_GET['bdv'])?$_GET['bdv']:($_COOKIE['bdv']?$_COOKIE['bdv']:$arrUsrData['usrProfitID']);
if ($_GET['bdv']=='MYSELF'){
$bdv = $arrUsrData['usrProfitID'];
}
SetCookie('bdv',$bdv,0);
$sqlWhere = "WHERE bdv = ".$oSQL->e($bdv);
include ('includes/inc_report_settings.php');
$oBudget = new Budget($budget_scenario);
$oReference = new Budget($reference);
include ('includes/inc_report_pcfilter.php');
$arrJS[]='js/rep_pnl.js';
// $arrJS[]='js/input_form.js';
include('includes/inc_group_buttons.php');
$sql = "SELECT * FROM common_db.tbl_profit WHERE pccID=".$oSQL->e($bdv);
$rs = $oSQL->q($sql);
$arrBDV = $oSQL->f($rs);
$arrUsrData["pagTitle$strLocal"] = 'Sales by '.($arrBDV['pccTitle']?$arrBDV['pccTitle']:'<Unknown>');
$arrDefaultParams = Array('currency'=>643,'period_type'=>'cm','denominator'=>1000,'bu_group'=>'');
$strQuery = http_build_query($arrDefaultParams);
$arrActions[] = Array('title'=>'NSD','action'=>'?bdv=9&type=bu_group&'.$strQuery);
$arrActions[] = Array('title'=>'JSD','action'=>'?bdv=130&type=bu_group&'.$strQuery);
if(!isset($_GET['pccGUID'])){
include ('includes/inc-frame_top.php');
echo '<h1>',$arrUsrData["pagTitle$strLocal"],': ',$oBudget->title,'</h1>';
echo '<p>',$oBudget->timestamp,'; ',$oBudget->rates,'</p>';
include ('includes/inc_report_selectors.php');
Budget::getProfitTabs('reg_sales', false, Array('bdv'=>$bdv));
$sql = "SELECT pccID, pccTitle FROM common_db.tbl_profit WHERE pccFlagFolder=0 ORDER BY pccTitle";
$rs = $oSQL->q($sql);
?>
<ul class='link-footer'>
<?php
while ($rw = $oSQL->f($rs)){
?><li><a href="?bdv=<?php echo $rw['pccID'];?>"><?php echo $rw['pccTitle'];?></a><?php
}
?>
</ul>
<div id='waterfall'>
<?php
if(strpos($oBudget->type,'Budget')!==false){
$period_type = 'fye';
} else {
$period_type = 'cm';
}
$sqlActual = "SUM(".$oBudget->getThisYTDSQL($period_type,$arrActualRates).")";
$sqlBudget = "SUM(".$oBudget->getThisYTDSQL($period_type,$arrBudgetRates).")";
$settings['gpcus'] = Array('title'=>"GP by customer sold by {$arrBDV['pccTitle']}",
'actual_title'=>$oBudget->title,
'budget_title'=>$oReference->title,
'sqlBase' => "SELECT customer_group_code as optValue,
customer_group_title as optText,
{$sqlActual} as Actual,
0 as Budget,
{$sqlActual} as Diff
FROM vw_master
{$sqlWhere}
AND scenario='{$oBudget->id}'
AND company='{$company}'
".Reports::GP_FILTER."
GROUP BY customer_group_code
UNION ALL
SELECT customer_group_code as optValue,
customer_group_title as optText,
0 as Actual,
{$sqlBudget} as Budget, -{$sqlBudget} as Diff
FROM vw_master
{$sqlWhere}
AND scenario='{$oReference->id}'
AND company='{$company}'
AND source<>'Estimate'
".Reports::GP_FILTER."
GROUP BY customer_group_code",
'tolerance'=>0.05,
'denominator'=>$denominator,
'limit'=>10);
$oWF = new Waterfall($settings['gpcus']);
$oWF->draw();
?>
</div>
<?php
include ('includes/inc-frame_bottom.php');
} else {
if ($_GET['pccGUID']=='all'){
} else {
$sqlWhere .= " AND pc in (SELECT pccID FROM vw_profit WHERE pccGUID=".$oSQL->e($_GET['pccGUID']).")";
}
$filter['bdv'] = $bdv;
$oReport = new Reports(Array('budget_scenario'=>$budget_scenario, 'reference'=>$reference,'currency'=>$currency, 'denominator'=>$denominator, 'filter'=>$filter, 'yact'=>false));
if (strpos($oBudget->type,'FYE')!== false){
// if (false){
$oReport->monthlyReport($type);
} elseif (strpos($oBudget->type,'Budget')!== false) {
$oReport->quarterly($type);
} else {
include ('includes/inc_report_buttons.php');
$oReport->periodicPnL($type);
?>
<h2>KPI</h2>
<?php
$oReport->salesByCustomer(' and bdv='.$oSQL->e($bdv));
}
}
?>