Michael RICOIS 2be85368b2 forward
2016-10-12 15:45:40 +02:00

1256 lines
46 KiB
PHP

<?php
class PiecesController extends Zend_Controller_Action
{
protected $theme;
protected $association_cj = array(
'9150', // Association syndicale libre
'9220', // Association déclarée
'9221', // Association déclarée "entreprises d'insertion par l'économique"
'9222', // Association intermédiaire
'9223', // Groupement d'employeurs
'9230', // Association déclarée reconnue d'utilité publique
'9240', // Congrégation
'9260', // Association de droit local
'9300', // Fondation
);
protected $siret;
protected $id;
public function init()
{
// --- Theme
$this->theme = Zend_Registry::get('theme');
require_once 'Scores/WsScores.php';
$request = $this->getRequest();
$this->siret = $request->getParam('siret');
$this->id = $request->getParam('id', 0);
}
public function indexAction(){}
/**
* Commande de status association
*/
public function cmdassociationAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
if ($request->isPost()) {
$siren = $request->getParam('siren');
$ws = new Scores_Ws_Client('pieces', '0.1');
$parameters = new stdClass();
$parameters->companyId = $siren;
$parameters->type = 'siren';
$result = $ws->setAssoStatut($parameters);
if ($result === false) {
$this->view->msg = "Erreur lors de l'enregistrement des informations";
} else {
$this->view->ref = strtoupper($result);
}
} else {
$user = new Scores_Utilisateur();
$this->view->UserEmail = $user->getEmail();
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->siren = substr($this->siret, 0,9);
$this->view->siret = $this->siret;
$this->view->id = $this->id;
$this->view->raisonSociale = $session->getRaisonSociale();
}
}
/**
* Commande de privilege
*/
public function privilegeAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$type = $request->getParam('type');
$siren = $request->getParam('siren');
if ($request->isPost()) {
try {
$ws = new Scores_Ws_Client('pieces', '0.1');
$parameters = new stdClass();
$parameters->companyId = $siren;
$parameters->doc = $type;
$result = $ws->setPrivileges($parameters);
if ($result === false) {
$this->view->msg = "Erreur lors de l'enregistrement des informations";
} else {
$this->view->ref = strtoupper($result);
}
} catch (Exception $e) {
$this->view->msg = $e->getMessage();
}
} else {
$this->view->type = $type;
$user = new Scores_Utilisateur();
$this->view->UserEmail = $user->getEmail();
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->siren = $siren;
$this->view->raisonSociale = $session->getRaisonSociale();
}
}
/**
* Affichage liste d'actes infogreffe
*/
public function actesAction()
{
$this->view->headScript()->appendFile($this->theme->pathScript.'/pieces.js', 'text/javascript');
$user = new Scores_Utilisateur();
$session = new Scores_Session_Entreprise($this->siret, $this->id);
//Catégorie Juridique
$cj = $session->getFormeJuridique();
if( in_array($cj, $this->association_cj) ) {
$this->_forward('associationactes');
}
$request = $this->getRequest();
$siren = substr($this->siret,0,9);
//Affichage des actes disponible
$ws = new WsScores();
$responses = $ws->getPiecesActes($siren);
Zend_Registry::get('firebug')->info($responses);
/*
* Construire la réponse pour affichage
* Date, Type, Décisions,
*/
$infosActes = array();
if ( $responses->nbReponses > 0 ) {
$items = $responses->result->item;
//Traitement des actes normaux
$infosActe = array();
foreach($items as $item) {
if ($item->ActeDate == '0000-00-00') {
$date = new Zend_Date($item->DepotDate, 'yyyy-MM-dd');
$infosActe['date'] = $date->toString('dd/MM/yyyy');
} else {
$date = new Zend_Date($item->ActeDate, 'yyyy-MM-dd');
$infosActe['date'] = $date->toString('dd/MM/yyyy');
}
$infosActe['isFileExist'] = false;
if ($item->File != '') {
$infosActe['isFileExist'] = true;
}
$infosActe['mode'] = $item->ModeDiffusion;
$infosActe['lib'] = $item->ActeTypeLabel;
switch($item->ModeDiffusion) {
case 'T':
if ( $user->checkPerm('actes') ) {
$href = $this->view->url(array(
'controller' => 'pieces',
'action' => 'acte',
'mode' => 'T',
'siren' => $siren,
'depotNum' => $item->DepotNum,
'depotDate' => $item->DepotDate,
'acteLabel' => $item->ActeTypeLabel,
'acteType' => $item->ActeType,
'acteNum' => $item->ActeNum,
'acteDate' => $item->ActeDate,
), 'default', true);
$title = "Télécharger le document correspondant";
} else {
$href = '#';
$title = "Vous n'avez pas les droits nécessaires pour commander le document correspondant.";
}
break;
case 'C':
if ( $user->checkPerm('actes') ) {
$href = $this->view->url(array(
'controller' => 'pieces',
'action' => 'acte',
'mode' => 'C',
'siren' => $siren,
'depotNum' => $item->DepotNum,
'depotDate' => $item->DepotDate,
'acteLabel' => $item->ActeTypeLabel,
'acteType' => $item->ActeType,
'acteNum' => $item->ActeNum,
'acteDate' => $item->ActeDate,
), 'default', true);
$title = "Commande d'une pièce officielle";
} else {
$href = '#';
$title = "Vous n'avez pas les droits nécessaires pour commander le document correspondant.";
}
break;
}
$infosActe['factice'] = $this->view->url(array(
'controller' => 'pieces',
'action' => 'acte',
'mode' => 'F',
'siren' => $siren,
'depotNum' => $item->DepotNum,
'depotDate' => $item->DepotDate,
'acteLabel' => $item->ActeTypeLabel,
'acteType' => $item->ActeType,
'acteNum' => $item->ActeNum,
'acteDate' => $item->ActeDate,
), 'default', true);
$infosActe['href'] = $href;
$infosActe['title'] = $title;
$data = '';
if( intval($item->DepotNum)>=0 ) {
$date = new Zend_Date($item->DepotDate, 'yyyy-MM-dd');
$data.= '<b>Dépot n°'.$item->DepotNum.' du '.$date->toString('dd/MM/yyyy').'</b>';
//Nombre de pages
$nbPage = 0;
if ( $item->FileNumberOfPages > 0 ) {
$nbPage = $item->FileNumberOfPages;
} elseif ( $item->ActeNumberOfPages > 0 ) {
$nbPage = $item->ActeNumberOfPages;
}
if( $nbPage > 1 ) {
$data.= '<br/>Document de '.$nbPage.' pages.';
} elseif( $nbPage == 1 ) {
$data.= '<br/>Document de '.$nbPage.' page.';
}
//Informations
if ( count($item->infos->item) > 0 ) {
foreach($item->infos->item as $txt) {
$data.= '<br/>'.$txt;
}
}
//@todo
if(!empty($acte['decision'])){
$data.= '<br/>'.$acte['decision'];
}
}
$infosActe['decision'] = $data;
$infosActes[] = $infosActe;
} // Fin acte
}
$this->view->assign('ModeEdition', $user->checkModeEdition());
$this->view->assign('InfosActes', $infosActes);
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
$this->view->assign('surveillance', $user->checkPerm('survbilan'));
}
/**
* Affichage liste de bilans infogreffe
*/
public function bilansAction()
{
$user = new Scores_Utilisateur();
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->headScript()->appendFile($this->theme->pathScript.'/pieces.js', 'text/javascript');
//Catégorie Juridique
$cj = $session->getFormeJuridique();
if( in_array($cj, $this->association_cj) ) {
$this->forward('associationbilans');
} else {
$request = $this->getRequest();
$siren = substr($this->siret,0,9);
//Affichage des bilans disponible
$ws = new WsScores();
$response = $ws->getPiecesBilans($siren);
$infosBilans = array();
if ( $response->nbReponses > 0 ) {
$items = $response->result->item;
foreach($items as $key => $item)
{
$infosBilan = array();
$date = new Zend_Date($item->DateCloture, 'yyyy-MM-dd');
$infosBilan['date'] = $date->toString('dd/MM/yyyy');
$infosBilan['dateIso'] = $date->toString('yyyy-MM-dd');
$infosBilan['type'] = 'Comptes '.$item->Type.' millésime '.$item->Millesime;
$infosBilan['typeCode'] = $item->Type;
$infosBilan['mode'] = $item->ModeDiffusion;
$infosBilan['isFileExist'] = false;
if ($item->File != '') {
$infosBilan['isFileExist'] = true;
}
switch($item->ModeDiffusion) {
case 'T':
if ( $user->checkPerm('actes') ) {
$href = $this->view->url(array(
'controller' => 'pieces',
'action' => 'bilan',
'siren' => $siren,
'mode' => 'T',
'type' => $item->Type,
'cloture' => $item->DateCloture,
), 'default', true);
$title = 'Télécharger le document correspondant';
} else {
$href = '#';
$title = 'Vous n\'avez pas les droits nécessaires pour commander le document correspondant.';
}
break;
case 'C':
if ( $user->checkPerm('actes') ) {
$href = $this->view->url(array(
'controller' => 'pieces',
'action' => 'bilan',
'siren' => $siren,
'mode' => 'C',
'type' => $item->Type,
'cloture' => $item->DateCloture,
), 'default', true);
$title = 'Recevoir le document directement par mail (sous 3/5 jours ouvrés)';
} else {
$href = '#';
$title = 'Vous n\'avez pas les droits nécessaires pour commander le document correspondant.';
}
break;
}
$infosBilan['factice'] = $this->view->url(array(
'controller' => 'pieces',
'action' => 'bilan',
'siren' => $siren,
'mode' => 'T',
'type' => $item->Type,
'cloture' => $item->DateCloture,
), 'default', true);
$infosBilan['href'] = $href;
$infosBilan['title'] = $title;
$infosBilan['duree'] = '';
if (intval($item->DureeExercice)>0) {
$infosBilan['duree'] = "Exercice sur ".$item->DureeExercice." mois";
}
$infosBilan['decision'] = 'Dépot n°'.$item->NumDepot;
if( !empty($item->File) && $item->NumberOfPages>0 ) {
$infosBilan['decision'].= "<br/>Document de ".$item->NumberOfPages." pages";
}
$infosBilan['isEnter'] = 0;
if ( empty($item->SaisieDate) || $item->SaisiDate=='0000-00-00' ) {
$infosBilan['saisie'] = "Bilan non saisi.";
} else if ( $item->SaisieCode == '00' ) {
$date = new Zend_Date($item->SaisieDate, 'yyyy-MM-dd');
$infosBilan['saisie'] = "Bilan saisi le ".$date->toString('dd/MM/yyyy').".";
if ( !empty($item->SaisieLabel) ) {
$infosBilan['saisie'].= '<img class="ui-icon ui-icon-info" style="float:right;" title="'.$item->SaisieLabel.'">';
}
$infosBilan['isEnter'] = 1;
} else {
$date = new Zend_Date($item->SaisieDate, 'yyyy-MM-dd');
$infosBilan['saisie'] = "Bilan non saisi le ".$date->toString('dd/MM/yyyy').".";
if ( !empty($item->SaisieLabel) ) {
$infosBilan['saisie'].= '<img class="ui-icon ui-icon-info" style="float:right;" title="'.$item->SaisieLabel.'">';
}
}
$infosBilans[] = $infosBilan;
}
}
$this->view->assign('ModeEdition', $user->checkModeEdition());
$this->view->assign('InfosBilans', $infosBilans);
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
$this->view->assign('surveillance', $user->checkPerm('survactes'));
}
}
/**
* Commande de saisie d'un bilan
* Boite de dialog
*/
public function bilanenterAction()
{
$request = $this->getRequest();
if ( $request->isXmlHttpRequest() ) {
$this->_helper->layout()->disableLayout();
}
$user = new Scores_Utilisateur();
$this->view->assign('isAuthorize', $user->checkPerm('UPLOADBILAN'));
$siren = $request->getParam('siren');
$date = $request->getParam('date');
$type = $request->getParam('type');
if ( $request->isPost() ) {
$ws = new Scores_Ws_Client('order', '0.1');
$parameters = new stdClass();
$parameters->siren = $siren;
$parameters->date = $date;
$parameters->type = $type;
$parameters->source = 'infogreffe';
$parameters->private = 0;
$result = $ws->setBilanInput($parameters);
if ($result === false) {
$this->view->msg = "Erreur lors du passage de la commande";
} else {
$this->view->msg = "Commande enregistré sous la référence ".strtoupper($result);
}
} else {
$this->view->assign('form', 'display');
$this->view->assign('siren', $siren);
$this->view->assign('date', $date);
if ($type == 'sociaux') {
$type = 'N';
}
if ( $type == 'consolides' ) {
$type = 'C';
}
$this->view->assign('type', $type);
}
}
/**
* Commande de bilan
*/
public function bilanAction()
{
//Désactivation affichage
$this->_helper->layout()->disableLayout();
$user = new Scores_Utilisateur();
if (!$user->checkPerm('ACTES')){
$this->_forward('perms', 'error');
}
$request = $this->getRequest();
$siren = $request->getParam('siren');
$this->view->assign('siren', $siren);
$mode = $request->getParam('mode');
$dateCloture = $request->getParam('cloture');
$type = $request->getParam('type');
$ws = new WsScores();
switch ($mode) {
case 'F':
$response = $ws->getPiecesBilan($siren, $type, $mode, $dateCloture, $ref);
if ($response===false) {
$this->view->assign('msg', "Erreur lors du passage de la commande.");
} else {
$this->view->assign('msg', "Enregistrement de votre commande sous la référence".$response.".");
}
break;
//Télécharger le fichier
case 'T':
$response = $ws->getPiecesBilan($siren, $type, $mode, $dateCloture);
if ( $response === false || $response == '' ) {
$this->view->assign('msg', "Fichier introuvable.");
} else {
try {
$client = new Zend_Http_Client($response);
$client->setStream();
$stream = $client->request('GET');
if ( $stream->isSuccessful() && substr($stream->getBody(),0,4)=='%PDF' ) {
$c = Zend_Registry::get('config');
$file = 'bilan-'.$siren.'-'.$type.'-'.$dateCloture.'.pdf';
if (copy($stream->getStreamName(), $c->profil->path->shared . '/temp/files/' . $file)) {
$this->view->assign('url', $this->view->url(array('module'=>'file',
'controller'=>'greffe', 'action'=>'bilan', 'q'=>$file), 'default', true));
} else {
$this->view->assign('msg', "Impossible de distribuer le fichier.");
}
} else {
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('firebug')->info('HTTP Exception : '.$e->getMessage());
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
}
break;
//Passer commande
case 'C':
$ref = $request->getParam('ref');
if ( $request->isXmlHttpRequest() ) {
//Enregistrement de la commande
if ( $request->isPost() ) {
$response = $ws->getPiecesBilan($siren, $type, $mode, $dateCloture, $ref);
if ($response===false) {
$this->view->assign('msg', "Erreur lors du passage de la commande.");
} else {
$this->view->assign('formEmail', true);
$this->view->assign('refCommande', $response);
$this->view->assign('msg',"Enregistrement de votre commande sous la référence ".strtoupper($response).".");
}
}
//Affichage du formulaire
else {
$user = new Scores_Utilisateur();
$email = explode(';',$user->getEmail());
$this->view->assign('email', $email[0]);
$validator = new Zend_Validate_EmailAddress();
$this->view->assign('emailValide', $validator->isValid($email[0]));
$this->view->assign('formCmd', true);
$this->view->assign('mode', $mode);
$date = new Zend_Date($dateCloture, 'yyyy-MM-dd');
$this->view->assign('LabelCloture', $date->toString('dd/MM/yyyy'));
$this->view->assign('cloture', $dateCloture);
$this->view->assign('type', $type);
}
}
break;
//Saisir email
case 'EMAIL':
if ( $request->isXmlHttpRequest() ) {
if ( $request->isPost() ) {
$id = $request->getParam('refCommande');
$email = trim($request->getParam('email'));
if ( !empty($email) ) {
$response = $ws->setPiecesBilanCmdEmail($id, $email);
if ( $response === false ) {
$this->view->assign('msg', "Impossible d'enregistrer un email pour la commande ".strtoupper($id).".");
} else {
$this->view->assign('msg', "Email ".$email." enregistré pour la commande ".strtoupper($id).".");
}
} else {
$this->view->assign('msg', "Email incorrect.");
}
}
}
break;
}
}
/**
* Commande d'acte
*/
public function acteAction()
{
//Désactivation affichage
$this->_helper->layout()->disableLayout();
$user = new Scores_Utilisateur();
if (!$user->checkPerm('ACTES')){
$this->_forward('perms', 'error');
}
$request = $this->getRequest();
$siren = $request->getParam('siren');
$this->view->assign('siren', $siren);
$mode = $request->getParam('mode');
$depotNum = $request->getParam('depotNum');
$depotDate = $request->getParam('depotDate');
$acteType = $request->getParam('acteType');
$acteNum = $request->getParam('acteNum');
$acteDate = $request->getParam('acteDate');
$ws = new WsScores();
switch ($mode) {
//Commande factice
case 'F':
//Enregistrement de la commande
$response = $ws->getPiecesActe($siren, $mode, $depotNum, $depotDate, $acteType, $acteNum, $acteDate, $ref);
if ($response===false) {
$this->view->assign('msg',"Erreur lors du passage de la commande.");
} else {
$this->view->assign('msg',"Enregistrement de votre commande sous la référence ".strtoupper($response).".");
}
break;
//Télécharger le fichier
case 'T':
$response = $ws->getPiecesActe($siren, $mode, $depotNum, $depotDate, $acteType, $acteNum, $acteDate);
if ( $response === false || $response == '' ) {
$this->view->assign('msg', "Fichier introuvable.");
} else {
try {
$client = new Zend_Http_Client($response);
$client->setStream();
$stream = $client->request('GET');
if ( $stream->isSuccessful() && substr($stream->getBody(),0,4)=='%PDF' ) {
$c = Zend_Registry::get('config');
$file = 'acte-'.$siren.'-'.$depotNum.'-'.$acteNum.'.pdf';
if (copy($stream->getStreamName(), $c->profil->path->shared . '/temp/files/' . $file)) {
$this->view->assign('url', $this->view->url(array('module'=>'file',
'controller'=>'greffe', 'action'=>'acte', 'q'=>$file), 'default', true));
} else {
$this->view->assign('msg', "Impossible de distribuer le fichier.");
}
} else {
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('firebug')->info('HTTP Exception : '.$e->getMessage());
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
}
break;
//Passer commande
case 'C':
$ref = $request->getParam('ref');
$label = $request->getParam('acteLabel');
if ( $request->isXmlHttpRequest() ) {
//Enregistrement de la commande
if ( $request->isPost() ) {
$response = $ws->getPiecesActe($siren, $mode, $depotNum, $depotDate, $acteType, $acteNum, $acteDate, $ref);
if ( $response === false ) {
$this->view->assign('msg', "Erreur lors du passage de la commande.");
} else {
$this->view->assign('formEmail', true);
$this->view->assign('refCommande', $response);
$this->view->assign('msg',"Enregistrement de votre commande sous la référence ".strtoupper($response).".");
}
}
//Affichage du formulaire
else {
$user = new Scores_Utilisateur();
$email = explode(';',$user->getEmail());
$this->view->assign('email', $email[0]);
$validator = new Zend_Validate_EmailAddress();
$this->view->assign('emailValide', $validator->isValid($email[0]));
$this->view->assign('formCmd', true);
$this->view->assign('mode', $mode);
$this->view->assign('depotNum', $depotNum);
$this->view->assign('depotDate', $depotDate);
$date = new Zend_Date($depotDate,'yyyy-MM-dd');
$this->view->assign('LabelDepotDate', $date->toString('dd/MM/yyyy'));
$this->view->assign('Label', $label);
$this->view->assign('acteType', $acteType);
$this->view->assign('acteNum', $acteNum);
$this->view->assign('acteDate', $acteDate);
$date = new Zend_Date($acteDate,'yyyy-MM-dd');
$this->view->assign('LabelActeDate', $date->toString('dd/MM/yyyy'));
}
}
break;
//Saisir email
case 'EMAIL':
if ( $request->isXmlHttpRequest() ) {
if ( $request->isPost() ) {
$id = $request->getParam('refCommande');
$email = trim($request->getParam('email'));
if ( !empty($email) ) {
$response = $ws->setPiecesActeCmdEmail($id, $email);
if ( $response === false ) {
$this->view->assign('msg', "Impossible d'enregistrer un email pour la commande ".strtoupper($id).".");
} else {
$this->view->assign('msg', "Email ".$email." enregistré pour la commande ".strtoupper($id).".");
}
} else {
$this->view->assign('msg', "Email incorrect.");
}
}
}
break;
}
}
/**
* Commande de pièces, kbis, privileges, nantissements
*/
public function commandeAction()
{
$request = $this->getRequest();
$this->view->headScript()->appendFile($this->theme->pathScript.'/pieces.js', 'text/javascript');
$siren = substr($this->siret, 0, 9);
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$user = new Scores_Utilisateur();
$permKbis = false;
$kbisErrCJ = false;
$kbisErrDEP = false;
if ($user->checkPerm('kbis')) {
$permKbis = true;
//Vérification que le kbis est disponible
if ( substr($session->getFormeJuridique(),0,1) == 7
|| substr($session->getFormeJuridique(),0,1) == 8
|| substr($session->getFormeJuridique(),0,1) == 9
|| in_array($session->getFormeJuridique(), array_merge(
array(1300,1500,1600,1700,1800,1900), $this->association_cj) ) ){
$kbisErrCJ = true;
}
//=> Département
$dep = substr($session->getCodeCommune(),0,2);
if ( in_array($dep, array('00','57','67','68','97','98')) ) {
$kbisErrDEP = true;
}
}
$permPriv = false;
if ($user->checkPerm('privileges')){
$permPriv = true;
}
$permSurvPriv = false;
if ($user->checkPerm('survpriv')){
$permSurvPriv = true;
}
$message = '';
$emails = explode(';',$user->getEmail());
$email = $emails[0];
$validator = new Zend_Validate_EmailAddress();
$this->view->assign('emailValid', $validator->isValid($email));
if ($request->isPost() && $request->getParam('op')=='privileges') {
$ref = $request->getParam('ref');
$privileges = $request->getParam('privileges');
$email = $request->getParam('email', '');
if (!empty($email)) {
if ( in_array('SprivSurv',$privileges) ) {
$ws = new WsScores();
$ws->setSurveillance($this->siret, $email, $ref, 'privileges');
$privilegesLog = join('-', $privileges);
}
$key = array_search('SprivSurv', $privileges);
if ($key!==FALSE) unset($privileges[$key]);
if (count($privileges)>0) {
$privilegesJ = join(', ', $privileges);
$privilegesLog = join('-', $privileges);
$mail = new Scores_Mail_Method();
$mail->setFromKey('contact');
$mail->addToKey('support');
$mail->setSubject('[COMMANDE PIECES] - PRIVILEGES par email');
$mail->setBodyText(
'COMMANDE DE PRIVILEGES - par email<br/>'.EOL.
'Demande pour recevoir ('.$privilegesJ.') pour SIREN : '.
'<a href="'.$this->view->url(array('controller'=>'identite', 'action'=>'fiche', 'siret'=> $this->siret), 'default', true).'">'.
$this->siret.'</a><br/>'.EOL.
'pour login '.$user->getLogin().'('.$email.')<br/>'.EOL.
'Référence : '.$ref
);
$mail->execute();
}
$message = 'Votre commande a bien été prise en compte, vous recevrez ces documents sur votre e-mail.';
$ws = new WsScores();
$ws->setLog('privileges', $this->siret, 0, 'mail:'.$privilegesLog);
} else {
$message = '<font color="red">Erreur : adresse email non renseignée.</font>';
$this->view->assign('ref', $ref);
$this->view->assign('privileges', $privileges);
$this->view->assign('email', $email);
}
$this->view->assign('message', $message);
}
$this->view->assign('KbisErreurCJ', $kbisErrCJ);
$this->view->assign('KbisErreurDEP', $kbisErrDEP);
$this->view->assign('permKbis', $permKbis);
$this->view->assign('permKbis', $permKbis);
$this->view->assign('permPriv', $permPriv);
$this->view->assign('permSurvPriv', $permSurvPriv);
$this->view->assign('user', $user);
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
}
/**
* Affichage status association
*/
public function associationactesAction()
{
$user = new Scores_Utilisateur();
$siren = substr($this->siret, 0,9);
$session = new Scores_Session_Entreprise($this->siret, $this->id);
// --- Liste des documents depuis le webservice
$ws = new Scores_Ws_Client('pieces', '0.1');
$params = new stdClass();
$params->companyId = $siren;
$result = $ws->getAssoActes($params);
$actes = array();
Zend_Registry::get('firebug')->info($result);
if (count($result->item) > 0) {
foreach ($result->item as $item) {
Zend_Registry::get('firebug')->info($item);
if ( $user->checkPerm('actes') ) {
$href = $this->view->url(array('controller'=>'pieces', 'action'=>'associationacte',
'siren'=>$siren, 'date'=> $item->Date), 'default', true);
$title = 'Télécharger le document correspondant';
} else {
$href = '#';
$title = "Vous n'avez pas les droits nécessaires pour commander le document correspondant.";
}
$actes[] = array(
'date' => substr($item->Date,8,2).'/'.substr($item->Date,5,2).'/'.substr($item->Date,0,4),
'type' => 'Statut',
'href' => $href,
'title' => $title,
'file' => $item->File,
'decision' => '',
);
}
}
$this->view->assign('actes', $actes);
$this->view->assign('email', $user->getEmail());
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
}
/**
* Enter description here ...
*/
public function associationacteAction()
{
// --- Désactivation affichage
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$siren = $request->getParam('siren');
$date = $request->getParam('date');
// --- Chemin du fichier
$ws = new Scores_Ws_Client('pieces', '0.1');
$params = new stdClass();
$params->companyId = $siren;
$params->type = 'siren';
$params->date = $date;
$result = $ws->getAssoActe($params);
if ($result === false) {
$this->view->assign('msg', "Erreur lors de la demande du fichier");
} else {
// --- Récupération du fichier
if ( !empty($result) ) {
try {
$client = new Zend_Http_Client($result);
$client->setStream();
$stream = $client->request('GET');
if ( $stream->isSuccessful() && substr($stream->getBody(),0,4)=='%PDF' ) {
$c = Zend_Registry::get('config');
$file = 'ST-'.$siren.'-'.$date.'.pdf';
if (copy($stream->getStreamName(), $c->profil->path->shared . '/temp/files/' . $file)) {
$this->view->assign('url', $this->view->url(array('module'=>'file', 'controller'=>'greffe',
'action'=>'association', 'q'=>$file), 'default', true));
} else {
$this->view->assign('msg', "Impossible de distribuer le fichier.");
}
} else {
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('firebug')->info('HTTP Exception : '.$e->getMessage());
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} else {
$this->view->assign('msg', "Fichier indisponible !");
}
}
}
/**
* Enter description here ...
*/
public function associationbilansAction()
{
$user = new Scores_Utilisateur();
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$siren = substr($this->siret,0,9);
$bilans = array();
if ( !empty($siren) || intval($siren)==0 ){
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$reponse = $ws->getPiecesBilans($siren);
$listBilans = $reponse->result->item;
Zend_Registry::get('firebug')->info($listBilans);
$decision = '';
foreach ( $listBilans as $item) {
if ( $user->checkPerm('actes') ) {
if ( !empty($item->File) ) {
$href = $this->view->url(array('controller'=>'pieces', 'action'=>'associationbilan',
'siren'=> $siren, 'dateCloture'=> $item->DateCloture, 'reference'=> $item->File),
'default', true);
$title = 'Télécharger le document correspondant';
} else {
$href = '#';
$title = 'Document inexistant.';
}
} else {
$href = '#';
$title = 'Vous n\'avez pas les droits nécessaires pour commander le document correspondant.';
}
$decision = $item->Type;
if ( !empty($item->NumberOfPages) ) {
$decision.= ', '.$item->NumberOfPages.' pages';
}
$bilans[] = array(
'date' => substr($item->DateCloture,6,2).'/'.substr($item->DateCloture,4,2).'/'.substr($item->DateCloture,0,4),
'type' => 'Bilan '.substr($item->DateCloture,0,4),
'href' => $href,
'title' => $title,
'decision' => $decision,
);
}
}
$this->view->assign('bilans', $bilans);
$this->view->assign('ModeEdition', $user->checkModeEdition());
$this->view->assign('siren', substr($this->siret, 0,9));
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
}
/**
* Bilan association
*/
public function associationbilanAction()
{
//Désactivation affichage
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$siren = $request->getParam('siren');
$diffusion = 'T';
$dateCloture = $request->getParam('dateCloture');
$reference = $request->getParam('reference');
$type = 'association';
//Récupération du l'URL
$ws = new WsScores();
$url = $ws->getPiecesBilan($siren, $type, $diffusion, $dateCloture, $reference);
if ( !empty($url) ) {
try {
$client = new Zend_Http_Client($url);
$client->setStream();
$stream = $client->request('GET');
if ( $stream->isSuccessful() && substr($stream->getBody(),0,4)=='%PDF' ) {
$c = Zend_Registry::get('config');
$file = 'bilan-'.$siren.'-'.$type.'-'.$dateCloture.'.pdf';
if (copy($stream->getStreamName(), $c->profil->path->shared . '/temp/files/' . $file)) {
$this->view->assign('url', $this->view->url(array('module'=>'file', 'controller'=>'greffe',
'action' => 'association', 'q'=>$file), 'default', true));
} else {
$this->view->assign('msg', "Impossible de distribuer le fichier.");
}
} else {
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('firebug')->info('HTTP Exception : '.$e->getMessage());
$this->view->assign('msg', "Erreur lors du téléchargement du fichier.");
}
} else {
$this->view->assign('msg', "Fichier indisponible !");
}
}
/**
* Gestion téléchargement des kbis
*/
public function kbisAction()
{
//Désactivation affichage
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$user = new Scores_Utilisateur();
$session = new Scores_Session_Entreprise($params['siret']);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
$siren = $request->getParam('siren');
$this->view->assign('siren', $siren);
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$mode = $request->getParam('mode');
switch ($mode) {
//Télécharger le fichier
case 'T':
$c = Zend_Registry::get('config');
$path = $c->profil->path->shared. '/temp/files/';
//Le fichier est déjà présent sur le serveur
if ( file_exists($path.'kbis-'.$siren.'.pdf')
&& date('Ymd', filemtime($path.'kbis-'.$siren.'.pdf'))==date('Ymd')
&& filesize($path.'kbis-'.$siren.'.pdf')>2000 ) {
$msg = '<u><a title="Cliquez ici pour visualiser le kbis" target="_blank" href="/file/greffe/kbis/q/kbis-'.$siren.'.pdf">Visualiser le Kbis <img src="/themes/default/images/interfaces/icone_pdf.gif"></a></u>';
$this->view->assign('message', $msg);
$this->view->assign('mode', $mode);
$ws->setLog('kbis', $siren, 0, 'direct');
}
//Téléchargement du fichier
else {
$info = $ws->getKbis($siren, 'T');
if ( substr($info,0,7)=='http://' ) {
//Suppression du fichier si il existe
if(file_exists($path.'kbis-'.$siren.'.pdf')) unlink($path.'kbis-'.$siren.'.pdf');
//On check si le fichier est présent sur l'url
try {
$client = new Zend_Http_Client($info);
$client->setStream();
$response = $client->request('GET');
//Ecriture du fichier sur le serveur en local
if ( $response->isSuccessful() && copy($response->getStreamName(), $path.'kbis-'.$siren.'.pdf') ) {
$msg = '<u><a title="Cliquez ici pour visualiser le kbis" target="_blank" href="/file/greffe/kbis/q/kbis-'.$siren.'.pdf">Visualiser le Kbis <img src="/themes/default/images/interfaces/icone_pdf.gif"></a></u>';
$this->view->assign('message', $msg);
$this->view->assign('mode', $mode);
}
//Fichier non disponible
else {
$this->view->assign('msg',"Impossible de récupérer le fichier");
}
} catch (Zend_Http_Client_Exception $e) {
$this->view->assign('msg',"Impossible de récupérer le fichier");
//echo " - Erreur ".$e->getMessage();
}
} else {
$this->view->assign('msg', $info);
}
}
break;
//Commande par email
case 'M':
$ref = $request->getParam('ref');
if ( $request->isXmlHttpRequest() ) {
//Enregistrement de la commande
if ( $request->isPost() ) {
$response = $ws->getKbis($siren, $mode, $ref);
if ( $response === false ) {
$this->view->assign('msg', "Erreur lors du passage de la commande.");
} else {
$this->view->assign('formEmail', true);
$this->view->assign('refCommande', $response);
$this->view->assign('msg',"Enregistrement de votre commande sous la référence ".strtoupper($response).".");
}
}
//Affichage du formulaire
else {
$email = explode(';',$user->getEmail());
$this->view->assign('email', $email[0]);
$validator = new Zend_Validate_EmailAddress();
$this->view->assign('emailValid', $validator->isValid($email[0]));
$this->view->assign('formCmd', true);
$this->view->assign('mode', $mode);
$this->view->assign('siren', $siren);
}
}
break;
//Commande KBIS original courrier
case 'C':
$ref = $request->getParam('ref');
if ( $request->isXmlHttpRequest() ) {
//Enregistrement de la commande
if ( $request->isPost() ) {
//Vérification des champs
$fields = array('societe', 'nom', 'prenom', 'adresse', 'cp', 'ville');
$params = $request->getParams();
$error = false;
foreach($fields as $field) {
if(empty($params[$field])) $error = true;
}
if(!$error) {
$response = $ws->getKbis($siren, $mode, $ref);
if ( $response === false ) {
$this->view->assign('msg', "Erreur lors du passage de la commande.");
} else {
$this->view->assign('refCommande', $response);
$this->view->assign('msg',"Enregistrement de votre commande sous la référence ".strtoupper($response).".");
}
} else {
$this->view->assign('message','<font color="red">'.$this->view->translate('Erreur : Tous les champs doivent être renseigner.').'</font>');
$this->view->assign('mode', $mode);
$this->view->assign('societe', $params['societe']);
$this->view->assign('nom', $params['nom']);
$this->view->assign('prenom', $params['prenom']);
$this->view->assign('adresse', $params['adresse']);
$this->view->assign('cp', $params['cp']);
$this->view->assign('ville', $params['ville']);
}
}
//Affichage du formulaire
else {
$email = explode(';', $user->getEmail());
$this->view->assign('email', $email[0]);
$this->view->assign('nom', $user->getNom());
$this->view->assign('prenom', $user->getPrenom());
$validator = new Zend_Validate_EmailAddress();
$this->view->assign('emailValid', $validator->isValid($email[0]));
$this->view->assign('formCmd', true);
$this->view->assign('mode', $mode);
}
}
break;
//Saisir email différent
case 'EMAIL':
if ( $request->isXmlHttpRequest() ) {
if ( $request->isPost() ) {
$id = $request->getParam('refCommande');
$email = trim($request->getParam('email'));
if ( !empty($email) ) {
$response = $ws->setPiecesKbisCmdEmail($id, $email);
if ( $response === false ) {
$this->view->assign('msg', "Impossible d'enregistrer un email pour la commande ".strtoupper($id).".");
} else {
$this->view->assign('msg', "Email ".$email." enregistré pour la commande ".strtoupper($id).".");
}
} else {
$this->view->assign('msg', "Email incorrect.");
}
}
}
break;
}
}
/**
* Affiche les privilèges
*/
public function privilegesAction()
{
$request = $this->getRequest();
$siren = substr($this->siret, 0, 9);
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
$ws = new Scores_Ws_Client('entreprise', '0.9');
$parameters = new stdClass();
$parameters->companyId = $siren;
$result = $ws->getPrivilegeList($parameters);
$this->view->assign('PrivilegesNb', $result->NbTotal);
$this->view->assign('PrivilegesMt', $result->MtTotal);
$this->view->assign('PrivilegesCumul', $result->Cumul->item);
$this->view->assign('Privileges', $result->List->item);
$user = new Scores_Utilisateur();
$this->view->assign('surveillance', $user->checkPerm('survpriv'));
}
/**
* Détail d'un privilege
*/
public function privilegedetailAction()
{
$request = $this->getRequest();
$id = $request->getParam('viewId');
$siren = substr($this->siret, 0, 9);
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('siret', $this->siret);
$this->view->assign('raisonSociale', $session->getRaisonSociale());
$ws = new Scores_Ws_Client('entreprise', '0.9');
$parameters = new stdClass();
$parameters->companyId = $siren;
$parameters->id = $id;
$result = $ws->getPrivilegeDetail($parameters);
$this->view->assign('Privilege', $result);
}
}