2011-11-28 15:08:17 +00:00
|
|
|
<?php
|
2011-12-05 08:14:54 +00:00
|
|
|
require_once 'WsScore/WsScore.php';
|
|
|
|
require_once realpath(dirname(__FILE__)).'/Types.php';
|
|
|
|
|
|
|
|
class Pieces extends WsScore
|
|
|
|
{
|
2012-03-08 14:19:02 +00:00
|
|
|
/**
|
|
|
|
* Récupération d'un kbis
|
|
|
|
* @param string $siren
|
|
|
|
* @param string $options
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-07-04 16:01:11 +00:00
|
|
|
public function getKbis($siren, $options = '')
|
2012-03-08 14:19:02 +00:00
|
|
|
{
|
|
|
|
$this->authenticate();
|
|
|
|
$this->permission('KBIS');
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
//Vérification du siren
|
|
|
|
if (intval($siren)==0) {
|
|
|
|
$this->sendError('1010');
|
|
|
|
} elseif (strlen($siren)!=9) {
|
|
|
|
$this->sendError('1020');
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
|
|
if ($_SERVER['SERVER_PORT']!='80'){
|
|
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
$c = Zend_Registry::get('config');
|
|
|
|
$path = realpath($c->profil->path->secure).'/kbis/';
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
//Le fichier existe avec une date de validité inférieure à 1 jour
|
2012-11-30 13:51:48 +00:00
|
|
|
$filepdf = $path.$siren.'.pdf';
|
2012-07-04 16:01:11 +00:00
|
|
|
if ( file_exists($filepdf) && date('Ymd', filemtime($filepdf))==date('Ymd') ) {
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-13 07:58:47 +00:00
|
|
|
$this->wsLog('kbis', $siren, basename($filepdf));
|
2012-12-12 15:57:47 +00:00
|
|
|
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-07-04 16:01:11 +00:00
|
|
|
} else {
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
$file = null;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
//On vérifie quand même si il n'existe pas une commande en html
|
2012-11-30 13:51:48 +00:00
|
|
|
$dir = $path.date('Ymd');
|
|
|
|
if ( file_exists($dir) ) {
|
2012-07-04 16:01:11 +00:00
|
|
|
foreach ( glob($dir.'/'.$siren.'-*.html') as $file ) {
|
2012-03-08 14:19:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
if ( empty($file) ) {
|
2012-07-04 16:01:11 +00:00
|
|
|
//Téléchargement du KBIS
|
2012-08-07 14:29:07 +00:00
|
|
|
$result = array();
|
2012-12-04 14:50:44 +00:00
|
|
|
exec('php '.$c->profil->path->batch.'/getKbis.php --siren '.$siren, $result);
|
2012-08-07 14:29:07 +00:00
|
|
|
$result = end($result);
|
2012-07-04 16:01:11 +00:00
|
|
|
if (substr($result,-5)=='.html')
|
|
|
|
{
|
2012-12-21 16:11:10 +00:00
|
|
|
$file = $dir.'/'.$result;
|
2012-07-04 16:01:11 +00:00
|
|
|
$this->wsLog('kbis', $siren, $result);
|
|
|
|
}
|
|
|
|
elseif ( $result!='ERREUR')
|
|
|
|
{
|
|
|
|
throw new SoapFault('MSG',$result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-29 14:46:41 +00:00
|
|
|
$text = 'La récupération du KBIS a échoué sur le siren : '.$siren;
|
|
|
|
sendMail(
|
2012-07-04 16:01:11 +00:00
|
|
|
'production@scores-decisions.com',
|
|
|
|
'supportdev@scores-decisions.com',
|
|
|
|
'[ERREUR KBIS]',
|
|
|
|
$text);
|
2012-03-08 14:19:02 +00:00
|
|
|
throw new SoapFault('0000',"Erreur récupération du kbis");
|
2012-07-04 16:01:11 +00:00
|
|
|
}
|
2012-03-13 07:58:47 +00:00
|
|
|
} else {
|
|
|
|
$this->wsLog('kbis', $siren, basename($file));
|
2012-07-04 16:01:11 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
//Génération du PDF
|
|
|
|
require_once 'wkhtmltopdf/wkhtmltopdf.php';
|
|
|
|
$pdf = new wkhtmltopdf();
|
2012-07-04 16:01:11 +00:00
|
|
|
$fileOut = $pdf->exec($file, $filepdf);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-03-08 14:19:02 +00:00
|
|
|
if ( !file_exists($filepdf) ) {
|
2012-07-04 16:01:11 +00:00
|
|
|
throw new SoapFault('0000',"Fichier PDF introuvable");
|
2012-03-08 14:19:02 +00:00
|
|
|
}
|
2012-12-12 15:57:47 +00:00
|
|
|
return $hostname.DOC_WEB_URL.'kbis/'.basename($filepdf);
|
2012-07-04 16:01:11 +00:00
|
|
|
}
|
2012-03-08 14:19:02 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-07 13:49:22 +00:00
|
|
|
/**
|
|
|
|
* Liste des bilans disponible au format image
|
|
|
|
* @param string $identifiant
|
|
|
|
* @param int $position
|
|
|
|
* @param int $nbRep
|
2013-02-18 15:14:36 +00:00
|
|
|
* @return Bilans
|
2012-08-07 13:49:22 +00:00
|
|
|
* @throws SoapFault
|
|
|
|
*/
|
2013-02-18 15:14:36 +00:00
|
|
|
public function getBilans($identifiant, $position = 0, $nbRep = 200)
|
2012-08-07 13:49:22 +00:00
|
|
|
{
|
|
|
|
$this->authenticate();
|
|
|
|
|
|
|
|
if ( empty($position) ) {
|
|
|
|
$position = 0;
|
|
|
|
}
|
|
|
|
if ($nbRep > 200) {
|
|
|
|
$nbRep = 200;
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
if ( strlen($identifiant)!=9 ) {
|
2012-08-14 13:46:24 +00:00
|
|
|
$this->sendError('1010');
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-07 13:49:22 +00:00
|
|
|
/*
|
|
|
|
* Entreprise avec des bilans
|
|
|
|
* Base RNCS
|
|
|
|
* Si association alors lire dans la base de données pour établir la liste
|
2012-08-14 13:46:24 +00:00
|
|
|
* //@todo : Enregistrer dans la base jo.greffes_bilans
|
2012-08-07 13:49:22 +00:00
|
|
|
*/
|
2012-08-14 13:46:24 +00:00
|
|
|
$iInsee = new MInsee();
|
2013-02-18 15:14:36 +00:00
|
|
|
$identite = $iInsee->getIdentiteLight($identifiant);
|
2012-08-14 13:46:24 +00:00
|
|
|
if (empty($identite['id'])){
|
|
|
|
$this->sendError('1020');
|
2012-08-07 13:49:22 +00:00
|
|
|
}
|
2012-08-14 13:46:24 +00:00
|
|
|
$fj = $identite['FJ'];
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
$assoFormeJuridique = array(
|
|
|
|
//Associations
|
|
|
|
'9210','9220','9221','9222','9223','9224','9230','9240','9260',
|
|
|
|
//Syndicats
|
|
|
|
'7345','7353','7354','7355','8410','8420','9110',
|
|
|
|
//Fondation
|
|
|
|
'9300',
|
|
|
|
);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
$list = array();
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
//Liste des bilans association
|
|
|
|
if ( in_array($fj, $assoFormeJuridique) ) {
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-21 17:03:56 +00:00
|
|
|
$bilansM = new Application_Model_JoAssoBilans();
|
2012-08-14 13:46:24 +00:00
|
|
|
//Comptage
|
|
|
|
$sql = $bilansM->select()
|
|
|
|
->from($bilansM, 'COUNT(*) as nb')
|
2013-02-18 15:14:36 +00:00
|
|
|
->where('siren=?', $identifiant);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
$nbBilans = $bilansM->fetchRow($sql)->nb;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
if ($nbBilans>0)
|
|
|
|
{
|
|
|
|
//Liste
|
|
|
|
$sql = $bilansM->select()
|
2013-02-21 17:03:56 +00:00
|
|
|
->from($bilansM, array('dateCloture', 'Assoc_Date_Declaration', 'pdfLink',
|
|
|
|
'typeCompte', 'pdfSize', 'pdfPage'))
|
2013-02-18 15:14:36 +00:00
|
|
|
->where('siren = ?', $identifiant)
|
2012-08-14 13:46:24 +00:00
|
|
|
->order('dateCloture DESC')
|
2012-11-30 13:51:48 +00:00
|
|
|
->limit($nbRep, $position);
|
2012-08-14 13:46:24 +00:00
|
|
|
$bilans = $bilansM->fetchAll($sql);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
if( $bilans->count() > 0) {
|
|
|
|
foreach ($bilans as $item) {
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
$filename = basename($item->pdfLink);
|
|
|
|
$file = SECURE_STORAGE . 'associations/bilans/' . $filename;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
$bilansList = new Bilan();
|
2012-11-30 13:51:48 +00:00
|
|
|
$bilansList->DateCloture = substr($item->dateCloture,0,4).substr($item->dateCloture,5,2).substr($item->dateCloture,8,2);
|
|
|
|
$bilansList->DateDepot = substr($item->Assoc_Date_Declaration,0,4).substr($item->Assoc_Date_Declaration,5,2).substr($item->Assoc_Date_Declaration,8,2);
|
|
|
|
$bilansList->DureeExercice = '';
|
|
|
|
$bilansList->Type = $item->typeCompte;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
//Chech file exist
|
|
|
|
if ( file_exists($file) )
|
|
|
|
{
|
|
|
|
$bilansList->File = 'ASS_'.$filename;
|
|
|
|
$bilansList->FileSize = $item->pdfSize;
|
|
|
|
$bilansList->NumberOfPages = $item->pdfPage;
|
|
|
|
$bilansList->ModeDiffusion = 'T';
|
|
|
|
}
|
|
|
|
$list[] = $bilansList;
|
|
|
|
}
|
2012-08-14 13:46:24 +00:00
|
|
|
}
|
2012-08-07 13:49:22 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-07 13:49:22 +00:00
|
|
|
}
|
2012-08-14 13:46:24 +00:00
|
|
|
//Liste des bilans Infogreffe
|
|
|
|
else
|
|
|
|
{
|
2013-02-18 15:14:36 +00:00
|
|
|
require_once 'Metier/Infogreffe/InfogreffeBi.php';
|
|
|
|
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
|
|
|
|
$list = $infogreffe->getList();
|
|
|
|
$nbBilans = count($list);
|
2012-08-14 13:46:24 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
$output = new Bilans();
|
2012-08-07 13:49:22 +00:00
|
|
|
$output->nbReponses = $nbBilans;
|
|
|
|
$output->result = $list;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-07 13:49:22 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
/**
|
|
|
|
* Commande du fichier (URL ou Référence de commande)
|
2012-11-30 13:51:48 +00:00
|
|
|
* @param string $identifiant
|
|
|
|
* SIREN ou autre identifiant
|
2012-08-14 13:46:24 +00:00
|
|
|
* @param string $diffusion
|
|
|
|
* Mode de diffusion T, C
|
|
|
|
* @param string $dateCloture
|
|
|
|
* Date de cloture du bilan (SSAAMMJJ)
|
|
|
|
* @param string $reference
|
|
|
|
* Nom du fichier ou référence de commande
|
|
|
|
* @return string
|
|
|
|
* URL ou identifiant de commande
|
|
|
|
*/
|
2012-11-30 13:51:48 +00:00
|
|
|
public function getBilan($identifiant, $diffusion, $dateCloture, $reference = '')
|
2012-08-07 13:49:22 +00:00
|
|
|
{
|
2012-08-14 13:46:24 +00:00
|
|
|
$this->authenticate();
|
|
|
|
$this->permission('actes');
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
if ( strlen($identifiant)!=9 ) {
|
2012-08-14 13:46:24 +00:00
|
|
|
$this->sendError('1010');
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
$output = '';
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
/**
|
|
|
|
* Association
|
|
|
|
*/
|
2012-08-14 13:46:24 +00:00
|
|
|
if ( substr($reference, 0,4) == 'ASS_' ) {
|
|
|
|
switch ( $diffusion ) {
|
|
|
|
case 'T':
|
2012-08-17 12:40:54 +00:00
|
|
|
if ( preg_match('/^ASS_([0-9]{9})_([0-9]{8})/', $reference, $parseRef) ) {
|
2012-08-14 13:46:24 +00:00
|
|
|
$controlSiren = $parseRef[1];
|
2012-08-17 12:40:54 +00:00
|
|
|
$controlDate = substr($parseRef[2],4,4).substr($parseRef[2],2,2).substr($parseRef[2],0,2);
|
2013-02-18 15:14:36 +00:00
|
|
|
if ( $controlSiren == $identifiant && $controlDate == $dateCloture) {
|
2012-11-30 13:51:48 +00:00
|
|
|
$filename = substr($reference,4);
|
|
|
|
//@todo : Emplacement des fichiers
|
|
|
|
$file = SECURE_STORAGE . 'associations/bilans/' . $filename;
|
2012-08-14 14:07:16 +00:00
|
|
|
$dest = DOC_WEB_LOCAL . 'associations/' . $reference;
|
2012-08-14 13:46:24 +00:00
|
|
|
if ( file_exists($file) && copy($file, $dest)) {
|
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
2012-11-30 13:51:48 +00:00
|
|
|
if ($_SERVER['SERVER_PORT']!='80') {
|
2012-08-14 13:46:24 +00:00
|
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
|
|
}
|
2013-02-18 15:14:36 +00:00
|
|
|
$output = $hostname . '/fichier/associations/' . basename($dest);
|
2013-02-28 14:58:25 +00:00
|
|
|
$dateClotureD = substr($dateCloture,4,2).'/'.substr($dateCloture,6,2).'/'.substr($dateCloture,0,4);
|
2013-02-18 15:14:36 +00:00
|
|
|
$this->wsLog('greffe_bilans', $identifiant, 'Bilan association au '.$dateClotureD);
|
2012-08-14 13:46:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 13:51:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch ( $diffusion )
|
|
|
|
{
|
|
|
|
case 'T':
|
2013-02-21 17:03:56 +00:00
|
|
|
$bilansM = new Application_Model_JoGreffesBilans();
|
2012-11-30 13:51:48 +00:00
|
|
|
$sql = $bilansM->select()
|
|
|
|
->where('siren=?', $identifiant)
|
|
|
|
->where('date_cloture=?', substr($dateCloture,0,4).'-'.substr($dateCloture,4,2).'-'.substr($dateCloture,6,2));
|
|
|
|
$infos = $bilansM->fetchRow($sql);
|
|
|
|
|
|
|
|
if ( $infos===null ) {
|
|
|
|
throw new SoapFault('ERR', 'Bilan indisponible');
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
//Go to Infogreffe service
|
|
|
|
if ( $infos->pdfLink=='' ) {
|
|
|
|
require_once 'Infogreffe/Infogreffe.php';
|
|
|
|
$infogreffe = new Infogreffe();
|
|
|
|
$url = $infogreffe->getBilan($siren, $diffusion, array(
|
|
|
|
'greffe' => $infos->numGreffe,
|
|
|
|
'dossier_millesime' => substr($infos->numRC,0,2),
|
|
|
|
'dossier_statut' => substr($infos->numRC,2,1),
|
|
|
|
'dossier_chrono' => substr($infos->numRC,3),
|
|
|
|
'num_depot' => $infos->num_depot,
|
|
|
|
'date_cloture' => WDate::dateT('Ymd','d/m/Y',$infos->date_cloture)
|
|
|
|
));
|
|
|
|
$pdf = $infogreffe->download($url);
|
2012-12-21 16:11:10 +00:00
|
|
|
|
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
} else {
|
|
|
|
$pdf = $infos->pdfLink;
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
if ( !empty($pdf) ) {
|
|
|
|
$file = SECURE_STORAGE . 'greffes/bilans/' . $pdf;
|
|
|
|
$dest = DOC_WEB_LOCAL . 'greffes/' . $pdf;
|
|
|
|
if ( file_exists($file) && copy($file, $dest)) {
|
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
|
|
if ($_SERVER['SERVER_PORT']!='80') {
|
|
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
|
|
}
|
|
|
|
$output = $hostname . '/data/greffes/' . basename($dest);
|
|
|
|
$this->wsLog('greffe_bilans', $siren, $dateCloture);
|
|
|
|
} else {
|
|
|
|
throw new SoapFault('ERR', 'Fichier introuvable');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
case 'C':
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-11-30 13:51:48 +00:00
|
|
|
// Renvoyer l'id de commande
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-14 13:46:24 +00:00
|
|
|
return $output;
|
2012-08-07 13:49:22 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
/**
|
|
|
|
* Liste des actes au format image
|
|
|
|
* @param string $identifiant
|
|
|
|
* @return Actes
|
|
|
|
*/
|
|
|
|
public function getActes($identifiant)
|
2012-08-07 13:49:22 +00:00
|
|
|
{
|
2013-02-18 15:14:36 +00:00
|
|
|
require_once 'Metier/Infogreffe/InfogreffeAc.php';
|
|
|
|
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
|
|
|
|
$list = $infogreffe->getList(true);
|
|
|
|
$nbActes = count($list);
|
|
|
|
|
|
|
|
if ($nbActes>0) {
|
|
|
|
//Information INPI
|
|
|
|
$rncs = new MRncs();
|
|
|
|
foreach ($list as $i => $item) {
|
|
|
|
$result = $rncs->getListeDepots($identifiant, $item->DepotDate);
|
|
|
|
if (count($result)>0) {
|
|
|
|
foreach ($result as $infos) {
|
|
|
|
$list[$i]->infos[] = $infos['libDepot'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 13:51:48 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
$output = new Actes();
|
|
|
|
$output->result = $list;
|
|
|
|
$output->nbReponses = $nbActes;
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2013-02-18 15:14:36 +00:00
|
|
|
return $output;
|
2012-08-07 13:49:22 +00:00
|
|
|
}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2012-08-07 13:49:22 +00:00
|
|
|
protected function getActe(){}
|
2012-12-21 16:11:10 +00:00
|
|
|
|
2011-12-05 08:14:54 +00:00
|
|
|
}
|