<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpClient\HttpClient;
use App\Controller\CommunController;
use App\Entity\UserClient;
use App\Services\libMQTT\src\ClientMQTT;
class ParametrageController extends AbstractController
{
protected $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function ParametrageListeTerminaux() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$commun= new CommunController($this->requestStack,$token);
$terminaux= $commun->ListeTerminaux();
// return new response(var_dump($terminaux));
return $this->render('ParametrageBundle/parametragelisteterminaux.html.twig', array('terminaux' => $terminaux ,'idclient' => $idclient));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
///***************Gestion des services***************** */
public function ParametrageServices($idTerminal) {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$commun= new CommunController($this->requestStack,$token);
$borne= $commun->TerminalById($idTerminal);
$services= $commun->ServicesTerminal($idTerminal);
//return new response(var_dump($services));
return $this->render('ParametrageBundle/ParametrageServices.html.twig', array('terminal' => $borne ,'idclient' => $idclient , 'services'=>$services));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function UpdateService($identifiant, $message='') {
//return new response(var_dump($identifiant));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
//$token = $request->getSession()->get('token');
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/services/".$identifiant,
['headers' => [
'Content-Type' => 'application/json',
]
]);
$service=null;
if($response->getStatusCode()==200) $service=json_decode($response->getContent(),true);
//return new response(var_dump($service));
$response1 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/service_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeservices=null;
if($response1->getStatusCode()==200) $typeservices=json_decode($response1->getContent(),true);
// return new response(var_dump($typeservices));
$param=explode("_",$identifiant);
$idTerminal=$param[0];
$commun= new CommunController($this->requestStack,$token);
$services= $commun->ServicesTerminal($idTerminal);
// return new response(var_dump($services));
return $this->render('ParametrageBundle/UpdateService.html.twig', array('idclient' => $idclient , 'service'=>$service , 'typeservices'=>$typeservices ,'message'=>$message , 'services'=>$services));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DoUpdateService($identifiant) {
//return new response(var_dump($identifiant));
$message='';
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
$postData = $request->request->all();
//return new response(var_dump($postData));
/* $idTypeService=$postData['idTypeService'];
$nom=$postData['nom'];
$description=$postData['description'];
$ptDistribution=$postData['ptDistribution'];*/
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('PATCH',
"http://apiionycar.netbase.fr/api/services/".$identifiant,
['headers' => [
'Content-Type' => 'application/merge-patch+json',
],
'json' => ['idServiceType' => intval($postData['idTypeService']) ,
'pointDistribution' => intval($postData['ptDistribution']),
'nom'=> $postData['nom'],
'description'=>$postData['description'] ],
]);
// return new response(var_dump($response));
if($response->getStatusCode()==200) $message='Modification prise en compte ';
else $message='Erreur lors de la modification du service';
/* $response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/services/".$identifiant,
['headers' => [
'Content-Type' => 'application/json',
]
]);
$service=null;
if($response->getStatusCode()==200) $service=json_decode($response->getContent(),true);*/
return $this->UpdateService($identifiant, $message);
// return $this->render('ParametrageBundle/UpdateService.html.twig', array('idclient' => $idclient , 'service'=>$service , 'typeservices'=>$typeservices , 'message'=>$message));
}
else
{
return $this->forward('App\Controller\LoginController::index');
}
}
public function AddService($idTerminal) {
//return new response(var_dump($identifiant));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response1 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/service_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeservices=null;
if($response1->getStatusCode()==200) $typeservices=json_decode($response1->getContent(),true);
// return new response(var_dump($typeservices));
$commun= new CommunController($this->requestStack,$token);
$services= $commun->ServicesTerminal($idTerminal);
// return new response(var_dump($services));
return $this->render('ParametrageBundle/AddService.html.twig', array('idclient' => $idclient , 'idTerminal'=>$idTerminal , 'typeservices'=>$typeservices ,'services'=>$services));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DoAddService() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$postData = $request->request->all();
// return new response(var_dump(intval($postData['idTypeService'])));
// return new response(var_dump($postData));
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('POST',
"http://apiionycar.netbase.fr/api/services",
['headers' => [
'Content-Type' => 'application/json',
],
'json' => ['idSite' => intval($postData['idTerminal']),
'pointDistribution' => intval($postData['ptDistribution']),
'idServiceType' => intval($postData['idTypeService']) ,
'nom'=> $postData['nom'],
'description'=>$postData['description'],
'disponible'=>0 ],
]);
// if($response->getStatusCode()==201)
return $this->forward('App\Controller\ParametrageController::ParametrageServices',[
'idTerminal'=>$postData['idTerminal']
]);
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
// return $this->ParametrageServices($postData['idTerminal']);
}
/*
public function DoDeleteService($identifiant) {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
// return new response(var_dump($identifiant));
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('DELETE',
"http://apiionycar.netbase.fr/api/services/".$identifiant,
['headers' => [
'Content-Type' => 'application/json',
]
]);
//return new response(var_dump($response));
return $this->ParametrageServices($postData['idTerminal']);
}*/
public function DeleteService() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$identifiant=$postData['identifiant'];
// return new response(var_dump($identifiant));
$param=explode("_",$identifiant);
$idTerminal=$param[0];
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('DELETE',
"http://apiionycar.netbase.fr/api/services/".$identifiant,
['headers' => [
'Content-Type' => 'application/json',
]
]);
$postData=null;
if($response->getStatusCode()==204) return new response(true);
else return new response(false);
}
/********** Fin gestion services*********/
/****** Gestion des tarifs *************/
public function ParametrageTarifs($idTerminal) {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
// return new response(var_dump($request->getSession()));
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{$token = $request->getSession()->get('token');
$commun= new CommunController($this->requestStack,$token);
$borne= $commun->TerminalById($idTerminal);
$tarifs= $commun->TarifsTerminal($idTerminal);
//return new response(var_dump($tarifs));
return $this->render('ParametrageBundle/ParametrageTarifs.html.twig', array('terminal' => $borne ,'idclient' => $idclient , 'tarifs'=>$tarifs));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DeleteTarif() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$idTarif=$postData['idTarif'];
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('DELETE',
"http://apiionycar.netbase.fr/api/tarifs/".$idTarif,
['headers' => [
'Content-Type' => 'application/json',
]
]);
if($response->getStatusCode()==204) return new response(true);
else return new response(false);
}
public function AddTarif($idTerminal) {
//return new response(var_dump($idTerminal));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
// service type
$response1 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/service_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeservices=null;
if($response1->getStatusCode()==200) $typeservices=json_decode($response1->getContent(),true);
// return new response(var_dump($typeservices));
//Unite type
$response2 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/unite_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeunites=null;
if($response2->getStatusCode()==200) $typeunites=json_decode($response2->getContent(),true);
// return new response(var_dump($typeunites));
$commun= new CommunController($this->requestStack,$token);
$tarifs= $commun->TarifsTerminal($idTerminal);
// return new response(var_dump($tarifs));
return $this->render('ParametrageBundle/AddTarif.html.twig', array('idclient' => $idclient , 'idTerminal'=>$idTerminal , 'typeservices'=>$typeservices ,'tarifs'=>$tarifs , 'typeunites'=>$typeunites));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DoAddTarif()
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$postData = $request->request->all();
// return new response(var_dump(intval($postData['idTypeService'])));
//return new response(var_dump($postData));
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('POST',
"http://apiionycar.netbase.fr/api/tarifs",
['headers' => [
'Content-Type' => 'application/json',
],
'json' => ['idSite' => intval($postData['idTerminal']),
'idServiceType' => intval($postData['idTypeService']) ,
'idUniteType' => intval($postData['idTypeUnite']),
//'devise'=> 'EUR',//$postData['devise'],
//'deviseSymbole'=>$postData['symbole'],
'prix'=>floatval($postData['prix']) ],
]);
//return new response(var_dump($response));
// if($response->getStatusCode()==201) return new response(true);
// else return new response(false);
return $this->forward('App\Controller\ParametrageController::ParametrageTarifs',[
'idTerminal'=>$postData['idTerminal']
]);
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function UpdateTarif($idTarif , $message='')
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
//Tarif
$response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/tarifs/".$idTarif,
['headers' => [
'Content-Type' => 'application/json',
]
]);
$tarif=null;
if($response->getStatusCode()==200) $tarif=json_decode($response->getContent(),true);
//return new response(var_dump($tarif));
//Type servuce
$response1 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/service_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeservices=null;
if($response1->getStatusCode()==200) $typeservices=json_decode($response1->getContent(),true);
// return new response(var_dump($typeservices));
//Type unite
$response2 = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/unite_types.json",
['headers' => [
'Content-Type' => 'application/json',
]
]);
$typeunites=null;
if($response2->getStatusCode()==200) $typeunites=json_decode($response2->getContent(),true);
// return new response(var_dump($typeunites));
//liste tarif
$idTerminal=0;
if($tarif!=null) $idTerminal=$tarif['idSite'];
$commun= new CommunController($this->requestStack,$token);
$tarifs= $commun->TarifsTerminal($idTerminal);
// return new response(var_dump($services));
return $this->render('ParametrageBundle/UpdateTarif.html.twig', array('idclient' => $idclient , 'tarif'=>$tarif , 'typeservices'=>$typeservices ,'message'=>$message , 'tarifs'=>$tarifs ,'typeunites'=>$typeunites));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DoUpdateTarif($idTarif)
{
//return new response(var_dump($identifiant));
$message='';
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('PATCH',
"http://apiionycar.netbase.fr/api/tarifs/".$idTarif,
['headers' => [
'Content-Type' => 'application/merge-patch+json',
],
'json' => ['idServiceType' => intval($postData['idTypeService']) ,
'idUniteType' => intval($postData['idTypeUnite']),
'prix'=> floatval($postData['prix']),
'devise'=>$postData['devise'] ],
]);
//return new response(var_dump($response->getStatusCode()));
if($response->getStatusCode()==200) $message='Modification prise en compte ';
else $message='Erreur lors de la modification du service';
return $this->UpdateTarif($idTarif, $message);
}
else
{
return $this->forward('App\Controller\LoginController::index');
}
}
/**********fin Gestion tarifs ***** */
/************Gestion site ***************/
public function ParametrageSite($idTerminal)
{
//return new response(var_dump('Site ='.$idTerminal));
//return new response(var_dump($identifiant));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
//$postData = $request->request->all();
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/terminal_ionycars/".$idTerminal,
['headers' => [
'Content-Type' => 'application/json',
],
]);
//return new response(var_dump($response->getStatusCode()));
if($response->getStatusCode()==200) $terminal=json_decode($response->getContent(),true);
else $terminal=null;
//SH 2024.03.13 gestion nouvel formulaire payzen iframe
$con= $this->getDoctrine()->getConnection();
$sql = $con->prepare("SELECT * FROM boutique_payzen");
$sql->execute();
$boutiques = $sql->fetchAll();
//fin SH
//return new response(var_dump($terminal));
return $this->render('ParametrageBundle/EditUpdateSite.html.twig', array('idclient' => $idclient , 'terminal'=>$terminal ,'boutiques'=>$boutiques ));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function UpdateSite()
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
//return new response(var_dump($postData));
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('PATCH',
"http://apiionycar.netbase.fr/api/terminal_ionycars/".$postData['idTerminal'],
['headers' => [
'Content-Type' => 'application/merge-patch+json',
],
'json' => ['nomTerminal' => $postData['nomTerminal'] ,
'gpsTerminal'=>$postData['gpsTerminal'] ],
]);
//return new response(var_dump($response));
if($response->getStatusCode()==200) return new response(true) ;
else return new response(false) ;
}
else return new response(false) ;
//return false;
}
public function UpdatePaySite()
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
//return new response(var_dump($postData));
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
if($postData['paiementProd']==='0') $bnqKey=$postData['testKey'];
else $bnqKey=$postData['prodKey'];
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('PATCH',
"http://apiionycar.netbase.fr/api/zone_terminals/".$postData['idTerminal']."_1",
['headers' => [
'Content-Type' => 'application/merge-patch+json',
],
'json' => ['BnqSiteId' => $postData['BnqSiteId'] ,
'BnqKey'=>trim($bnqKey),
'paiementProd' => intval($postData['paiementProd']) ,
'testKeyPayzen'=>trim($postData['testKey']) ,
'prodKeyPayzen'=>trim($postData['prodKey']) ,
'testPwdPayzen'=>trim($postData['testPwd']) , //SH 2022.05.30
'prodPwdPayzen'=>trim($postData['prodPwd']) , //SH 2022.05.30
],
]);
// return new response(var_dump($response));
if($response->getStatusCode()==200) return new response(true) ;
else return new response(false) ;
}
else return new response(false) ;
//return false;
}
public function ConfigTPE()
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
/// return new response(var_dump($postData));
if($idclient!=null)
{
$topic=$postData['idTerminal']."/in/SetConfig/TPE";
// return new response(var_dump($topic));
$res=$this->MessageMQTT($topic,$postData['action']);
//$res=$this->MessageMQTT($topic,1);
return new response(var_dump($res));
}
else return new response(false) ;
//return false;
}
//SH 2024.04.29 gesion formulaire payzen iframe
public function UpdateBoutiqueSite()
{
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
//return new response(var_dump($postData));
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
$con= $this->getDoctrine()->getConnection();
$sql = $con->prepare("SELECT *
FROM boutique_payzen where ID_BOUTIQUE=?");
$sql->bindValue(1, $postData['boutiquePayzen']);
$sql->execute();
$boutique = $sql->fetch();
//return new response(var_dump($boutique));
if($postData['paiementProd']==='0') $bnqKey=$boutique['TEST_KEY'];
else $bnqKey=$boutique['PROD_KEY'];
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('PATCH',
"http://apiionycar.netbase.fr/api/zone_terminals/".$postData['idTerminal']."_1",
['headers' => [
'Content-Type' => 'application/merge-patch+json',
],
'json' => ['BnqSiteId' => $postData['boutiquePayzen'] ,
'BnqKey'=>trim($bnqKey),
'paiementProd' => intval($postData['paiementProd']) ,
'testKeyPayzen'=> trim($boutique['TEST_KEY']) ,
'prodKeyPayzen'=> trim($boutique['PROD_KEY']) ,
'testPwdPayzen'=>' ' ,
'prodPwdPayzen'=>' ' ,
],
]);
// return new response(var_dump($response));
if($response->getStatusCode()==200) return new response(true) ;
else return new response(false) ;
}
else return new response(false) ;
//return false;
}
//fin SH
/***************Fin Site**************/
public function MessageMQTT($sujet,$message) {
//return new Response(var_dump($sujet));
$server = '192.168.1.22';
$port=1883;
$clientId='api_isipay';
$client = new ClientMQTT($server,$port, $clientId);
$client->setAuthDetails("urbaflux", "BJdYM#t8ucvN?yZMu");
$client->setParamServer($server,$port, $clientId);
$result = $client->connect();
// return new Response(var_dump($result));
$result = $client->publish($sujet ,$message , 0);
$client->close();
return $result;
}
public function ParametrageBadges($idTerminal)
{
//return new response(var_dump('Site ='.$idTerminal));
//return new response(var_dump($identifiant));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$terminal = null;
if($idclient!=null)
{
$commun= new CommunController($this->requestStack,'');
$tokenvalid= $commun-> VerifValiditeToken();
if($tokenvalid==true) $token = $request->getSession()->get('token');
else $token=$commun->getTokenApi($idclient);
//$postData = $request->request->all();
// $terminal= $commun->TerminalById($idTerminal);
$httpClient = HttpClient::create([
'auth_bearer' => $token
]);
$response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/terminal_ionycars/".$idTerminal,
['headers' => [
'Content-Type' => 'application/json',
],
]);
// return new response(var_dump($response->getStatusCode()));
if($response->getStatusCode()==200)
{
$terminal=json_decode($response->getContent(),true);
//return new response(var_dump($terminal));
}
$response = $httpClient->request('GET',
"http://apiionycar.netbase.fr/api/liste_badges/".$idTerminal,
['headers' => [
'Content-Type' => 'application/json',
],
]);
// return new response(var_dump($response->getStatusCode()));
$badgesHex = null;
$badgesHexInv = null;
if($response->getStatusCode()==200)
{
$listeBadges=json_decode($response->getContent(),true);
$badges = $listeBadges['listeBadges'];
$badges = explode( ';', $badges );
$j=0;
for($i = 0; $i < count($badges); $i++)
{
if($badges[$i]!='')
{
if(($idTerminal==1198) or ($idTerminal==1154))
{
$badgesHex[$j]=strtoupper(dechex($badges[$i]));
$badgesHexInv[$j]['DEC']=$badges[$i];
$badgesHexInv[$j]['HEX']=$badgesHex[$j];
$badgesHexInv[$j]['HEXINV']=substr($badgesHex[$j],4,2).':'.substr($badgesHex[$j],2,2).':'.substr($badgesHex[$j],0,2).':**';
$j++;
}
else
{
// $badgesHex[$j]=strtoupper(dechex($badges[$i]));
$badgesHex[$j]='';
if(strlen($badges[$i])<=7)
{
$nbChar=8-strlen($badges[$i]);
for($k=0;$k<$nbChar;$k++) $badgesHex[$j]=$badgesHex[$j].'0';
}
$badgesHex[$j].=strtoupper($badges[$i]);
$badgesHexInv[$j]['DEC']=hexdec($badgesHex[$j]);
$badgesHexInv[$j]['HEX']=$badgesHex[$j];
$badgesHexInv[$j]['HEXINV']= $badgesHexInv[$j]['HEX'];
$j++;
}
}
}
}
else $badges=null;
// return new response(var_dump($badgesHex));
// return new response(var_dump($badgesHexInv));
//SH 2024.07.10 synchronisation des badges
$synchroBadges = null;
$con = $this->getDoctrine()->getConnection('ionycar');
$sql = $con->prepare("SELECT * FROM tb_action_badge where synchro=0 and idSite=?");
$sql->bindValue(1, $idTerminal);
$sql->execute();
$synchroBadges = $sql->fetchAll();
//return new response(var_dump($synchroBadges));
//fin SH
return $this->render('ParametrageBundle/ParametrageBadges.html.twig', array('idclient' => $idclient , 'terminal' =>$terminal , 'badges'=>$badges ,
'badgesHexInv' =>$badgesHexInv , 'synchro' => $synchroBadges ));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function AddBadge() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$badge=$postData['badge'];
$idTerminal = $postData['idTerminal'];
//return new response(var_dump($badge));
$topic=$idTerminal.'/in/AddBadge';
$res=$this->MessageMQTT($topic,$badge);
$this->ajoutActionBadge($idTerminal , $badge);//SH 2024.07.09 synchro mode offline
return new response($topic);
}
//SH 2024.04.12 ajout d'une liste de badge
public function AddListeBadges() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$badges=$postData['badges'];
$idTerminal = $postData['idTerminal'];
$badges = explode(",", $badges);
// return new response(var_dump($badges));
$topic=$idTerminal.'/in/AddBadge';
for($i=0;$i<count($badges);$i++)
{
$res=$this->MessageMQTT($topic,$badges[$i]);
$this->ajoutActionBadge($idTerminal , $badges[$i]);//SH 2024.07.09 synchro mode offline
}
return new response($topic);
}
//fin SH
public function DeleteBadge() {
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$clients = null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$token = $request->getSession()->get('token');
$postData = $request->request->all();
$badge=$postData['badge'];
$idTerminal = $postData['idTerminal'];
//return new response(var_dump($badge));
if($badge =='tout') $topic=$idTerminal.'/in/DeleteAll';
else $topic=$idTerminal.'/in/DeleteBadge';
$res=$this->MessageMQTT($topic,$badge);
return new response($topic);
}
/*************SH 2024.03.13 gestion nouveau formulaire de paiement payzen forfait GO************/
function BoutiquesPayzen()
{
//return new Response(var_dump('Boutiques Payzen'));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
if($idclient!=null)
{
$con= $this->getDoctrine()->getConnection();
$sql = $con->prepare("SELECT * FROM boutique_payzen");
$sql->execute();
$boutiques = $sql->fetchAll();
// return new Response(var_dump($boutiques));
return $this->render('ParametrageBundle/ParametrageBoutiques.html.twig', array('boutiques' => $boutiques ,'idclient' => $idclient));
}
else {
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function AddBoutique() {
// return new response(var_dump('AddBoutique'));
$request = $this->requestStack->getCurrentRequest();
$postData = $request->request->all();
//return new response(var_dump($postData));
try
{
$con = $this->getDoctrine()->getConnection();
$sql = $con->prepare("insert into boutique_payzen (ID_BOUTIQUE, LIB_BOUTIQUE, TEST_KEY, PROD_KEY
) values (?,?,?,?);");
$sql->bindValue(1, $postData['idBoutique']);
$sql->bindValue(2, $postData['libBoutique']);
$sql->bindValue(3, $postData['cleTest']);
$sql->bindValue(4, $postData['cleProd']);
$sql->execute();
return new Response(true);
//return true ;
}
catch (\Exception $e) {
return new Response(false);
}
}
public function UpdateBoutique($identifiant, $message='') {
//return new response(var_dump($identifiant));
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
if($idclient!=null)
{
$con= $this->getDoctrine()->getConnection();
$sql = $con->prepare("SELECT *
FROM boutique_payzen where ID_BOUTIQUE=?");
$sql->bindValue(1, $identifiant);
$sql->execute();
$boutique = $sql->fetch();
// return new response(var_dump($boutique));
return $this->render('ParametrageBundle/UpdateBoutique.html.twig', array('idclient' => $idclient , 'boutique'=>$boutique ,'message'=>$message ));
}
else
{
$error = 'Fin de session';
$lastUsername ='';
return $this->render('LoginBundle/login.html.twig',
array('last_login'=> $lastUsername,
'error'=>$error));
}
}
public function DoUpdateBoutique($identifiant) {
// return new response(var_dump($identifiant));
$message='';
$idclient=null;
$request = $this->requestStack->getCurrentRequest();
$idclient=$request->getSession()->get('idClient');
$postData = $request->request->all();
//return new response(var_dump($postData));
if($idclient!=null)
{
try
{
$con = $this->getDoctrine()->getConnection();
$sql = $con->prepare("update boutique_payzen set LIB_BOUTIQUE=? , TEST_KEY=? , PROD_KEY=?
where ID_BOUTIQUE = ? ;");
$sql->bindValue(1, $postData['libBoutique']);
$sql->bindValue(2, $postData['cleTest']);
$sql->bindValue(3, $postData['cleProd']);
$sql->bindValue(4, $identifiant);
$sql->execute();
$message='Modification prise en compte ';
}
catch (\Exception $e) {
$message='Erreur lors de la modification du service';
}
return $this->UpdateBoutique($identifiant, $message);
//return $this->render('ParametrageBundle/UpdateBoutique.html.twig', array('idclient' => $idclient , 'service'=>$service , 'typeservices'=>$typeservices , 'message'=>$message));
}
else
{
return $this->forward('App\Controller\LoginController::index');
}
}
/************* FIN SH ********/
//SH 2024.07.09 ajout synchronistion badge mode offline
public function ajoutActionBadge($idTerminal , $badge)
{
$con = $this->getDoctrine()->getConnection('ionycar');
$sql = $con->prepare("insert into tb_action_badge ( idSite , badge, synchro) values (?,?,?);");
$sql->bindValue(1, $idTerminal);
$sql->bindValue(2, $badge);
$sql->bindValue(3, 0);
$sql->execute();
return new Response(true);
}
public function VerifBadge()
{
$request = $this->requestStack->getCurrentRequest();
$postData = $request->request->all();
$idTerminal=$postData['idTerminal'];
$liste=$postData['listeBadges'];
$listeBadge= explode(";", $liste);
//return new response(var_dump($listeBadge));
for($i=0;$i<count($listeBadge);$i++)
{
$con = $this->getDoctrine()->getConnection('ionycar');
$sql = $con->prepare("update tb_action_badge set synchro=1 ,dateSynchro=?
where LOWER(badge) = ? and synchro=0 ;");
$sql->bindValue(1, date('Y-m-d H:i:s'));
$sql->bindValue(2, strtolower($listeBadge[$i]));
$sql->execute();
$message='Modification prise en compte ';
}
return new response(var_dump($message));
}
public function SynchroBadges($idTerminal)
{
$request = $this->requestStack->getCurrentRequest();
$con = $this->getDoctrine()->getConnection('ionycar');
$sql = $con->prepare("SELECT * FROM tb_action_badge where synchro=0 and idSite=?");
$sql->bindValue(1, $idTerminal);
$sql->execute();
$badges = $sql->fetchAll();
//return new response(var_dump($badges));
if(count($badges)>0)
{
$topic=strval($idTerminal).'/in/AddBadge';
for($i=0;$i<count($badges);$i++)
{
$res=$this->MessageMQTT($topic,$badges[$i]['badge']);
}
}
return new response(var_dump($badges));
}
//fin SH
}