SD-12 Correction des appels surnuméraires + histo des conso
This commit is contained in:
parent
a6352a7c97
commit
601e79f329
@ -40,7 +40,7 @@ class Metier_Credit_Information extends Scores_Ws_Server
|
||||
'getListeConventions' => 'Conventions collectives',
|
||||
'getMarques' => 'Marques déposées',
|
||||
'getIndiScore' => 'Indiscore',
|
||||
'getIndiScore2' => 'Rapport de synthèse',
|
||||
'getReportSynthese' => 'Rapport de synthèse',
|
||||
'getRapport' => 'Rapport complet',
|
||||
'getValo' => 'Valorisation',
|
||||
);
|
||||
@ -90,10 +90,12 @@ class Metier_Credit_Information extends Scores_Ws_Server
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$infos['commande']=$stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
$siren=$infos['commande']['siret'];
|
||||
$siren=substr($infos['commande']['siret'],0,9);
|
||||
$nic=substr($infos['commande']['siret'],9,5);
|
||||
try {
|
||||
$stmt = $this->conn->prepare('SELECT * FROM insee.identite WHERE SIREN=:siren and nic="00072"');
|
||||
$stmt = $this->conn->prepare('SELECT * FROM insee.identite WHERE SIREN=:siren and nic=:nic');
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->bindValue('nic', $nic);
|
||||
$stmt->execute();
|
||||
$infos['societe']=$stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||
@ -104,4 +106,114 @@ class Metier_Credit_Information extends Scores_Ws_Server
|
||||
|
||||
return $infos;
|
||||
}
|
||||
public function getHistoUser($user,$nbligpaid=20,$nbligused=50){
|
||||
$idUser = $user->id;
|
||||
if(intval($idUser)==0){
|
||||
throw new SoapFault('MSG', 'Authentification défectueuse');
|
||||
}
|
||||
$this->redresseRapports($idUser);
|
||||
$sql = "SELECT * FROM sdv1.credit__balance c
|
||||
WHERE c.idUser=:idUser";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
try {
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
throw(new SoapFault('MSG', 'Acces base impossible'));
|
||||
}
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$res=$stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$info->balance=$res;
|
||||
}else{
|
||||
$info->balance=null;
|
||||
}
|
||||
$sql = "SELECT * FROM sdv1.credit__paid c
|
||||
WHERE c.idUser=:idUser order by id desc limit ".$nbligpaid;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
$info->paid=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$sql = "SELECT * FROM sdv1.credit__consumption c
|
||||
inner join credit__rate r on c.idLog=r.idLog
|
||||
WHERE c.idUser=:idUser and r.idClient=:idClient order by c.id desc limit ".$nbligused;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->bindValue('idClient', $user->idClient);
|
||||
$stmt->execute();
|
||||
$info->used=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$info->libelle=$this->libelles;
|
||||
//$this->wsLog(__FUNCTION__,$idUser,'0');
|
||||
return $info;
|
||||
|
||||
}
|
||||
public function getMensuelConso($user){
|
||||
$glue=";";
|
||||
$idUser = $user->id;
|
||||
if(intval($idUser)==0){
|
||||
throw new SoapFault('MSG', 'Authentification défectueuse');
|
||||
}
|
||||
$sql = 'SELECT * FROM sdv1.credit__consumption c
|
||||
inner join credit__rate r on c.idLog=r.idLog
|
||||
WHERE c.idUser=:idUser and r.idClient=:idClient and created>"'.Date('Y-m-d',time()-31*24*3600).'"
|
||||
order by c.id desc';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->bindValue('idClient', $user->idClient);
|
||||
$stmt->execute();
|
||||
$info=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$tab=array();
|
||||
foreach($info as $row){
|
||||
$tab[]=implode($glue,array(
|
||||
'date' => $row['created'],
|
||||
'nb_credit' => $row['consumption'],
|
||||
'fonction' => $this->libelles[$row['idLog']],
|
||||
'siren' => substr($row['siret'],0,9)
|
||||
));
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
/*
|
||||
* Les rapports Complets et Rapports de synthèse font des appels surnuméraires au WS
|
||||
* Cette fonction corrige ces appels avant affichage
|
||||
*/
|
||||
private function redresseRapports($idUser){
|
||||
if(intval($idUser)==0){
|
||||
throw new SoapFault('MSG', 'Authentification défectueuse');
|
||||
}
|
||||
$sql='select * from sdv1.credit__consumption
|
||||
where idLog="getReportSynthese" or idLog="getRapport" and idUser=:idUser
|
||||
and created>"'.Date('Y-m-d',time()-30*24*3600).'" order by id desc;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
$rapports=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
foreach($rapports as $row){
|
||||
$sql='select SUM(consumption) as mtt from sdv1.credit__consumption
|
||||
where (idLog="getLiens" or idLog="getDirigeants" or idLog="getAnnoncesLegales")
|
||||
and idUser='.intval($idUser).'
|
||||
and substr(siret,1,9)="'.substr($row['siret'],0,9).'"
|
||||
and created>"'.Date('Y-m-d H:i:s',strtotime($row['created'])-10).'"
|
||||
and created<"'.Date('Y-m-d H:i:s',strtotime($row['created'])+10).'";';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$res=$stmt->fetch(\PDO::FETCH_OBJ);
|
||||
if(intval($res->mtt)>0){
|
||||
$sql='update sdv1.credit__balance set balance=balance+'.$res->mtt.' where idUser='.intval($idUser).';';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$sql='update sdv1.credit__consumption set consumption=0, idLog=concat(idLog,"free")
|
||||
where (idLog="getLiens" or idLog="getDirigeants" or idLog="getAnnoncesLegales")
|
||||
and idUser='.intval($idUser).'
|
||||
and substr(siret,1,9)="'.substr($row['siret'],0,9).'"
|
||||
and created>"'.Date('Y-m-d H:i:s',strtotime($row['created'])-10).'"
|
||||
and created<"'.Date('Y-m-d H:i:s',strtotime($row['created'])+10).'";';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -387,15 +387,6 @@ class Scores_Ws_Server
|
||||
}
|
||||
$this->decLog($this->idLog,$siret);
|
||||
}
|
||||
protected function decLog($idLog=null,$siret='0'){
|
||||
if($this->idMainLog=='getRapport' && $this->idLog!=$this->idMainLog){
|
||||
return true;
|
||||
}
|
||||
$this->idLog=$idLog;
|
||||
$crdt=new Metier_Credit_Decrement();
|
||||
$ok=$crdt->setUsed($this->idLog,$this->User,$siret);
|
||||
return $ok;
|
||||
}
|
||||
/**
|
||||
* Authenticate with SoapHeader, Optional (Authentication could be done by sending HTTP Basic header - see the doc)
|
||||
* @param string $username
|
||||
@ -480,12 +471,6 @@ class Scores_Ws_Server
|
||||
* @throws SoapFault
|
||||
*/
|
||||
protected function checkCredit($idLog){
|
||||
if(
|
||||
$idLog=="getRapport"
|
||||
|| $idLog=="getIndiScore2"
|
||||
){
|
||||
$this->idMainLog=$idLog;
|
||||
}
|
||||
//if(empty($idLog)){$idLog=$this->getIdLog();}
|
||||
//@todo:retirer la securite apres verif
|
||||
if(!empty($idLog)){
|
||||
@ -495,6 +480,17 @@ class Scores_Ws_Server
|
||||
$ok=$crdt->canUse($idLog,$this->User);
|
||||
return $ok->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs access to payable WebService
|
||||
* @throws SoapFault
|
||||
*/
|
||||
protected function decLog($idLog=null,$siret='0'){
|
||||
$this->idLog=$idLog;
|
||||
$crdt=new Metier_Credit_Decrement();
|
||||
$ok=$crdt->setUsed($this->idLog,$this->User,$siret);
|
||||
return $ok;
|
||||
}
|
||||
/**
|
||||
* I keep this one oldie but goodie
|
||||
*
|
||||
|
@ -2,6 +2,7 @@
|
||||
return array(
|
||||
'GetCredit' => 'GetCredit',
|
||||
'InfoCredit' => 'InfoCredit',
|
||||
'PayCredit' => 'PayCredit',
|
||||
'MensuelconsoCredit' => 'MensuelconsoCredit',
|
||||
'PayCredit' => 'PayCredit',
|
||||
'UseCredit' => 'UseCredit',
|
||||
);
|
||||
|
@ -42,52 +42,24 @@ class Credit extends Scores_Ws_Server
|
||||
*/
|
||||
public function infoCredit()
|
||||
{
|
||||
$service='credit';
|
||||
$info=new infoCredit();
|
||||
$this->authenticate();
|
||||
$this->permission($this->libdroits,__FUNCTION__);
|
||||
$crdt=new Metier_Credit_Information();
|
||||
return $crdt->getHistoUser($this->User,20,50);
|
||||
}
|
||||
|
||||
$idUser = $this->User->id;
|
||||
if(intval($idUser)==0){
|
||||
throw new SoapFault('MSG', 'Authentification défectueuse');
|
||||
}
|
||||
$sql = "SELECT * FROM sdv1.credit__balance c
|
||||
WHERE c.idUser=:idUser";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
try {
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
throw(new SoapFault('MSG', 'Acces base impossible'));
|
||||
}
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$res=$stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$info->balance=$res;
|
||||
}else{
|
||||
$info->balance=null;
|
||||
}
|
||||
$sql = "SELECT * FROM sdv1.credit__paid c
|
||||
WHERE c.idUser=:idUser order by id desc limit 20";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
$info->paid=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$sql = "SELECT * FROM sdv1.credit__consumption c
|
||||
inner join credit__rate r on c.idLog=r.idLog
|
||||
WHERE c.idUser=:idUser and r.idClient=:idClient order by c.id desc limit 20";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->bindValue('idClient', $this->User->idClient);
|
||||
$stmt->execute();
|
||||
$info->used=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$crdt=new Metier_Credit_Information();
|
||||
$info->libelle=$crdt->libelles;
|
||||
//$this->wsLog(__FUNCTION__,$idUser,'0');
|
||||
return $info;
|
||||
/**
|
||||
* Retourne la totalite des infos de crédit à un utilisateur
|
||||
* @return infoCredit
|
||||
*/
|
||||
public function mensuelconsoCredit()
|
||||
{
|
||||
$info=new mensuelconsoCredit();
|
||||
$this->authenticate();
|
||||
$this->permission($this->libdroits,__FUNCTION__);
|
||||
$crdt=new Metier_Credit_Information();
|
||||
return $crdt->getHistoUser($this->User,0,10000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,7 +150,7 @@ class Credit extends Scores_Ws_Server
|
||||
* @param string idLog
|
||||
* @return UseCredit
|
||||
*/
|
||||
public function useCredit($idLog)
|
||||
public function useCredit($idLog,$siren='extranet')
|
||||
{
|
||||
$UseCreditResult=new UseCredit();
|
||||
$UseCreditResult->idLog=$idLog;
|
||||
@ -189,7 +161,7 @@ class Credit extends Scores_Ws_Server
|
||||
if(!$ok->result){
|
||||
$UseCreditResult->result=false;
|
||||
}else{
|
||||
$ok=$crdt->setUsed($idLog,$this->User,'extranet');
|
||||
$ok=$crdt->setUsed($idLog,$this->User,$siren);
|
||||
$UseCreditResult->result=true;
|
||||
}
|
||||
return $UseCreditResult;
|
||||
|
@ -27,6 +27,29 @@ class InfoCredit{
|
||||
public $libelle;
|
||||
}
|
||||
|
||||
class MensuelconsoCredit{
|
||||
/**
|
||||
* Etat actuel du compte
|
||||
* @var array
|
||||
*/
|
||||
public $balance;
|
||||
/**
|
||||
* 100 derniers Mouvements en entree du compte
|
||||
* @var array
|
||||
*/
|
||||
public $paid;
|
||||
/**
|
||||
* 100 derniers Mouvements en sortie du compte
|
||||
* @var array
|
||||
*/
|
||||
public $used;
|
||||
/**
|
||||
* Les libelles des codes fonction
|
||||
* @var array
|
||||
*/
|
||||
public $libelle;
|
||||
}
|
||||
|
||||
class PayCredit
|
||||
{
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ require_once __DIR__ . '/Types.php';
|
||||
|
||||
class Entreprise extends Scores_Ws_Server
|
||||
{
|
||||
private $freeService=false;
|
||||
/**
|
||||
* Retourne les informations identitaires de l'entreprise ou de l'établissement demandé
|
||||
* @param string $siret Siren de l'entreprise ou siret de l'établissement
|
||||
@ -2238,9 +2239,14 @@ class Entreprise extends Scores_Ws_Server
|
||||
$perm = false;
|
||||
//@todo : Gestion des droits
|
||||
switch($niveau){
|
||||
case 4:
|
||||
$perms = array('indiscore', 'indiscorep');
|
||||
$niveau=1;
|
||||
$idLog='getReportSynthese';
|
||||
break;
|
||||
case 3:
|
||||
$perms = array('indiscore3', 'indiscore3p');
|
||||
$idLog='getReportSynthese';
|
||||
$idLog='getRapport';
|
||||
break;
|
||||
case 2:
|
||||
$perms = array('indiscore2', 'indiscore2p', 'indiscore3', 'indiscore3p');
|
||||
@ -2263,7 +2269,11 @@ class Entreprise extends Scores_Ws_Server
|
||||
if ($perm === false) {
|
||||
$this->sendError('0902');
|
||||
}
|
||||
$this->checkCredit($idLog);
|
||||
if($this->freeService){
|
||||
$this->checkCredit('freeService');
|
||||
}else{
|
||||
$this->checkCredit($idLog);
|
||||
}
|
||||
$tabRet = array();
|
||||
$this->logger->info("IndiScore demandée pour $siren en niveau $niveau");
|
||||
if (strlen($siren) > 9 || (substr($siren,0,9)*1) < 100 ){
|
||||
@ -4880,7 +4890,8 @@ class Entreprise extends Scores_Ws_Server
|
||||
if ($perm === false) {
|
||||
$this->sendError('0902');
|
||||
}
|
||||
$this->checkCredit(__FUNCTION__);
|
||||
$this->checkCredit('getRapport');
|
||||
$this->freeService=true;
|
||||
$accesDist=true;
|
||||
$nivComment=2;
|
||||
if ($niveau==1){
|
||||
@ -4899,6 +4910,8 @@ class Entreprise extends Scores_Ws_Server
|
||||
$result->Ratios = $this->getRatios($siren, $page="rapport$niveau");
|
||||
$result->Annonces = $this->getAnnonces($siren, $filtre, $idAnn);
|
||||
}
|
||||
$this->decLog('getRapport',$siren);
|
||||
$this->freeService=false;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user