|
@@ -7,6 +7,12 @@ function BUDGET_ANALYTICS() {
|
|
|
$args = array();
|
|
$args = array();
|
|
|
$args['year'] = V::get('zest_year', '', $_REQUEST, 'int');
|
|
$args['year'] = V::get('zest_year', '', $_REQUEST, 'int');
|
|
|
$args['_print'] = V::get('_print', '', $_REQUEST, 'int');
|
|
$args['_print'] = V::get('_print', '', $_REQUEST, 'int');
|
|
|
|
|
+ $args['_task'] = V::get('_task', '', $_REQUEST, 'word');
|
|
|
|
|
+
|
|
|
|
|
+ if ('test_fetchDataFromTables' == $args['_task']) {
|
|
|
|
|
+ $budgetAnalyticsRouter->test_fetchDataFromTables();
|
|
|
|
|
+ die('.EOF TEST test_fetchDataFromTables');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (!$args['_print']) {
|
|
if (!$args['_print']) {
|
|
|
$budgetAnalyticsRouter->menu($args['year']);
|
|
$budgetAnalyticsRouter->menu($args['year']);
|
|
@@ -115,7 +121,7 @@ jQuery(document).ready(function () {
|
|
|
$months[] = $i + 1;
|
|
$months[] = $i + 1;
|
|
|
}
|
|
}
|
|
|
$this->css();
|
|
$this->css();
|
|
|
- //echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;">';print_r($costs);echo'</pre>';
|
|
|
|
|
|
|
+ if(V::get('DBG','',$_GET)){echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;display:none">';print_r($costs);echo'</pre>';}
|
|
|
?>
|
|
?>
|
|
|
<div class="container">
|
|
<div class="container">
|
|
|
<div style="float:right;color:#aaa;"><?php echo date("Y-m-d"); ?></div>
|
|
<div style="float:right;color:#aaa;"><?php echo date("Y-m-d"); ?></div>
|
|
@@ -298,10 +304,13 @@ jQuery(document).ready(function () {
|
|
|
union
|
|
union
|
|
|
select `p`.`ID` AS `ID_PROJECT`
|
|
select `p`.`ID` AS `ID_PROJECT`
|
|
|
, date_format(`k`.`K_DATA_OTRZYMANEJ_KORESP`,'%Y-%m') AS `MONTH`
|
|
, date_format(`k`.`K_DATA_OTRZYMANEJ_KORESP`,'%Y-%m') AS `MONTH`
|
|
|
- , sum(`k`.`COST_VALUE`) AS `COST`,sum(`k`.`INCOME_VALUE`) AS `INCOME`
|
|
|
|
|
|
|
+ , sum(`k`.`COST_VALUE`) AS `COST`
|
|
|
|
|
+ , sum(`k`.`INCOME_VALUE`) AS `INCOME`
|
|
|
, 'CHILD' AS `TYPE`
|
|
, 'CHILD' AS `TYPE`
|
|
|
from (`IN7_MK_BAZA_DYSTRYBUCJI` `p`
|
|
from (`IN7_MK_BAZA_DYSTRYBUCJI` `p`
|
|
|
- join `IN7_DZIENNIK_KORESP` `k` on((((`k`.`COST_VALUE` > 0) or (`k`.`INCOME_VALUE` > 0)) and (`k`.`path` like concat('%-',`p`.`ID`,'-%')))))
|
|
|
|
|
|
|
+ join `IN7_DZIENNIK_KORESP` `k` on((((`k`.`COST_VALUE` > 0) or (`k`.`INCOME_VALUE` > 0))
|
|
|
|
|
+ and (`k`.`path` like concat('%-',`p`.`ID`,'-%'))))
|
|
|
|
|
+ )
|
|
|
group by `p`.`ID`, date_format(`k`.`K_DATA_OTRZYMANEJ_KORESP`, '%Y-%m')
|
|
group by `p`.`ID`, date_format(`k`.`K_DATA_OTRZYMANEJ_KORESP`, '%Y-%m')
|
|
|
";
|
|
";
|
|
|
$sql = "
|
|
$sql = "
|
|
@@ -323,4 +332,95 @@ jQuery(document).ready(function () {
|
|
|
group by `t1`.`ID_PROJECT`, `t1`.`MONTH`
|
|
group by `t1`.`ID_PROJECT`, `t1`.`MONTH`
|
|
|
";
|
|
";
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public function test_fetchDataFromTables() {
|
|
|
|
|
+ $this->projectCost = array();
|
|
|
|
|
+ $this->projectPath = array();
|
|
|
|
|
+ $this->projectDesc = array();
|
|
|
|
|
+ $this->tableProjectCost = array();
|
|
|
|
|
+ $db = DB::getDB();
|
|
|
|
|
+
|
|
|
|
|
+ $sql = "select `ID`, `P_ID`, `M_DIST_DESC`
|
|
|
|
|
+ from `IN7_MK_BAZA_DYSTRYBUCJI`
|
|
|
|
|
+ order by `ID`
|
|
|
|
|
+ ";
|
|
|
|
|
+ $res = $db->query($sql);
|
|
|
|
|
+ while ($row = $db->fetch($res)) {
|
|
|
|
|
+ $project_P_ID[$row->P_ID][] = $row->ID;
|
|
|
|
|
+ $this->projectDesc[$row->ID] = $row->M_DIST_DESC;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function buildProjectTree($flat,$id,$tree) {
|
|
|
|
|
+ if (isset($flat[$id])) {
|
|
|
|
|
+ foreach ($flat[$id] as $child) {
|
|
|
|
|
+ $tree[$id][$child] = @buildProjectTree($flat, $child, $tree[$id]);
|
|
|
|
|
+ }
|
|
|
|
|
+ return $tree[$id];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $projectTree[0] = buildProjectTree($project_P_ID, 0, null);
|
|
|
|
|
+ //print_r($projectTree);
|
|
|
|
|
+
|
|
|
|
|
+ $this->test_fetchDataFromTables__buildProjectPath($projectTree, null);
|
|
|
|
|
+ //print_r($this->projectPath);
|
|
|
|
|
+
|
|
|
|
|
+ $sql = "
|
|
|
|
|
+ select `ID_PROJECT`
|
|
|
|
|
+ , `TRANSFER_OPPOSITE_ID_PROJECT`
|
|
|
|
|
+ , date_format(`K_DATA_OTRZYMANEJ_KORESP`, '%Y-%m') as MONTH
|
|
|
|
|
+ , sum(`COST_VALUE`) as COST
|
|
|
|
|
+ from `IN7_DZIENNIK_KORESP`
|
|
|
|
|
+ where `COST_VALUE`>0
|
|
|
|
|
+ and `K_DATA_OTRZYMANEJ_KORESP` like '2015%'
|
|
|
|
|
+ group by `ID_PROJECT`, `MONTH`
|
|
|
|
|
+ order by `MONTH`, `ID_PROJECT`, `TRANSFER_OPPOSITE_ID_PROJECT`
|
|
|
|
|
+ ";
|
|
|
|
|
+ $res = $db->query($sql);
|
|
|
|
|
+ while ($row = $db->fetch($res)) {
|
|
|
|
|
+ foreach ($this->projectPath[$row->ID_PROJECT] as $id) {
|
|
|
|
|
+ if ($row->ID_PROJECT == $id) @$this->projectCost[$id][$row->MONTH]['SELF'] += $row->COST;
|
|
|
|
|
+ else @$this->projectCost[$id][$row->MONTH]['CHILD'] += $row->COST;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($row->TRANSFER_OPPOSITE_ID_PROJECT) {
|
|
|
|
|
+ foreach ($this->projectPath[$row->TRANSFER_OPPOSITE_ID_PROJECT] as $id) {
|
|
|
|
|
+ if ($row->TRANSFER_OPPOSITE_ID_PROJECT == $id) @$this->projectCost[$id][$row->MONTH]['SELF']-=$row->COST;
|
|
|
|
|
+ else @$this->projectCost[$id][$row->MONTH]['CHILD'] -= $row->COST;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //echo'<pre>$projectTree: ';print_r($projectTree);echo'</pre>';
|
|
|
|
|
+ //echo'<pre>projectCost: ';print_r($this->projectCost);echo'</pre>';
|
|
|
|
|
+
|
|
|
|
|
+ $this->test_fetchDataFromTables__genTableProjectCost($projectTree);
|
|
|
|
|
+
|
|
|
|
|
+ echo'<pre>tableProjectCost: ';print_r($this->tableProjectCost);echo'</pre>';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function test_fetchDataFromTables__genTableProjectCost($tree) {
|
|
|
|
|
+ //if (!empty($tree)) echo '<p>DBG: F.' . __FUNCTION__ . ": tree(" . count($tree) . ")" . '</p>';
|
|
|
|
|
+ if (isset($tree)) {
|
|
|
|
|
+ foreach ($tree as $id => $child) {
|
|
|
|
|
+ //echo '<p>DBG: F.' . __FUNCTION__ . ": tree=>child({$id}) isset(" . (isset($this->projectCost[$id])) . ")" . '</p>';
|
|
|
|
|
+ if (isset($this->projectCost[$id])) {
|
|
|
|
|
+ $this->tableProjectCost[$id]['PATH'] = implode('-', $this->projectPath[$id]);
|
|
|
|
|
+ $this->tableProjectCost[$id]['DESC'] = @$this->projectDesc[$id];
|
|
|
|
|
+ $this->tableProjectCost[$id]['COST'] = $this->projectCost[$id];
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->test_fetchDataFromTables__genTableProjectCost($child);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function test_fetchDataFromTables__buildProjectPath($tree, $ppath) {
|
|
|
|
|
+ if (isset($tree)) {
|
|
|
|
|
+ foreach ($tree as $id => $child) {
|
|
|
|
|
+ $this->projectPath[$id] = $ppath;
|
|
|
|
|
+ $this->projectPath[$id][] = $id;
|
|
|
|
|
+ $this->test_fetchDataFromTables__buildProjectPath($child, $this->projectPath[$id]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|