Commit 6683a9fb authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Export/Import de TVA (autre objets de base en cours)

parent ff362b46
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -586,6 +586,7 @@ return array(
            \Oscar\Service\ConnectorService::class => \Oscar\Service\ConnectorServiceFactory::class,
            \Oscar\Service\ContractDocumentService::class => \Oscar\Service\ContractDocumentServiceFactory::class,
            \Oscar\Service\DocumentFormatterService::class => \Oscar\Service\DocumentFormatterServiceFactory::class,
            \Oscar\Service\Fixture\FixtureService::class => \Oscar\Service\Fixture\FixtureServiceFactory::class,
            \Oscar\Service\GearmanJobLauncherService::class => \Oscar\Service\GearmanJobLauncherServiceFactory::class,
            \Oscar\Service\JsonFormatterService::class => \Oscar\Service\JsonFormatterServiceFactory::class,
            'Logger' => \Oscar\Service\LoggerServiceFactory::class,
+78 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Command;

use Exception;
use Oscar\Connector\ConnectorRepport;
use Oscar\Service\ConnectorService;
use Oscar\Service\Fixture\FixtureService;
use Oscar\Service\OscarConfigurationService;
use Oscar\Service\OscarUserContext;
use Oscar\Service\PersonService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Laminas\Json\Json;

class OscarFixturesExportCommand extends OscarCommandAbstract
{
    protected static $defaultName = 'fixtures:export';

    protected function configure()
    {
        $this
            ->setDescription("Importation de données")
            ->addArgument("file", InputArgument::OPTIONAL, "Fichier de données", null)
            ->addOption(
                'replace',
                'r',
                InputOption::VALUE_NONE,
                'Remplacer si le fichier existe'
            )
            ->addOption(
                'keys',
                'k',
                InputOption::VALUE_NONE,
                'Clefs à exporter'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);

        $io = new SymfonyStyle($input, $output);

        $io->title("Importation des données");


        $replace = $input->getOption('replace');
        $keys = $input->getOption('keys');
        $file = $input->getArgument('file');


        if ($file != null && file_exists($file)) {
            if(!$replace){
                $io->error("Fichier '$file' existe déjà.'");
                return self::FAILURE;
            }
            $io->title("Exportation de $file");
        }


        /** @var FixtureService $fixtureService */
        $fixtureService = $this->getServicemanager()->get(FixtureService::class);

        $datas = $fixtureService->export(['tva']);
        $out = json_encode($datas, JSON_PRETTY_PRINT);
        if( $file === null ) {
            echo $out;
        }


        return Command::SUCCESS;
    }
}
+72 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Command;

use Exception;
use Oscar\Connector\ConnectorRepport;
use Oscar\Service\ConnectorService;
use Oscar\Service\Fixture\FixtureService;
use Oscar\Service\OscarConfigurationService;
use Oscar\Service\OscarUserContext;
use Oscar\Service\PersonService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Laminas\Json\Json;

class OscarFixturesImportCommand extends OscarCommandAbstract
{
    protected static $defaultName = 'fixtures:import';

    protected function configure()
    {
        $this
            ->setDescription("Importation de données")
            ->addArgument("file", InputArgument::REQUIRED, "Fichier de données")
            ->addOption(
                'simulate',
                's',
                InputOption::VALUE_NONE,
                'Affiche les informations'
            )
            ->addOption(
                'purge',
                'p',
                InputOption::VALUE_NONE,
                'Supprime les données avant (non implémenté)'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);

        $io = new SymfonyStyle($input, $output);

        $io->title("Importation des données");


        $simulate = $input->getOption('simulate');
        $purge = $input->getOption('purge');
        $file = $input->getArgument('file');
        if (!file_exists($file)) {
            $io->error("Fichier inaccessible '$file'.'");
            return self::FAILURE;
        }

        $io->title("Importation de $file");

        $datas = json_decode(file_get_contents($file), true);

        /** @var FixtureService $fixtureService */
        $fixtureService = $this->getServicemanager()->get(FixtureService::class);

        $fixtureService->import($datas);


        return Command::SUCCESS;
    }
}
+82 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Command;

use Doctrine\ORM\EntityManager;
use Oscar\Entity\Privilege;
use Oscar\Entity\Role;
use Oscar\Service\Fixture\FixtureService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class OscarRolesInitCommand extends OscarCommandAbstract
{
    protected static $defaultName = 'roles:init';

    protected function configure()
    {
        $this
            ->setDescription("Création des rôles de base utilisteur/Administrateur avec les privilèges de base");
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);

        $io = new SymfonyStyle($input, $output);

        $io->title("Initialisation des rôles");


        /** @var FixtureService $fixtureService */
        $fixtureService = $this->getServicemanager()->get(FixtureService::class);

        $json = <<<EOF
    { "user_role": [
        {
          "parent_id": null,
          "role_id": "Utilisateur",
          "is_default": true,
          "ldap_filter": "",
          "spot": 4,
          "description": null,
          "principal": false,
          "accessible_exterieur": true,
          "displayed": true
        },
        {
          "parent_id": null,
          "role_id": "Administrateur",
          "is_default": false,
          "ldap_filter": null,
          "spot": 4,
          "description": null,
          "principal": false,
          "accessible_exterieur": true,
          "displayed": true
        }
      ]
    }
EOF;

        $fixtureService->import(json_decode($json, true));

        /** @var EntityManager $entityManager */
        $entityManager = $this->getServicemanager()->get(EntityManager::class);
        $administrateur = $entityManager->getRepository(Role::class)->findOneBy(["roleId" => "Administrateur"]);

        $privileges = $entityManager->getRepository(Privilege::class)->findAll();
        foreach ($privileges as $privilege) {
            if (!$privilege->hasRole($administrateur)) {
                $io->info("add $privilege to $administrateur");
                $privilege->addRole($administrateur);
            }
        }
        $entityManager->flush();


        return Command::SUCCESS;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -1489,12 +1489,18 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                if ($projectGrant->getId()) {
                    $projectGrant->setDateUpdated(new \DateTime());
                }

                try {
                    $this->getEntityManager()->persist($projectGrant);
                    if ($project) {
                        $project->touch();
                    }

                    $this->getEntityManager()->flush($projectGrant);
                } catch (\Exception $e) {
                    $this->getLoggerService()->critical("Can't create activity : " . $e->getMessage());
                    throw $e;
                }

                if ($organizationsDatas) {
                    foreach ($organizationsDatas as $organizationsData) {
Loading