1170 lines
36 KiB
PHP
Raw Normal View History

2013-11-05 11:18:30 +00:00
<?php
require_once 'framework/fwk.php';
require_once 'Metier/insee/classMInsee.php';
require_once 'Metier/insee/classMSirene.php';
require_once 'Metier/partenaires/classMBilans.php';
require_once 'Metier/partenaires/classMBourse.php';
require_once 'Metier/partenaires/classMTva.php';
require_once 'Metier/partenaires/classMMap.php';
require_once 'Metier/partenaires/classMGreffes.php';
require_once 'Metier/partenaires/classMPrivileges.php';
require_once 'Metier/scores/classMFinancier.php';
require_once 'Metier/scores/classMSolvabilite.php';
require_once __DIR__ . '/Types.php';
2013-11-05 11:18:30 +00:00
2014-05-24 09:12:09 +00:00
class Pieces extends Scores_Ws_Server
2013-11-05 11:18:30 +00:00
{
/**
* Récupération d'un kbis
* @param string $siren
* SIREN ou SIRET siege
2014-02-13 14:17:20 +00:00
* @param string $diffusion
* Mode de diffusion (T=Téléchargement|M=Email|C=Courrier)
2014-02-13 14:17:20 +00:00
* @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');
2014-08-18 09:39:57 +00:00
$siren = substr($siren, 0, 9);
2013-11-05 11:18:30 +00:00
//Vérification du siren
if ( intval($siren)==0 ) {
2013-11-05 11:18:30 +00:00
$this->sendError('1010');
2014-08-18 09:39:57 +00:00
} elseif ( strlen($siren)!=9 ) {
2013-11-05 11:18:30 +00:00
$this->sendError('1020');
}
if ( empty($diffusion) ) {
$diffusion = 'T';
}
$iInsee = new MInsee();
$identite = $iInsee->getIdentiteLight($siren);
$refCommande = uniqid();
$commandeM = new Application_Model_Sdv1GreffeCommandesKb();
try {
$id = $commandeM->insert(array(
'refCommande' => $refCommande,
'login' => $this->User->login,
'email' => $this->User->email,
'refClient' => $reference,
'mode' => $diffusion,
'siren' => $siren,
'raisonSociale' => $identite['Nom'],
'dateInsert' => date('YmdHis'),
2015-07-06 14:03:16 +00:00
'dateCommande' => date('YmdHis'),
));
} catch (Zend_Db_Exception $e) {
}
2014-02-13 14:17:20 +00:00
switch ( $diffusion ) {
2014-08-18 09:39:57 +00:00
//Demande de KBIS par email
case 'M':
//Demande de KBIS original par courrier
2014-02-13 14:17:20 +00:00
case 'C':
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-08-18 09:39:57 +00:00
//Téléchargement du KBIS (payant)
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));
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
2015-07-06 14:03:16 +00:00
return $hostname.'/fichier/kbis/'.basename($filepdf);
2014-02-13 14:17:20 +00:00
} 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'];
2014-02-13 14:17:20 +00:00
//Téléchargement du KBIS
$result = array();
exec('php '.$c->profil->path->batch.'/getKbis.php --siren '.$siren, $result);
2014-02-13 14:17:20 +00:00
$result = end($result);
if (substr($result,-5)=='.html')
{
$file = $dir.'/'.$result;
2014-02-13 14:17:20 +00:00
$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 Scores_Wkhtml_Pdf();
$fileOut = $pdf->exec($file, $filepdf);
if ( !file_exists($filepdf) ) {
throw new SoapFault('0000',"Fichier PDF introuvable");
}
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
2015-07-06 14:03:16 +00:00
return $hostname.'/fichier/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) {
2015-07-06 14:03:16 +00:00
$filename = basename($item->pdfLink);
$c = Zend_Registry::get('config');
$file = $c->profil->path->secure.'/association/bilans/' . $filename;
2013-11-05 11:18:30 +00:00
$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
{
$infogreffe = new SdMetier_Infogreffe_DocBI($identifiant);
2014-02-25 16:33:07 +00:00
try {
$list = $infogreffe->getList();
} catch (Exception $e) {
if ($this->User->idClient==1) {
2014-02-25 16:33:07 +00:00
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'));
if ( $item->Type == 'consolides' ) {
$sql->where('typeBilan = "C"');
} elseif ( $item->Type == 'sociaux' ) {
$sql->where('typeBilan="N" OR typeBilan="S"');
}
2014-02-07 16:14:36 +00:00
$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);
}
//Override SaisieDate
if ( $row === null ) {
//Reset greffe_bilans : duree_exercice, saisie_date, saisie_code, ctrl_code, pages
if ( $item->SaisieDate !== null ) {
try {
$bilansM = new Application_Model_JoGreffesBilans();
$bilansM->update(array(
'duree_exercice' => null,
'saisie_date' => null,
'saisie_code' => null,
'ctrl_code' => null,
'pages' => null,
), array('siren='.$identifiant, 'num_depot='.$item->NumDepot) );
} catch (Zend_Db_Exception $e) {
file_put_contents('debug.log', $e->getMessage()."\n", FILE_APPEND);
}
}
$item->DureeExercice = null;
$item->SaisieDate = null;
$item->SaisieCode = null;
} else {
2014-02-07 16:14:36 +00:00
$item->DureeExercice = $row->dureeExercice;
$item->SaisieDate = substr($row->dateProvPartenaire,0,4).'-'.
substr($row->dateProvPartenaire,4,2).'-'.
substr($row->dateProvPartenaire,6,2);
2014-02-07 16:14:36 +00:00
$item->SaisieCode = '00';
//@todo : Améliorer le label de retour - partenaire de saisie
//$item->SaisieLabel = '';
}
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';
}
}
}
}
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 = $c->profil->path->files . '/' . $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->User->login,
'email' => $this->User->email,
2014-02-07 16:14:36 +00:00
'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
$infogreffe = new SdMetier_Infogreffe_DocBI($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);
2014-03-24 16:02:28 +00:00
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
2014-02-07 16:14:36 +00:00
} catch (Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
2014-07-10 07:20:29 +00:00
if ( $e->getCode() == $infogreffe::INT ) {
throw new SoapFault('ERR', "Erreur lors de la commande auprès de notre prestataire.");
}
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 = $c->profil->path->files . '/' . 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));
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' ) {
$infogreffe = new SdMetier_Infogreffe_DocBI($identifiant);
2014-02-07 16:14:36 +00:00
try {
$infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id);
2014-03-24 16:02:28 +00:00
$commandeM->update(array('dateCommande'=> date('YmdHis')), 'id='.$id);
2014-02-07 16:14:36 +00:00
$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');
}
$infogreffe = new SdMetier_Infogreffe_DocAC($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'];
}
}
}
}
$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->User->login,
'email' => $this->User->email,
2014-02-07 16:14:36 +00:00
'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
$infogreffe = new SdMetier_Infogreffe_DocAC($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);
2014-07-10 07:20:29 +00:00
if ( $e->getCode() == $infogreffe::INT ) {
throw new SoapFault('ERR', "Erreur lors de la commande auprès de notre prestataire.");
}
2014-02-07 16:14:36 +00:00
}
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 = $c->profil->path->files . '/' . 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-06-04 09:35:29 +00:00
$this->wsLog('greffe_actes', $identifiant, basename($dest));
2014-02-25 16:33:07 +00:00
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
}
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
$infogreffe = new SdMetier_Infogreffe_DocAC($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;
}
2014-05-24 09:02:11 +00:00
/**
* 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.");
}
$commandeM = new Application_Model_Sdv1GreffeCommandesAc();
$sql = $commandeM->select()
->where('login=?', $this->User->login)
2014-05-24 09:02:11 +00:00
->where('refCommande=?', $id);
try {
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result !== null ) {
if ( is_int($email) ) {
//Id of secondary email
} else {
$dataUpdate = array('email' => $email);
try {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
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.");
}
$commandeM = new Application_Model_Sdv1GreffeCommandesBi();
2014-05-24 09:02:11 +00:00
$sql = $commandeM->select()
->where('login=?', $this->User->login)
2014-05-24 09:02:11 +00:00
->where('refCommande=?', $id);
try {
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result !== null ) {
if ( is_int($email) ) {
//Id of secondary email
} else {
$dataUpdate = array('email' => $email);
2014-05-24 09:02:11 +00:00
try {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
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.");
}
$commandeM = new Application_Model_Sdv1GreffeCommandesKb();
2014-05-24 09:02:11 +00:00
$sql = $commandeM->select()
->where('login=?', $this->User->login)
2014-05-24 09:02:11 +00:00
->where('refCommande=?', $id);
try {
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result !== null ) {
if ( is_int($email) ) {
//Id of secondary email
} else {
$dataUpdate = array('email' => $email);
2014-05-24 09:02:11 +00:00
try {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
2014-05-24 09:02:11 +00:00
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');
$commandeM = new Application_Model_Sdv1GreffeCommandesKb();
$sql = $commandeM->select()
->where('login=?', $this->User->login)
->where('refCommande=?', $id);
try {
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result !== null ) {
$dataUpdate = array('infos' => $infos);
try {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
}
return false;
}
2015-06-05 15:29:18 +00:00
/**
* 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
$statutM = new Application_Model_JoAssoStatut();
$statutSql = $statutM->select()->where('companyId=?', $companyId);
$statutResult = $statutM->fetchAll($statutSql);
$output = array();
if (count($statutResult) > 0) {
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
2015-09-16 15:45:44 +00:00
* 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
2015-09-16 15:45:44 +00:00
try {
$statutM = new Application_Model_JoAssoStatut();
$statutSql = $statutM->select()
->where('companyId=?', $companyId)
->where('statutDate=?', $date);
$statutResult = $statutM->fetchRow($statutSql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ($statutResult === null) {
return false;
}
// --- Distribuer le fichier
if ( !empty($statutResult->statutFile) ) {
$c = Zend_Registry::get('config');
$file = $c->profil->path->secure.'/association/actes/' . $statutResult->statutFile;
$dest = $c->profil->path->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');
2015-06-05 15:29:18 +00:00
$inseeM = new MInsee();
if ($type == 'siren') {
$result = $inseeM->getIdentiteLight($companyId);
$companyName = $result['Nom'];
} elseif ($type == 'waldec') {
$result = $inseeM->getEtablissementsParId('AUTRE', $companyId);
$companyName = $result['Nom'];
}
2015-06-05 15:29:18 +00:00
$refCommande = uniqid();
2015-06-05 15:29:18 +00:00
try {
$commandeM = new Application_Model_Sdv1OrderAssoStatut();
$commandeM->insert(array(
'refCommande' => $refCommande,
'companyId' => $companyId,
'typeId' => $type,
'companyName' => $companyName,
'userId' => $this->User->id,
'userLogin' => $this->User->login,
2015-06-05 15:29:18 +00:00
'userEmail' => $this->User->email,
'dateInsert' => date('YmdHis'),
));
return $refCommande;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
2015-06-05 15:29:18 +00:00
return false;
}
2015-06-05 15:29:18 +00:00
/**
* 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();
2015-04-03 11:56:47 +00:00
$this->permission('actes');
2015-06-05 15:29:18 +00:00
// --- Vérification que la commande existe
try {
$commandeM = new Application_Model_Sdv1OrderAssoStatut();
$sql = $commandeM->select()
->where('userLogin=?', $this->User->login)
->where('refCommande=?', $id);
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
2015-06-05 15:29:18 +00:00
// --- 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 {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
}
2015-06-05 15:29:18 +00:00
return false;
}
2015-06-05 15:29:18 +00:00
/**
* 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();
2015-04-03 11:56:47 +00:00
$this->permission('privileges');
2015-06-05 15:29:18 +00:00
$inseeM = new MInsee();
$result = $inseeM->getIdentiteLight($companyId);
$companyName = $result['Nom'];
2015-06-05 15:29:18 +00:00
$refCommande = uniqid();
2015-06-05 15:29:18 +00:00
try {
$commandeM = new Application_Model_Sdv1OrderPrivileges();
$commandeM->insert(array(
'refCommande' => $refCommande,
'docType' => $doc,
'companyId' => $companyId,
'companyName' => $companyName,
'userId' => $this->User->id,
'userLogin' => $this->User->login,
2015-04-03 11:56:47 +00:00
'userEmail' => $this->User->email,
'dateInsert' => date('YmdHis'),
));
return $refCommande;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
2015-06-05 15:29:18 +00:00
return false;
}
2015-06-05 15:29:18 +00:00
/**
* 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();
2015-06-05 15:29:18 +00:00
$validator = new Zend_Validate_EmailAddress();
if ( !$validator->isValid($email) ){
throw new SoapFault('ERR', "Adresse email invalide.");
}
2015-06-05 15:29:18 +00:00
$commandeM = new Application_Model_Sdv1OrderPrivileges();
$sql = $commandeM->select()
->where('login=?', $this->User->login)
->where('refCommande=?', $id);
try {
$result = $commandeM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient==1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result !== null ) {
if ( is_int($email) ) {
//Id of secondary email
} else {
$dataUpdate = array('email' => $email);
try {
$commandeM->update($dataUpdate, "refCommande='".$id."'");
return true;
} catch (Zend_Db_Exception $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
}
}
return false;
}
2015-06-05 15:29:18 +00:00
2013-11-05 11:18:30 +00:00
}