629 lines
19 KiB
PHP
Raw Normal View History

2013-11-05 11:18:30 +00:00
<?php
require_once 'WsScore/WsScore.php';
require_once realpath(dirname(__FILE__)).'/Types.php';
class Pieces extends WsScore
{
/**
* Récupération d'un kbis
* @param string $siren
2014-02-13 14:17:20 +00:00
* SIREN
* @param string $diffusion
* Mode de diffusion (M|C)
* @param string $reference
* Reference du client
2013-11-05 11:18:30 +00:00
* @return string
*/
2014-02-25 16:33:07 +00:00
public function getKbis($siren, $diffusion = 'T', $reference = '')
2013-11-05 11:18:30 +00:00
{
$this->authenticate();
$this->permission('KBIS');
//Vérification du siren
if (intval($siren)==0) {
$this->sendError('1010');
} elseif (strlen($siren)!=9) {
$this->sendError('1020');
}
2014-02-13 14:17:20 +00:00
switch ( $diffusion ) {
case 'M':
case 'C':
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
$refCommande = uniqid();
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($siren);
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
$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'),
));
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
return $refCommande;
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
break;
2013-11-05 11:18:30 +00:00
2014-02-25 16:33:07 +00:00
case 'T':
2014-02-13 14:17:20 +00:00
default:
2013-11-05 11:18:30 +00:00
2014-02-13 14:17:20 +00:00
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT']!='80'){
$hostname.= ':'.$_SERVER['SERVER_PORT'];
2013-11-05 11:18:30 +00:00
}
2014-02-13 14:17:20 +00:00
$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);
2013-11-05 11:18:30 +00:00
}
2014-02-13 14:17:20 +00:00
break;
2013-11-05 11:18:30 +00:00
}
}
/**
* Liste des bilans disponible au format image
* @param string $identifiant
* SIREN ou autre identifiant
* @param int $position
* Numéro de page
* @param int $nbRep
* Nombre de réponse par page (max=200)
* @return Bilans
* @throws SoapFault
*/
public function getBilans($identifiant, $position = 0, $nbRep = 200)
{
// @todo : Code Saisie + Date saisie
$this->authenticate();
if ( empty($position) ) {
$position = 0;
}
if ($nbRep > 200) {
$nbRep = 200;
}
if ( strlen($identifiant)!=9 ) {
$this->sendError('1010');
}
2014-01-29 08:39:29 +00:00
/**
2013-11-05 11:18:30 +00:00
* Entreprise avec des bilans
* Base RNCS
* Si association alors lire dans la base de données pour établir la liste
* //@todo : Enregistrer dans la base jo.greffes_bilans
*/
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($identifiant);
if (empty($identite['id'])){
$this->sendError('1020');
}
$fj = $identite['FJ'];
$assoFormeJuridique = array(
//Associations
'9210','9220','9221','9222','9223','9224','9230','9240','9260',
//Syndicats
'7345','7353','7354','7355','8410','8420','9110',
//Fondation
'9300',
);
$list = array();
/**
* Liste des bilans association
*/
if ( in_array($fj, $assoFormeJuridique) ) {
$bilansM = new Application_Model_JoAssoBilans();
//Comptage
$sql = $bilansM->select()
->from($bilansM, 'COUNT(*) as nb')
->where('siren=?', $identifiant);
$nbBilans = $bilansM->fetchRow($sql)->nb;
if ($nbBilans>0)
{
//Liste
$sql = $bilansM->select()
->from($bilansM, array('dateCloture', 'Assoc_Date_Declaration', 'pdfLink',
'typeCompte', 'pdfSize', 'pdfPage'))
->where('siren = ?', $identifiant)
->order('dateCloture DESC')
->limit($nbRep, $position);
$bilans = $bilansM->fetchAll($sql);
if( $bilans->count() > 0) {
foreach ($bilans as $item) {
$filename = basename($item->pdfLink);
$file = SECURE_STORAGE . 'association/bilans/' . $filename;
$bilansList = new Bilan();
$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;
//Chech file exist
if ( file_exists($file) )
{
$bilansList->File = 'ASS_'.$filename;
$bilansList->FileSize = $item->pdfSize;
$bilansList->NumberOfPages = $item->pdfPage;
$bilansList->ModeDiffusion = 'T';
}
$list[] = $bilansList;
}
}
}
}
//Liste des bilans Infogreffe
else
{
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
2014-02-25 16:33:07 +00:00
try {
$list = $infogreffe->getList();
} catch (Exception $e) {
if ($this->tabInfoUser['idClient']==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
2013-11-05 11:18:30 +00:00
$nbBilans = count($list);
2014-01-29 08:39:29 +00:00
2014-02-07 16:14:36 +00:00
//Ajout d'informations supplémentaires
if ( count($list)>0 ) {
foreach ( $list as $i => $item ) {
//Surcharge des codes de saisie
$date = new Zend_Date($item->DateCloture, 'yyyy-MM-dd');
try {
$liasseM = new Application_Model_JoBilans();
$sql = $liasseM->select()
->where('siren=?', $identifiant)
->where('dateExercice=?', $date->toString('yyyyMMdd'));
$row = $liasseM->fetchRow($sql);
2014-02-25 16:33:07 +00:00
} catch (Zend_Db_Exception $e) {
2014-02-07 16:14:36 +00:00
//file_put_contents('debug.log', $e->getMessage()."\n", FILE_APPEND);
}
if ( $row !== null ) {
$item->DureeExercice = $row->dureeExercice;
$item->SaisieDate = substr($row->dateProvPartenaire,0,4).'-'.substr($row->dateProvPartenaire,4,2).'-'.substr($row->dateProvPartenaire,6,2);
$item->SaisieCode = '00';
//@todo : Améliorer le label de retour - partenaire de saisie
//$item->SaisieLabel = '';
$list[$i] = $item;
}
if ( $item->ModeDiffusion == 'C' ) {
$cmdM = new Application_Model_Sdv1GreffeCommandesBi();
$sql = $cmdM->select()
->where('siren=?', $identifiant)
->where('bilanCloture=?', $item->DateCloture);
$row = $cmdM->fetchRow($sql);
if ( $row !== null ) {
$item->ModeDiffusion = 'O';
$list[$i] = $item;
}
}
}
}
2014-01-29 08:39:29 +00:00
2013-11-05 11:18:30 +00:00
}
$this->wsLog('greffe_bilans', $identifiant, 'Liste');
$output = new Bilans();
$output->nbReponses = $nbBilans;
$output->result = $list;
return $output;
}
/**
* Commande du fichier (URL ou Référence de commande)
* @param string $identifiant
* SIREN ou autre identifiant
* @param string $dateCloture
2014-01-16 10:47:25 +00:00
* Date de cloture du bilan (SSAA-MM-JJ)
2013-11-05 11:18:30 +00:00
* @param string $type
* Type de compte (null|sociaux|consolides)
* @param string $diffusion
* Mode de diffusion (T|C)
* @param string $reference
* Nom du fichier ou référence de commande
* @throws SoapFault
* @return string
* URL ou identifiant de commande
*/
2014-01-16 10:47:25 +00:00
public function getBilan($identifiant, $dateCloture, $type, $diffusion, $reference = '')
2013-11-05 11:18:30 +00:00
{
$this->authenticate();
$this->permission('actes');
if ( strlen($identifiant)!=9 ) {
$this->sendError('1010');
2014-02-07 16:14:36 +00:00
}
if ( empty($reference) ) {
$reference = '';
2013-11-05 11:18:30 +00:00
}
$output = '';
/**
* Association
*/
if ( substr($reference, 0,4) == 'ASS_' ) {
switch ( $diffusion ) {
case 'T':
if ( preg_match('/^ASS_([0-9]{9})_([0-9]{8})/', $reference, $parseRef) ) {
$controlSiren = $parseRef[1];
$controlDate = substr($parseRef[2],4,4).substr($parseRef[2],2,2).substr($parseRef[2],0,2);
if ( $controlSiren == $identifiant && $controlDate == $dateCloture) {
$filename = substr($reference,4);
$c = Zend_Registry::get('config');
2014-02-07 16:14:36 +00:00
$file = $c->profil->path->secure . '/association/bilans/' . $filename;
$dest = APPLICATION_PATH . '/../data/files/associations/' . $reference;
2013-11-05 11:18:30 +00:00
if ( file_exists($file) && copy($file, $dest)) {
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT']!='80') {
$hostname.= ':'.$_SERVER['SERVER_PORT'];
}
$output = $hostname . '/fichier/associations/' . basename($dest);
$dateClotureD = substr($dateCloture,4,2).'/'.substr($dateCloture,6,2).'/'.substr($dateCloture,0,4);
$this->wsLog('greffe_bilans', $identifiant, 'Bilan association au '.$dateClotureD);
}
}
}
break;
}
2014-02-07 16:14:36 +00:00
return $output;
2013-11-05 11:18:30 +00:00
}
/**
* Entreprise
*/
else {
2014-02-07 16:14:36 +00:00
//Génération identifiant de commande unique
$refCommande = uniqid();
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($identifiant);
//Sauvegarde dans la base
$commandeM = new Application_Model_Sdv1GreffeCommandesBi();
$id = $commandeM->insert(array(
'refCommande' => $refCommande,
'login' => $this->tabInfoUser['login'],
'email' => $this->tabInfoUser['email'],
'refClient' => $reference,
'mode' => $diffusion,
'siren' => $identifiant,
'raisonSociale' => $identite['Nom'],
'bilanCloture' => $dateCloture,
'bilanType' => $type,
'dateInsert' => date('YmdHis'),
));
2013-11-05 11:18:30 +00:00
switch ( $diffusion ) {
case 'T':
2014-02-07 16:14:36 +00:00
//Passer la commande chez infogreffe
2013-11-05 11:18:30 +00:00
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
2014-02-25 16:33:07 +00:00
//$infogreffe->debug = true;
2014-02-07 16:14:36 +00:00
try {
$pdf = $infogreffe->getCommandeT($dateCloture, $type, $id);
} catch (Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
}
//Distribuer le fichier
2013-11-05 11:18:30 +00:00
if ( !empty($pdf) ) {
$c = Zend_Registry::get('config');
2014-02-07 16:14:36 +00:00
$file = $c->profil->infogreffe->storage->path . '/' . $pdf;
$dest = APPLICATION_PATH . '/../data/files/greffes/' . basename($file);
2013-11-05 11:18:30 +00:00
if ( file_exists($file) && copy($file, $dest)) {
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
if ( $_SERVER['SERVER_PORT'] != '80' ) {
$hostname.= ':'.$_SERVER['SERVER_PORT'];
}
2014-02-07 16:14:36 +00:00
$output = $hostname . '/fichier/greffes/' . basename($dest); // @todo : Chemin du fichier
2014-01-16 10:47:25 +00:00
$this->wsLog('greffe_bilans', $identifiant, basename($dest));
2014-02-25 16:33:07 +00:00
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
2013-11-05 11:18:30 +00:00
} else {
throw new SoapFault('ERR', 'Fichier introuvable');
}
2014-01-16 10:47:25 +00:00
}
2013-11-05 11:18:30 +00:00
break;
case 'C':
2014-01-29 08:39:29 +00:00
case 'F':
2013-11-05 11:18:30 +00:00
//Commande chez Infogreffe
2014-01-29 08:39:29 +00:00
if ( $diffusion == 'C' ) {
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
2014-02-07 16:14:36 +00:00
try {
$infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id);
$this->wsLog('greffe_bilans', $identifiant, $refCommande);
} catch(Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
2014-01-29 08:39:29 +00:00
}
2013-11-05 11:18:30 +00:00
}
2014-02-07 16:14:36 +00:00
$output = $refCommande;
2013-11-05 11:18:30 +00:00
break;
}
2014-02-07 16:14:36 +00:00
return $output;
}
2013-11-05 11:18:30 +00:00
}
/**
* Liste des actes au format image
* @param string $identifiant
2014-01-16 10:47:25 +00:00
* SIREN ou autre identifiant
* @param int $position
* Numéro de page
* @param int $nbRep
* Nombre de réponse par page (max=200)
* @throws SoapFault
2013-11-05 11:18:30 +00:00
* @return Actes
*/
2014-01-16 10:47:25 +00:00
public function getActes($identifiant, $position = 0, $nbRep = 200)
2013-11-05 11:18:30 +00:00
{
2014-01-16 10:47:25 +00:00
$this->authenticate();
if ( empty($position) ) {
$position = 0;
}
if ($nbRep > 200) {
$nbRep = 200;
}
if ( strlen($identifiant)!=9 ) {
$this->sendError('1010');
}
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($identifiant);
if (empty($identite['id'])){
$this->sendError('1020');
}
2013-11-05 11:18:30 +00:00
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
2014-02-07 16:14:36 +00:00
$list = $infogreffe->getList();
2013-11-05 11:18:30 +00:00
$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'];
}
}
}
2014-01-29 08:39:29 +00:00
//@todo : Marquer les éléments en commande courrier si déjà commandé ModeDiffusion = O
2013-11-05 11:18:30 +00:00
}
$this->wsLog('greffe_actes', $identifiant, 'Liste');
$output = new Actes();
$output->result = $list;
$output->nbReponses = $nbActes;
return $output;
}
/**
* @todo :
* @param string $identifiant
* SIREN
* @param string $diffusion
* Mode de diffusion (C|T)
* @param string $depotNum
*
* @param string $depotDate
*
* @param string $acteType
* Type de l'acte
* @param string $acteNum
* Numéro de l'acte
* @param string $acteDate
* Date de l'acte
* @param string $reference
* A DETERMINER
* @throws SoapFault
* @return string
* URL ou identifiant de commande
*/
public function getActe($identifiant, $diffusion, $depotNum, $depotDate, $acteType, $acteNum, $acteDate, $reference = '')
{
$this->authenticate();
$this->permission('actes');
if ( strlen($identifiant)!=9 ) {
$this->sendError('1010');
}
$output = '';
2014-02-07 16:14:36 +00:00
//Génération identifiant de commande unique
$refCommande = uniqid();
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($identifiant);
//Sauvegarde dans la base
$commandeM = new Application_Model_Sdv1GreffeCommandesAc();
$id = $commandeM->insert(array(
'refCommande' => $refCommande,
'login' => $this->tabInfoUser['login'],
'email' => $this->tabInfoUser['email'],
'refClient' => $reference,
'siren' => $identifiant,
'mode' => $diffusion,
'raisonSociale' => $identite['Nom'],
'depotNum' => $depotNum,
'depotDate' => $depotDate,
'acteType' => $acteType,
'acteDate' => $acteDate,
'acteNum' => $acteNum,
'dateInsert' => date('YmdHis'),
));
2013-11-05 11:18:30 +00:00
switch ( $diffusion ) {
case 'T':
2014-02-07 16:14:36 +00:00
//Passer la commande chez Infogreffe
2013-11-05 11:18:30 +00:00
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
2014-02-07 16:14:36 +00:00
try {
$pdf = $infogreffe->getCommandeT($depotDate, $depotNum, $acteType, $acteDate, $acteNum, $id);
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
} catch (Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
}
2013-11-05 11:18:30 +00:00
2014-02-07 16:14:36 +00:00
//Distribuer le fichier
2013-11-05 11:18:30 +00:00
if ( !empty($pdf) ) {
$c = Zend_Registry::get('config');
2014-02-07 16:14:36 +00:00
$file = $c->profil->infogreffe->storage->path . '/' . $pdf;
$dest = APPLICATION_PATH . '/../data/files/greffes/' . basename($file);
2013-11-05 11:18:30 +00:00
if ( file_exists($file) && copy($file, $dest)) {
2014-02-25 16:33:07 +00:00
2013-11-05 11:18:30 +00:00
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
if ( $_SERVER['SERVER_PORT'] != '80' ) {
$hostname.= ':'.$_SERVER['SERVER_PORT'];
}
2014-02-07 16:14:36 +00:00
$output = $hostname . '/fichier/greffes/' . basename($dest);
2014-02-25 16:33:07 +00:00
$this->wsLog('greffe_actes', $siren, basename($dest));
return $output;
2013-11-05 11:18:30 +00:00
} else {
throw new SoapFault('ERR', 'Fichier introuvable');
}
2013-11-05 11:18:30 +00:00
}
2014-02-25 16:33:07 +00:00
return false;
2013-11-05 11:18:30 +00:00
break;
case 'C':
2014-01-29 08:39:29 +00:00
case 'F':
2013-11-05 11:18:30 +00:00
2014-02-07 16:14:36 +00:00
if ( $diffusion == 'C' ) {
2014-01-29 08:39:29 +00:00
//Commande chez Infogreffe
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
2014-02-07 16:14:36 +00:00
try {
$infogreffe->getCommandeC($depotDate, $depotNum, $acteType, $acteDate, $acteNum, 'G-AC-'.$id);
$commandeM->update(array('dateCommande'=> date('YmdHis')), 'id='.$id);
2014-02-07 16:14:36 +00:00
$this->wsLog('greffe_actes', $identifiant, $refCommande);
} catch(Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
2014-01-29 08:39:29 +00:00
}
2013-11-05 11:18:30 +00:00
}
return $refCommande;
break;
}
return $output;
}
}