2016-08-30 10:24:06 +02:00
|
|
|
<?php
|
|
|
|
require_once dirname(__FILE__) . '/Service.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Infogreffe : Document Bilan
|
|
|
|
*/
|
|
|
|
class Metier_Infogreffe_DocBI extends Metier_Infogreffe_Service
|
|
|
|
{
|
|
|
|
const INT = 1000;
|
|
|
|
|
|
|
|
/**
|
2016-10-12 11:03:18 +02:00
|
|
|
* Type de comptes
|
2016-08-30 10:24:06 +02:00
|
|
|
* consolides|sociaux
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-11-24 16:02:49 +01:00
|
|
|
public $type_comptes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PDO Connection with Doctrine
|
|
|
|
* @var \Doctrine\DBAL\Connection
|
|
|
|
*/
|
|
|
|
protected $conn;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Infogreffe : Document Bilan
|
|
|
|
* @param \Doctrine\DBAL\Connection $conn
|
|
|
|
*/
|
2016-10-12 11:03:18 +02:00
|
|
|
public function __construct($conn = null)
|
2016-08-30 10:24:06 +02:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
// Set Database
|
|
|
|
if ($conn === null) {
|
|
|
|
$this->conn = Zend_Registry::get('doctrine');
|
2016-11-24 16:02:49 +01:00
|
|
|
} else {
|
2016-10-12 11:03:18 +02:00
|
|
|
$this->conn = $conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set type
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->type_document = 'BI';
|
2016-10-12 11:03:18 +02:00
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
/**
|
|
|
|
* Défini le SIREN
|
|
|
|
* @param string $siren
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setSiren($siren)
|
|
|
|
{
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->siren = $siren;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param $onlyDb
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getList($onlyDb = false)
|
|
|
|
{
|
|
|
|
$this->mode_diffusion = 'XL';
|
|
|
|
$this->reference_client = 'list-' . $this->siren;
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
// Requete WebService
|
2016-08-30 10:24:06 +02:00
|
|
|
$bilansXML = null;
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($onlyDb === false) {
|
2016-10-12 11:03:18 +02:00
|
|
|
// Infogreffe webservice
|
2016-11-24 16:02:49 +01:00
|
|
|
try {
|
|
|
|
$xml = $this->callRequest();
|
|
|
|
$requestOk = true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$requestOk = false;
|
|
|
|
// @todo : get error message
|
|
|
|
}
|
|
|
|
if ($requestOk === true) {
|
|
|
|
// Set All line state to 0
|
|
|
|
try {
|
|
|
|
$this->conn->update('jo.greffes_bilans',
|
|
|
|
array('actif' => 0), array('siren' => $this->siren));
|
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
$bilansXML = $this->formatList($xml);
|
2016-11-24 16:02:49 +01:00
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
// Lecture de la base de données
|
|
|
|
$columns = array(
|
|
|
|
'siren',
|
|
|
|
'numRC',
|
|
|
|
'LPAD(numGreffe,4,0) AS numGreffe',
|
|
|
|
'pdfLink',
|
|
|
|
'pdfSize',
|
|
|
|
'pdfPage',
|
|
|
|
'millesime',
|
|
|
|
'num_depot',
|
|
|
|
'date_cloture',
|
|
|
|
'type_comptes',
|
|
|
|
'mode_diffusion',
|
|
|
|
'duree_exercice',
|
|
|
|
'saisie_date',
|
|
|
|
'saisie_code',
|
|
|
|
'pages',
|
|
|
|
);
|
2016-10-12 15:47:33 +02:00
|
|
|
try {
|
|
|
|
$qb = $this->conn->createQueryBuilder();
|
|
|
|
$qb->select($columns)->from('jo.greffes_bilans')
|
|
|
|
->where('siren=:siren')->setParameter('siren', $this->siren)->andWhere('actif=1')
|
|
|
|
->orderBy('date_cloture', 'DESC')->orderBy('num_depot', 'DESC')
|
2016-11-04 09:04:36 +01:00
|
|
|
->orderBy('date_cloture', 'DESC');
|
2016-10-12 15:47:33 +02:00
|
|
|
$stmt = $qb->execute();
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-10-12 15:47:33 +02:00
|
|
|
throw new Exception(__METHOD__ . ': ' . $e->getMessage());
|
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
|
|
|
|
$bilans = array();
|
2016-10-12 11:03:18 +02:00
|
|
|
if ($stmt->rowCount() > 0) {
|
|
|
|
$rows = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
2016-11-24 16:02:49 +01:00
|
|
|
foreach ($rows as $row) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$item = new stdClass();
|
|
|
|
$item->File = $row->pdfLink;
|
|
|
|
$item->FileSize = $row->pdfSize;
|
|
|
|
$item->NumberOfPages = $row->pdfPage;
|
|
|
|
$item->Millesime = $row->millesime;
|
|
|
|
$item->NumDepot = $row->num_depot;
|
|
|
|
$item->DateCloture = $row->date_cloture;
|
2016-11-24 16:02:49 +01:00
|
|
|
if (empty($row->type_comptes)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$item->Type = 'sociaux';
|
|
|
|
} else {
|
|
|
|
$item->Type = $row->type_comptes;
|
|
|
|
}
|
|
|
|
$mode_diffusion = explode(',', $row->mode_diffusion);
|
|
|
|
|
|
|
|
if (in_array('T', $mode_diffusion) || !empty($item->File)) {
|
|
|
|
$item->ModeDiffusion = 'T';
|
2016-11-24 16:02:49 +01:00
|
|
|
} elseif (in_array('C', $mode_diffusion)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$item->ModeDiffusion = 'C';
|
|
|
|
} else {
|
|
|
|
$item->ModeDiffusion = '';
|
|
|
|
}
|
|
|
|
$item->DureeExercice = $row->duree_exercice;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Following data are not as expected as the type and other data could change
|
|
|
|
* Only num depot don't change.
|
|
|
|
*/
|
|
|
|
$item->SaisieDate = $row->saisie_date;
|
|
|
|
$item->SaisieCode = $row->saisie_code;
|
2016-11-24 16:02:49 +01:00
|
|
|
switch ($row->saisie_code) {
|
|
|
|
case '00': $item->SaisieLabel = "Bilan saisi sans anomalie"; break;
|
|
|
|
case '01': $item->SaisieLabel = "Bilan saisi avec des incohérences comptables à la source du document (issues du remettant)"; break;
|
|
|
|
case '02': $item->SaisieLabel = "Bilan avec Actif, Passif ou Compte de Résultat nul"; break;
|
|
|
|
case '03': $item->SaisieLabel = "Bilan incomplet (des pages manquent)"; break;
|
|
|
|
case '04': $item->SaisieLabel = "Bilan complet non détaillé (seuls les totaux et sous totaux sont renseignés)"; break;
|
|
|
|
case '05': $item->SaisieLabel = "Bilan reçu en double exemplaire"; break;
|
|
|
|
case '06': $item->SaisieLabel = "Bilan intermédiaire - Situation provisoire"; break;
|
|
|
|
case '07': $item->SaisieLabel = "Bilan illisible"; break;
|
|
|
|
case 'A7': $item->SaisieLabel = "Bilan illisible, présentant un cadre gris très foncés (dans lesquels sont inscrits en général les totaux)"; break;
|
|
|
|
case 'B7': $item->SaisieLabel = "Bilan manuscrits"; break;
|
|
|
|
case 'C7': $item->SaisieLabel = "Bilan illisible, présentant des caractères trop gras"; break;
|
|
|
|
case 'D7': $item->SaisieLabel = "Bilan scanné en biais ou qui présentent des pages rognées"; break;
|
|
|
|
case 'E7': $item->SaisieLabel = "Bilan numérisés trop clairement (comme une imprimante dont la cartouche est presque vide)"; break;
|
|
|
|
case 'F7': $item->SaisieLabel = "Bilan illisible"; break;
|
|
|
|
case '08': $item->SaisieLabel = "Bilan consolidé"; break;
|
|
|
|
case '09': $item->SaisieLabel = "Déclaration d'impôts"; break;
|
|
|
|
case '10': $item->SaisieLabel = "Document autre que bilan"; break;
|
|
|
|
case '11': $item->SaisieLabel = "Bilan de clôture de liquidation"; break;
|
|
|
|
case '12': $item->SaisieLabel = "Bilan de Société financière"; break;
|
|
|
|
case '13': $item->SaisieLabel = "Bilan de Société d'assurance"; break;
|
|
|
|
case '14': $item->SaisieLabel = "Bilan de Société immobilière"; break;
|
|
|
|
case '15': $item->SaisieLabel = "Bilan de Société étrangère"; break;
|
|
|
|
default: $item->SaisieLabel = ""; break;
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
$bilans[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bilans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
/**
|
|
|
|
* Download file
|
|
|
|
* @param string $dateCloture
|
|
|
|
* Format AAAA-MM-DD
|
|
|
|
* @param string $type
|
|
|
|
* sociaux ou consolides
|
|
|
|
* @params int $orderId
|
|
|
|
* Id de commande pour l'enregistrement dans la table de gestion
|
|
|
|
* @throws Exception
|
|
|
|
* @return string
|
|
|
|
* Return path (not complete) and filename
|
|
|
|
*/
|
2016-08-30 10:24:06 +02:00
|
|
|
public function getCommandeT($dateCloture = null, $type = 'sociaux', $orderId = null)
|
|
|
|
{
|
2016-10-12 11:03:18 +02:00
|
|
|
// Lire dans la base de données
|
|
|
|
$columns = array(
|
|
|
|
'siren',
|
|
|
|
'numRC',
|
|
|
|
'LPAD(numGreffe,4,0) AS numGreffe',
|
|
|
|
'pdfLink',
|
|
|
|
'millesime',
|
|
|
|
'num_depot',
|
|
|
|
'date_cloture',
|
|
|
|
'type_comptes',
|
|
|
|
);
|
|
|
|
$qb = $this->conn->createQueryBuilder();
|
|
|
|
$qb->select($columns)->from('jo.greffes_bilans')
|
|
|
|
->where('siren=:siren')->setParameter('siren', $this->siren)
|
2016-11-04 09:10:34 +01:00
|
|
|
->andWhere('date_cloture=:date')->setParameter('date', $dateCloture);
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($type == 'sociaux' || $type == '') {
|
2016-10-12 11:03:18 +02:00
|
|
|
$qb->andWhere("(type_comptes='sociaux' OR type_comptes='')");
|
2016-08-30 10:24:06 +02:00
|
|
|
} else {
|
2016-10-12 11:03:18 +02:00
|
|
|
$qb->andWhere('type_comptes=:type')->setParameter('type', $type);
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
2016-10-12 11:03:18 +02:00
|
|
|
$qb->orderBy('dateInsert', 'DESC')->orderBy('num_depot', 'DESC');
|
|
|
|
$stmt = $qb->execute();
|
2016-08-30 10:24:06 +02:00
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($stmt->rowCount() == 0) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception("Element doesn't exist");
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
|
|
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->mode_diffusion = 'T';
|
|
|
|
$this->reference_client = 'T'.date('YmdHis');
|
|
|
|
$this->greffe = $row->numGreffe;
|
2016-11-24 16:02:49 +01:00
|
|
|
$this->dossier_millesime = substr($row->numRC, 0, 2);
|
|
|
|
$this->dossier_statut = substr($row->numRC, 2, 1);
|
|
|
|
$this->dossier_chrono = substr($row->numRC, 3);
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->num_depot = $row->num_depot;
|
|
|
|
$this->date_cloture = $row->date_cloture;
|
|
|
|
$this->type_comptes = $row->type_comptes;
|
|
|
|
|
|
|
|
$dir = $this->getFilePath($type, $dateCloture);
|
2016-11-24 16:02:49 +01:00
|
|
|
if (! file_exists($this->config->storage->path . '/' . $dir)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
mkdir($this->config->storage->path . '/' . $dir, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set the filename
|
|
|
|
$filename = $dir . '/' . $this->getFileName($type, $dateCloture);
|
|
|
|
|
|
|
|
if ($row->pdfLink != '') {
|
|
|
|
|
|
|
|
//Check if filename exist
|
2016-11-24 16:02:49 +01:00
|
|
|
if (! file_exists($this->config->storage->path . '/' . $filename)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception('File not found', self::INT);
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
} elseif (file_exists($this->config->storage->path . '/' . $filename)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
|
|
|
|
//Analyser le fichier - Nombre de page et taille
|
|
|
|
$infos = $this->pdfInfos($this->config->storage->path . '/' . $filename);
|
|
|
|
|
|
|
|
//Enregistrer les infos du fichier dans la base de données
|
|
|
|
if (false !== $infos) {
|
|
|
|
$this->dbSetFile(basename($filename), $infos['size'], $infos['pages'], $infos['version']);
|
|
|
|
} else {
|
|
|
|
$this->dbSetFile(basename($filename));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$xml = $this->callRequest();
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (Exception $e) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception($e->getMessage(), $e->getCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
$bilan = $this->formatItem($xml);
|
|
|
|
$url = $bilan['url_acces'];
|
2016-11-24 16:02:49 +01:00
|
|
|
if (empty($url)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception('File url not given');
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($orderId !== null) {
|
2016-11-02 12:33:27 +01:00
|
|
|
$this->conn->update('sdv1.greffe_commandes_bi', array(
|
2016-10-12 11:03:18 +02:00
|
|
|
'cmdUrl' => $url,
|
|
|
|
'dateCommande' => date('YmdHis')),
|
|
|
|
array('id' => $orderId));
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Récupérer le fichier
|
|
|
|
$getfile = $this->download($url, $filename);
|
|
|
|
|
|
|
|
//Analyser le fichier - Nombre de page et taille
|
|
|
|
$infos = $this->pdfInfos($getfile);
|
|
|
|
|
|
|
|
//Enregistrer les infos du fichier dans la base de données
|
|
|
|
if (false !== $infos) {
|
|
|
|
$this->dbSetFile(basename($filename), $infos['size'], $infos['pages'], $infos['version']);
|
|
|
|
} else {
|
|
|
|
$this->dbSetFile(basename($filename));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo : Vérifier fonctionnement
|
|
|
|
* @param string $dateCloture
|
|
|
|
* @param string $type
|
|
|
|
* @param string $reference
|
|
|
|
* @throws Exception
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function getCommandeC($dateCloture = null, $type = 'sociaux', $reference = '')
|
|
|
|
{
|
|
|
|
$this->mode_diffusion = 'C';
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
// Lire dans la base de données
|
|
|
|
$columns = array(
|
|
|
|
'siren',
|
|
|
|
'numRC',
|
|
|
|
'LPAD(numGreffe,4,0) AS numGreffe',
|
|
|
|
'pdfLink',
|
|
|
|
'millesime',
|
|
|
|
'num_depot',
|
|
|
|
'date_cloture',
|
|
|
|
'type_comptes',
|
|
|
|
);
|
|
|
|
$qb = $this->conn->createQueryBuilder();
|
|
|
|
$qb->select($columns)->from('jo.greffes_bilans')
|
|
|
|
->where('siren=:siren')->setParameter('siren', $this->siren)
|
2016-11-03 15:45:29 +01:00
|
|
|
->andWhere('date_cloture=:date')->setParameter('date', $dateCloture);
|
2016-10-12 11:03:18 +02:00
|
|
|
if ($type == 'sociaux') {
|
|
|
|
$qb->andWhere("(type_comptes='sociaux' OR type_comptes='')");
|
2016-08-30 10:24:06 +02:00
|
|
|
} else {
|
2016-10-12 11:03:18 +02:00
|
|
|
$qb->andWhere('type_comptes=:type')->setParameter('type', $type);
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
2016-10-12 11:03:18 +02:00
|
|
|
$stmt = $qb->execute();
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($stmt->rowCount() == 0) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception('Not exist');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->reference_client = $reference;
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
|
|
|
2016-08-30 10:24:06 +02:00
|
|
|
//Générer les paramètres de commande depuis la base de données
|
|
|
|
$this->greffe = $row->numGreffe;
|
2016-11-24 16:02:49 +01:00
|
|
|
$this->dossier_millesime = substr($row->numRC, 0, 2);
|
|
|
|
$this->dossier_statut = substr($row->numRC, 2, 1);
|
|
|
|
$this->dossier_chrono = substr($row->numRC, 3);
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->num_depot = $row->num_depot;
|
|
|
|
$this->date_cloture = $row->date_cloture;
|
|
|
|
|
|
|
|
//Faire la requete
|
|
|
|
try {
|
|
|
|
$xml = $this->callRequest();
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (Exception $e) {
|
2016-08-30 10:24:06 +02:00
|
|
|
//La prise en charge du courrier est effective
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($e->getCode() != 17) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of file
|
|
|
|
* @param string $type
|
|
|
|
* @param string $dateCloture
|
|
|
|
* Format : AAAA-MM-JJ
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFileName($type, $dateCloture)
|
|
|
|
{
|
2016-10-12 11:03:18 +02:00
|
|
|
if ($type == '') {
|
2016-08-30 10:24:06 +02:00
|
|
|
$type = 'sociaux';
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
$date = substr($dateCloture, 0, 4).substr($dateCloture, 5, 2).substr($dateCloture, 8, 2);
|
2016-08-30 10:24:06 +02:00
|
|
|
|
|
|
|
return 'bilan-' . $this->siren . '-' . $type . '-' . $date . '.pdf';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Path of file
|
|
|
|
* @param string $type
|
|
|
|
* @param string $dateCloture
|
|
|
|
* Format : AAAA-MM-JJ
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilePath($type, $dateCloture)
|
|
|
|
{
|
2016-10-12 11:03:18 +02:00
|
|
|
if ($type == '') {
|
2016-08-30 10:24:06 +02:00
|
|
|
$type = 'sociaux';
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
return 'bilans' . '/' . $type . '/' . substr($dateCloture, 0, 4);
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format XML to Array for a list of items
|
|
|
|
* @param string $xml
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function formatList($xml)
|
|
|
|
{
|
|
|
|
//Parse XML to make an array
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->loadXML($xml);
|
|
|
|
$liste_bilan_complet = $doc->getElementsByTagName('liste_bilan_complet')->item(0);
|
|
|
|
$bilan_complet = $liste_bilan_complet->getElementsByTagName('bilan_complet');
|
|
|
|
|
|
|
|
$bilans = array();
|
2016-10-12 11:03:18 +02:00
|
|
|
if (count($bilan_complet) > 0) {
|
2016-11-24 16:02:49 +01:00
|
|
|
foreach ($bilan_complet as $element) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$bilan = array();
|
|
|
|
$num_gest = $element->getElementsByTagName('num_gest')->item(0);
|
|
|
|
$bilan['num_gest']['greffe'] = $num_gest->getElementsByTagName('greffe')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_millesime'] = $num_gest->getElementsByTagName('dossier_millesime')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_statut'] = $num_gest->getElementsByTagName('dossier_statut')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_chrono'] = $num_gest->getElementsByTagName('dossier_chrono')->item(0)->nodeValue;
|
|
|
|
$bilan['dossier_millesime'] = $num_gest->getElementsByTagName('dossier_millesime')->item(0)->nodeValue;
|
|
|
|
$bilan['dossier_statut'] = $num_gest->getElementsByTagName('dossier_statut')->item(0)->nodeValue;
|
|
|
|
$bilan['dossier_chrono'] = $num_gest->getElementsByTagName('dossier_chrono')->item(0)->nodeValue;
|
|
|
|
$bilan['num_siren'] = $element->getElementsByTagName('num_siren')->item(0)->nodeValue;
|
|
|
|
$bilan['date_cloture'] = $element->getElementsByTagName('date_cloture')->item(0)->nodeValue;
|
|
|
|
$bilan['date_cloture_iso'] = $element->getElementsByTagName('date_cloture_iso')->item(0)->nodeValue;
|
|
|
|
$bilan['millesime'] = $element->getElementsByTagName('millesime')->item(0)->nodeValue;
|
|
|
|
$bilan['num_depot'] = $element->getElementsByTagName('num_depot')->item(0)->nodeValue;
|
|
|
|
$bilan['type_comptes'] = $element->getElementsByTagName('type_comptes')->item(0)->nodeValue;
|
|
|
|
$mode_diffusion = $element->getElementsByTagName('mode_diffusion')->item(0)->getElementsByTagName('mode');
|
2016-11-24 16:02:49 +01:00
|
|
|
foreach ($mode_diffusion as $mode) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$bilan['mode_diffusion'][] = $mode->getAttribute('type');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Enregistrer dans la bdd
|
|
|
|
$this->dbUpdateItem($bilan);
|
|
|
|
|
|
|
|
//Génération de l'index pour le tri
|
|
|
|
$date = $bilan['date_cloture_iso'];
|
2016-11-24 16:02:49 +01:00
|
|
|
if (!empty($date)) {
|
|
|
|
$key = substr($date, 0, 4).substr($date, 5, 2).substr($date, 8, 2).'-'.$bilan['num_depot'];
|
|
|
|
//Affectation liste générale avec un index permettant le tri
|
|
|
|
$bilans[$key] = $bilan;
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
krsort($bilans);
|
|
|
|
return $bilans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format XML to Array for one item
|
|
|
|
* @param string $xml
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function formatItem($xml)
|
|
|
|
{
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->loadXML($xml);
|
|
|
|
$bilan_complet = $doc->getElementsByTagName('bilan_complet')->item(0);
|
|
|
|
$bilan = array();
|
|
|
|
$bilan['num_gest'] = array();
|
|
|
|
$num_gest = $bilan_complet->getElementsByTagName('num_gest')->item(0);
|
|
|
|
$bilan['num_gest']['greffe'] = $num_gest->getElementsByTagName('greffe')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_millesime'] = $num_gest->getElementsByTagName('dossier_millesime')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_statut'] = $num_gest->getElementsByTagName('dossier_statut')->item(0)->nodeValue;
|
|
|
|
$bilan['num_gest']['dossier_chrono'] = $num_gest->getElementsByTagName('dossier_chrono')->item(0)->nodeValue;
|
|
|
|
$bilan['num_siren'] = $bilan_complet->getElementsByTagName('num_siren')->item(0)->nodeValue;
|
|
|
|
$bilan['date_cloture'] = $bilan_complet->getElementsByTagName('date_cloture')->item(0)->nodeValue;
|
|
|
|
$bilan['date_cloture_iso'] = $bilan_complet->getElementsByTagName('date_cloture_iso')->item(0)->nodeValue;
|
|
|
|
$bilan['millesime'] = $bilan_complet->getElementsByTagName('millesime')->item(0)->nodeValue;
|
|
|
|
$bilan['num_depot'] = $bilan_complet->getElementsByTagName('num_depot')->item(0)->nodeValue;
|
|
|
|
$bilan['type_comptes'] = $bilan_complet->getElementsByTagName('type_comptes')->item(0)->nodeValue;
|
|
|
|
$bilan['url_acces'] = $bilan_complet->getElementsByTagName('url_acces')->item(0)->nodeValue;
|
|
|
|
|
|
|
|
return $bilan;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update informations about an item in database
|
|
|
|
* @param array $list
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
protected function dbUpdateItem($list)
|
|
|
|
{
|
2016-10-12 11:03:18 +02:00
|
|
|
// Insert or Update
|
2016-08-30 10:24:06 +02:00
|
|
|
$data = array(
|
|
|
|
'siren' => $list['num_siren'],
|
|
|
|
'numRC' => $list['num_gest']['dossier_millesime'].
|
|
|
|
$list['num_gest']['dossier_statut'].$list['num_gest']['dossier_chrono'],
|
|
|
|
//'numRC2' => '',
|
|
|
|
'numGreffe' => intval($list['num_gest']['greffe']),
|
|
|
|
'millesime' => $list['millesime'],
|
|
|
|
'num_depot' => $list['num_depot'],
|
|
|
|
'date_cloture' => $list['date_cloture_iso'],
|
|
|
|
'type_comptes' => $list['type_comptes'],
|
2016-11-24 16:02:49 +01:00
|
|
|
'mode_diffusion' => join(',', $list['mode_diffusion']),
|
2016-08-30 10:24:06 +02:00
|
|
|
'actif' => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
2016-10-12 11:03:18 +02:00
|
|
|
$sql = "SELECT * FROM jo.greffes_bilans
|
|
|
|
WHERE siren=:siren AND num_depot=:num AND date_cloture=:date ORDER BY dateInsert";
|
|
|
|
$stmt = $this->conn->prepare($sql);
|
|
|
|
$stmt->bindValue('siren', $this->siren);
|
|
|
|
$stmt->bindValue('num', $list['num_depot']);
|
|
|
|
$stmt->bindValue('date', $list['date_cloture_iso']);
|
|
|
|
$stmt->execute();
|
|
|
|
// Insert
|
|
|
|
if ($stmt->rowCount() == 0) {
|
|
|
|
$data['dateInsert'] = date('YmdHis');
|
2016-08-30 10:24:06 +02:00
|
|
|
try {
|
2016-10-12 11:03:18 +02:00
|
|
|
$result = $this->conn->insert('jo.greffes_bilans', $data);
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-10-12 11:03:18 +02:00
|
|
|
// Update
|
|
|
|
else {
|
|
|
|
// Get first Item
|
|
|
|
$item = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
|
|
|
|
|
|
// Correction anomalie item multiple
|
|
|
|
if ($stmt->rowCount() > 1) {
|
|
|
|
$this->conn->beginTransaction();
|
|
|
|
try {
|
|
|
|
while ($rowDel = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
2016-11-24 16:02:49 +01:00
|
|
|
$this->conn->delete('jo.greffes_bilans', array(
|
2016-10-12 11:03:18 +02:00
|
|
|
'id' => $rowDel->id));
|
|
|
|
}
|
|
|
|
$this->conn->commit();
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-10-12 11:03:18 +02:00
|
|
|
$this->conn->rollBack();
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
// Real Update
|
|
|
|
try {
|
|
|
|
$result = $this->conn->update('jo.greffes_bilans', $data,
|
|
|
|
array('id' => $item->id));
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-10-12 11:03:18 +02:00
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-10-12 11:03:18 +02:00
|
|
|
throw new Exception($e->getMessage());
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set file informations in database
|
|
|
|
* @param string $filename
|
|
|
|
* @param int $size
|
|
|
|
* @param int $numberOfPage
|
|
|
|
* @param string $version
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function dbSetFile($filename, $size = 0, $numberOfPage = '', $version = '')
|
|
|
|
{
|
|
|
|
$data = array(
|
2016-10-12 11:03:18 +02:00
|
|
|
'pdfLink' => $filename,
|
|
|
|
'pdfSize' => $size,
|
|
|
|
'pdfPage' => $numberOfPage,
|
|
|
|
'pdfVer' => $version,
|
2016-11-24 16:02:49 +01:00
|
|
|
'pdfDate' => date('Ymd'),
|
2016-08-30 10:24:06 +02:00
|
|
|
);
|
|
|
|
|
2016-10-12 11:03:18 +02:00
|
|
|
$identifier = array(
|
|
|
|
'siren' => $this->siren,
|
|
|
|
'date_cloture' => $this->date_cloture,
|
|
|
|
'type_comptes' => $this->type_comptes,
|
2016-08-30 10:24:06 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
2016-10-12 11:03:18 +02:00
|
|
|
$result = $this->conn->update('jo.greffes_bilans', $data, $identifier);
|
2016-11-24 16:02:49 +01:00
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
2016-08-30 10:24:06 +02:00
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
}
|