Loading module/Oscar/src/Oscar/Controller/TimesheetController.php +3 −44 Changes for module/Oscar/src/Oscar/Controller/TimesheetController.php: 3 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -1045,51 +1045,10 @@ class TimesheetController extends AbstractOscarController public function resumeAction(){ $roles = $this->getOscarUserContext()->getRoleIdPrimary(); $organizations = $this->getPersonService()->getOrganizationsPersonWithPrincipalRole( $this->getCurrentPerson()); foreach ($organizations as $organization) { echo "<li> O : $organization</li>"; } return [ 'datas' => $this->getTimesheetService()->getResumePerson($this->getCurrentPerson()) ]; // $structures = $this->getEntityManager()->getRepository(OrganizationPerson::class)->createQueryBuilder('s') // ->where('s.person = :person AND s.role IN(:roles)') // ->setParameters([ // 'person' => $currentPerson, // 'roles' => $roles, // ]) // ->getQuery() // ->getResult() // ; // // // $projects = []; // // /** @var OrganizationPerson $organizationPerson */ // foreach( $structures as $organizationPerson ){ // $orgaId = $organizationPerson->getOrganization()->getId(); // if( !isset($projects[$orgaId]) ){ // $projects[$orgaId] = [ // 'organization' => $organizationPerson->getOrganization(), // 'projects' => [] // ]; // } // /** @var ProjectPartner $partner */ // foreach($organizationPerson->getOrganization()->getProjects() as $partner ){ // if( in_array($partner->getRole(), $this->getOscarUserContext()->getRolesOrganisationLeader())) // $projects[$orgaId]['projects'][] = $partner->getProject(); // } // /** @var ActivityOrganization $activityPartner */ // foreach($organizationPerson->getOrganization()->getActivities() as $activityPartner ){ // // Cas des activités sans projet // if( $activityPartner->getActivity()->getProject() && in_array($activityPartner->getRole(), $this->getOscarUserContext()->getRolesOrganisationLeader()) ) // $projects[$orgaId]['projects'][] = $activityPartner->getActivity()->getProject(); // } // } die("RESUME"); } public function validationsAction() { Loading module/Oscar/src/Oscar/Entity/Activity.php +14 Changes for module/Oscar/src/Oscar/Entity/Activity.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1900,6 +1900,20 @@ class Activity implements ResourceInterface return self::class; } public function getDateStartStr(){ if( $this->getDateStart() ){ return $this->getDateStart()->format('Y-m-d'); } return ""; } public function getDateEndStr(){ if( $this->getDateEnd() ){ return $this->getDateEnd()->format('Y-m-d'); } return ""; } public function toJson() { return [ Loading module/Oscar/src/Oscar/Entity/TimeSheet.php +7 Changes for module/Oscar/src/Oscar/Entity/TimeSheet.php: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -399,6 +399,13 @@ class TimeSheet implements ITrackable ]; } /** * @return string */ public function getPeriodCode(){ return $this->getDateFrom()->format('Y-m'); } public function toJson(){ $activityId = null; $activityLabel = null; Loading module/Oscar/src/Oscar/Service/TimesheetService.php +145 Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 145 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -925,6 +925,151 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa return $total; } public function getActivitiesWithDeclarant( Person $person ){ return $this->getEntityManager()->getRepository(Activity::class)->createQueryBuilder('a') ->innerJoin('a.workPackages', 'wp') ->innerJoin('wp.persons', 'wpp') ->where('wpp.person = :person') ->getQuery() ->setParameter('person', $person) ->getResult(); } public function getResumePerson( Person $person ){ $declarantInActivities = $this->getActivitiesWithDeclarant($person); $now = new \DateTime(); $periodNow = $now->format('Y-m'); $minPeriod = $now->getTimestamp(); $maxPeriod = $now->getTimestamp(); $datas = [ 'minDate' => "", 'maxDate' => "", 'periods' => [], 'activities' => [], 'validations' => [], 'horslots' => [] ]; $periodsDetails = []; foreach ($this->getOthersWP() as $hl) { $datas['horslots'][$hl['code']] = [ 'code' => $hl['code'], 'label' => $hl['label'] ]; } /** @var Activity $activity */ foreach ($declarantInActivities as $activity) { $activityDatas = [ 'id' => $activity->getId(), 'acronym' => $activity->getAcronym(), 'label' => $activity->getLabel(), 'workpackages' => [], 'total' => 0.0, 'start' => $activity->getDateStartStr(), 'dateend' => $activity->getDateEndStr(), ]; $workPackagesId = []; /** @var WorkPackage $workPackage */ foreach ($activity->getWorkPackages() as $workPackage) { $workPackagesId[] = $workPackage->getId(); $activityDatas['workpackages'][$workPackage->getId()] = [ 'id' => $workPackage->getId(), 'code' => $workPackage->getCode(), 'label' => $workPackage->getLabel(), 'available' => $workPackage->hasPerson($person), 'total' => 0.0 ]; } if( $activity->getDateStart() && $activity->getDateEnd() ){ $periods = DateTimeUtils::allperiodsBetweenTwo($activity->getDateStart()->format('Y-m'), $activity->getDateEnd()->format('Y-m')); foreach ($periods as $period) { if( !array_key_exists($period, $periodsDetails) ){ $split = explode('-', $period); $year = $split[0]; $month = $split[1]; $periodsDetails[$period] = [ 'period' => $period, 'month' => $month, 'year' => $year, 'past' => $period < $periodNow, 'current' => $period == $periodNow, 'futur' => $period > $periodNow, 'activities_id' => [], 'workpackages_id' => [], 'unexpected' => false, 'total' => 0.0, 'total_activities' => 0.0, 'total_horslots' => 0.0, 'validations_id' => [] ]; } $periodsDetails[$period]['activities_id'][] = $activity->getId(); $periodsDetails[$period]['workpackages_id'] = $workPackagesId; } } if( $activity->getDateStart() ) { $minPeriod = min($minPeriod, $activity->getDateStart()->getTimestamp()); } if( $activity->getDateEnd() ) { $maxPeriod = max($maxPeriod, $activity->getDateEnd()->getTimestamp()); } $datas['activities'][$activityDatas['id']] = $activityDatas; } $timesheets = $this->getEntityManager()->getRepository(TimeSheet::class)->findBy(['person' => $person]); /** @var TimeSheet $timesheet */ foreach ($timesheets as $timesheet) { $period = $timesheet->getPeriodCode(); if( !array_key_exists($period, $periodsDetails) ){ $periodsDetails[$period] = [ 'period' => $period, 'activities_id' => [], 'workpackages_id' => [], 'unexpected' => true, 'total' => 0.0, 'total_activities' => 0.0, 'total_horslots' => 0.0, 'validations_id' => [] ]; } $total = $timesheet->getDuration(); $periodsDetails[$period]['total'] += $total; if( $timesheet->getActivity() ){ $periodsDetails[$period]['total_activities'] += $total; } else { $periodsDetails[$period]['total_horslots'] += $total; } } $declarations = $this->getEntityManager()->getRepository(ValidationPeriod::class)->findBy(['declarer' => $person]); /** @var ValidationPeriod $declaration */ foreach ($declarations as $declaration) { $period = DateTimeUtils::getCodePeriod($declaration->getYear(), $declaration->getMonth()); $periodsDetails[$period]['validations_id'][] = $declaration->getId(); $datas['validations'][$declaration->getId()] = $declaration->toJson(); } $datas['periods'] = $periodsDetails; $datas['minDate'] = \DateTime::createFromFormat('U', $minPeriod)->format('Y-m'); $datas['maxDate'] = \DateTime::createFromFormat('U', $maxPeriod)->format('Y-m'); return $datas; } public function getDaysPeriodInfosPerson(Person $person, $year, $month) { Loading module/Oscar/view/oscar/timesheet/resume.phtml +15 −7 Changes for module/Oscar/view/oscar/timesheet/resume.phtml: 15 added lines, 7 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 13/11/18 * Time: 10:48 */ No newline at end of file <div class="container"> <div id="app">Chargement</div> <script> require(['vue', 'TimesheetPersonResume'], function(Vue, TimesheetPersonResume){ new Vue({ el: "#app", render: function(h){ return h(TimesheetPersonResume.default, { props: { datas: <?= json_encode($datas) ?>}}); } }) }); </script> </div> No newline at end of file Loading
module/Oscar/src/Oscar/Controller/TimesheetController.php +3 −44 Changes for module/Oscar/src/Oscar/Controller/TimesheetController.php: 3 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -1045,51 +1045,10 @@ class TimesheetController extends AbstractOscarController public function resumeAction(){ $roles = $this->getOscarUserContext()->getRoleIdPrimary(); $organizations = $this->getPersonService()->getOrganizationsPersonWithPrincipalRole( $this->getCurrentPerson()); foreach ($organizations as $organization) { echo "<li> O : $organization</li>"; } return [ 'datas' => $this->getTimesheetService()->getResumePerson($this->getCurrentPerson()) ]; // $structures = $this->getEntityManager()->getRepository(OrganizationPerson::class)->createQueryBuilder('s') // ->where('s.person = :person AND s.role IN(:roles)') // ->setParameters([ // 'person' => $currentPerson, // 'roles' => $roles, // ]) // ->getQuery() // ->getResult() // ; // // // $projects = []; // // /** @var OrganizationPerson $organizationPerson */ // foreach( $structures as $organizationPerson ){ // $orgaId = $organizationPerson->getOrganization()->getId(); // if( !isset($projects[$orgaId]) ){ // $projects[$orgaId] = [ // 'organization' => $organizationPerson->getOrganization(), // 'projects' => [] // ]; // } // /** @var ProjectPartner $partner */ // foreach($organizationPerson->getOrganization()->getProjects() as $partner ){ // if( in_array($partner->getRole(), $this->getOscarUserContext()->getRolesOrganisationLeader())) // $projects[$orgaId]['projects'][] = $partner->getProject(); // } // /** @var ActivityOrganization $activityPartner */ // foreach($organizationPerson->getOrganization()->getActivities() as $activityPartner ){ // // Cas des activités sans projet // if( $activityPartner->getActivity()->getProject() && in_array($activityPartner->getRole(), $this->getOscarUserContext()->getRolesOrganisationLeader()) ) // $projects[$orgaId]['projects'][] = $activityPartner->getActivity()->getProject(); // } // } die("RESUME"); } public function validationsAction() { Loading
module/Oscar/src/Oscar/Entity/Activity.php +14 Changes for module/Oscar/src/Oscar/Entity/Activity.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1900,6 +1900,20 @@ class Activity implements ResourceInterface return self::class; } public function getDateStartStr(){ if( $this->getDateStart() ){ return $this->getDateStart()->format('Y-m-d'); } return ""; } public function getDateEndStr(){ if( $this->getDateEnd() ){ return $this->getDateEnd()->format('Y-m-d'); } return ""; } public function toJson() { return [ Loading
module/Oscar/src/Oscar/Entity/TimeSheet.php +7 Changes for module/Oscar/src/Oscar/Entity/TimeSheet.php: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -399,6 +399,13 @@ class TimeSheet implements ITrackable ]; } /** * @return string */ public function getPeriodCode(){ return $this->getDateFrom()->format('Y-m'); } public function toJson(){ $activityId = null; $activityLabel = null; Loading
module/Oscar/src/Oscar/Service/TimesheetService.php +145 Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 145 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -925,6 +925,151 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa return $total; } public function getActivitiesWithDeclarant( Person $person ){ return $this->getEntityManager()->getRepository(Activity::class)->createQueryBuilder('a') ->innerJoin('a.workPackages', 'wp') ->innerJoin('wp.persons', 'wpp') ->where('wpp.person = :person') ->getQuery() ->setParameter('person', $person) ->getResult(); } public function getResumePerson( Person $person ){ $declarantInActivities = $this->getActivitiesWithDeclarant($person); $now = new \DateTime(); $periodNow = $now->format('Y-m'); $minPeriod = $now->getTimestamp(); $maxPeriod = $now->getTimestamp(); $datas = [ 'minDate' => "", 'maxDate' => "", 'periods' => [], 'activities' => [], 'validations' => [], 'horslots' => [] ]; $periodsDetails = []; foreach ($this->getOthersWP() as $hl) { $datas['horslots'][$hl['code']] = [ 'code' => $hl['code'], 'label' => $hl['label'] ]; } /** @var Activity $activity */ foreach ($declarantInActivities as $activity) { $activityDatas = [ 'id' => $activity->getId(), 'acronym' => $activity->getAcronym(), 'label' => $activity->getLabel(), 'workpackages' => [], 'total' => 0.0, 'start' => $activity->getDateStartStr(), 'dateend' => $activity->getDateEndStr(), ]; $workPackagesId = []; /** @var WorkPackage $workPackage */ foreach ($activity->getWorkPackages() as $workPackage) { $workPackagesId[] = $workPackage->getId(); $activityDatas['workpackages'][$workPackage->getId()] = [ 'id' => $workPackage->getId(), 'code' => $workPackage->getCode(), 'label' => $workPackage->getLabel(), 'available' => $workPackage->hasPerson($person), 'total' => 0.0 ]; } if( $activity->getDateStart() && $activity->getDateEnd() ){ $periods = DateTimeUtils::allperiodsBetweenTwo($activity->getDateStart()->format('Y-m'), $activity->getDateEnd()->format('Y-m')); foreach ($periods as $period) { if( !array_key_exists($period, $periodsDetails) ){ $split = explode('-', $period); $year = $split[0]; $month = $split[1]; $periodsDetails[$period] = [ 'period' => $period, 'month' => $month, 'year' => $year, 'past' => $period < $periodNow, 'current' => $period == $periodNow, 'futur' => $period > $periodNow, 'activities_id' => [], 'workpackages_id' => [], 'unexpected' => false, 'total' => 0.0, 'total_activities' => 0.0, 'total_horslots' => 0.0, 'validations_id' => [] ]; } $periodsDetails[$period]['activities_id'][] = $activity->getId(); $periodsDetails[$period]['workpackages_id'] = $workPackagesId; } } if( $activity->getDateStart() ) { $minPeriod = min($minPeriod, $activity->getDateStart()->getTimestamp()); } if( $activity->getDateEnd() ) { $maxPeriod = max($maxPeriod, $activity->getDateEnd()->getTimestamp()); } $datas['activities'][$activityDatas['id']] = $activityDatas; } $timesheets = $this->getEntityManager()->getRepository(TimeSheet::class)->findBy(['person' => $person]); /** @var TimeSheet $timesheet */ foreach ($timesheets as $timesheet) { $period = $timesheet->getPeriodCode(); if( !array_key_exists($period, $periodsDetails) ){ $periodsDetails[$period] = [ 'period' => $period, 'activities_id' => [], 'workpackages_id' => [], 'unexpected' => true, 'total' => 0.0, 'total_activities' => 0.0, 'total_horslots' => 0.0, 'validations_id' => [] ]; } $total = $timesheet->getDuration(); $periodsDetails[$period]['total'] += $total; if( $timesheet->getActivity() ){ $periodsDetails[$period]['total_activities'] += $total; } else { $periodsDetails[$period]['total_horslots'] += $total; } } $declarations = $this->getEntityManager()->getRepository(ValidationPeriod::class)->findBy(['declarer' => $person]); /** @var ValidationPeriod $declaration */ foreach ($declarations as $declaration) { $period = DateTimeUtils::getCodePeriod($declaration->getYear(), $declaration->getMonth()); $periodsDetails[$period]['validations_id'][] = $declaration->getId(); $datas['validations'][$declaration->getId()] = $declaration->toJson(); } $datas['periods'] = $periodsDetails; $datas['minDate'] = \DateTime::createFromFormat('U', $minPeriod)->format('Y-m'); $datas['maxDate'] = \DateTime::createFromFormat('U', $maxPeriod)->format('Y-m'); return $datas; } public function getDaysPeriodInfosPerson(Person $person, $year, $month) { Loading
module/Oscar/view/oscar/timesheet/resume.phtml +15 −7 Changes for module/Oscar/view/oscar/timesheet/resume.phtml: 15 added lines, 7 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 13/11/18 * Time: 10:48 */ No newline at end of file <div class="container"> <div id="app">Chargement</div> <script> require(['vue', 'TimesheetPersonResume'], function(Vue, TimesheetPersonResume){ new Vue({ el: "#app", render: function(h){ return h(TimesheetPersonResume.default, { props: { datas: <?= json_encode($datas) ?>}}); } }) }); </script> </div> No newline at end of file