1332 lines
42 KiB
PHP
1332 lines
42 KiB
PHP
<?php
|
|
use mikehaertl\wkhtmlto\Pdf;
|
|
|
|
require_once __DIR__ . '/Types.php';
|
|
|
|
class Pieces extends Scores_Ws_Server
|
|
{
|
|
/**
|
|
* Récupération d'un kbis
|
|
* @param string $siren
|
|
* SIREN ou SIRET siege
|
|
* @param string $diffusion
|
|
* Mode de diffusion (T=Téléchargement|M=Email|C=Courrier)
|
|
* @param string $reference
|
|
* Reference du client
|
|
* @return string
|
|
*/
|
|
public function getKbis($siren, $diffusion = 'T', $reference = '')
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('KBIS');
|
|
|
|
$siren = substr($siren, 0, 9);
|
|
|
|
// Vérification du siren
|
|
if (intval($siren) == 0) {
|
|
$this->sendError('1010');
|
|
} elseif (strlen($siren) != 9) {
|
|
$this->sendError('1020');
|
|
}
|
|
if (empty($diffusion)) {
|
|
$diffusion = 'T';
|
|
}
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$identite = $iInsee->getIdentiteLight($siren);
|
|
|
|
$refCommande = uniqid();
|
|
|
|
// Sauvegarde dans la base
|
|
$data = array(
|
|
'refCommande' => $refCommande,
|
|
'login' => $this->User->login,
|
|
'email' => $this->User->email,
|
|
'refClient' => $reference,
|
|
'mode' => $diffusion,
|
|
'siren' => $siren,
|
|
'raisonSociale' => $identite['Nom'],
|
|
'dateInsert' => date('YmdHis'),
|
|
'dateCommande' => date('YmdHis'),
|
|
);
|
|
try {
|
|
$this->conn->insert('sdv1.greffe_commandes_kb', $data);
|
|
$id = $this->conn->lastInsertId();
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
switch ($diffusion) {
|
|
|
|
// Demande de KBIS par email
|
|
case 'M':
|
|
// Demande de KBIS original par courrier
|
|
case 'C':
|
|
|
|
return $refCommande;
|
|
|
|
break;
|
|
|
|
// Téléchargement du KBIS (payant)
|
|
case 'T':
|
|
default:
|
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ($_SERVER['SERVER_PORT']!='80'){
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$path = realpath($c->profil->path->shared).'/datafile/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));
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_kb',
|
|
array('dateEnvoi'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
|
|
return $hostname.'/fichier/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) ) {
|
|
|
|
$identifiant = $identite['Siret'];
|
|
|
|
//Téléchargement du KBIS
|
|
$result = array();
|
|
exec('php '.APPLICATION_PATH.'/../bin/kbis.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;
|
|
throw new SoapFault('0000',"Erreur récupération du kbis");
|
|
}
|
|
} else {
|
|
$this->wsLog('kbis', $siren, basename($file));
|
|
}
|
|
|
|
// Génération du PDF
|
|
$pdf = new Pdf();
|
|
$options = array(
|
|
'binary' => $c->profil->wkhtmltopdf->path,
|
|
'commandOptions' => array(
|
|
'useExec' => true,
|
|
),
|
|
'ignoreWarnings' => true,
|
|
'disable-internal-links',
|
|
);
|
|
$pdf->setOptions($options);
|
|
$pdf->addPage($file);
|
|
$pdf->saveAs($filepdf);
|
|
|
|
if ( !file_exists($filepdf) ) {
|
|
throw new SoapFault('0000', "Fichier PDF introuvable");
|
|
}
|
|
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_kb',
|
|
array('dateEnvoi'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
|
|
return $hostname.'/fichier/kbis/'.basename($filepdf);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
}
|
|
|
|
/**
|
|
* 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 Metier_Insee_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)) {
|
|
|
|
try {
|
|
$sql = "SELECT dateCloture, Assoc_Date_Declaration, pdfLink, typeCompte, pdfSize, pdfPage
|
|
FROM jo.asso_bilans WHERE siren = :siren ORDER BY dateCloture DESC";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('siren', $identifiant);
|
|
$stmt->execute();
|
|
} catch (\Doctrine\DBAL\DBALException $e) {}
|
|
|
|
$nbBilans = $stmt->rowCount();
|
|
if ($nbBilans > 0) {
|
|
$bilanResult = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
|
foreach ($bilanResult as $item) {
|
|
|
|
$filename = basename($item->pdfLink);
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$file = $c->profil->path->shared.'/datafile/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;
|
|
|
|
// Check 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 {
|
|
$infogreffe = new Metier_Infogreffe_DocBI();
|
|
$infogreffe->setSiren($identifiant);
|
|
try {
|
|
$list = $infogreffe->getList();
|
|
}
|
|
catch (Exception $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
$nbBilans = count($list);
|
|
|
|
// Ajout d'informations supplémentaires
|
|
if ( count($list) > 0 ) {
|
|
foreach ($list as $i => $item) {
|
|
// Surcharge des codes de saisie
|
|
$date = DateTime::createFromFormat('Y-m-d', $item->DateCloture);
|
|
try {
|
|
$sql = "SELECT * FROM jo.bilans
|
|
WHERE siren = :siren AND dateExercice = :date";
|
|
if ( $item->Type == 'consolides' ) {
|
|
$sql.= " AND typeBilan = 'C'";
|
|
} elseif ( $item->Type == 'sociaux' ) {
|
|
$sql.= " AND (typeBilan='N' OR typeBilan='S')";
|
|
}
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('siren', $identifiant);
|
|
$stmt->bindValue('date', $date->format('Ymd'));
|
|
$stmt->execute();
|
|
// Override SaisieDate
|
|
if ($stmt->rowCount() == 0) {
|
|
// Reset greffe_bilans : duree_exercice, saisie_date, saisie_code, ctrl_code, pages
|
|
if ( $item->SaisieDate !== null ) {
|
|
try {
|
|
$data = array(
|
|
'duree_exercice' => null,
|
|
'saisie_date' => null,
|
|
'saisie_code' => null,
|
|
'ctrl_code' => null,
|
|
'pages' => null,
|
|
);
|
|
$this->conn->update('jo.greffes_bilans', $data, array(
|
|
'siren' => $identifiant,
|
|
'num_depot' => $item->NumDepot));
|
|
} catch (\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
$item->DureeExercice = null;
|
|
$item->SaisieDate = null;
|
|
$item->SaisieCode = null;
|
|
}
|
|
else {
|
|
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$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 = '';
|
|
}
|
|
} catch (\Doctrine\DBAL\DBALException $e) {}
|
|
|
|
if ($item->ModeDiffusion == 'C') {
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.greffe_commandes_bi
|
|
WHERE siren = :siren AND bilanCloture :cloture";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('siren', $identifiant);
|
|
$stmt->bindValue('bilanCloture', $item->DateCloture);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$item->ModeDiffusion = 'O';
|
|
}
|
|
} catch (\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$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
|
|
* Date de cloture du bilan (SSAA-MM-JJ)
|
|
* @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
|
|
*/
|
|
public function getBilan($identifiant, $dateCloture, $type, $diffusion, $reference = '')
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
if (strlen($identifiant) != 9) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
if (empty($reference)) {
|
|
$reference = '';
|
|
}
|
|
|
|
$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');
|
|
$file = $c->profil->path->shared . '/datafile/association/bilans/' . $filename;
|
|
$dest = $c->profil->path->shared . '/files/' . $reference;
|
|
|
|
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;
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Entreprise
|
|
*/
|
|
else {
|
|
|
|
// Génération identifiant de commande unique
|
|
$refCommande = uniqid();
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$identite = $iInsee->getIdentiteLight($identifiant);
|
|
|
|
// Sauvegarde dans la base
|
|
$data = array(
|
|
'refCommande' => $refCommande,
|
|
'login' => $this->User->login,
|
|
'email' => $this->User->email,
|
|
'refClient' => $reference,
|
|
'mode' => $diffusion,
|
|
'siren' => $identifiant,
|
|
'raisonSociale' => $identite['Nom'],
|
|
'bilanCloture' => $dateCloture,
|
|
'bilanType' => $type,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
try {
|
|
$this->conn->insert('sdv1.greffe_commandes_bi', $data);
|
|
$id = $this->conn->lastInsertId();
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
switch ($diffusion) {
|
|
|
|
case 'T':
|
|
|
|
// Passer la commande chez infogreffe
|
|
$infogreffe = new Metier_Infogreffe_DocBI();
|
|
$infogreffe->setSiren($identifiant);
|
|
//$infogreffe->debug = true;
|
|
try {
|
|
$pdf = $infogreffe->getCommandeT($dateCloture, $type, $id);
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_bi',
|
|
array('dateEnvoi'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
catch (Exception $e) {
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_bi',
|
|
array('cmdError'=> $e->getMessage()), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
if ( $e->getCode() == $infogreffe::INT ) {
|
|
throw new SoapFault('ERR', "Erreur lors de la commande auprès de notre prestataire.");
|
|
}
|
|
}
|
|
|
|
// Distribuer le fichier
|
|
if ( !empty($pdf) ) {
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$file = null;
|
|
if ( file_exists($c->profil->infogreffe->storage->path . '/OCR/' . $pdf) ) {
|
|
$file = $c->profil->infogreffe->storage->path . '/OCR/' . $pdf;
|
|
} elseif ( file_exists($c->profil->infogreffe->storage->path . '/' . $pdf) ) {
|
|
$file = $c->profil->infogreffe->storage->path . '/' . $pdf;
|
|
}
|
|
$dest = $c->profil->path->shared . '/files/' . basename($file);
|
|
|
|
if ( $file !== null && copy($file, $dest) ) {
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ( $_SERVER['SERVER_PORT'] != '80' ) {
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
$output = $hostname . '/fichier/greffes/' . basename($dest); // @todo : Chemin du fichier
|
|
$this->wsLog('greffe_bilans', $identifiant, basename($dest));
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', 'Fichier introuvable');
|
|
}
|
|
|
|
}
|
|
break;
|
|
|
|
case 'C':
|
|
case 'F':
|
|
|
|
// Commande chez Infogreffe
|
|
if ( $diffusion == 'C' ) {
|
|
$infogreffe = new Metier_Infogreffe_DocBI();
|
|
$infogreffe->setSiren($identifiant);
|
|
try {
|
|
$infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id);
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_bi',
|
|
array('dateCommande'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
$this->wsLog('greffe_bilans', $identifiant, $refCommande);
|
|
}
|
|
catch(Exception $e) {
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_bi',
|
|
array('cmdError'=> $e->getMessage()), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
}
|
|
|
|
$output = $refCommande;
|
|
break;
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Liste des actes 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)
|
|
* @throws SoapFault
|
|
* @return Actes
|
|
*/
|
|
public function getActes($identifiant, $position = 0, $nbRep = 200)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( empty($position) ) {
|
|
$position = 0;
|
|
}
|
|
if ($nbRep > 200) {
|
|
$nbRep = 200;
|
|
}
|
|
|
|
if ( strlen($identifiant)!=9 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$identite = $iInsee->getIdentiteLight($identifiant);
|
|
if (empty($identite['id'])){
|
|
$this->sendError('1020');
|
|
}
|
|
|
|
$infogreffe = new Metier_Infogreffe_DocAC();
|
|
$infogreffe->setSiren($identifiant);
|
|
$list = $infogreffe->getList();
|
|
$nbActes = count($list);
|
|
|
|
if ($nbActes>0) {
|
|
//Information INPI
|
|
$rncs = new Metier_Partenaires_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'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->wsLog('greffe_actes', $identifiant, 'Liste');
|
|
|
|
$output = new Actes();
|
|
$output->result = $list;
|
|
$output->nbReponses = $nbActes;
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Acte : Commande d'un fichier
|
|
* @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 = '';
|
|
|
|
// Génération identifiant de commande unique
|
|
$refCommande = uniqid();
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$identite = $iInsee->getIdentiteLight($identifiant);
|
|
|
|
// Sauvegarde dans la base
|
|
$data = array(
|
|
'refCommande' => $refCommande,
|
|
'login' => $this->User->login,
|
|
'email' => $this->User->email,
|
|
'refClient' => $reference,
|
|
'siren' => $identifiant,
|
|
'mode' => $diffusion,
|
|
'raisonSociale' => $identite['Nom'],
|
|
'depotNum' => $depotNum,
|
|
'depotDate' => $depotDate,
|
|
'acteType' => $acteType,
|
|
'acteDate' => $acteDate,
|
|
'acteNum' => $acteNum,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
try {
|
|
$this->conn->insert('sdv1.greffe_commandes_ac', $data);
|
|
$id = $this->conn->lastInsertId();
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
switch ($diffusion) {
|
|
|
|
case 'T':
|
|
|
|
// Passer la commande chez Infogreffe
|
|
$infogreffe = new Metier_Infogreffe_DocAC();
|
|
$infogreffe->setSiren($identifiant);
|
|
try {
|
|
$pdf = $infogreffe->getCommandeT($depotDate, $depotNum, $acteType, $acteDate, $acteNum, $id);
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_ac',
|
|
array('dateEnvoi'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
catch (Exception $e) {
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_ac',
|
|
array('cmdError'=> $e->getMessage()), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
|
|
if ( $e->getCode() == $infogreffe::INT ) {
|
|
throw new SoapFault('ERR', "Erreur lors de la commande auprès de notre prestataire.");
|
|
}
|
|
}
|
|
|
|
// Distribuer le fichier
|
|
if ( !empty($pdf) ) {
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$file = null;
|
|
if ( file_exists($c->profil->infogreffe->storage->path . '/OCR/' . $pdf) ) {
|
|
$file = $c->profil->infogreffe->storage->path . '/OCR/' . $pdf;
|
|
} elseif ( file_exists($c->profil->infogreffe->storage->path . '/' . $pdf) ) {
|
|
$file = $c->profil->infogreffe->storage->path . '/' . $pdf;
|
|
}
|
|
$dest = $c->profil->path->shared . '/files/' . basename($file);
|
|
|
|
if ( $file !== null && copy($file, $dest)) {
|
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ( $_SERVER['SERVER_PORT'] != '80' ) {
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
$output = $hostname . '/fichier/greffes/' . basename($dest);
|
|
$this->wsLog('greffe_actes', $identifiant, basename($dest));
|
|
return $output;
|
|
|
|
} else {
|
|
throw new SoapFault('ERR', 'Fichier introuvable.');
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
case 'F':
|
|
|
|
if ( $diffusion == 'C' ) {
|
|
// Commande chez Infogreffe
|
|
$infogreffe = new Metier_Infogreffe_DocAC();
|
|
$infogreffe->setSiren($identifiant);
|
|
try {
|
|
$infogreffe->getCommandeC($depotDate, $depotNum, $acteType, $acteDate, $acteNum, 'G-AC-'.$id);
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_ac',
|
|
array('dateCommande'=> date('YmdHis')), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
$this->wsLog('greffe_actes', $identifiant, $refCommande);
|
|
}
|
|
catch(Exception $e) {
|
|
try {
|
|
$this->conn->update('sdv1.greffe_commandes_ac',
|
|
array('cmdError'=> $e->getMessage()), array('id' => $id));
|
|
}
|
|
catch(\Doctrine\DBAL\DBALException $e) {}
|
|
}
|
|
}
|
|
|
|
return $refCommande;
|
|
|
|
break;
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Set an email associated to the command
|
|
* @param string $id
|
|
* @param string $email
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setActeCmdEmail($id, $email)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
if ( !$validator->isValid($email) ){
|
|
throw new SoapFault('ERR', "Adresse email invalide.");
|
|
}
|
|
|
|
// --- Vérification que la commande existe
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.greffe_commandes_ac WHERE login = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
if ( is_int($email) ) {
|
|
//Id of secondary email
|
|
}
|
|
else {
|
|
$dataUpdate = array('email' => $email);
|
|
try {
|
|
$result = $this->conn->update('sdv1.greffe_commandes_ac', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set an email associated to the command
|
|
* @param string $id
|
|
* @param string $email
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setBilanCmdEmail($id, $email)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
if ( !$validator->isValid($email) ){
|
|
throw new SoapFault('ERR', "Adresse email invalide.");
|
|
}
|
|
|
|
// --- Vérification que la commande existe
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.greffe_commandes_bi WHERE login = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
if ( is_int($email) ) {
|
|
//Id of secondary email
|
|
}
|
|
else {
|
|
$dataUpdate = array('email' => $email);
|
|
try {
|
|
$result = $this->conn->update('sdv1.greffe_commandes_bi', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set an email associated to the command
|
|
* @param string $id
|
|
* @param string $email
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setKbisCmdEmail($id, $email)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('KBIS');
|
|
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
if ( !$validator->isValid($email) ){
|
|
throw new SoapFault('ERR', "Adresse email invalide.");
|
|
}
|
|
|
|
// --- Vérification que la commande existe
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.greffe_commandes_kb WHERE login = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
if ( is_int($email) ) {
|
|
//Id of secondary email
|
|
}
|
|
else {
|
|
$dataUpdate = array('email' => $email);
|
|
try {
|
|
$result = $this->conn->update('sdv1.greffe_commandes_kb', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Ajouter des informations pour la commande, principalement lors de commande courrier
|
|
* @param string $id
|
|
* Identifiant de la commande
|
|
* @param string $infos
|
|
* Information au format json
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setKbisCmdLetter($id, $infos)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('KBIS');
|
|
|
|
// --- Vérification que la commande existe
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.greffe_commandes_kb WHERE login = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() == 0) {
|
|
return false;
|
|
}
|
|
|
|
// --- Update
|
|
$dataUpdate = array('infos' => $infos);
|
|
try {
|
|
$result = $this->conn->update('sdv1.greffe_commandes', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Statut association - Liste
|
|
* @param string $companyId
|
|
* @param string $type
|
|
* @return AssoActe[]
|
|
*/
|
|
public function getAssoActes($companyId, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
// --- Lecture de la table des actes associations
|
|
try {
|
|
$sql = "SELECT * FROM jo.asso_statut WHERE companyId = :companyId";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('companyId', $companyId);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$output = array();
|
|
if ($stmt->rowCount() > 0) {
|
|
$statutResult = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
|
foreach ($statutResult as $item) {
|
|
$statut = new AssoActe();
|
|
$statut->Date = $item->statutDate;
|
|
$statut->File = $item->statutFile;
|
|
$statut->DateInsert = $item->dateInsert;
|
|
$output[] = $statut;
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Statut association - Fichier
|
|
* @param string $companyId
|
|
* Identifiant, siren de l'entreprise
|
|
* @param string $type
|
|
* @param string $date
|
|
* Date au format AAAA-MM-JJ
|
|
* @throws SoapFault
|
|
* @return string
|
|
* URL ou identifiant de commande
|
|
*/
|
|
public function getAssoActe($companyId, $type = null, $date)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
// --- Lecture table des actes associations
|
|
try {
|
|
$sql = "SELECT * FROM jo.asso_statut WHERE companyId = :companyId AND statutDate = :date";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('companyId', $companyId);
|
|
$stmt->bindValue('date', $date);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() == 0) {
|
|
return false;
|
|
}
|
|
|
|
$statutResult = $stmt->fetch(\PDO::FETCH_BOTH);
|
|
|
|
// --- Distribuer le fichier
|
|
if ( !empty($statutResult->statutFile) ) {
|
|
$c = Zend_Registry::get('config');
|
|
$file = $c->profil->path->shared . '/datafile/association/actes/' . $statutResult->statutFile;
|
|
$dest = $c->profil->path->shared . '/files/' . basename($file);
|
|
if ( file_exists($file) && copy($file, $dest)) {
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ( $_SERVER['SERVER_PORT'] != '80' ) {
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
$output = $hostname . '/fichier/greffes/' . basename($dest);
|
|
$this->wsLog('assoacte', $companyId, basename($dest));
|
|
return $output;
|
|
} else {
|
|
throw new SoapFault('ERR', 'Fichier introuvable.');
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Commande de statut association
|
|
* @param string $companyId
|
|
* @param string $type (siren|waldec)
|
|
* @throws SoapFault
|
|
* @return mixed
|
|
*/
|
|
public function setAssoStatut($companyId, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
$inseeM = new Metier_Insee_MInsee();
|
|
if ($type == 'siren') {
|
|
$result = $inseeM->getIdentiteLight($companyId);
|
|
$companyName = $result['Nom'];
|
|
} elseif ($type == 'waldec') {
|
|
$result = $inseeM->getEtablissementsParId('AUTRE', $companyId);
|
|
$companyName = $result['Nom'];
|
|
}
|
|
|
|
$refCommande = uniqid();
|
|
|
|
try {
|
|
$data = array(
|
|
'refCommande' => $refCommande,
|
|
'companyId' => $companyId,
|
|
'typeId' => $type,
|
|
'companyName' => $companyName,
|
|
'userId' => $this->User->id,
|
|
'userLogin' => $this->User->login,
|
|
'userEmail' => $this->User->email,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
$result = $this->conn->insert('sdv1.order_asso_statut', $data);
|
|
if ($result) {
|
|
return $refCommande;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Modifier une commande de statut association
|
|
* @param string $id
|
|
* Référence de commande
|
|
* @param string $data
|
|
* Objet json (email, reference)
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setAssoStatutDetail($id, $data)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
|
|
// --- Vérification que la commande existe
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.order_asso_statut WHERE userLogin = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() == 0) {
|
|
return false;
|
|
}
|
|
|
|
// --- Paramètres envoyés
|
|
$params = json_decode($data, true);
|
|
$dataUpdate = array();
|
|
if (count($params) > 0) {
|
|
foreach ($params as $k => $v) {
|
|
switch ($k) {
|
|
case 'email':
|
|
// --- Vérification email
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
if ( !$validator->isValid($v) ){
|
|
throw new SoapFault('ERR', "Adresse email invalide.");
|
|
}
|
|
$dataUpdate['email'] = $v;
|
|
break;
|
|
case 'reference':
|
|
$dataUpdate['reference'] = $v;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Mise à jour de la commande
|
|
if (count($dataUpdate) > 0) {
|
|
try {
|
|
$result = $this->conn->update('sdv1.order_asso_statut', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Commande de privileges
|
|
* @param string $companyId
|
|
* Siren
|
|
* @param string $doc
|
|
* Type de privilege (privsecu, privtres, nantfond, declcrea)
|
|
* @throws SoapFault
|
|
* @return mixed
|
|
*/
|
|
public function setPrivileges($companyId, $doc = null)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('privileges');
|
|
|
|
$inseeM = new Metier_Insee_MInsee();
|
|
$result = $inseeM->getIdentiteLight($companyId);
|
|
$companyName = $result['Nom'];
|
|
|
|
$refCommande = uniqid();
|
|
|
|
try {
|
|
$data = array(
|
|
'refCommande' => $refCommande,
|
|
'docType' => $doc,
|
|
'companyId' => $companyId,
|
|
'companyName' => $companyName,
|
|
'userId' => $this->User->id,
|
|
'userLogin' => $this->User->login,
|
|
'userEmail' => $this->User->email,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
$result = $this->conn->insert('sdv1.order_privileges', $data);
|
|
if ($result) {
|
|
return $refCommande;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Défini un email pour la commande de privilege
|
|
* @param string $id
|
|
* @param string $email
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setPrivilegesEmail($id, $email)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
if ( !$validator->isValid($email) ){
|
|
throw new SoapFault('ERR', "Adresse email invalide.");
|
|
}
|
|
|
|
try {
|
|
$sql = "SELECT * FROM sdv1.order_privileges WHERE login = :login AND refCommande = :id";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bindValue('login', $this->User->login);
|
|
$stmt->bindValue('id', $id);
|
|
$stmt->execute();
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
if ( is_int($email) ) {
|
|
//Id of secondary email
|
|
}
|
|
else {
|
|
$dataUpdate = array('email' => $email);
|
|
try {
|
|
$result = $this->conn->update('sdv1.order_privileges', $dataUpdate,
|
|
array('refCommande' => $id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
}
|
|
catch (\Doctrine\DBAL\DBALException $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} |