Commit 41c7b6fc authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Up : Calendrier déclarant (Fix, affichage en pourcentage OK, accès import)

 - Fix : Calendrier : divers problèmes d'affichage/fautes/défaut
 - AxiosOscar : Mode plein écran pour les erreurs/écrans de chargement
 - Activity : Accès PCRU (à corriger)
 - DEV : Mise à jour des librairies JS
 - Fix alerte de compatibilité SASS
parent 67af2613
Loading
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -245,13 +245,6 @@ timesheet:
        defaults:
          action: declarant

    declarant2:
      type: segment
      options:
        route: /declarant2
        defaults:
          action: declarant2

    checkperiod:
      type: segment
      options:
+12 −11
Original line number Diff line number Diff line
@@ -203,20 +203,20 @@ class PublicController extends AbstractOscarController implements UseTimesheetSe
        ];
    }

    /**
     * @throws OscarException
     */
    public function testAction()
    {
        if (DEBUG_OSCAR) {
//            $createRoot = new ActivityType();
//            $this->getEntityManager()->persist($createRoot);
//            $createRoot->setLft(1);
//            $createRoot->setRgt(2);
//            $createRoot->setLabel('ROOT');
//
//            $this->getLoggerService()->info("-----------------------------------------------------------");
//            $this->getLoggerService()->info("Création du Noeud ROOT : " . $createRoot->trac());
//
//            $this->getEntityManager()->flush($createRoot);

            if( $this->isAjax() ){
                $sleep = $this->getRequest()->getQuery('sleep');
                if( $sleep ){
                    sleep($sleep);
                    throw new OscarException("SLEEP : $sleep");
                }
            }
            return [];
        }
        die("DEV ONLY");
    }
@@ -225,6 +225,7 @@ class PublicController extends AbstractOscarController implements UseTimesheetSe
     * Page d'accueil.
     *
     * @return ViewModel
     * @throws OscarException
     */
    public function indexAction()
    {
+45 −221
Original line number Diff line number Diff line
@@ -2301,26 +2301,23 @@ class TimesheetController extends AbstractOscarController
        ];
    }

    /**
     * API de validation des heures.
     *
     * @return Response
     */
    public function validatorAPIAction()
    {
        return $this->getResponseNotImplemented();
    }

    protected function getOthersWP()
    {
        return $this->getTimesheetService()->getOthersWP();
    }


    /**
     * @param Person $person
     * @return Response
     * @throws OscarException
     * @throws \DateMalformedStringException
     * @throws \Doctrine\ORM\Exception\NotSupported
     * @throws \Doctrine\ORM\Exception\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function sendTimesheet(Person $person)
    {


        // JOUR
        $datas = $this->getJsonREST();
        $timesheetsDatas = $datas['timesheets'];
@@ -2499,14 +2496,12 @@ class TimesheetController extends AbstractOscarController
        } catch (\Exception $e) {
            return $this->getResponseInternalError("Déclaration invalide : " . $e->getMessage());
        }

        return $this->getResponseUnauthorized("Pas encore disponible");
    }

    /**
     * RÉCUPÉRATION des DÉCLARATIONS.
     *
     * @return array|Response
     * @return Response
     * @throws \Exception
     */
    public function declarantAction()
@@ -2572,201 +2567,27 @@ class TimesheetController extends AbstractOscarController
                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Envoi de données
                case 'POST' :
                    $action = $this->params()->fromPost('action', 'send');
                    $comments = $this->params()->fromPost('comments', null);

                    if ($comments) {
                        $comments = json_decode($comments, JSON_OBJECT_AS_ARRAY);
                    }

                    // Ajout des créneaux
                    if ($action == 'add') {
                        try {
                            return $this->sendTimesheet($currentPerson);
                        } catch (\Exception $e) {
                            return $this->getResponseInternalError($e->getMessage());
                        }
                    }

                    if ($action == 'comment') {
                        try {
                            $timesheetService->saveCommentFromPost($currentPerson, $_POST);
                            return $this->getResponseOk();
                        } catch (OscarException $e) {
                            return $this->getResponseInternalError($e->getMessage());
                        }

                        return $this->getResponseNotImplemented("Enregistrement de commentaire");
                    }

                    $datas = json_decode($this->params()->fromPost('datas'));

                    if (!$datas) {
                        return $this->getResponseBadRequest('Problème de transmission des données');
                    }

                    if (!$datas->from || !$datas->to) {
                        $this->getLoggerService()->info("FOO : " . json_encode($datas));
                        return $this->getResponseInternalError("La période soumise est incomplète");
                    }

                    try {
                        $firstDay = new \DateTime($datas->from);
                        $this->getTimesheetService()->verificationPeriod(
                            $currentPerson,
                            $firstDay->format('Y'),
                            $firstDay->format('m')
                        );
                    } catch (\Exception $e) {
                        return $this->getResponseInternalError("Déclaration invalide : " . $e->getMessage());
                    }

                    try {
                        $from = new \DateTime($datas->from);
                        $to = new \DateTime($datas->to);
                        $timesheetService->sendPeriod($from, $to, $currentPerson, $comments);
                        return $this->getResponseOk();
                    } catch (\Exception $e) {
                        return $this->getResponseInternalError(
                            'Erreur de soumission de la période : ' . $e->getMessage()
                        );
                    }
                    return $this->getResponseNotImplemented("Erreur inconnue");
                    break;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Suppression
                case 'DELETE' :
                    try {
                        $idsCreneaux = explode(',', $this->params()->fromQuery('id'));
                        $timesheetService->delete($idsCreneaux, $currentPerson);
                        return $this->getResponseOk();
                    } catch (\Exception $e) {
                        return $this->getResponseInternalError($e->getMessage());
                    }
                    break;
            }
        }
        $datas = $this->getTimesheetService()->getTimesheetDatasPersonPeriod($currentPerson, $period);
        if ($usurpation) {
            $datas['usurpation'] = $usurpation;
        }
        return $datas;
    }

    /**
     * RÉCUPÉRATION des DÉCLARATIONS.
     *
     * @return array|Response
     * @throws \Exception
     */
    public function declarant2Action()
    {
        if (!$this->getOscarUserContextService()->getCurrentPerson()) {
            return $this->getResponseInternalError("Vous avez été déconnecté de Oscar");
        }

        // Méthode d'accès
        $method = $this->getHttpXMethod();

        // Durée d'un jour "normal"
        $today = new \DateTime();
        $year = (int)$this->params()->fromQuery('year', $today->format('Y'));
        $month = (int)$this->params()->fromQuery('month', $today->format('m'));
        $format = $this->params()->fromQuery('format', null);
        $period = sprintf('%s-%s', $year, $month);
        $declarerId = $this->params()->fromQuery('person', null);
        $usurpation = false;

        // Vérification de declarerId
        if ($declarerId && !preg_match('/[0-9]*/', $declarerId)) {
            return $this->getResponseBadRequest("Identifiant de déclarant incorrect");
        }

        if ($declarerId) {
            $usurpation = $declarerId;
        } else {
            $declarerId = $this->getCurrentPerson()->getId();
        }

        /** @var Person $currentPerson */
        $currentPerson = $this->getPersonService()->getPersonById($declarerId); //$this->getCurrentPerson();

        // On test l'authorisation à l'usurpation si besoin
        if ($declarerId != $this->getCurrentPerson()->getId()) {
            if (!($this->getOscarUserContextService()->hasPrivileges(
                    Privileges::PERSON_FEED_TIMESHEET
                ) || $currentPerson->getTimesheetsBy()->contains($this->getCurrentPerson()))) {
                throw new UnAuthorizedException(
                    "Vous n'êtes pas authorisé à compléter la feuille de temps de $currentPerson"
                );
            }
        }

        /** @var TimesheetService $timesheetService */
        $timesheetService = $this->getTimesheetService();


        if ($this->isAjax() || $format == 'json') {
            switch ($method) {
                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Récupération des créneaux de la période
                case 'GET' :
                    $datas = $this->getTimesheetService()->getTimesheetDatasPersonPeriod($currentPerson, $period);
                    if ($usurpation) {
                        $datas['usurpation'] = $usurpation;
                    }

                    return $this->ajaxResponse($datas);
                    break;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Envoi de données
                case 'POST' :

                    // Récupération des données
                    $posted =$this->getJsonREST();
                    $this->getLoggerService()->info(print_r($posted, true));

                    $action = $posted['action'];
                    $comments = $posted['comments'];

                    if ($comments) {
                        //throw new OscarException("A corriger");
                    }

                    // Ajout des créneaux
                    if ($action == 'add') {
                    try {
                        switch($action){
                            case 'add':
                                return $this->sendTimesheet($currentPerson);
                        } catch (\Exception $e) {
                            return $this->getResponseInternalError($e->getMessage());
                        }
                    }

                    if ($action == 'comment') {
                        try {
                            case 'comment':
                                $timesheetService->saveCommentFromPost($currentPerson, $posted);
                                return $this->getResponseOk();
                        } catch (OscarException $e) {
                            return $this->getResponseInternalError($e->getMessage());
                        }

                        return $this->getResponseNotImplemented("Enregistrement de commentaire");
                    }

                    $datas = $posted;

                    if (!$datas) {
                        return $this->getResponseBadRequest('Problème de transmission des données');
                    }

                    if (!$datas['from'] || !$datas['to']) {
                            default:
                                if (!$posted['from'] || !$posted['to']) {
                                    return $this->getResponseInternalError("La période soumise est incomplète");
                                }

                                try {
                        $firstDay = new \DateTime($datas['from']);
                        $this->getLoggerService()->info("Premier jour : " . $firstDay->format('Y-m-d H:i:s'));
                                    $firstDay = new \DateTime($posted['from']);
                                    $this->getTimesheetService()->verificationPeriod(
                                        $currentPerson,
                                        $firstDay->format('Y'),
@@ -2777,8 +2598,8 @@ class TimesheetController extends AbstractOscarController
                                }

                                try {
                        $from = new \DateTime($datas['from']);
                        $to = new \DateTime($datas['to']);
                                    $from = new \DateTime($posted['from']);
                                    $to = new \DateTime($posted['to']);
                                    $timesheetService->sendPeriod($from, $to, $currentPerson, $comments);
                                    return $this->getResponseOk();
                                } catch (\Exception $e) {
@@ -2786,7 +2607,10 @@ class TimesheetController extends AbstractOscarController
                                        'Erreur de soumission de la période : ' . $e->getMessage()
                                    );
                                }
                    return $this->getResponseNotImplemented("Erreur inconnue");
                        }
                    } catch (OscarException $e) {
                        return $this->jsonError($e->getMessage());
                    }

                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Suppression
+1 −0
Original line number Diff line number Diff line
@@ -456,6 +456,7 @@ class ProjectGrantApiService implements UseEntityManager, UsePersonService, UseO
                'edit'           => $urlPlugin->fromRoute('contract/edit', ['id' => $activity->getId()]),
                'change_project' => $urlPlugin->fromRoute('contract/moveToProject', ['id' => $activity->getId()]),
                'new_project'    => $urlPlugin->fromRoute('project/new') . '?ids=' . $activity->getId(),
                'pcru' => $urlPlugin->fromRoute('contract/pcru-infos', ['id' => $activity->getId()])
            ]
        ];
    }
+0 −1
Original line number Diff line number Diff line
@@ -4226,7 +4226,6 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat
        $submitable = false;
        $submitableInfos = "Vous ne pouvez pas soumettre cette période pour une raison inconnue";
        $importEnable = $this->getOscarConfigurationService()->getConfiguration('importEnable');

        $hasConflict = false;

        $editable = false;
Loading