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
|
||||
* @param string $siren
|
||||
* SIREN
|
||||
* @param string $options
|
||||
* To define
|
||||
* SIREN
|
||||
* @param string $diffusion
|
||||
* Mode de diffusion (M|C)
|
||||
* @param string $reference
|
||||
* Reference du client
|
||||
* @return string
|
||||
*/
|
||||
public function getKbis($siren, $options = '')
|
||||
public function getKbis($siren, $diffusion, $reference = '')
|
||||
{
|
||||
$this->authenticate();
|
||||
$this->permission('KBIS');
|
||||
@ -23,70 +25,93 @@ class Pieces extends WsScore
|
||||
} elseif (strlen($siren)!=9) {
|
||||
$this->sendError('1020');
|
||||
}
|
||||
|
||||
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
||||
if ($_SERVER['SERVER_PORT']!='80'){
|
||||
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
||||
}
|
||||
|
||||
$c = Zend_Registry::get('config');
|
||||
$path = realpath($c->profil->path->secure).'/kbis/';
|
||||
|
||||
//Le fichier existe avec une date de validité inférieure à 1 jour
|
||||
$filepdf = $path.$siren.'.pdf';
|
||||
if ( file_exists($filepdf) && date('Ymd', filemtime($filepdf))==date('Ymd') ) {
|
||||
|
||||
$this->wsLog('kbis', $siren, basename($filepdf));
|
||||
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
||||
|
||||
} 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;
|
||||
|
||||
switch ( $diffusion ) {
|
||||
|
||||
case 'M':
|
||||
case 'C':
|
||||
$refCommande = uniqid();
|
||||
|
||||
$iInsee = new MInsee();
|
||||
$identite = $iInsee->getIdentiteLight($siren);
|
||||
|
||||
$commande = new Application_Model_Sdv1GreffeCommandesKb();
|
||||
$id = $commande->insert(array(
|
||||
'refCommande' => $refCommande,
|
||||
'login' => $this->tabInfoUser['login'],
|
||||
'email' => $this->tabInfoUser['email'],
|
||||
'refClient' => $reference,
|
||||
'mode' => $diffusion,
|
||||
'siren' => $siren,
|
||||
'raisonSociale' => $identite['Nom'],
|
||||
'dateInsert' => date('YmdHis'),
|
||||
));
|
||||
break;
|
||||
default:
|
||||
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
||||
if ($_SERVER['SERVER_PORT']!='80'){
|
||||
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$c = Zend_Registry::get('config');
|
||||
$path = realpath($c->profil->path->secure).'/kbis/';
|
||||
|
||||
//Le fichier existe avec une date de validité inférieure à 1 jour
|
||||
$filepdf = $path.$siren.'.pdf';
|
||||
if ( file_exists($filepdf) && date('Ymd', filemtime($filepdf))==date('Ymd') ) {
|
||||
|
||||
$this->wsLog('kbis', $siren, basename($filepdf));
|
||||
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
||||
|
||||
} 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