finish provider on backend

This commit is contained in:
Tiavina 2025-02-13 16:28:39 +03:00
parent 5989a64c01
commit 18687ce020
5 changed files with 262 additions and 0 deletions

View File

@ -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'],
]
];

View File

@ -0,0 +1,126 @@
<?php
namespace OCA\Gestion\Controller;
use Exception;
use OCA\Gestion\Service\ConfigurationService;
use OCA\Gestion\Service\NavigationService;
use OCA\Gestion\Service\Order\OrderPdfService;
use OCA\Gestion\Service\Order\OrderService;
use OCA\Gestion\Service\Provider\ProviderService;
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 OCA\Gestion\Db\Bdd;
use OCP\IURLGenerator;
use OCP\IConfig;
date_default_timezone_set('Europe/Paris');
class ProviderController 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 $providerService;
private $logger;
/**
* Constructor
*/
public function __construct($AppName,
IRequest $request,
$UserId,
Bdd $myDb,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IMailer $mailer,
Iconfig $config,
IUserSession $userSession,
IGroupManager $groupManager,
NavigationService $navigationService,
ConfigurationService $configurationService,
LoggerInterface $logger,
ProviderService $providerService
){
parent::__construct($AppName, $request);
$this->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;
}
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace OCA\Gestion\Db;
use OCA\Gestion\Constants\OrderStatusConstant;
use OCA\Gestion\Constants\ThanatoTypeConstant;
use OCA\Gestion\Helpers\OrderHelpers;
use OCP\IDBConnection;
use \Datetime;
use OCA\Gestion\Constants\BddConstant;
use Ramsey\Uuid\Uuid;
class ProviderRepository {
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 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
)
);
}
}

View File

@ -0,0 +1,54 @@
<?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\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);
}
}

View File

@ -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;