diff --git a/gestion/appinfo/routes.php b/gestion/appinfo/routes.php index 4561da0..3f04a12 100644 --- a/gestion/appinfo/routes.php +++ b/gestion/appinfo/routes.php @@ -188,5 +188,13 @@ return [ ['name' => 'order#orderProduct', 'url' => '/orderProduct', 'verb' => 'GET'], ['name' => 'order#getOrderProducts','url' => '/orderProduct/list', 'verb' => 'PROPFIND'], ['name' => 'order#createDefaultOrderProduct','url' => '/orderProduct/createDefaultOrderProduct', 'verb' => 'POST'], + + + //vehicles + ['name' => 'vehicle#vehicle', 'url' => '/vehicle', 'verb' => 'GET'], + ['name' => 'vehicle#getVehicles','url' => '/vehicle/list', 'verb' => 'PROPFIND'], + ['name' => 'vehicle#getAvailableVehicles','url' => '/vehicle/available-list', 'verb' => 'PROPFIND'], + ['name' => 'vehicle#getVehiclePurchaseTypes','url' => '/vehicle/purchase-type/list', 'verb' => 'PROPFIND'], + ['name' => 'vehicle#createDefaultVehicle','url' => '/vehicle/createDefaultVehicle', 'verb' => 'POST'] ] ]; \ No newline at end of file diff --git a/gestion/lib/Constants/VehiclePurchaseTypeConstant.php b/gestion/lib/Constants/VehiclePurchaseTypeConstant.php new file mode 100644 index 0000000..82fe06e --- /dev/null +++ b/gestion/lib/Constants/VehiclePurchaseTypeConstant.php @@ -0,0 +1,10 @@ +idNextcloud = $UserId; + $this->urlGenerator = $urlGenerator; + $this->mailer = $mailer; + $this->config = $config; + $this->navigationService = $navigationService; + $this->configurationService = $configurationService; + $this->logger = $logger; + $this->vehicleService = $vehicleService; + + 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 vehicle() { + return new TemplateResponse('gestion', 'vehicle', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink())); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getVehicles() { + $vehicles = $this->vehicleService->getVehicles(); + return $vehicles; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function createDefaultVehicle() { + try{ + $this->vehicleService->createDefaultVehicle(); + return true; + } + catch(Exception $e){ + return null; + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getVehiclePurchaseTypes() { + try{ + $types = $this->vehicleService->getVehiclePurchaseTypes(); + return $types; + } + catch(Exception $e){ + return json_encode([]); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getAvailableVehicles() { + try{ + $vehicles = $this->vehicleService->getAvailableVehicles(); + return $vehicles; + } + catch(Exception $e){ + return json_encode([]); + } + } +} diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index e63ee51..e14a493 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -42,13 +42,14 @@ class Bdd { "fk_client_group_id","fk_produit_id","ht_amount","client_group_name", "provider_name","provider_last_name","provider_company_name","provider_siret_number","provider_phone","provider_email", "provider_address","provider_city","fk_provider_id", - "label","fk_order_id","fk_order_item_id","quantity"); + "label","fk_order_id","fk_order_item_id","quantity", + "brand","model","immatriculation","purchase_date","fk_vehicle_purchase_type_key","purchase_date"); $this->whiteTable = array("client", "lieu", "trajet", "devis", "produit_devis", "facture", "produit", "configuration", "ligne_trajet", "thanato", "article", "defunt", "article_devis", "bibliotheque", "bijou_defunt", "obs_defunt", "hypo_defunt", "orders","thanato_product_discount", "client_group_discount","client_group","provider", - "order_product","order_item"); + "order_product","order_item","vehicle"); $this->tableprefix = '*PREFIX*' ."gestion_"; $this->pdo = $db; $this->l = $l; diff --git a/gestion/lib/Db/VehicleRepository.php b/gestion/lib/Db/VehicleRepository.php new file mode 100644 index 0000000..cafbe67 --- /dev/null +++ b/gestion/lib/Db/VehicleRepository.php @@ -0,0 +1,85 @@ +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 getVehicles(){ + $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle"; + return $this->execSQL($sql, []); + } + + public function createDefaultVehicle(){ + $date = new DateTime(); + $date = $date->format("Y-m-d"); + $sql = "INSERT INTO `".$this->gestionTablePrefix."vehicle` ( + `purchase_date` + ) + VALUES (?);"; + $this->execSQLNoData($sql, array( + $date + ) + ); + } + + public function getVehiclePurchaseTypes(){ + $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle_purchase_type"; + return $this->execSQL($sql, []); + } + + public function getVehicleCount(){ + $count = 0; + $sql = "SELECT COUNT(vehicle.id) as vehicle_count + FROM ".$this->gestionTablePrefix."vehicle as vehicle;"; + + $result = $this->execSQLNoJsonReturn($sql,[]); + if(!empty($result)){ + $count = $result[0]["vehicle_count"]; + } + return $count; + } + + public function getAvailableVehicles(){ + $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle as vehicle + WHERE vechile.fk_thanato_id IS NULL + "; + + return $this->execSQL($sql, []); + } + +} \ No newline at end of file diff --git a/gestion/lib/Service/MenuStatisticService.php b/gestion/lib/Service/MenuStatisticService.php index d8a86d3..bf445fe 100644 --- a/gestion/lib/Service/MenuStatisticService.php +++ b/gestion/lib/Service/MenuStatisticService.php @@ -30,6 +30,7 @@ use OCA\Gestion\Constants\BddConstant; use OCA\Gestion\Db\Bdd; use OCA\Gestion\Db\OrderBdd; use OCA\Gestion\Db\ProviderRepository; +use OCA\Gestion\Db\VehicleRepository; use OCA\Gestion\Service\Order\OrderService; use OCP\IURLGenerator; use Psr\Log\LoggerInterface; @@ -39,15 +40,18 @@ class MenuStatisticService { private $gestionBdd; private $orderBdd; private $providerRepository; + private $vehicleRepository; public function __construct( Bdd $gestionBdd, OrderBdd $orderBdd, - ProviderRepository $providerRepository + ProviderRepository $providerRepository, + VehicleRepository $vehicleRepository ) { $this->gestionBdd = $gestionBdd; $this->orderBdd = $orderBdd; $this->providerRepository = $providerRepository; + $this->vehicleRepository = $vehicleRepository; } /** @@ -73,6 +77,7 @@ class MenuStatisticService { $res['clientGroupDiscount'] = json_decode($this->gestionBdd->getClientGroupDiscountCount())[0]->c; $res['clientGroupFacturation'] = json_decode($this->gestionBdd->getClientGroupFacturationCount())[0]->c; $res['orderProduct'] = $this->orderBdd->getOrderProductCount(); + $res['vehicle'] = $this->vehicleRepository->getVehicleCount(); return $res; } diff --git a/gestion/lib/Service/NavigationService.php b/gestion/lib/Service/NavigationService.php index fe1dd67..49e9210 100644 --- a/gestion/lib/Service/NavigationService.php +++ b/gestion/lib/Service/NavigationService.php @@ -60,6 +60,7 @@ class NavigationService { "clientGroupFacturation" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroupFacturation"), "provider" => $this->urlGenerator->linkToRouteAbsolute("gestion.provider.provider"), "orderProduct" => $this->urlGenerator->linkToRouteAbsolute("gestion.order.orderProduct"), + "vehicle" => $this->urlGenerator->linkToRouteAbsolute("gestion.vehicle.vehicle"), ); } diff --git a/gestion/lib/Service/Vehicle/VehicleService.php b/gestion/lib/Service/Vehicle/VehicleService.php new file mode 100644 index 0000000..2f49b93 --- /dev/null +++ b/gestion/lib/Service/Vehicle/VehicleService.php @@ -0,0 +1,62 @@ + + * + * @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\Vehicle; + +use OCA\Gestion\Db\ProviderRepository; +use OCA\Gestion\Db\VehicleRepository; +use Psr\Log\LoggerInterface; + +class VehicleService { + private $providerRepository; + private $vehicleRepository; + + /** @var LoggerInterface */ + private $logger; + + public function __construct( + VehicleRepository $vehicleRepository, + LoggerInterface $logger) { + $this->logger = $logger; + $this->vehicleRepository = $vehicleRepository; + } + + public function getVehicles(){ + return $this->vehicleRepository->getVehicles(); + } + + public function createDefaultVehicle(){ + $this->vehicleRepository->createDefaultVehicle(); + } + + public function getVehiclePurchaseTypes(){ + return $this->vehicleRepository->getVehiclePurchaseTypes(); + } + + public function getAvailableVehicles(){ + return $this->vehicleRepository->getAvailableVehicles(); + } +} diff --git a/gestion/lib/Sql/20250221-THANATO_VEHICLE.sql b/gestion/lib/Sql/20250221-THANATO_VEHICLE.sql new file mode 100644 index 0000000..3f2170b --- /dev/null +++ b/gestion/lib/Sql/20250221-THANATO_VEHICLE.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS oc_gestion_vehicle_purchase_type( + type_key VARCHAR(200) PRIMARY KEY, + type_label VARCHAR(200) DEFAULT '' +); + +insert into oc_gestion_vehicle_purchase_type(type_key,type_label) VALUES +('LOA','Loa'), +('LLD','Lld'), +('CREDIT','Crédit'); + + +CREATE TABLE IF NOT EXISTS oc_gestion_vehicle( + id INT AUTO_INCREMENT PRIMARY KEY, + brand VARCHAR(200) DEFAULT '', + model VARCHAR(200) DEFAULT '', + immatriculation VARCHAR(200) DEFAULT '', + purchase_date DATE, + fk_vehicule_purchase_type_key VARCHAR(200) DEFAULT 'LOA', + fk_thanato_id INT +); \ No newline at end of file