Commit c0568f8b authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Vue de synthèse OK (ajout des sous-totaux pour les groupes multiples)

parent 6bbcc763
Loading
Loading
Loading
Loading
+87 −21
Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 87 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -1194,50 +1194,99 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
            'persons' => []
        ];

        /** @var string[] $ceStr Liste des acronymes des autres activités */
        $ceStr = [];

        $strData = [];

        $totaux = [
            // Totaux Lots
            'wps' => [

            ],

            'totalMain' => 0.0,

            // Totaux autres projets
            'ce' => [

            ],
            'totalCe' => 0.0,

            // Totaux hors-lots
            'others' => [

            ],

            // Total groupes
            'groups' => [

            ],

            // Total
            'total'     => 0.0
        ];


        /** @var [] $others Détails des Hors-Lots */
        $others = $this->getOthersWP();

        /** @var Activity $activity */
        $activity = $this->getEntityManager()->getRepository(Activity::class)->find($idActivity);

        /** @var integer[] $personIds Identififiants des déclarants de l'activité */
        $personIds = [];

        /** @var Person $person */
        foreach ($activity->getDeclarers() as $person) {
            $personIds[] = $person->getId();
        }

        $strData = [];
        $lots = [];
        /** @var string[] $lotsStr Liste des codes des lots de travail de l'activité */
        $lotsStr = [];
        $othersGroups = [];

        /** @var [] $lots Détails des Lots de travail de l'activité */
        $lots = [];

        /** @var $lot WorkPackage */
        foreach( $activity->getWorkPackages() as $lot){
            $lots[$lot->getId()] = $lot->toArray();
            $lotsStr[] = $lot->getCode();
            $totaux['wps'][$lot->getCode()] = 0.0;
        }

        $ceStr = [];
        // Hors-lots
        $othersGroups = [];

        // Données des déclarants pour la période
        $datas = $this->getTimesheetRepository()->getPersonPeriodSynthesis($personIds, $period);

        // Parse préabable pour obtenir la liste des autres projets dans lesquel les déclarants sont identifiés
        foreach ($datas as $d){
            if( $d['activity_id'] && $d['activity_id'] != $idActivity ){
                $acronym = $d['acronym'];
                if( !in_array($acronym, $ceStr) ){
                    $ceStr[] = $d['acronym'];
                    $ceStr[] = $acronym;
                    $totaux['ce'][$acronym] = 0.0;
                }
            }
        }

        $others = $this->getOthersWP();

        foreach ($others as $key=>$other) {
            if( $key == 'research' ) continue;

            $totaux['others'][$key] = 0.0;

            $group = $other['group'];

            if( !array_key_exists($group, $othersGroups) ){
                $othersGroups[$group] = [];
                $totaux['groups'][$group] = 0.0;
            }

            $othersGroups[$group][$key] = $other;
        }

        // INITIALISATION de la SORTIE
        foreach ($activity->getDeclarers() as $person) {
            $personIds[] = $person->getId();
            $output['persons'][$person->getId()] = $this->getTimesheetDatasPersonPeriod($person, $period);
@@ -1251,10 +1300,8 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
                    'total' => 0.0
                ],
                'totalMain' => 0.0,
                'totalProjets' => 0.0,
//                'totalProjets' => 0.0,
                'totalProjects' => 0.0,
                'totalResearch' => 0.0,
                //'totalProjets' => 0.0,
            ];

            foreach ($lotsStr as $l){
@@ -1266,12 +1313,18 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
            }

            foreach ($others as $key=>$other) {
                if( $key != 'research' ){
                $group = $other['group'];

                $strData[(string)$person]['others'][$key] = 0.0;
                    $strData[(string)$person]['totaux'][$other['group']] = 0.0;
                } else {
                    $strData[(string)$person]['othersGroups'][$other['group']] = 0.0;
                $strData[(string)$person]['totaux'][$group] = 0.0;

                if( !array_key_exists($group, $strData[(string)$person]['othersGroups']) ){
                    $strData[(string)$person]['othersGroups'][$group] = [
                        'total' => 0.0,
                        'others' => []
                    ];
                }
                $strData[(string)$person]['othersGroups'][$group]['others'][$key] = 0.0;
            }
        }

@@ -1280,20 +1333,25 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
            $person = $d['person'];
            $key = $d['itemkey'];
            $duration = (float)$d['duration'];

            $activityId = $d['activity_id'];

            // Hors-lot
            if( !$activityId ){
                $group = $others[$key]['group'];

                if( $key == 'research' ){
                    $strData[$person]['otherresearch'] += $duration;
                    $strData[$person]['totalResearch'] += $duration;
                } else {
                $strData[$person]['others'][$key] += $duration;
                $strData[$person]['othersGroups'][$group]['others'][$key] += $duration;
                $strData[$person]['othersGroups'][$group]['total'] += $duration;
                $strData[$person]['totaux'][$group] += $duration;

                if( $group == 'research' ){
                    $strData[$person]['otherresearch'] += $duration;
                    $strData[$person]['totalResearch'] += $duration;
                    $totaux['totalResearch'] += $duration;
                }
                $totaux['groups'][$group] += $duration;
                $totaux['others'][$key] += $duration;

            } else {
                // Projet
                if($activityId == $idActivity){
@@ -1302,24 +1360,32 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
                    }
                    $strData[$person]['totalMain'] += $duration;
                    $strData[$person]['main'][$key] += $duration;
                    $totaux['wps'][$key] += $duration;
                    $totaux['totalMain'] += $duration;
                } else {
                    $acronym = $d['acronym'];
                    $strData[$person]['ce'][$acronym] += $duration;
                    $strData[$person]['totalProjects'] += $duration;
                    $totaux['totalCe'] += $duration;
                    $totaux['ce'][$acronym] += $duration;
                }
                $totaux['totalResearch'] += $duration;
                $strData[$person]['totalResearch'] += $duration;
            }
            $strData[$person]['totaux']['total'] += $duration;
            $totaux['total'] += $duration;
        }

        $output['foo'] = $strData;
        $output['others'] = $others;
        $output['othersGroups'] = $othersGroups;
        $output['ces'] = $ceStr;
        $output['datas'] = $datas;
       // $output['datas'] = $datas;
        $output['totaux'] = $totaux;
        $output['wps'] = $lots;
        $output['activity'] = $activity->toArray();


        return $output;
    }

+241 −40
Changes for module/Oscar/view/oscar/timesheet/synthesis-activity-period.phtml: 241 added lines, 40 removed lines.
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@
$labels = [
    "abs" => "Absent",
    "education" => "Éducation",
    "other" => "Autre"
    "other" => "Autre",
    "research" => "Recherche"
]
?>
<style>
@@ -37,16 +38,36 @@ $labels = [
    .duration {
        text-align: right;
    }


    tr {
        border: none;
    }
    th {
        border: solid thin rgba(255,255,255,.2);
    }
    .table > thead > tr > th {
        border: none;
    }
    .table > thead > tr th {
        border: solid thin rgba(255,255,255,.2);
        vertical-align: center;
    }
</style>

<table class="table table-condensed" style="border: 0">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th class="research" colspan="<?= count($wps)+1 +count($ces)+2 ?>"><i class="icon-beaker"></i> Recherche</th>
            <?php
            // Nombre de colonne dans les groupe
            $colWP      = count($wps) + (count($wps)>1 ? 1 : 0);
            $colCE      = count($ces) + (count($ces)>1 ? 1 : 0);
            $colSEARCH  = count($othersGroups['research']) + (count($othersGroups['research'])>1 ? 1 : 0);

            $colEDU = count()
            ?>
            <th class="research" colspan="<?= $colWP + $colCE + $colSEARCH +1 ?>"><i class="icon-beaker"></i> Recherche</th>

            <?php foreach ($othersGroups as $k=>$othersGroup):?>
            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k == 'research') continue;?>
                <th class="<?= $k ?>" colspan="<?= count($othersGroup)+(count($othersGroup)>1 ? 1 : 0) ?>">
                    <i class="icon-<?= $k ?>"></i>
                    <?= $labels[$k] ?>
@@ -55,46 +76,58 @@ $labels = [
        </tr>
        <tr>
            <th>&nbsp;</th>
            <th colspan="<?= count($wps)+1 ?>" class="main">
                <strong title="<?= $activity['label'] ?>">
                    <i class="icon-cube"></i>
                    <?= $activity['projectacronym'] ?></strong>
            </th>
            <?php foreach ($ces as $acronym): ?>
                <th class="research ce" rowspan="2">
                    <strong><i class="icon-cube"></i><?= $acronym ?></strong>
                </th>
            <?php endforeach; ?>

            <th class="research" rowspan="2">Autres</th>
            <th class="main" rowspan="2"><strong>TOTAL</strong></th>
            <?php foreach ($othersGroups as $k=>$othersGroup):?>
            <th class="research" colspan="<?= $colWP ?>"><i class="icon-cubes"></i> PROJET</th>
            <th class="research" colspan="<?= $colCE ?>"><i class="icon-cubes"></i> autres projets</th>
            <th class="research" colspan="<?= $colSEARCH ?>"><i class="icon-cubes"></i> autres recherches</th>
            <th class="research" rowspan="2">TOTAL</th>

            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k == 'research') continue;?>
                <?php foreach ($othersGroup as $other): ?>
            <th class="<?= $k ?>" rowspan="2"><?= $other['label'] ?></th>
                    <th class="<?= $k ?>" rowspan="2">
                        <?= $other['label'] ?>
                    </th>
                <?php endforeach; ?>
                <?php if( count($othersGroup) > 1): ?>
                    <th class="<?= $k ?>" rowspan="2">Total</th>
                    <th class="<?= $k ?>" rowspan="2">
                        <strong>Total</strong>
                    </th>
                <?php endif; ?>
            <?php endforeach; ?>

            <th>&nbsp;</th>
        </tr>
        <tr>
            <th>&nbsp;</th>
        <?php foreach ($wps as $id=>$wp): ?>
            <th class="main">
                <strong title="<?= $wp['label'] ?>">
                    <?= $wp['code'] ?>
                </strong>

            <?php foreach ($wps as $code=>$wp): ?>
                <th class="research activity">
                    <strong><i class="icon-archive"></i><?= $wp['code'] ?></strong>
                </th>
            <?php endforeach; ?>
            <?php if( count($wps) > 1): ?>
                <th class="research activity">
                    <strong>Total</strong>
                </th>
            <?php endif; ?>

        <th class="main">
            <?php foreach ($ces as $acronym): ?>
                <th class="research ce" rowspan="2">
                    <strong><i class="icon-cube"></i><?= $acronym ?></strong>
                </th>
            <?php endforeach; ?>
            <?php if( count($ces) > 1): ?>
                <th class="research activity">
                    <strong>Total</strong>
                </th>
            <th class="">
                <strong>TOTAL MOIS</strong>
            <?php endif; ?>

            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k != 'research') continue;?>
                <th class="<?= $k ?>" colspan="<?= count($othersGroup)+(count($othersGroup)>1 ? 1 : 0) ?>">
                    <i class="icon-<?= $k ?>"></i>
                    <?= $labels[$k] ?>
                </th>
            <?php endforeach; ?>

        </tr>
    </thead>
    <tbody>
@@ -116,27 +149,195 @@ $labels = [
                </td>
            <?php endforeach; ?>

        <td class="research duration">
            <?= $this->duration($line['otherresearch']) ?>

            <?php if( count($ces) > 1): ?>
                <th class="research duration">
                    <strong><?= $this->duration($line['totalProjects']) ?></strong>
                </th>
            <?php endif; ?>

            <?php if( array_key_exists('research', $line['othersGroups'] ) ): ?>
                <?php foreach ($line['othersGroups']['research']['others'] as $duration): ?>
                    <td class="ce research duration">
                        <?= $this->duration($duration) ?>
                    </td>
        <td class="main duration">
            <strong><?= $this->duration($line['totalResearch']) ?></strong>
                <?php endforeach; ?>


            <?php endif; ?>

            <td class="ce research duration">
                <strong>
                <?= $this->duration($line['totalResearch']) ?>
                </strong>
            </td>

        <?php foreach ($othersGroups as $k=>$othersGroup): $group = $othersGroup['group']; ?>
            <?php foreach ($othersGroup as $other):?>
                <td class="<?= $k ?> duration"><?= $this->duration($line['others'][$other['code']]) ?></td>
            <?php foreach ($line['othersGroups']['research'] as $dt): ?>
                <?php foreach ($dt['others'] as $other=>$duration): ?>
                <td class="ce research duration">
                    d<?= $this->duration($duration) ?>
                </td>
                <?php endforeach; ?>
            <?php if(count($othersGroup) > 1): ?>
            <td class="<?= $k ?> duration"><strong><?= $this->duration($line['totaux'][$k]) ?></strong></td>
                <?php if( count($dt['others']) > 1): ?>
                <td class="ce research duration">
                    <strong><?= $this->duration($dt['total']) ?></strong>
                </td>
                <?php endif; ?>
            <?php endforeach; ?>

            <?php foreach ($line['othersGroups'] as $group=>$dt): if($group == 'research') continue;?>
                <?php foreach ($dt['others'] as $other=>$duration): ?>
                    <td class="ce <?= $group ?> duration">
                        <?= $this->duration($duration) ?>
                    </td>
                <?php endforeach; ?>
                <?php if( count($dt['others']) > 1): ?>
                    <td class="ce <?= $group ?> duration">
                        <strong><?= $this->duration($dt['total']) ?></strong>
                    </td>
                <?php endif; ?>
            <?php endforeach; ?>

            <td style="background: #fff" class="duration">
            <?= $line['totaux']['total'] ?>
                <strong><?= $this->duration($line['totaux']['total']) ?></strong>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>

    <tfoot>
    <tr>
        <th>&nbsp;</th>
        <?php foreach( $totaux['wps'] as $wp=>$duration ): ?>
            <th class="duration">
                <strong><?= $this->duration($duration) ?></strong>
            </th>
        <?php endforeach; ?>

        <?php if( count($wps) > 1 ): ?>
            <th class="duration">
                <strong><?= $this->duration($totaux['totalMain']) ?></strong>
            </th>
        <?php endif; ?>


        <?php foreach( $totaux['ce'] as $acronym=>$duration ): ?>
            <th class="duration">
                <strong><?= $this->duration($duration) ?></strong>
            </th>
        <?php endforeach; ?>
        <?php if( count($ces) > 1 ): ?>
            <th class="duration">
                <strong><?= $this->duration($totaux['totalCe']) ?></strong>
            </th>
        <?php endif; ?>

        <?php foreach ($othersGroups as $group=>$dt): if($group != 'research') continue;?>

            <?php foreach ($dt as $code=>$other): ?>
                <td class="duration">
                    <strong><?= $this->duration($totaux['others'][$code]) ?></strong>
                </td>
            <?php endforeach; ?>
            <?php if( count($dt['others']) > 1): ?>
                <td class="duration">
                    <strong><?= $this->duration($totaux['groups']['research']) ?></strong>
                </td>
            <?php endif; ?>
        <?php endforeach; ?>
        <td class="duration">
            <strong><?= $this->duration($totaux['totalResearch']) ?></strong>
        </td>

        <?php foreach ($othersGroups as $group=>$dt): if($group == 'research') continue;?>

            <?php foreach ($dt as $code=>$other): ?>
                <td class="duration">
                    <strong><?= $this->duration($totaux['others'][$code]) ?></strong>
                </td>
            <?php endforeach; ?>
            <?php if( count($dt) > 1): ?>
                <td class="duration">
                    <strong><?= $this->duration($totaux['groups'][$group]) ?></strong>
                </td>
            <?php endif; ?>
        <?php endforeach; ?>
        <td class="duration">
            <strong><?= $this->duration($totaux['total']) ?></strong>
        </td>


        <th>&nbsp;</th>
    </tr>
    </tfoot>
</table>
<pre><?php var_dump($othersGroups) ?></pre>

<?php /*
<table class="table table-condensed" style="border: 0">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th class="research" colspan="<?= count($wps)+1 +count($ces)+1 + count($research) ?>"><i class="icon-beaker"></i> Recherche</th>

            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k == 'research') continue;?>
                <th class="<?= $k ?>" colspan="<?= count($othersGroup)+(count($othersGroup)>1 ? 1 : 0) ?>">
                    <i class="icon-<?= $k ?>"></i>
                    <?= $labels[$k] ?>
                </th>
            <?php endforeach; ?>
        </tr>
        <tr>
            <th>&nbsp;</th>
            <th colspan="<?= count($wps)+1 ?>" class="main">
                <strong title="<?= $activity['label'] ?>">
                    <i class="icon-cube"></i>
                    <?= $activity['projectacronym'] ?></strong>
            </th>
            <?php foreach ($ces as $acronym): ?>
                <th class="research ce" rowspan="2">
                    <strong><i class="icon-cube"></i><?= $acronym ?></strong>
                </th>
            <?php endforeach; ?>

            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k != 'research') continue;?>
                <th class="<?= $k ?>" colspan="<?= count($othersGroup)+(count($othersGroup)>1 ? 1 : 0) ?>">
                    <i class="icon-<?= $k ?>"></i>
                    <?= $labels[$k] ?>
                </th>
            <?php endforeach; ?>

            <th class="main" rowspan="2"><strong>TOTAL</strong></th>
            <?php foreach ($othersGroups as $k=>$othersGroup): if( $k == 'research') continue; ?>
                <?php foreach ($othersGroup as $other):?>
            <th class="<?= $k ?>" rowspan="2"><?= $other['label'] ?></th>
                <?php endforeach; ?>
                <?php if(count($othersGroup) > 1): ?>
                    <th class="<?= $k ?>" rowspan="2">Total</th>
                <?php endif; ?>
            <?php endforeach; ?>

            <th>&nbsp;</th>
        </tr>
        <tr>
            <th>&nbsp;</th>
        <?php foreach ($wps as $id=>$wp): ?>
            <th class="main">
                <strong title="<?= $wp['label'] ?>">
                    <?= $wp['code'] ?>
                </strong>
            </th>
        <?php endforeach; ?>

        <th class="main">
            <strong>Total</strong>
        </th>
        </th>
            <th class="">
                <strong>TOTAL MOIS</strong>
            </th>
        </tr>
    </thead>
    <tbody>
/****/

?>
 No newline at end of file