962 lines
30 KiB
PHP

<?php
require_once 'framework/fwk.php';
require_once 'framework/mail/sendMail.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';
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 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'),
));
} catch (Zend_Db_Exception $e) {
}
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->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);
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) ) {
$identifiant = $identite['Siret'];
//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");
}
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
return $hostname.DOC_WEB_URL.'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 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);
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 = 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"');
}
$row = $liasseM->fetchRow($sql);
} catch (Zend_Db_Exception $e) {
//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 {
$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 = '';
}
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';
}
}
}
}
}
$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->secure . '/association/bilans/' . $filename;
$dest = $c->profil->path->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 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,
'refClient' => $reference,
'mode' => $diffusion,
'siren' => $identifiant,
'raisonSociale' => $identite['Nom'],
'bilanCloture' => $dateCloture,
'bilanType' => $type,
'dateInsert' => date('YmdHis'),
));
switch ( $diffusion ) {
case 'T':
//Passer la commande chez infogreffe
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
//$infogreffe->debug = true;
try {
$pdf = $infogreffe->getCommandeT($dateCloture, $type, $id);
$commandeM->update(array('dateEnvoi'=> date('YmdHis')), 'id='.$id);
} catch (Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
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 = $c->profil->infogreffe->storage->path . '/' . $pdf;
$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); // @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' ) {
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
try {
$infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id);
$commandeM->update(array('dateCommande'=> date('YmdHis')), 'id='.$id);
$this->wsLog('greffe_bilans', $identifiant, $refCommande);
} catch(Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
}
}
$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 MInsee();
$identite = $iInsee->getIdentiteLight($identifiant);
if (empty($identite['id'])){
$this->sendError('1020');
}
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
$list = $infogreffe->getList();
$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'];
}
}
}
//@todo : Marquer les éléments en commande courrier si déjà commandé ModeDiffusion = O
}
$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 = '';
//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,
'refClient' => $reference,
'siren' => $identifiant,
'mode' => $diffusion,
'raisonSociale' => $identite['Nom'],
'depotNum' => $depotNum,
'depotDate' => $depotDate,
'acteType' => $acteType,
'acteDate' => $acteDate,
'acteNum' => $acteNum,
'dateInsert' => date('YmdHis'),
));
switch ( $diffusion ) {
case 'T':
//Passer la commande chez Infogreffe
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
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);
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 = $c->profil->infogreffe->storage->path . '/' . $pdf;
$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('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
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
try {
$infogreffe->getCommandeC($depotDate, $depotNum, $acteType, $acteDate, $acteNum, 'G-AC-'.$id);
$commandeM->update(array('dateCommande'=> date('YmdHis')), 'id='.$id);
$this->wsLog('greffe_actes', $identifiant, $refCommande);
} catch(Exception $e) {
$commandeM->update(array('cmdError'=> $e->getMessage()), 'id='.$id);
}
}
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.");
}
$commandeM = new Application_Model_Sdv1GreffeCommandesAc();
$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;
}
/**
* 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();
$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 {
$dateUpdate = 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;
}
/**
* 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();
$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 {
$dateUpdate = 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;
}
/**
* 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 ) {
$dateUpdate = 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;
}
/**
* Financial account : Place an order to have number enter in database
* @param string $siren
* @param string $date
* @param string $type N:Normal, S:Simplifié, C:Consolidé
* @param string $source
* @param integer $private
* @throws SoapFault
* @return string
*/
public function setBilanEnterCmd($siren, $date, $type, $source, $private = 0)
{
$this->authenticate();
$this->permission('UPLOADBILAN');
//Check siren
$refCommande = uniqid();
$data = array(
'refCommande' => $refCommande,
'siren' => $siren,
'userId' => $this->User->id,
'bilanConfidentiel' => $private,
'bilanSource' => $source,
'bilanCloture' => $date,
'bilanType' => $type,
'dateInsert' => date('YmdHis'),
);
try {
$commandeM = new Application_Model_Sdv1BilanCommandeEnter();
$commandeM->insert($data);
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");
}
}
}
/**
* Financial account : Tag file is sent
* @param string $ref
* @throws SoapFault
* @return boolean
*/
public function setBilanEnterFile($ref)
{
$this->authenticate();
$this->permission('UPLOADBILAN');
$data = array(
'bilanFileSent' => date('YmdHis'),
);
try {
$commandeM = new Application_Model_Sdv1BilanCommandeEnter();
$commandeM->update($data, "refCommande=$ref");
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;
}
}