Commit 967c2397 authored by Stéphane Bouvry's avatar Stéphane Bouvry
Browse files

UI validation + Admin : Possibilité d'éditer les critères horaires sur une...

UI validation + Admin : Possibilité d'éditer les critères horaires sur une déclaration en cours de traitement
parent 411948e0
Loading
Loading
Loading
Loading
+24 −7
Changes for module/Oscar/src/Oscar/Controller/TimesheetController.php: 24 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -1520,13 +1520,31 @@ class TimesheetController extends AbstractOscarController
                return $this->ajaxResponse($return);

                case 'POST' :
                    $action = $this->params()->fromPost('action', 'add');
                    $person_id = $this->params()->fromPost('person_id');

                    $person = $this->getPersonService()->getPerson($person_id);

                    // Modification des heures pour la périodes
                    if( $action == 'changeschedule') {
                        $days = json_decode($this->params()->fromPost('days'));
                        $period = $this->params()->fromPost('period');

                        try {
                            $this->getTimesheetService()->changePersonSchedulePeriod($person, $days, $period);
                            return $this->getResponseOk();
                        } catch (OscarException $e){
                            return $this->getResponseInternalError($e->getMessage());
                        }
                    }

                    //
                    else {

                        $type = $this->params()->fromPost('type');
                        $declaration_id = $this->params()->fromPost('declaration_id');
                    $action = $this->params()->fromPost('action', 'add');

                        $validation = $this->getTimesheetService()->getValidationPeriod($declaration_id);
                    $person = $this->getPersonService()->getPerson($person_id);


                        if( !in_array($type, ['adm', 'sci', 'prj']) ){
                            return $this->getResponseInternalError('Type de validation inconnu');
@@ -1534,6 +1552,7 @@ class TimesheetController extends AbstractOscarController

                        if( $action == 'delete' ){
                            $this->getTimesheetService()->removeValidatorToValidation($type, $person, $validation);
                            return $this->getResponseOk();
                        } else {
                            $this->getTimesheetService()->addValidatorToValidation($type, $person, $validation);
                            $return = [
@@ -1542,11 +1561,9 @@ class TimesheetController extends AbstractOscarController
                            ];
                            return $this->ajaxResponse($return);
                        }
                    }



                    return $this->getResponseOk();
//                    return $this->getResponseNotImplemented("En cours d'implémentation");
                    return $this->getResponseBadRequest("Erreur d'API");

                case 'DELETE':
                    $person_id = $this->params()->fromQuery('person_id');
+35 −5
Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 35 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -100,6 +100,38 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
    }


    public function changePersonSchedulePeriod($person, $days, $period){
        try {
            $this->getLogger()->debug("Modification des horaires pour $person en $period : " . json_encode(($days)));
            $periodDatas = DateTimeUtils::extractPeriodDatasFromString($period);
            $declarations = $this->getEntityManager()->getRepository(ValidationPeriod::class)->createQueryBuilder('d')
                ->where('d.declarer = :person AND d.year = :year AND d.month = :month')
                ->setParameters([
                    'person' => $person,
                    'year' => $periodDatas['year'],
                    'month' => $periodDatas['month'],
                ])
                ->getQuery()
                ->getResult();

            /** @var ValidationPeriod $declaration */
            foreach ($declarations as $declaration) {
                $schedule = $declaration->getSchedule();
                $scheduleJson = json_decode($schedule, JSON_OBJECT_AS_ARRAY);
                if( !$scheduleJson ){
                    $scheduleJson = [];
                }
                $scheduleJson['days'] = $days;
                $declaration->setSchedule(json_encode($scheduleJson));
            }

            $this->getEntityManager()->flush($declarations);
        } catch( \Exception $e ){
            throw new OscarException($e->getMessage());
        }
    }


    public function getDatasDeclarations()
    {
        $output = [];
@@ -116,6 +148,7 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
                    'period' => $period,
                    'person' => (string)$declaration->getDeclarer(),
                    'person_id' => $declaration->getDeclarer()->getId(),
                    'settings' => $declaration->getSchedule(),
                    'declarations' => [],
                ];
            }
@@ -607,7 +640,7 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        }
    }

    //public function


    public function getValidationsForValidator2(Person $validator, $declarer = null, $period = null)
    {
@@ -632,8 +665,6 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        $periodIds = [];
        $output = [];



        /** @var ValidationPeriod $period */
        foreach ($periods as $period) {
            $periodIds[] = $period->getId();
@@ -674,14 +705,13 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
                'validableStep' => $validateCurrentState,
                'validabe' => $period->isValidable(),
                'validators' => $validators,
                'currentStep' => 5,
                'total' => 0.0,
                'label' => "Inconnu",
                'status' => $period->getStatus(),
                'statusMessage' => $this->getStatusMessage($period->getStatus()),
            ];



            // Déclarations sur des activités
            if( $period->getObject() == 'activity' ){
                /** @var Activity $activity */
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+192 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading