|
@@ -0,0 +1,254 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+function BUDGET_ANALYTICS() {
|
|
|
|
|
+
|
|
|
|
|
+ $budgetAnalyticsRouter = new BudgetAnalyticsRouter();
|
|
|
|
|
+
|
|
|
|
|
+ $_print = V::get('_print', '', $_REQUEST);
|
|
|
|
|
+ if (!$_print) {
|
|
|
|
|
+ $budgetAnalyticsRouter->menu();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $args = array();
|
|
|
|
|
+ $args['year'] = V::get('zest_year', '', $_REQUEST, 'int');
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($args['year'])) {
|
|
|
|
|
+ ?>
|
|
|
|
|
+ <div class="alert alert-warning">
|
|
|
|
|
+ Nie wybrano roku.
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <?
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $costs = $budgetAnalyticsRouter->getCostsByYear($args['year']);
|
|
|
|
|
+ if (empty($costs)) {
|
|
|
|
|
+ ?>
|
|
|
|
|
+ <div class="alert alert-warning">
|
|
|
|
|
+ Brak danych na wybrany rok.
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <?
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $projTree = $budgetAnalyticsRouter->buildProjectTree($costs);
|
|
|
|
|
+ //$orderby = V::get('orderby', '', $_GET);
|
|
|
|
|
+ //$view_type = V::get('view_type', '', $_GET);
|
|
|
|
|
+ //$budgetAnalyticsRouter->cyfrowe($projekty, $grupyKosztow, $costs, $orderby, $view_type);
|
|
|
|
|
+ $budgetAnalyticsRouter->printCostsForYear($projTree, $costs, $args['year']);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class BudgetAnalyticsRouter {
|
|
|
|
|
+
|
|
|
|
|
+ function menu() {
|
|
|
|
|
+ //SE_Layout::menu();
|
|
|
|
|
+ ?>
|
|
|
|
|
+<div class="jumbotron">
|
|
|
|
|
+ <div class="container">
|
|
|
|
|
+ <form class="form-inline" method="POST">
|
|
|
|
|
+ <input type="hidden" name="task" value="zest_year" />
|
|
|
|
|
+ <label for="zest_year">Zestawienie kosztów projektów na podstawie korespondencji:</label>
|
|
|
|
|
+ <div class="input-group date" id="fldZestYear">
|
|
|
|
|
+ <input type="text" name="zest_year" class="form-control" value="" />
|
|
|
|
|
+ <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <button type="submit" id="fldZestYearBtn" class="btn btn-primary" autocomplete="off">
|
|
|
|
|
+ Pokaż
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</div>
|
|
|
|
|
+<script type="text/javascript">
|
|
|
|
|
+jQuery(document).ready(function () {
|
|
|
|
|
+ jQuery('#fldZestYearBtn').on('click', function () {
|
|
|
|
|
+ jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
|
|
|
|
|
+ jQuery(this).parent().submit();
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ jQuery("#fldZestYear").datetimepicker({
|
|
|
|
|
+ format: "YYYY",
|
|
|
|
|
+ defaultDate: new Date(<?php echo date("Y"); ?>, <?php echo intval(date("m")); ?>, 1),
|
|
|
|
|
+ // minDate: new Date(2014, 11, 1),
|
|
|
|
|
+ // maxDate: "<?php echo date("Y"); ?>"
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+</script>
|
|
|
|
|
+ <?php
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function css() {
|
|
|
|
|
+ ?>
|
|
|
|
|
+ <style type="text/css">
|
|
|
|
|
+.oferta-programowa { border-collapse:collapse; border:1px solid #7EC5FF; }
|
|
|
|
|
+.oferta-programowa td { border:1px solid #7EC5FF; }
|
|
|
|
|
+.oferta-programowa .prog-group { color:#7A7A7A; }
|
|
|
|
|
+.oferta-programowa .cyfrowe-prog-count {}
|
|
|
|
|
+.oferta-programowa .p2 { padding:0 2px; }
|
|
|
|
|
+.oferta-programowa .c { text-align:center; }
|
|
|
|
|
+.oferta-programowa .r { text-align:right; }
|
|
|
|
|
+.oferta-programowa .cyfrowe-prog-count td { background-color:#fff; }
|
|
|
|
|
+.oferta-programowa .hd { background-color:#FF5F5F; color:#fff; font-weight:bold; }
|
|
|
|
|
+.oferta-programowa .nr { color:#7A7A7A; }
|
|
|
|
|
+.oferta-programowa thead th { border:1px solid #7EC5FF; }
|
|
|
|
|
+
|
|
|
|
|
+#oferta-programowa-cyfrowe thead { background:none; }
|
|
|
|
|
+#oferta-programowa-cyfrowe thead th { vertical-align:bottom; border:none; }
|
|
|
|
|
+#oferta-programowa-cyfrowe .logo { text-align:center; background-color:#fff; border:none; }
|
|
|
|
|
+#oferta-programowa-cyfrowe .vertical { height:30px; white-space:nowrap; line-height:30px; padding:2px 0; }
|
|
|
|
|
+
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-24 {background-color:#EBEBEB;} /* Biały */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-25 {background-color:#B88019;} /* Brązowy */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-26 {background-color:#CACACA;} /* Srebrny */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-27 {background-color:#FFE554;} /* Złoty */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-28 {background-color:#E7E4E4;} /* Platynowy */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-8 {background-color:#94CFFF;} /* CANAL+ */
|
|
|
|
|
+#oferta-programowa-cyfrowe .prog-pakiet-10 {background-color:#77A3FF;} /* CANAL+ HD */
|
|
|
|
|
+
|
|
|
|
|
+#oferta-programowa-analogowe { }
|
|
|
|
|
+
|
|
|
|
|
+/* print table background colors */
|
|
|
|
|
+table td, table th { -webkit-print-color-adjust:exact; }
|
|
|
|
|
+table { page-break-after:auto }
|
|
|
|
|
+tr { page-break-inside:avoid; page-break-after:auto; position:relative; }
|
|
|
|
|
+td { page-break-inside:avoid; page-break-after:auto; position:relative; }
|
|
|
|
|
+thead { display:table-header-group }
|
|
|
|
|
+tfoot { display:table-footer-group }
|
|
|
|
|
+
|
|
|
|
|
+ .cost { padding:0 2px; min-width:30px; text-align:right; }
|
|
|
|
|
+ .cost-only_child { color:#777; }
|
|
|
|
|
+ .cost-only_self { color:red; }
|
|
|
|
|
+ .cost-self_and_child { color:orange; }
|
|
|
|
|
+ </style>
|
|
|
|
|
+ <?php
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function printCostsForYear($projOrder, $costs, $year) {
|
|
|
|
|
+ $months = array();
|
|
|
|
|
+ for ($i = 0; $i < 12; $i++) {
|
|
|
|
|
+ $months[] = $i + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->css();
|
|
|
|
|
+ //echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;">';print_r($costs);echo'</pre>';
|
|
|
|
|
+?>
|
|
|
|
|
+ <div style="float:right;color:#aaa;"><?php echo date("Y-m-d"); ?></div>
|
|
|
|
|
+ <h1>Zestawienie kosztów projektów na podstawie korespondencji</h1>
|
|
|
|
|
+ <table cellspacing="0" cellpadding="0" border="0" id="oferta-programowa-cyfrowe" class="oferta-programowa">
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td colspan="3" style="text-align:right">
|
|
|
|
|
+ miesiąc
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <?php foreach ($months as $month) { ?>
|
|
|
|
|
+ <th class="c"><?php echo $month; ?></th>
|
|
|
|
|
+ <?php } ?>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ <?php $t = 1; ?>
|
|
|
|
|
+ <?php foreach ($projOrder as $projPath => $projId) : ?>
|
|
|
|
|
+ <?php $projectInfo = $costs[$projId]; ?>
|
|
|
|
|
+ <tr class="row-<?php echo ($t = 1 - $t); ?>">
|
|
|
|
|
+ <td class="p2 r nr"><?php echo $projectInfo->path; ?></td>
|
|
|
|
|
+ <td class="p2" style="max-width:300px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"><?php echo $projectInfo->M_DIST_DESC; ?></td>
|
|
|
|
|
+ <td class="p2 r nr"><input type="checkbox" name="selectedProject" value="<?php echo $projectInfo->ID_PROJECT; ?>" /></td>
|
|
|
|
|
+ <?php foreach ($months as $month) : ?>
|
|
|
|
|
+ <?php if (array_key_exists($month, $projectInfo->costsByMonth)) : ?>
|
|
|
|
|
+ <?php $vCost = V::get($month, '', $projectInfo->costsByMonth); ?>
|
|
|
|
|
+ <?php if ($vCost->COST_CHILD > 0) : ?>
|
|
|
|
|
+ <?php $title = "Koszt projektu {$vCost->COST_SELF} / koszt podprojektów {$vCost->COST_CHILD}"; ?>
|
|
|
|
|
+ <?php if ($vCost->COST_SELF > 0) : ?>
|
|
|
|
|
+ <td class="cost cost-self_and_child"><span class="ttip" title="<?php echo $title; ?>"><?php echo $vCost->COST_TOTAL; ?></span></td>
|
|
|
|
|
+ <?php else : ?>
|
|
|
|
|
+ <td class="cost cost-only_child"><span class="ttip" title="<?php echo $title; ?>"><?php echo $vCost->COST_TOTAL; ?></span></td>
|
|
|
|
|
+ <?php endif; ?>
|
|
|
|
|
+ <?php else : ?>
|
|
|
|
|
+ <td class="cost cost-only_self"><?php echo $vCost->COST_TOTAL; ?></td>
|
|
|
|
|
+ <?php endif; ?>
|
|
|
|
|
+ <?php else : ?>
|
|
|
|
|
+ <td style="min-width:30px"> </td>
|
|
|
|
|
+ <?php endif; ?>
|
|
|
|
|
+ <?php endforeach; ?>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ <?php endforeach; ?>
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
|
|
+<script>
|
|
|
|
|
+ jQuery(document).ready(function(){
|
|
|
|
|
+ jQuery('.ttip').tooltip();
|
|
|
|
|
+ });
|
|
|
|
|
+</script>
|
|
|
|
|
+<?php
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getCostsByYear($year) {
|
|
|
|
|
+ $db = DB::getDB();
|
|
|
|
|
+ $costs = array();
|
|
|
|
|
+ $sql = "
|
|
|
|
|
+ select
|
|
|
|
|
+ t.`ID_PROJECT`
|
|
|
|
|
+ , t.`M_DIST_DESC`
|
|
|
|
|
+ , t.`P_ID`
|
|
|
|
|
+ , t.`path`
|
|
|
|
|
+ , t.`MONTH`
|
|
|
|
|
+ , t.`COST_SELF`
|
|
|
|
|
+ , t.`COST_CHILD`
|
|
|
|
|
+ , t.`COST_TOTAL`
|
|
|
|
|
+ , t.`INCOME_SELF`
|
|
|
|
|
+ , t.`INCOME_CHILD`
|
|
|
|
|
+ , t.`INCOME_TOTAL`
|
|
|
|
|
+ from `test_budget_project_synthetics_view` as t
|
|
|
|
|
+ where 1=1
|
|
|
|
|
+ and t.`MONTH` like '{$year}-%'
|
|
|
|
|
+ ";
|
|
|
|
|
+ $res = $db->query($sql);
|
|
|
|
|
+ while ($r = $db->fetch($res)) {
|
|
|
|
|
+ if (!array_key_exists($r->ID_PROJECT, $costs)) {
|
|
|
|
|
+ $projectInfo = new stdClass();
|
|
|
|
|
+ $projectInfo->ID_PROJECT = $r->ID_PROJECT;
|
|
|
|
|
+ $projectInfo->M_DIST_DESC = $r->M_DIST_DESC;
|
|
|
|
|
+ $projectInfo->path = $r->path;
|
|
|
|
|
+ $projectInfo->costsByMonth = array();
|
|
|
|
|
+ $costs[$r->ID_PROJECT] = $projectInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ $cost = new stdClass();
|
|
|
|
|
+ $cost->MONTH = $r->MONTH;
|
|
|
|
|
+ $cost->COST_SELF = $r->COST_SELF;
|
|
|
|
|
+ $cost->COST_CHILD = $r->COST_CHILD;
|
|
|
|
|
+ $cost->COST_TOTAL = $r->COST_TOTAL;
|
|
|
|
|
+ $cost->INCOME_SELF = $r->INCOME_SELF;
|
|
|
|
|
+ $cost->INCOME_CHILD = $r->INCOME_CHILD;
|
|
|
|
|
+ $cost->INCOME_TOTAL = $r->INCOME_TOTAL;
|
|
|
|
|
+ $monthNum = intval(substr($r->MONTH, 5, 2));
|
|
|
|
|
+ $costs[$r->ID_PROJECT]->costsByMonth[$monthNum] = $cost;
|
|
|
|
|
+ }
|
|
|
|
|
+ return $costs;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function buildProjectTree($costs) {
|
|
|
|
|
+ $projPaths = array();
|
|
|
|
|
+ foreach ($costs as $idProject => $projectInfo) {
|
|
|
|
|
+ $projPaths[$projectInfo->path] = $projectInfo->ID_PROJECT;
|
|
|
|
|
+ }
|
|
|
|
|
+ //echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;">projPaths: ';print_r($projPaths);echo'</pre>';
|
|
|
|
|
+ uksort($projPaths, array($this, 'sortPathsCallback'));
|
|
|
|
|
+ //echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;">projPaths sorted: ';print_r($projPaths);echo'</pre>';
|
|
|
|
|
+ return $projPaths;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function sortPathsCallback($a, $b) {
|
|
|
|
|
+ $ea = explode('-', $a);
|
|
|
|
|
+ $eb = explode('-', $b);
|
|
|
|
|
+ $la = count($ea);
|
|
|
|
|
+ $lb = count($eb);
|
|
|
|
|
+ $lmin = min($la, $lb);
|
|
|
|
|
+ for ($i = 0; $i < $lmin; $i++) {
|
|
|
|
|
+ if ($ea[$i] < $eb[$i]) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ } else if ($ea[$i] > $eb[$i]) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $la - $lb;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|