diff --git a/gestion/appinfo/routes.php b/gestion/appinfo/routes.php index 2ce2868..aa1af19 100644 --- a/gestion/appinfo/routes.php +++ b/gestion/appinfo/routes.php @@ -175,5 +175,10 @@ return [ //client group facturation ['name' => 'page#getClientGroupFacturations', 'url' => '/client/getClientGroupFacturations', 'verb' => 'PROPFIND'], ['name' => 'page#createDefaultClientGroupFacturation', 'url' => '/client/createDefaultClientGroupFacturation', 'verb' => 'POST'], + + //provider + ['name' => 'provider#provider', 'url' => '/provider', 'verb' => 'GET'], + ['name' => 'provider#getProviders','url' => '/provider/list', 'verb' => 'PROPFIND'], + ['name' => 'provider#createDefaultProvider','url' => '/provider/createDefaultProvider', 'verb' => 'POST'], ] ]; \ No newline at end of file diff --git a/gestion/lib/Controller/ProviderController.php b/gestion/lib/Controller/ProviderController.php new file mode 100644 index 0000000..4fb9ce3 --- /dev/null +++ b/gestion/lib/Controller/ProviderController.php @@ -0,0 +1,126 @@ +idNextcloud = $UserId; + $this->myDb = $myDb; + $this->urlGenerator = $urlGenerator; + $this->mailer = $mailer; + $this->config = $config; + $this->navigationService = $navigationService; + $this->configurationService = $configurationService; + $this->logger = $logger; + $this->providerService = $providerService; + + if ($userSession->isLoggedIn()) { + $this->user = $userSession->getUser(); + } + + if ($this->user != null) { + $groups = $groupManager->getUserGroups($this->user); + $this->groups = []; + foreach ($groups as $group) { + $this->groups[] = $group->getGID(); + } + } + + try{ + $this->storage = $rootFolder->getUserFolder($this->idNextcloud); + }catch(\OC\User\NoUserException $e){ + + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function provider() { + return new TemplateResponse('gestion', 'provider', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink())); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getProviders() { + $providers = $this->providerService->getProvidersAsArray(); + return json_encode($providers); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function createDefaultProvider() { + try{ + $this->providerService->createDefaultProvider($this->idNextcloud); + return true; + } + catch(Exception $e){ + return null; + } + } +} diff --git a/gestion/lib/Db/ProviderRepository.php b/gestion/lib/Db/ProviderRepository.php new file mode 100644 index 0000000..b551208 --- /dev/null +++ b/gestion/lib/Db/ProviderRepository.php @@ -0,0 +1,62 @@ +gestionTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX ."gestion_"; + $this->defaultTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX; + $this->pdo = $db; + } + + private function execSQL($sql, $conditions){ + $stmt = $this->pdo->prepare($sql); + $stmt->execute($conditions); + $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + return json_encode($data); + } + + private function execSQLNoData($sql, $conditions){ + $stmt = $this->pdo->prepare($sql); + $stmt->execute($conditions); + $stmt->closeCursor(); + } + + private function execSQLNoJsonReturn($sql, $conditions){ + $stmt = $this->pdo->prepare($sql); + $stmt->execute($conditions); + $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + return $data; + } + + public function getProvidersList(){ + $sql = "SELECT * FROM ".$this->gestionTablePrefix."provider as provider"; + return $this->execSQLNoJsonReturn($sql,[]); + } + + public function createDefaultProvider($idNextCloud){ + $sql = "INSERT INTO `".$this->gestionTablePrefix."provider` ( + `id_nextcloud` + ) + VALUES (?);"; + $this->execSQLNoData($sql, array( + $idNextCloud + ) + ); + } + +} \ No newline at end of file diff --git a/gestion/lib/Service/Provider/ProviderService.php b/gestion/lib/Service/Provider/ProviderService.php new file mode 100644 index 0000000..80ecbb5 --- /dev/null +++ b/gestion/lib/Service/Provider/ProviderService.php @@ -0,0 +1,54 @@ + + * + * @author Anna Larch + * @author Richard Steinmetz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +namespace OCA\Gestion\Service\Provider; + +use OCA\Gestion\Db\OrderBdd; +use OCA\Gestion\Db\ProviderRepository; +use OCA\Gestion\Helpers\FileExportHelpers; +use Psr\Log\LoggerInterface; + +class ProviderService { + private $providerRepository; + + /** @var LoggerInterface */ + private $logger; + + public function __construct( + ProviderRepository $providerRepository, + LoggerInterface $logger) { + $this->logger = $logger; + $this->providerRepository = $providerRepository; + } + + public function getProvidersAsArray(){ + return $this->providerRepository->getProvidersList(); + } + + public function createDefaultProvider($idNextCloud){ + $this->providerRepository->createDefaultProvider($idNextCloud); + } +} diff --git a/gestion/lib/Sql/20250213-ADD_ORDER_PROVIDER.sql b/gestion/lib/Sql/20250213-ADD_ORDER_PROVIDER.sql new file mode 100644 index 0000000..2ba1563 --- /dev/null +++ b/gestion/lib/Sql/20250213-ADD_ORDER_PROVIDER.sql @@ -0,0 +1,15 @@ +create table oc_gestion_provider ( + id INT PRIMARY KEY AUTO_INCREMENT, + provider_name VARCHAR(255) DEFAULT '', + provider_last_name VARCHAR(255) DEFAULT '', + provider_company_name VARCHAR(255) DEFAULT '', + provider_siret_number VARCHAR(255) DEFAULT '', + provider_phone VARCHAR(255) DEFAULT '', + provider_email VARCHAR(255) DEFAULT '', + provider_address VARCHAR(255) DEFAULT '', + provider_city VARCHAR(255) DEFAULT '', + id_nextcloud VARCHAR(255) DEFAULT '' +); + +alter table oc_gestion_orders +add column fk_provider_id INT DEFAULT NULL; \ No newline at end of file