Remove Application_Model

This commit is contained in:
Michael RICOIS 2017-02-07 13:19:00 +01:00
parent 180d3c517c
commit 0324f3d011
2 changed files with 195 additions and 177 deletions

View File

@ -100,15 +100,22 @@ class Entreprise extends Scores_Ws_Server
// --- Indicateur Adresse RNVP
try {
$rnvpM = new Application_Model_VillesRnvpSources();
$sql = $rnvpM->select(true)->columns(array('dateRetourRnvp','codeRetour'))
->where('source=?', $entrep['Source'])->where('source_id=?', $entrep['SourceId']);
$rnvpResult = $rnvpM->fetchRow($sql);
if ($rnvpResult !== null) {
$identite->AdresseRnvpDate = $rnvpResult->dateRetourRnvp;
$identite->AdresseRnvpCode = $rnvpResult->codeRetour;
$sql = "SELECT dateRetourRnvp, codeRetour FROM villes.rnvp_sources
WHERE source=:source AND source_id=:id";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('source', $entrep['Source']);
$stmt->bindValue('id', $entrep['SourceId']);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$rnvpResult = $stmt->fetch(\PDO::FETCH_OBJ);
$identite->AdresseRnvpDate = $rnvpResult->dateRetourRnvp;
$identite->AdresseRnvpCode = $rnvpResult->codeRetour;
}
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
} catch (Zend_Db_Exception $e) {}
}
$identite->Civilite = $entrep['Civilite'];
$identite->NbEtab = $entrep['NbEtab'];
@ -296,7 +303,7 @@ class Entreprise extends Scores_Ws_Server
$identite->GroupeName = $grpHeadFiche->RS;
// --- Recherche code Isin
$nbIdNum = 3;
for ($i=0;$i<$nbIdNum;$i++) {
for ($i = 0; $i < $nbIdNum; $i++) {
if( !empty($grpHeadFiche->{'idLoc'.$i.'Num'}) && $grpHeadFiche->{'idLoc'.$i.'Type'} == 63 ) {
$identite->GroupeIsin = $grpHeadFiche->{'idLoc'.$i.'Num'};
break;
@ -304,22 +311,25 @@ class Entreprise extends Scores_Ws_Server
}
$identite->GroupeCountryCode = $grpHeadFiche->adresse_pays;
if (!empty($grpHeadFiche->adresse_pays)) {
try {
$countryM = new Application_Model_JoTabPays();
$sql = $countryM->select()->from($countryM, array('codPays3', 'libPays'));
$result = $countryM->fetchAll($sql);
} catch (Zend_Db_Adapter_Exception $e) {}
$tabPays = array();
if ( $result->count()>0 ) {
foreach ( $result as $item ) {
$tabPays[$item->codPays3] = $item->libPays;
try {
$sql = "SELECT codPays3, libPays FROM jo.tabPays";
$stmt = $this->conn->executeQuery($sql);
if ($stmt->rowCount() > 0) {
while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$tabPays[$item->codPays3] = $item->libPays;
}
}
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
$libPays = '';
if ($grpHeadFiche->adresse_pays!='') {
$libPays = array_key_exists($grpHeadFiche->adresse_pays, $tabPays) ?
$tabPays[$grpHeadFiche->adresse_pays] : $grpHeadFiche->adresse_pays;
$tabPays[$grpHeadFiche->adresse_pays] : $grpHeadFiche->adresse_pays;
} else {
$libPays = $tabPays['FRA'];
}
@ -399,17 +409,21 @@ class Entreprise extends Scores_Ws_Server
//Date du dernier bilan - MOIS/JOUR au pire chercher dans l'annonce
try {
$bilanM = new Application_Model_JoBilans();
$sql = $bilanM->select(true)
->columns(array('dateExercice'))
->where('siren=?', $siren)
->order('dateExercice DESC')->limit(1);
$result = $bilanM->fetchRow($sql);
if ($result !== null) {
$output->CompteArretMois = substr($result->dateExercice,4,2);
$output->CompteArretJour = substr($result->dateExercice,6,2);
}
} catch(Zend_Db_Exception $e) {}
$sql = "SELECT dateExercice FROM jo.bilans
WHERE siren=:siren ORDER BY dateExercice DESC LIMIT 0,1";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$output->CompteArretMois = substr($result->dateExercice,4,2);
$output->CompteArretJour = substr($result->dateExercice,6,2);
}
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
//=> Avec l'adresse du premier siège
$output->ConstitutionTribunalCode = '';
@ -418,8 +432,7 @@ class Entreprise extends Scores_Ws_Server
$iInsee = new Metier_Insee_MInsee($iDb);
$dirs = $iInsee->getDirigeants($siren, false);
$liste = array();
foreach ($dirs as $nb => $dir)
{
foreach ($dirs as $nb => $dir) {
$dirigeant = new AvisRncsAdmin();
$dirigeant->Code = $dir['Fonction'];
@ -545,17 +558,19 @@ class Entreprise extends Scores_Ws_Server
throw new SoapFault('ERR', 'Identifiant incorrect.');
}
try {
$etabM = new Application_Model_JoEtablissements();
$sql = $etabM->select(true)->columns(array('LPAD(source,3,0) AS source', 'LPAD(source_id,20,0) AS sourceId'))
->where('siren=?', substr($companyId,0,9))
->where('nic=?', substr($companyId,9,5));
$etabResult = $etabM->fetchRow($sql);
if ($etabResult === null) {
$sql = "SELECT LPAD(source,3,0) AS source, LPAD(source_id,20,0) AS sourceId
FROM jo.etablissements WHERE siren=:siren AND nic=:nic";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', substr($companyId,0,9));
$stmt->bindValue('nic', substr($companyId,9,5));
$stmt->execute();
if ($stmt->rowCount() == 0) {
throw new SoapFault('MSG', 'Etablissement inconnu.');
}
$source = $etabResult->source;
$sourceId = $etabResult->source_id;
} catch (Zend_Db_Exception $e) {
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {

View File

@ -2273,15 +2273,14 @@ class Interne extends Scores_Ws_Server
if (empty($nbRep)) $nbRep = 50;
if ($nbRep>200) $nbRep = 200;
$bilansM = new Application_Model_FedasoBilans();
$sql = $bilansM->select()->order('dateEntree DESC');
$qb = $this->conn->createQueryBuilder();
$qb->select('*')->from('sdv1.fedaso_bilans')->orderBy('dateEntree', 'DESC');
if (is_array($filtre) && count($filtre)>0) {
foreach($filtre as $item) {
switch($item->key) {
case 'siren':
$sql->where('siren=?', $item->value);
$qb->where('siren=:siren')->setParameter('siren', $item->value);
break;
case 'etat':
@ -2302,20 +2301,25 @@ class Interne extends Scores_Ws_Server
}
}
//Select user id
$sql->where('idUtilisateur=?', $idUtilisateur);
// Select user id
$qb->where('idUtilisateur=:id')->setParameter('id', $idUtilisateur);
//Paginate
$sql->limit($nbRep, $position);
//Get results
$results = $bilansM->fetchAll($sql)->toArray();
// Paginate
$qb->setMaxResults($nbRep)->setFirstResult($position);
try {
$stmt = $qb->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
$iInsee = new Metier_Insee_MInsee();
$output = array();
if (count($results)>0) {
foreach ($results as $result) {
if ($stmt->rowCount() > 0) {
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$entrep = $iInsee->getIdentiteLight($result['siren']);
$saisie = new BilanSaisieInfos();
@ -2359,17 +2363,17 @@ class Interne extends Scores_Ws_Server
{
$this->authenticate();
if ( strlen($siret)!=9 && strlen($siret)!=14 ) {
if ( strlen($siret) != 9 && strlen($siret) != 14 ) {
$this->sendError('1010');
}
$siren = substr($siret,0,9);
if (intval($siren)==0 ) {
if (intval($siren) == 0) {
$this->sendError('1010');
}
$nic = substr($siret,9,5);
if (intval($nic)==0) {
if (intval($nic) == 0) {
$nic = '00000';
}
@ -2378,65 +2382,70 @@ class Interne extends Scores_Ws_Server
if ($filtre !== null && !in_array($filtre, $typeToSelect)) {
throw new SoapFault('ERR', "Unknown filtre");
}
$telephonieM = new Application_Model_JoTelephonie();
$sql = $telephonieM->select()
->from($telephonieM, array(
'id',
'LPAD(siren,9,0) AS siren',
'LPAD(nic,5,0) AS nic',
'typeTel',
'infoTel',
'LPAD(telephone, 10, 0) AS telephone',
'partenaire',
"dateProvPartenaire",
'IF(dateSuppr!=0,1,0) AS deleted',
))
->where('actif=1')
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
->where('siren=?',$siren);
// Comptage
$qb = $this->conn->createQueryBuilder();
$qb->select(array('COUNT(*) AS nb'))
->from('jo.telephonie')
->where('actif=1')
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
->where('siren=:siren')->setParameter('siren', $siren);
if ( intval($nic) > 0 ) {
$sql->where('nic=?',$nic);
$qb->where('nic=:nic')->setParameter('nic', $nic);
}
$stmt = $qb->execute();
$nbContacts = 0;
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$nbContacts = $result->nb;
}
if ( $filtre != null ) {
$sql->where('typeTel=?', $filtre);
}
$sql->order('typeTel ASC');
$sql->order('dateInsert DESC')->limit($nbRep, $position);
try {
$contacts = $telephonieM->fetchAll($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
//Comptage
$sql = $telephonieM->select()
->from($telephonieM, 'COUNT(*) as nb')
->where('actif=1')
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
->where('siren=?',$siren);
// List
$qb = $this->conn->createQueryBuilder();
$qb->select(array(
'id',
'LPAD(siren,9,0) AS siren',
'LPAD(nic,5,0) AS nic',
'typeTel',
'infoTel',
'LPAD(telephone, 10, 0) AS telephone',
'partenaire',
"dateProvPartenaire",
'IF(dateSuppr!=0,1,0) AS deleted'))
->from('jo.telephonie')
->where('actif=1')
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
->where('siren=:siren')->setParameter('siren', $siren);
if ( intval($nic) > 0 ) {
$sql->where('nic=?',$nic);
}
$result = $telephonieM->fetchRow($sql);
$nbContacts = 0;
if ( $result !== null ) {
$nbContacts = $result->nb;
$qb->where('nic=:nic')->setParameter('nic', $nic);
}
if ($filtre != null) {
$qb->where('typeTel=:filtre')->setParameter('filtre', $filtre);
}
$qb->orderBy('typeTel', 'ASC')
->orderBy('dateInsert', 'DESC')
->setFirstResult($position)->setMaxResults($nbRep);
try {
$listStmt = $qb->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
$list = array();
if ( $contacts->count() > 0) {
foreach ( $contacts as $item ) {
if ($listStmt->rowCount() > 0) {
while ($item = $listStmt->fetch(\PDO::FETCH_OBJ)) {
$contact = new ContactEt();
$contact->id = $item->id;
$contact->siren = $item->siren;
@ -2456,7 +2465,7 @@ class Interne extends Scores_Ws_Server
$contact->date = $date->format('Y-m-d');
$contact->deleted = false;
if ($item->deleted==1) {
if ($item->deleted == 1) {
$contact->deleted = true;
}
@ -2464,7 +2473,7 @@ class Interne extends Scores_Ws_Server
}
}
//Return
// Return
$output = new ContactEtReturn();
$output->nbReponses = $nbContacts;
$output->result = $list;
@ -2489,13 +2498,15 @@ class Interne extends Scores_Ws_Server
//Retrieve data
try {
$idlocalM = new Application_Model_Sdv1TabIdLocal();
$sql = $idlocalM->select()
->where('codPays=?', $codeCountry)
->orWhere('codPays IS NULL')
->where('dateSuppr=?', '0000-00-00 00:00:00');
$row = $idlocalM->fetchAll($sql);
} catch (Zend_Db_Exception $e) {
$sql = "SELECT id, idLocal, idLocalLong, idPrincipal, infoIden FROM sdv1.tabIdLocal
WHERE (codePays=:pays OR codePays IS NULL) AND dateSuppr='0000-00-00 00:00:00'";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('pays', $codeCountry);
$stmt->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient!=1) {
throw new SoapFault('ERR', "Application error");
} else {
@ -2504,8 +2515,8 @@ class Interne extends Scores_Ws_Server
}
$output = array();
if ($row->count()>0) {
foreach ( $row as $item ) {
if ($stmt->rowCount() > 0) {
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$struct = new CountryId();
$struct->internalId = $item->id;
$struct->name = $item->idLocal;
@ -2539,77 +2550,69 @@ class Interne extends Scores_Ws_Server
{
$this->authenticate();
if ( strlen($siret)!=9 && strlen($siret)!=14 ) {
if (strlen($siret) != 9 && strlen($siret) != 14) {
$this->sendError('1010');
}
$siren = substr($siret,0,9);
if ( intval($siren)==0 ) {
if (intval($siren) == 0) {
$this->sendError('1010');
}
if( strtolower($type)=='indiscore' ) {
$type = ( $this->User->typeScore==20 ) ? 'indiScore20' : 'indiScore';
if(strtolower($type) == 'indiscore') {
$type = ($this->User->typeScore == 20) ? 'indiScore20' : 'indiScore';
}
$scoresDb = new Application_Model_JoScoresSurveillance();
$motifLib = array(
'ajout' => "Initialisation",
'ancien' => "Score trop ancien",
'bilans1' => "Publication bilan",
'bilans2' => "Publication bilan",
'bilansasso'=> "Publication bilan Association",
'bodacc' => "Publication Bodacc",
'collecte' => "Publication JAL ou Greffe",
'dirigeants'=> "Modification de l'administration",
'impayes' => "Informations de paiements",
'insee' => "Modification identitaires INSEE",
'jour' => "Modifications identitaires",
'liens' => "Mise à jour de la structure du groupe",
'modifenc' => "Autre modification identitaire",
'privileges'=> "Mise à jour des privilèges",
'regulier' => "Informations de paiements",
'rncs' => "Modifications identitaires RNCS",
'default' => "Modification identitaire",
);
$sql1 = $scoresDb->select()
->from(array('j'=>'scores_surveillance'), array("j.$type", 'j.encours', 'j.indiScoreDate', 'j.sourceModif'), 'jo')
->where('siren=?',$siren)
->where('indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR)')
->group('indiScoreDate');
$sql2 = $scoresDb->select()
->from(array('h'=>'scores_surveillance'), array("h.$type", 'h.encours', 'h.indiScoreDate', 'h.sourceModif'), 'historiques')
->where('siren=?',$siren)
->where('indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR)')
->group('indiScoreDate');
$query = $scoresDb->select()
->union(array($sql1, $sql2))
->group('indiScoreDate')
->order('indiScoreDate DESC');
try {
$rows = $scoresDb->fetchAll($query);
} catch(Exception $e) {
if ($this->User->idClient==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
$motifLib = array(
'ajout' => "Initialisation",
'ancien' => "Score trop ancien",
'bilans1' => "Publication bilan",
'bilans2' => "Publication bilan",
'bilansasso'=> "Publication bilan Association",
'bodacc' => "Publication Bodacc",
'collecte' => "Publication JAL ou Greffe",
'dirigeants'=> "Modification de l'administration",
'impayes' => "Informations de paiements",
'insee' => "Modification identitaires INSEE",
'jour' => "Modifications identitaires",
'liens' => "Mise à jour de la structure du groupe",
'modifenc' => "Autre modification identitaire",
'privileges'=> "Mise à jour des privilèges",
'regulier' => "Informations de paiements",
'rncs' => "Modifications identitaires RNCS",
'default' => "Modification identitaire",
);
try {
$sql = "(SELECT j.$type, j.encours, j.indiScoreDate, j.sourceModif FROM jo.scores_surveillance j
WHERE siren=:siren AND indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR) GROUP BY indiScoreDate)
UNION (SELECT h.$type, h.encours, h.indiScoreDate, h.sourceModif FROM historiques.scores_surveillance h
WHERE siren=:siren AND indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR) GROUP BY indiScoreDate)
ORDER BY indiScoreDate DESC GROUP BY indiScoreDate ";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
$list = array();
foreach($rows as $row) {
$item = new ScoresHisto();
$item->date = $row->indiScoreDate;
$item->value = $row->{$type};
$item->label = $motifLib[$row->sourceModif];
$item->encours = round($row->encours/1000,1);
$list[] = $item;
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
$item = new ScoresHisto();
$item->date = $row->indiScoreDate;
$item->value = $row->{$type};
$item->label = $motifLib[$row->sourceModif];
$item->encours = round($row->encours/1000,1);
$list[] = $item;
}
}
$output = new ScoresHistoReturn();