Issue #0001833:
This commit is contained in:
parent
790aa91b56
commit
debe30b5a7
6
application/models/Sdv1GreffeCommandesKb.php
Normal file
6
application/models/Sdv1GreffeCommandesKb.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
class Application_Model_Sdv1GreffeCommandesKb extends Zend_Db_Table_Abstract
|
||||||
|
{
|
||||||
|
protected $_name = 'greffe_commandes_kb';
|
||||||
|
protected $_schema = 'sdv1';
|
||||||
|
}
|
@ -7,12 +7,14 @@ class Pieces extends WsScore
|
|||||||
/**
|
/**
|
||||||
* Récupération d'un kbis
|
* Récupération d'un kbis
|
||||||
* @param string $siren
|
* @param string $siren
|
||||||
* SIREN
|
* SIREN
|
||||||
* @param string $options
|
* @param string $diffusion
|
||||||
* To define
|
* Mode de diffusion (M|C)
|
||||||
|
* @param string $reference
|
||||||
|
* Reference du client
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getKbis($siren, $options = '')
|
public function getKbis($siren, $diffusion, $reference = '')
|
||||||
{
|
{
|
||||||
$this->authenticate();
|
$this->authenticate();
|
||||||
$this->permission('KBIS');
|
$this->permission('KBIS');
|
||||||
@ -23,70 +25,93 @@ class Pieces extends WsScore
|
|||||||
} elseif (strlen($siren)!=9) {
|
} elseif (strlen($siren)!=9) {
|
||||||
$this->sendError('1020');
|
$this->sendError('1020');
|
||||||
}
|
}
|
||||||
|
|
||||||
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
switch ( $diffusion ) {
|
||||||
if ($_SERVER['SERVER_PORT']!='80'){
|
|
||||||
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
case 'M':
|
||||||
}
|
case 'C':
|
||||||
|
$refCommande = uniqid();
|
||||||
$c = Zend_Registry::get('config');
|
|
||||||
$path = realpath($c->profil->path->secure).'/kbis/';
|
$iInsee = new MInsee();
|
||||||
|
$identite = $iInsee->getIdentiteLight($siren);
|
||||||
//Le fichier existe avec une date de validité inférieure à 1 jour
|
|
||||||
$filepdf = $path.$siren.'.pdf';
|
$commande = new Application_Model_Sdv1GreffeCommandesKb();
|
||||||
if ( file_exists($filepdf) && date('Ymd', filemtime($filepdf))==date('Ymd') ) {
|
$id = $commande->insert(array(
|
||||||
|
'refCommande' => $refCommande,
|
||||||
$this->wsLog('kbis', $siren, basename($filepdf));
|
'login' => $this->tabInfoUser['login'],
|
||||||
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
'email' => $this->tabInfoUser['email'],
|
||||||
|
'refClient' => $reference,
|
||||||
} else {
|
'mode' => $diffusion,
|
||||||
|
'siren' => $siren,
|
||||||
$file = null;
|
'raisonSociale' => $identite['Nom'],
|
||||||
|
'dateInsert' => date('YmdHis'),
|
||||||
//On vérifie quand même si il n'existe pas une commande en html
|
));
|
||||||
$dir = $path.date('Ymd');
|
break;
|
||||||
if ( file_exists($dir) ) {
|
default:
|
||||||
foreach ( glob($dir.'/'.$siren.'-*.html') as $file ) {
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
||||||
break;
|
if ($_SERVER['SERVER_PORT']!='80'){
|
||||||
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$c = Zend_Registry::get('config');
|
||||||
if ( empty($file) ) {
|
$path = realpath($c->profil->path->secure).'/kbis/';
|
||||||
//Téléchargement du KBIS
|
|
||||||
$result = array();
|
//Le fichier existe avec une date de validité inférieure à 1 jour
|
||||||
exec('php '.$c->profil->path->batch.'/getKbis.php --siren '.$siren, $result);
|
$filepdf = $path.$siren.'.pdf';
|
||||||
$result = end($result);
|
if ( file_exists($filepdf) && date('Ymd', filemtime($filepdf))==date('Ymd') ) {
|
||||||
if (substr($result,-5)=='.html')
|
|
||||||
{
|
$this->wsLog('kbis', $siren, basename($filepdf));
|
||||||
$file = $dir.'/'.$result;
|
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
||||||
$this->wsLog('kbis', $siren, $result);
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$file = null;
|
||||||
|
|
||||||
|
//On vérifie quand même si il n'existe pas une commande en html
|
||||||
|
$dir = $path.date('Ymd');
|
||||||
|
if ( file_exists($dir) ) {
|
||||||
|
foreach ( glob($dir.'/'.$siren.'-*.html') as $file ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty($file) ) {
|
||||||
|
//Téléchargement du KBIS
|
||||||
|
$result = array();
|
||||||
|
exec('php '.$c->profil->path->batch.'/getKbis.php --siren '.$siren, $result);
|
||||||
|
$result = end($result);
|
||||||
|
if (substr($result,-5)=='.html')
|
||||||
|
{
|
||||||
|
$file = $dir.'/'.$result;
|
||||||
|
$this->wsLog('kbis', $siren, $result);
|
||||||
|
}
|
||||||
|
elseif ( $result!='ERREUR')
|
||||||
|
{
|
||||||
|
throw new SoapFault('MSG',$result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$text = 'La récupération du KBIS a échoué sur le siren : '.$siren;
|
||||||
|
sendMail(
|
||||||
|
'production@scores-decisions.com',
|
||||||
|
'supportdev@scores-decisions.com',
|
||||||
|
'[ERREUR KBIS]',
|
||||||
|
$text);
|
||||||
|
throw new SoapFault('0000',"Erreur récupération du kbis");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->wsLog('kbis', $siren, basename($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Génération du PDF
|
||||||
|
$pdf = new Scores_Wkhtml_Pdf();
|
||||||
|
$fileOut = $pdf->exec($file, $filepdf);
|
||||||
|
|
||||||
|
if ( !file_exists($filepdf) ) {
|
||||||
|
throw new SoapFault('0000',"Fichier PDF introuvable");
|
||||||
|
}
|
||||||
|
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
||||||
}
|
}
|
||||||
elseif ( $result!='ERREUR')
|
|
||||||
{
|
|
||||||
throw new SoapFault('MSG',$result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$text = 'La récupération du KBIS a échoué sur le siren : '.$siren;
|
|
||||||
sendMail(
|
|
||||||
'production@scores-decisions.com',
|
|
||||||
'supportdev@scores-decisions.com',
|
|
||||||
'[ERREUR KBIS]',
|
|
||||||
$text);
|
|
||||||
throw new SoapFault('0000',"Erreur récupération du kbis");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->wsLog('kbis', $siren, basename($file));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Génération du PDF
|
|
||||||
$pdf = new Scores_Wkhtml_Pdf();
|
|
||||||
$fileOut = $pdf->exec($file, $filepdf);
|
|
||||||
|
|
||||||
if ( !file_exists($filepdf) ) {
|
|
||||||
throw new SoapFault('0000',"Fichier PDF introuvable");
|
|
||||||
}
|
|
||||||
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user