add credit
This commit is contained in:
parent
1e2b321353
commit
58a0e240a3
130
src/Metier/Credit/Balance.php
Normal file
130
src/Metier/Credit/Balance.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
class Metier_Credit_Balance
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
public function getCreditClient($idClient=0)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__balance c where 1";
|
||||
if(intval($idClient)>0){
|
||||
$sql.=" and idClient=:idClient";
|
||||
}
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
if(intval($idClient)>0){
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
}
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$creditResult = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $creditResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idUser
|
||||
* @param int $val
|
||||
*/
|
||||
public function addCreditByIdUser($idUser, $val = 1)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__balance c
|
||||
WHERE c.idUser=:idUser";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
}catch(Exception $e){
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$creditResult = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
|
||||
$balance = $creditResult->balance;
|
||||
|
||||
$balance += $val;
|
||||
|
||||
$data=array(
|
||||
'balance' => $balance,
|
||||
'updated' => Date('Y-m-d H:i:s')
|
||||
);
|
||||
try{
|
||||
$this->conn->update('sdv1.credit__balance', $data,array('idUser' => $idUser));
|
||||
}
|
||||
catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->logCredit($val,$creditResult);
|
||||
}
|
||||
}
|
||||
private function logCredit($val, $creditResult){
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$user = $auth->getIdentity();
|
||||
if($val>0){
|
||||
$values=array(
|
||||
'idUser' => $creditResult->idUser,
|
||||
'idCmd' => $creditResult->idUser.'ww'.time(),
|
||||
'login' => $creditResult->login,
|
||||
'nbCredit' => $val,
|
||||
'amount' =>0,
|
||||
'amount_ht' => 0,
|
||||
'amount_tva' => 0,
|
||||
'currency' => '',
|
||||
'valid' => 1,
|
||||
'date_sent' => Date('Y-m-d H:i:s'),
|
||||
'date_received' => null,
|
||||
'paybox_answer' => null,
|
||||
'transaction' => json_encode(array('level' => 'Régularisation Backoffice','date' =>Date('Y-m-d H:i:s'), 'user' => $user->id)),
|
||||
'comment' => 'Regularisation gratuite'
|
||||
);
|
||||
try{
|
||||
$this->conn->insert('sdv1.credit__paid',$values);
|
||||
}catch(Exception $e){
|
||||
|
||||
}
|
||||
}
|
||||
if($val<0){
|
||||
$values=array(
|
||||
'idUser' => $creditResult->idUser,
|
||||
'idLog' => 'Regularisation par '. $this->user .' le '.Date('Y-m-d'),
|
||||
'login' => $creditResult->login,
|
||||
'consumption' => $val * (-1),
|
||||
'created' => Date('Y-m-d H:i:s'),
|
||||
);
|
||||
try{
|
||||
$this->conn->insert('sdv1.credit__consumption',$values);
|
||||
}catch(Exception $e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
src/Metier/Credit/BalanceTable.php
Normal file
6
src/Metier/Credit/BalanceTable.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class Metier_Credit_Balance_Table extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'credit__balance';
|
||||
protected $_schema = 'sdv1';
|
||||
}
|
98
src/Metier/Credit/Consumption.php
Normal file
98
src/Metier/Credit/Consumption.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
class Metier_Credit_Consumption
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Libelle des fonctions ws sous credit
|
||||
* @var array
|
||||
*/
|
||||
public $libelles=array(
|
||||
'getIdentite' => 'Fiche d\'identité',
|
||||
'getIdentiteProcol' => 'Fiche procédure collective',
|
||||
'getListeEtablissements' => 'Liste des établissements',
|
||||
'getLiens' => 'Liens inter-entreprises',
|
||||
'getGroupeInfos' => 'Informations Groupe',
|
||||
'getListeEvenements' => 'Modifications Insee',
|
||||
'getDirigeants' => 'Liste ou Historique des dirigeants',
|
||||
'getSynthese' => 'Synthèse financière',
|
||||
'getBilan' => 'Bilan Compte de résultat',
|
||||
'getRatios' => 'Ratios financiers',
|
||||
'getFlux' => 'Flux de trésorerie',
|
||||
'getListeBilans' => 'Liasse fiscale',
|
||||
'getInfosBourse' => 'Bourse et Cotations',
|
||||
'getBanques' => 'Relations bancaires',
|
||||
'getSubventionList' => 'Subventions',
|
||||
'getAnnoncesLegales' => 'Annonces légales',
|
||||
'getAnnoncesBalo' => 'Annonces BALO',
|
||||
'getAnnoncesBoamp' => 'Annonces BOAMP',
|
||||
'getListeCompetences' => 'Rubrique de Compétences territoriales',
|
||||
'getAnnoncesAsso' => 'Annonces JO Associations',
|
||||
'getListeConventions' => 'Conventions collectives',
|
||||
'getMarques' => 'Marques déposées',
|
||||
'getIndiScore' => 'Indiscore',
|
||||
'getReportSynthese' => 'Rapport de synthèse',
|
||||
'getRapport' => 'Rapport complet',
|
||||
'getValo' => 'Valorisation',
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idUser
|
||||
* @return array
|
||||
*/
|
||||
public function getConsumptionByIdUser($idUser)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__consumption c
|
||||
WHERE c.idUser=:idUser and consumption>0";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$consumption = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$sql = "SELECT u.idClient, u.login, s.Service,cl.nom as nomclient
|
||||
FROM sdv1.utilisateurs u
|
||||
inner join sdv1.utilisateurs_service s on u.login=s.login
|
||||
inner join sdv1.clients cl on u.idClient=cl.id
|
||||
WHERE u.id=:idUser";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
try {
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$identity = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return array('consumption' => $consumption, 'identity' => $identity);
|
||||
}
|
||||
}
|
6
src/Metier/Credit/ConsumptionTable.php
Normal file
6
src/Metier/Credit/ConsumptionTable.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class Metier_Credit_Consumption_Table extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'credit__consumption';
|
||||
protected $_schema = 'sdv1';
|
||||
}
|
130
src/Metier/Credit/Contact.php
Normal file
130
src/Metier/Credit/Contact.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
class Metier_Credit_Contact
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Categorie de message
|
||||
* @var array
|
||||
*/
|
||||
private $categories=array(
|
||||
'facturation',
|
||||
'commercial',
|
||||
'autre'
|
||||
);
|
||||
|
||||
/**
|
||||
* Etape de traitement
|
||||
* @var array
|
||||
*/
|
||||
private $stages=array(
|
||||
'1' => 'A traiter',
|
||||
'2' => 'En cours',
|
||||
'3' => 'Clos'
|
||||
);
|
||||
|
||||
/**
|
||||
* Libelle des champs de valeur
|
||||
* @var array
|
||||
*/
|
||||
private $libelles=array(
|
||||
'id' => 'Reference enregistrement',
|
||||
'idUSer' => 'Reference utilisateur',
|
||||
'begin' => 'Message du',
|
||||
'subject' => 'Categorie',
|
||||
'message' => 'Message envoyé',
|
||||
'stage' => 'Etape',
|
||||
'answer' => 'Suivi'
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Libelles correspondants aux id
|
||||
* @return array
|
||||
*/
|
||||
public function getLibelles()
|
||||
{
|
||||
return array('libelles' => $this->libelles, 'stages' => $this->stages,'subjects' => $this->subjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste des messages
|
||||
* @return array
|
||||
*/
|
||||
public function getListeContacts($where='',$page=0){
|
||||
$sql='select * from sdv1.credit__contact c inner join sdv1.utilisateurs u on c.idUser=u.id where '.$where.' limit 50 offset '.intval($page).';';
|
||||
try {
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$listecontacts = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}else{
|
||||
$listecontacts = array();
|
||||
}
|
||||
return $listecontacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistrement du suivi
|
||||
* @return array
|
||||
*/
|
||||
public function sendSuivi($id,$answer,$comment){
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$user = $auth->getIdentity();
|
||||
$answer=$answer.'[DE : '.$user->username.'][Date : '.Date('Y-m-d H:i:s').']'.$comment;
|
||||
$values=array(
|
||||
'answer' => $answer,
|
||||
'stage' => 2,
|
||||
);
|
||||
$ok=$this->conn->update('sdv1.credit__contact',$values, array('id' => $id));
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cloture de demande
|
||||
* @return array
|
||||
*/
|
||||
public function closeSuivi($id){
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$user = $auth->getIdentity();
|
||||
$sql='select * from sdv1.credit__contact where id=:id;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $id);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 1 ) {
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
}else{return false;}
|
||||
//$result=$this->conn->select()->from(array('c' => 'sdv1.credit__contact'))->where('id = ' . $id)->fetch();
|
||||
//var_dump($result);die;
|
||||
$answer=$result->answer.'[DE : '.$user->username.'][Date : '.Date('Y-m-d H:i:s').']Cloture de la demande.';
|
||||
$values=array(
|
||||
'answer' => $answer,
|
||||
'stage' => 3,
|
||||
);
|
||||
$ok=$this->conn->update('sdv1.credit__contact',$values, array('id' => $id));
|
||||
return $ok;
|
||||
}
|
||||
}
|
231
src/Metier/Credit/Information.php
Normal file
231
src/Metier/Credit/Information.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
|
||||
class Metier_Credit_Information extends Scores_Ws_Server
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Libelle des fonctions ws sous credit
|
||||
* @var array
|
||||
*/
|
||||
public $libelles=array(
|
||||
'getIdentite' => 'Fiche d\'identité',
|
||||
'getIdentiteProcol' => 'Fiche procédure collective',
|
||||
'getListeEtablissements' => 'Liste des établissements',
|
||||
'getLiens' => 'Liens inter-entreprises',
|
||||
'getGroupeInfos' => 'Informations Groupe',
|
||||
'getListeEvenements' => 'Modifications Insee',
|
||||
'getDirigeants' => 'Liste ou Historique des dirigeants',
|
||||
'getSynthese' => 'Synthèse financière',
|
||||
'getBilan' => 'Bilan Compte de résultat',
|
||||
'getRatios' => 'Ratios financiers',
|
||||
'getFlux' => 'Flux de trésorerie',
|
||||
'getListeBilans' => 'Liasse fiscale',
|
||||
'getInfosBourse' => 'Bourse et Cotations',
|
||||
'getBanques' => 'Relations bancaires',
|
||||
'getSubventionList' => 'Subventions',
|
||||
'getAnnoncesLegales' => 'Annonces légales',
|
||||
'getAnnoncesBalo' => 'Annonces BALO',
|
||||
'getAnnoncesBoamp' => 'Annonces BOAMP',
|
||||
'getListeCompetences' => 'Rubrique de Compétences territoriales',
|
||||
'getAnnoncesAsso' => 'Annonces JO Associations',
|
||||
'getListeConventions' => 'Conventions collectives',
|
||||
'getMarques' => 'Marques déposées',
|
||||
'getIndiScore' => 'Indiscore',
|
||||
'getReportSynthese' => 'Rapport de synthèse',
|
||||
'getRapport' => 'Rapport complet',
|
||||
'getValo' => 'Valorisation',
|
||||
);
|
||||
|
||||
/**
|
||||
* tranches autorisées pour les crédits
|
||||
* @var array
|
||||
*/
|
||||
private $tranches=array(
|
||||
'1' => array(
|
||||
'200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ),
|
||||
'500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ),
|
||||
'1000' => array('montant' => 10000,'montantht' => 8333, 'tva' => 1667, ),
|
||||
),
|
||||
'195' => array(
|
||||
'200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ),
|
||||
'500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ),
|
||||
'1000' => array('montant' => 10000,'montantht' => 8333, 'tva' => 1667, ),
|
||||
),
|
||||
);
|
||||
|
||||
public function __construct($db = null)
|
||||
{
|
||||
// Set Database
|
||||
if ($this->conn === null) {
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
} else {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recuperation des informations necessaires a la facturation
|
||||
* @param int $id
|
||||
*/
|
||||
public function getInfosFacture($id,$user){
|
||||
if(intval($id)>0){
|
||||
$sql='select c.*, u.idClient, u.siret, u.email,u.nom,u.prenom
|
||||
from sdv1.credit__paid c inner join sdv1.utilisateurs u on c.idUser=u.id
|
||||
where c.id= :id;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $id);
|
||||
}else{
|
||||
$sql='select u.idClient, u.siret, u.email,u.nom,u.prenom
|
||||
from sdv1.utilisateurs u
|
||||
where u.id= :id;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $user->id);
|
||||
}
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$infos['commande']=$stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}else{
|
||||
$infos['commande']=null;
|
||||
return $infos;
|
||||
}
|
||||
$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=:nic');
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->bindValue('nic', $nic);
|
||||
$stmt->execute();
|
||||
$infos['societe']=$stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$iInsee = new Metier_Insee_MInsee();
|
||||
$infos['entrep']= $iInsee->getIdentiteEntreprise($siren, $nic, 0, false);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
src/Metier/Credit/Paid.php
Normal file
95
src/Metier/Credit/Paid.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
class Metier_Credit_Paid
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idUser
|
||||
* @return array
|
||||
*/
|
||||
public function getPaidByIdUser($idUser)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__paid c
|
||||
WHERE c.idUser=:idUser";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$paidResult = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $paidResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idPaid
|
||||
* @return array
|
||||
*/
|
||||
public function getPaidFromFacture($idPaid)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT
|
||||
u.nom as UserName,
|
||||
u.prenom as UserFirstname,
|
||||
ct.nom as ClientName,
|
||||
ct.fac_dest as ClientFacDest,
|
||||
ct.fac_adr1 as ClientFacAdr1,
|
||||
ct.fac_adr2 as ClientFacAdr2,
|
||||
ct.fac_adr3 as ClientFacAdr3,
|
||||
cp.idCmd as idCmd,
|
||||
cp.amount as amount,
|
||||
cp.amount_ht as amount_ht
|
||||
FROM sdv1.credit__paid cp
|
||||
LEFT JOIN sdv1.utilisateurs u ON u.id = cp.idUser
|
||||
LEFT JOIN sdv1.clients ct ON ct.id = u.idClient
|
||||
WHERE cp.id=:idPaid";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idPaid', $idPaid);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$paidResult = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $paidResult;
|
||||
}
|
||||
public function setNewComment($idPaid,$comment)
|
||||
{
|
||||
try {
|
||||
$stmt = $this->conn->update('sdv1.credit__paid',array('comment' => $comment),array('id' => $idPaid));
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
src/Metier/Credit/PaidTable.php
Normal file
6
src/Metier/Credit/PaidTable.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class Metier_Credit_Paid_Table extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'credit__paid';
|
||||
protected $_schema = 'sdv1';
|
||||
}
|
168
src/Metier/Credit/Rating.php
Normal file
168
src/Metier/Credit/Rating.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
class Metier_Credit_Rating
|
||||
{
|
||||
protected $ratetypes=array(
|
||||
1 => 'Paybox',
|
||||
2 => 'Forfait limité'
|
||||
);
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Libelle des fonctions ws sous credit
|
||||
* @var array
|
||||
*/
|
||||
protected $libelles=array(
|
||||
'getIdentite' => 'Fiche d\'identité',
|
||||
'getIdentiteProcol' => 'Fiche procédure collective',
|
||||
'getListeEtablissements' => 'Liste des établissements',
|
||||
'getLiens' => 'Liens inter-entreprises',
|
||||
'getGroupeInfos' => 'Informations Groupe',
|
||||
'getListeEvenements' => 'Modifications Insee',
|
||||
'getDirigeants' => 'Liste ou Historique des dirigeants',
|
||||
'getSynthese' => 'Synthèse financière',
|
||||
'getBilan' => 'Bilan Compte de résultat',
|
||||
'getRatios' => 'Ratios financiers',
|
||||
'getFlux' => 'Flux de trésorerie',
|
||||
'getListeBilans' => 'Liasse fiscale',
|
||||
'getInfosBourse' => 'Bourse et Cotations',
|
||||
'getBanques' => 'Relations bancaires',
|
||||
'getSubventionList' => 'Subventions',
|
||||
'getAnnoncesLegales' => 'Annonces légales',
|
||||
'getAnnoncesBalo' => 'Annonces BALO',
|
||||
'getAnnoncesBoamp' => 'Annonces BOAMP',
|
||||
'getGreffeAffaireList' => 'Contentieux judiciaires',
|
||||
'getInfosReg' => 'Information réglementée',
|
||||
'getListeCompetences' => 'Rubrique de Compétences territoriales',
|
||||
'getAnnoncesAsso' => 'Annonces JO Associations',
|
||||
'getListeConventions' => 'Conventions collectives',
|
||||
'getMarques' => 'Marques déposées',
|
||||
'getIndiScore' => 'Indiscore',
|
||||
'getReportSynthese' => 'Rapport de synthèse',
|
||||
'getRapport' => 'Rapport complet',
|
||||
'getValo' => 'Valorisation',
|
||||
);
|
||||
private $defaultVals=array(
|
||||
'idClient' => 0,
|
||||
'serviceCode' => '',
|
||||
'idLog' => '',
|
||||
'cost' => 0,
|
||||
'rateType' => 0
|
||||
);
|
||||
public function __construct()
|
||||
{
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Libelles correspondants aux idLogs
|
||||
* @return array
|
||||
*/
|
||||
public function getLibelles()
|
||||
{
|
||||
return $this->libelles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Libelles correspondants aux idLogs
|
||||
* @return array
|
||||
*/
|
||||
public function getRateTypes()
|
||||
{
|
||||
return $this->ratetypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idUser
|
||||
* @return array
|
||||
*/
|
||||
public function getRatingByIdClient($idClient,$serviceCode=null,$rateType=null,$getDefaultvars=false)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__rate r
|
||||
WHERE r.idClient=:idClient
|
||||
order by serviceCode, idLog;";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$rating = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}else{
|
||||
if($getDefaultvars){
|
||||
try {
|
||||
$sql = "SELECT DISTINCT idLog FROM sdv1.credit__rate r
|
||||
WHERE r.rateType=:rateType
|
||||
order by idLog;";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('rateType', $rateType);
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$rating = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
foreach($rating as $o){
|
||||
$data=array(
|
||||
'idClient' => $idClient,
|
||||
'serviceCode' => $serviceCode,
|
||||
'idLog' => $o->idLog,
|
||||
'cost' => 0,
|
||||
'rateType' => $rateType
|
||||
);
|
||||
$this->conn->insert('sdv1.credit__rate',$data);
|
||||
}
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__rate r
|
||||
WHERE r.idClient=:idClient
|
||||
order by serviceCode, idLog;";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$rating = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}else{
|
||||
$rating=null;
|
||||
}
|
||||
}
|
||||
|
||||
return $rating;
|
||||
}
|
||||
public function updateCost($id,$cost){
|
||||
$sql = "SELECT * FROM sdv1.credit__rate r
|
||||
WHERE r.id=:id;";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $id);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() ==1 ) {
|
||||
$rating = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$idClient=$rating->idClient;
|
||||
$this->conn->update('sdv1.credit__rate',array('cost' => intval($cost)),array('id' =>$id));
|
||||
}else{
|
||||
$idClient=null;
|
||||
}
|
||||
return $idClient;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user