finish vehicle from backend , wip frontend part
This commit is contained in:
parent
2c8174d99d
commit
d95643ee24
@ -188,5 +188,13 @@ return [
|
|||||||
['name' => 'order#orderProduct', 'url' => '/orderProduct', 'verb' => 'GET'],
|
['name' => 'order#orderProduct', 'url' => '/orderProduct', 'verb' => 'GET'],
|
||||||
['name' => 'order#getOrderProducts','url' => '/orderProduct/list', 'verb' => 'PROPFIND'],
|
['name' => 'order#getOrderProducts','url' => '/orderProduct/list', 'verb' => 'PROPFIND'],
|
||||||
['name' => 'order#createDefaultOrderProduct','url' => '/orderProduct/createDefaultOrderProduct', 'verb' => 'POST'],
|
['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']
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
10
gestion/lib/Constants/VehiclePurchaseTypeConstant.php
Normal file
10
gestion/lib/Constants/VehiclePurchaseTypeConstant.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\Gestion\Constants;
|
||||||
|
abstract class VehiclePurchaseTypeConstant
|
||||||
|
{
|
||||||
|
const LOA_TYPE = "LOA";
|
||||||
|
const LLD_TYPE = "LLD";
|
||||||
|
const CREDIT_TYPE = "CREDIT";
|
||||||
|
}
|
||||||
149
gestion/lib/Controller/VehicleController.php
Normal file
149
gestion/lib/Controller/VehicleController.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\Gestion\Controller;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use OCA\Gestion\Service\ConfigurationService;
|
||||||
|
use OCA\Gestion\Service\NavigationService;
|
||||||
|
use OCA\Gestion\Service\Vehicle\VehicleService;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
defined("TAB1") or define("TAB1", "\t");
|
||||||
|
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IRequest;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use OCP\Mail\IMailer;
|
||||||
|
use OCP\Files\IRootFolder;
|
||||||
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\AppFramework\Controller;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\IConfig;
|
||||||
|
|
||||||
|
date_default_timezone_set('Europe/Paris');
|
||||||
|
|
||||||
|
class VehicleController extends Controller {
|
||||||
|
private $idNextcloud;
|
||||||
|
private $urlGenerator;
|
||||||
|
private $mailer;
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/** @var IRootStorage */
|
||||||
|
private $storage;
|
||||||
|
|
||||||
|
private $user;
|
||||||
|
private $groups = [];
|
||||||
|
|
||||||
|
/** @var \OCA\Gestion\Service\NavigationService */
|
||||||
|
private $navigationService;
|
||||||
|
|
||||||
|
private $vehicleService;
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct($AppName,
|
||||||
|
IRequest $request,
|
||||||
|
$UserId,
|
||||||
|
IRootFolder $rootFolder,
|
||||||
|
IURLGenerator $urlGenerator,
|
||||||
|
IMailer $mailer,
|
||||||
|
Iconfig $config,
|
||||||
|
IUserSession $userSession,
|
||||||
|
IGroupManager $groupManager,
|
||||||
|
NavigationService $navigationService,
|
||||||
|
ConfigurationService $configurationService,
|
||||||
|
LoggerInterface $logger,
|
||||||
|
VehicleService $vehicleService
|
||||||
|
){
|
||||||
|
|
||||||
|
parent::__construct($AppName, $request);
|
||||||
|
|
||||||
|
$this->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([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,13 +42,14 @@ class Bdd {
|
|||||||
"fk_client_group_id","fk_produit_id","ht_amount","client_group_name",
|
"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_name","provider_last_name","provider_company_name","provider_siret_number","provider_phone","provider_email",
|
||||||
"provider_address","provider_city","fk_provider_id",
|
"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",
|
$this->whiteTable = array("client", "lieu", "trajet", "devis", "produit_devis", "facture", "produit",
|
||||||
"configuration", "ligne_trajet", "thanato", "article", "defunt", "article_devis",
|
"configuration", "ligne_trajet", "thanato", "article", "defunt", "article_devis",
|
||||||
"bibliotheque", "bijou_defunt", "obs_defunt", "hypo_defunt",
|
"bibliotheque", "bijou_defunt", "obs_defunt", "hypo_defunt",
|
||||||
"orders","thanato_product_discount",
|
"orders","thanato_product_discount",
|
||||||
"client_group_discount","client_group","provider",
|
"client_group_discount","client_group","provider",
|
||||||
"order_product","order_item");
|
"order_product","order_item","vehicle");
|
||||||
$this->tableprefix = '*PREFIX*' ."gestion_";
|
$this->tableprefix = '*PREFIX*' ."gestion_";
|
||||||
$this->pdo = $db;
|
$this->pdo = $db;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
|
|||||||
85
gestion/lib/Db/VehicleRepository.php
Normal file
85
gestion/lib/Db/VehicleRepository.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\Gestion\Db;
|
||||||
|
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
use \Datetime;
|
||||||
|
use OCA\Gestion\Constants\BddConstant;
|
||||||
|
|
||||||
|
class VehicleRepository {
|
||||||
|
private $gestionTablePrefix;
|
||||||
|
|
||||||
|
private $defaultTablePrefix;
|
||||||
|
private IDbConnection $pdo;
|
||||||
|
|
||||||
|
public function __construct(IDbConnection $db) {
|
||||||
|
$this->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, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -30,6 +30,7 @@ use OCA\Gestion\Constants\BddConstant;
|
|||||||
use OCA\Gestion\Db\Bdd;
|
use OCA\Gestion\Db\Bdd;
|
||||||
use OCA\Gestion\Db\OrderBdd;
|
use OCA\Gestion\Db\OrderBdd;
|
||||||
use OCA\Gestion\Db\ProviderRepository;
|
use OCA\Gestion\Db\ProviderRepository;
|
||||||
|
use OCA\Gestion\Db\VehicleRepository;
|
||||||
use OCA\Gestion\Service\Order\OrderService;
|
use OCA\Gestion\Service\Order\OrderService;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -39,15 +40,18 @@ class MenuStatisticService {
|
|||||||
private $gestionBdd;
|
private $gestionBdd;
|
||||||
private $orderBdd;
|
private $orderBdd;
|
||||||
private $providerRepository;
|
private $providerRepository;
|
||||||
|
private $vehicleRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Bdd $gestionBdd,
|
Bdd $gestionBdd,
|
||||||
OrderBdd $orderBdd,
|
OrderBdd $orderBdd,
|
||||||
ProviderRepository $providerRepository
|
ProviderRepository $providerRepository,
|
||||||
|
VehicleRepository $vehicleRepository
|
||||||
) {
|
) {
|
||||||
$this->gestionBdd = $gestionBdd;
|
$this->gestionBdd = $gestionBdd;
|
||||||
$this->orderBdd = $orderBdd;
|
$this->orderBdd = $orderBdd;
|
||||||
$this->providerRepository = $providerRepository;
|
$this->providerRepository = $providerRepository;
|
||||||
|
$this->vehicleRepository = $vehicleRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,6 +77,7 @@ class MenuStatisticService {
|
|||||||
$res['clientGroupDiscount'] = json_decode($this->gestionBdd->getClientGroupDiscountCount())[0]->c;
|
$res['clientGroupDiscount'] = json_decode($this->gestionBdd->getClientGroupDiscountCount())[0]->c;
|
||||||
$res['clientGroupFacturation'] = json_decode($this->gestionBdd->getClientGroupFacturationCount())[0]->c;
|
$res['clientGroupFacturation'] = json_decode($this->gestionBdd->getClientGroupFacturationCount())[0]->c;
|
||||||
$res['orderProduct'] = $this->orderBdd->getOrderProductCount();
|
$res['orderProduct'] = $this->orderBdd->getOrderProductCount();
|
||||||
|
$res['vehicle'] = $this->vehicleRepository->getVehicleCount();
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -60,6 +60,7 @@ class NavigationService {
|
|||||||
"clientGroupFacturation" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroupFacturation"),
|
"clientGroupFacturation" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.clientGroupFacturation"),
|
||||||
"provider" => $this->urlGenerator->linkToRouteAbsolute("gestion.provider.provider"),
|
"provider" => $this->urlGenerator->linkToRouteAbsolute("gestion.provider.provider"),
|
||||||
"orderProduct" => $this->urlGenerator->linkToRouteAbsolute("gestion.order.orderProduct"),
|
"orderProduct" => $this->urlGenerator->linkToRouteAbsolute("gestion.order.orderProduct"),
|
||||||
|
"vehicle" => $this->urlGenerator->linkToRouteAbsolute("gestion.vehicle.vehicle"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
62
gestion/lib/Service/Vehicle/VehicleService.php
Normal file
62
gestion/lib/Service/Vehicle/VehicleService.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* Calendar App
|
||||||
|
*
|
||||||
|
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
|
||||||
|
*
|
||||||
|
* @author Anna Larch <anna.larch@gmx.net>
|
||||||
|
* @author Richard Steinmetz <richard@steinmetz.cloud>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
gestion/lib/Sql/20250221-THANATO_VEHICLE.sql
Normal file
20
gestion/lib/Sql/20250221-THANATO_VEHICLE.sql
Normal file
@ -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
|
||||||
|
);
|
||||||
Loading…
x
Reference in New Issue
Block a user