Commit 0c4d008c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Filtre sur le Compte Général accessible depuis la liste des comptes (Menu Administration)

parent f73f7474
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -67,7 +67,11 @@
                'input': a.annexe == 1
              }">
      <h3>
        <code title="Code utilisé dans SIFAC">{{ a.codeFull }}</code>
        <code title="Code utilisé dans SIFAC">
          <a :href="'/activites-de-recherche/advancedsearch?q=&criteria[]=cb2%3B'+a.codeFull" style="color: white">
            {{ a.codeFull }}
          </a>
        </code>
        <strong>
          {{ a.label }}
          <small title="Numéro dans OSCAR">({{ a.code }})</small>
+26 −26
Original line number Diff line number Diff line
@@ -2493,6 +2493,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
            $organizations = [];
            $persons = [];

            $accountsInfos = $this->getSpentService()->getAccountsInfosUsed();

            $queryPersons = $this->getEntityManager()->createQueryBuilder()
                ->select('a.id')
@@ -2762,13 +2763,24 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        // Récupération de l'organisation
                        $value1 = $crit['val1'] = explode(',', $params[1]);
                        try {
                            $codeAccounts = $value1;
                            $ids = $this->getSpentService()->getIdsActivitiesForAccounts($codeAccounts);
                            $compteGeneralList = $accountsInfos->getCompteGeneralListByAccountIds($value1);
                            $ids = $this->getSpentService()->getIdsActivitiesForAccounts($compteGeneralList);
                        } catch (\Exception $e) {
                            die("SOUCIS");
                        }
                        break;

                    case 'cb2':
                        // Récupération de l'organisation
                        $value1 = $crit['val1'] = explode(',', $params[1]);

                        try {
                            $ids = $this->getSpentService()->getIdsActivitiesForCompteGeneral($value1);
                        } catch (\Exception $e) {
                            throw new OscarException($e->getMessage());
                        }
                        break;

                    case 'ao' :
                    case 'so' :
                        $organizationId[] = $value1;
@@ -2809,25 +2821,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif

                        $ids = array_keys($query->setParameters($queryParam)->getQuery()->getArrayResult());

//                        try {
//                            $organization = $this->getOrganizationService()->getOrganization($value1);
//                            $organizations[$organization->getId()] = $organization;
//                            $crit['val1Label'] = (string)$organization;
//                            $crit['val2Label'] = $value2 >= 0 ? $this->getOscarUserContextService(
//                            )->getRolesOrganizationInActivity()[$value2] : '';
//                            if ($value2 > 0) {
//                                $roleOrganisation = $this->getEntityManager()->getRepository(
//                                    OrganizationRole::class
//                                )->find($value2);
//                                $queryParam['roleObj'] = $roleOrganisation;
//                                $query = $queryOrganisationRole;
//                            } else {
//                                $query = $queryOrganisationNoRole;
//                            }
//                            $ids = array_keys($query->setParameters($queryParam)->getQuery()->getArrayResult());
//                        } catch (\Exception $e) {
//                            $crit['error'] = "Impossible de filtrer sur l'organisation (" . $e->getMessage() . ")";
//                        }
                        break;

                    // Filtre sur le statut de l'activité
@@ -2838,6 +2831,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        $parameters['withstatus'][] = $value1;
                        $qb->andWhere('c.status IN (:withstatus)');
                        break;

                    case 'ss' :
                        if (!isset($parameters['withoutstatus'])) {
                            $parameters['withoutstatus'] = [];
@@ -2846,7 +2840,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        $qb->andWhere('c.status NOT IN (:withoutstatus)');
                        break;


                    case 'at' :

                        if (!isset($parameters['withtype'])) {
@@ -2866,6 +2859,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        );
                        $result = $qb->setParameters($parameters)->getQuery()->getResult();
                        break;

                    case 'st' :
                        if (!isset($parameters['withouttype'])) {
                            $parameters['withouttype'] = [];
@@ -2876,6 +2870,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                            $this->getActivityTypeService()->getTypeIdsInside($value1)
                        );
                        break;

                    // Filtre sur la/les incidences financière
                    case 'af' :
                        if (!isset($parameters['withfinancial'])) {
@@ -2884,6 +2879,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        }
                        $parameters['withfinancial'][] = Activity::getFinancialImpactValues()[$value1];
                        break;

                    case 'sf' :
                        if (!isset($parameters['withoutfinancial'])) {
                            $parameters['withoutfinancial'] = [];
@@ -2891,6 +2887,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        }
                        $parameters['withoutfinancial'][] = Activity::getFinancialImpactValues()[$value1];
                        break;

                    case 'cnt' :
                        if ($params[1]) {
                            if (!isset($parameters['countries'])) {
@@ -2901,6 +2898,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                            $parameters['countries'] = $value1;
                        }
                        break;

                    case 'tnt' :
                        if ($params[1]) {
                            if (!isset($parameters['typeorga'])) {
@@ -2912,6 +2910,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                            $parameters['typeorga'] = $typeIds;
                        }
                        break;

                    case 'aj':
                        $progressStr = $params[2];
                        $progressArray = null;
@@ -2925,10 +2924,12 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        }
                        $filterIds = $this->getActivityService()->getActivityIdsByJalon($crit['val1'], $progressArray);
                        break;

                    case 'ds' :
                        $qb->andWhere('dis.id = :discipline');
                        $parameters['discipline'] = $value1;
                        break;

                    case 'add' :
                    case 'adf' :
                    case 'adm' :
@@ -2962,7 +2963,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        break;
                }
                $criterias[] = $crit;
                if ($type == 'ap' || $type == 'ao' || $type == 'pm' || $type == 'om' || $type == 'fdt' || $type == 'cb') {
                if ($type == 'ap' || $type == 'ao' || $type == 'pm' || $type == 'om'
                    || $type == 'fdt' || $type == 'cb' || $type == 'cb2') {
                    if ($filterIds === null) {
                        $filterIds = $ids;
                    } else {
@@ -3011,10 +3013,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                );
            }


            $activities = null;


            if ($startEmpty === false) {
                if ($projectview == 'on') {
                    $qbIds = $qb->select('DISTINCT c.id');
@@ -3075,7 +3075,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                    'typeorgas' => $this->getOrganizationService()->getOrganizationTypesSelect(),
                    'countries' => $this->getOrganizationService()->getCountriesList(),
                    'fieldsCSV' => $this->getActivityService()->getFieldsCSV(),
                    'accounts' => $this->getSpentService()->getUsedAccount(),
                    'accounts' => $accountsInfos->getAccounts(),
                    'persons' => $persons,
                    'filterJalons' => $jalonsFilters,
                    'activities' => $activities,
+16 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ use Oscar\Traits\UseLoggerService;
use Oscar\Traits\UseLoggerServiceTrait;
use Oscar\Traits\UseOscarConfigurationService;
use Oscar\Traits\UseOscarConfigurationServiceTrait;
use Oscar\Utils\AccountInfoUtil;
use Oscar\Utils\StringUtils;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
@@ -533,7 +534,7 @@ class SpentService implements UseLoggerService, UseOscarConfigurationService, Us
    /**
     * @return SpentTypeGroupRepository
     */
    protected function getSpentTypeRepository()
    public function getSpentTypeRepository()
    {
        return $this->getEntityManager()->getRepository(SpentTypeGroup::class);
    }
@@ -626,10 +627,17 @@ class SpentService implements UseLoggerService, UseOscarConfigurationService, Us
        return $this->getParentWithAnnexe($plan, $codeParent);
    }

    public function getIdsActivitiesForAccounts( array $codesAccounts ) :array
    public function getIdsActivitiesForCompteGeneral( array $compteGeneral ) :array
    {
        //$codesAccounts = array_map(function($c){ return '00'.$c; }, $codesAccounts);
        $pfis = $this->getSpentTypeRepository()->getPfiForCodesAccounts($compteGeneral);
        /** @var ActivityRepository $activityRepository */
        $activityRepository = $this->getEntityManager()->getRepository(Activity::class);
        $idsActivities = $activityRepository->getActivitiesIdsByPfis($pfis);
        return $idsActivities;
    }

    public function getIdsActivitiesForAccounts( array $codesAccounts ) :array
    {
        $pfis = $this->getSpentTypeRepository()->getPfiForCodesAccounts($codesAccounts);

        /** @var ActivityRepository $activityRepository */
@@ -777,6 +785,11 @@ class SpentService implements UseLoggerService, UseOscarConfigurationService, Us
        return $accountInfos;
    }

    public function getAccountsInfosUsed() :AccountInfoUtil
    {
        return AccountInfoUtil::getInstance($this);
    }



    /**
+82 −0
Original line number Diff line number Diff line
<?php


namespace Oscar\Utils;


use Oscar\Service\SpentService;

class AccountInfoUtil
{
    private array $correspondances;
    private array $accountInfos;


    public static function getInstance(SpentService $spentService): AccountInfoUtil
    {
        // Liste des comptes général dans les dépenses rééls (Donnèes SIFAC)
        $usedAccounts = $spentService->getSpentTypeRepository()->getUsedAccount();
        $instance = new AccountInfoUtil();

        $instance->correspondances = [];
        $instance->accountInfos = [];

        foreach ($usedAccounts as $compte) {
            $infos = $spentService->getCompte($compte);
            $compteId = $infos["id"];

            $instance->correspondances[$compte] = $compteId;

            if (!array_key_exists($compteId, $instance->accountInfos)) {
                $instance->accountInfos[$compteId] = $infos;
                $instance->accountInfos[$compteId]['compteGeneral'] = [];
            }
            $instance->accountInfos[$compteId]['compteGeneral'][] = $compte;
        }

        return $instance;
    }

    public function getAccountInfoById(int $id): ?array
    {
        if (array_key_exists($id, $this->accountInfos)) {
            return $this->accountInfos[$id];
        }
        return null;
    }

    public function getAccountIdByCompteGeneral(string $compteGeneral): ?int
    {
        if (array_key_exists($compteGeneral, $this->correspondances)) {
            return $this->correspondances[$compteGeneral];
        }
        return null;
    }

    public function getCompteGeneralListByAccountIds(array $accountIds): array
    {
        $ids = [];
        foreach ($accountIds as $accountId) {
            $accountInfo = $this->getAccountInfoById($accountId);
            $ids = array_merge($ids, $accountInfo['compteGeneral']);
        }
        return array_unique($ids);
    }

    public function getAccountByCompteGeneral(string $compteGeneral): ?array
    {
        $accountId = $this->getAccountIdByCompteGeneral($compteGeneral);
        if($accountId){
            return $this->getAccountInfoById($accountId);
        }
        return null;
    }

    public function getAccounts() :array {
        return $this->accountInfos;
    }

    public function getCorrespondances() :array {
        return $this->correspondances;
    }
}
 No newline at end of file
+23 −1
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@
            <small>{{typeLabel}}</small>
            <select class="select2 form-control val1 changer types" id="filter_account" multiple>
                <?php foreach( $accounts as $account ): ?>
                <option value="<?= $account["codeFull"] ?>"><?= $account["codeFull"] ?> - <?= $account["label"] ?></option>
                <option value="<?= $account["id"] ?>"><?= $account["code"] ?> - <?= $account["label"] ?></option>
                <?php endforeach; ?>
            </select>
            <nav>
@@ -248,6 +248,21 @@
        </article>
    </script>

    <script type="text/x-handlebars" id="accountscode-tpl">
        <article class="criteria criteria-account card">
            <div class="icon-bank"></div>
            {{#if error}}<strong class="text-danger"><i class="icon-attention-1"></i> {{error}}</strong>{{/if}}
            <input type="hidden" name="criteria[]" class="criteria" value="{{criteria}}"/>
            <input type="text" class="form-control val1 changer" value="{{val1}}" />
            <small>{{typeLabel}}</small>
            <nav>
                <a href="#" class="delete">
                    <i class="icon-cancel-outline"></i>
                </a>
            </nav>
        </article>
    </script>

    <script type="text/x-handlebars" id="typeorga-tpl">
        <article class="criteria criteria-typeorga card">
            <div class="icon-tag"></div>
@@ -758,6 +773,12 @@
                        datas.label = "Dépenses sur le compte";
                        dom = $(tplAccount(datas));
                    }
                    // accountscode
                    else if(datas.type == 'cb2' ) {
                        datas.label = "Code de compte général";
                        dom = $(tplAccountCode(datas));
                    }

                    else if(datas.type == 'cnt' ) {
                        datas.label = "Pays d'une des organisations";
                        dom = $(tplCountry(datas));
@@ -1015,6 +1036,7 @@
                // Gabarits pour les critères
                var tpl = Handlebars.compile($('#criteria-tpl').html()),
                    tplAccount = Handlebars.compile($('#accounts-tpl').html()),
                    tplAccountCode = Handlebars.compile($('#accountscode-tpl').html()),
                    tplDate = Handlebars.compile($('#date-criteria-tpl').html()),
                    tplStatus = Handlebars.compile($('#status-criteria-tpl').html()),
                    tplCountry = Handlebars.compile($('#country-tpl').html()),
Loading