2016-08-30 10:24:06 +02:00
|
|
|
<?php
|
|
|
|
class Metier_Defaillance_Detect
|
|
|
|
{
|
|
|
|
protected $debug = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code de la forme juridique
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $FJ;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Date de cloture du bilan (AAAAMMJJ)
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $BilanCloture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actif Insee
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $InseeActif;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actif RCS
|
|
|
|
* @var unknown
|
|
|
|
*/
|
|
|
|
protected $RcsActif;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nombre d'établissement actif
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $EtabActifNb;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rgsitre des métiers
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $NumRM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RCS
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $IsRCS;
|
|
|
|
|
|
|
|
protected $Situation = '';
|
|
|
|
protected $SituationDateStart;
|
|
|
|
protected $SituationDateEnd;
|
|
|
|
protected $SituationLastEven = '';
|
|
|
|
protected $SituationNbMonthPast = 0;
|
|
|
|
protected $PlanDateStart;
|
|
|
|
protected $PlanDateEnd;
|
|
|
|
protected $PlanPeriod = 120;
|
|
|
|
|
2016-11-23 11:50:35 +01:00
|
|
|
protected $ListEvenProcol = array();
|
2016-08-30 10:24:06 +02:00
|
|
|
protected $ListEvenProcolDelete = array();
|
2016-11-23 11:50:35 +01:00
|
|
|
protected $ListEvenAbsorption = array();
|
|
|
|
protected $ListEvenRadiation = array();
|
|
|
|
protected $ListEvenDissolution = array();
|
2016-08-30 10:24:06 +02:00
|
|
|
|
|
|
|
protected $ProcolMaxYear = 12;
|
|
|
|
|
|
|
|
protected $Even;
|
|
|
|
protected $EvenDateJugement;
|
|
|
|
protected $EvenTxt;
|
|
|
|
protected $EvenDelete = 0;
|
|
|
|
|
|
|
|
protected $DateToday;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeline des événements de défaillance
|
|
|
|
* { Situation, Even, DateStart, DateEnd }
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $Timeline = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Détection des défaillances
|
|
|
|
* Instancier la class, puis sur chaque annonce faire le traitement.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "=== Situation Juridique ===\n");
|
|
|
|
}
|
2016-08-30 10:24:06 +02:00
|
|
|
|
|
|
|
// Définir la date du jour
|
|
|
|
$this->DateToday = date('Ymd');
|
|
|
|
|
2016-11-23 11:50:35 +01:00
|
|
|
// Liste des événements au départ d'une procol
|
|
|
|
$this->ListEvenProcol = include __DIR__ . '/EvenProcol.php';
|
|
|
|
|
|
|
|
// Liste des événements d'absorption
|
|
|
|
$this->ListEvenAbsorption = include __DIR__ . '/EvenAbsorption.php';
|
|
|
|
|
|
|
|
// Liste des événements de radiation
|
|
|
|
$this->ListEvenRadiation = include __DIR__ . '/EvenRadiation.php';
|
|
|
|
|
|
|
|
// Liste des événements de dissolution
|
|
|
|
$this->ListEvenDissolution = include __DIR__ . '/EvenDissolution.php';
|
|
|
|
|
2016-08-30 10:24:06 +02:00
|
|
|
// Définir la liste des évenéments de la rubrique procol avec le paramètre d'effacement
|
|
|
|
$this->ListEvenProcolDelete = include __DIR__ . '/ProcolDelete.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFJ($val)
|
|
|
|
{
|
|
|
|
$this->FJ = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBilanCloture($val)
|
|
|
|
{
|
|
|
|
$this->BilanCloture = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setInseeActif($val)
|
|
|
|
{
|
|
|
|
$this->InseeActif = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRcsActif($val)
|
|
|
|
{
|
|
|
|
$this->RcsActif = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEtabActif($val)
|
|
|
|
{
|
|
|
|
$this->EtabActifNb = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRM($val)
|
|
|
|
{
|
|
|
|
$this->IsRM = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGreffe($val)
|
|
|
|
{
|
|
|
|
$this->IsRCS = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la situation
|
|
|
|
* @return string
|
|
|
|
* Code situation juridique
|
|
|
|
*/
|
|
|
|
public function getSituation()
|
|
|
|
{
|
|
|
|
return $this->Situation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la timeline
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTimeline()
|
|
|
|
{
|
|
|
|
return $this->Timeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lecture de la période et de la date
|
|
|
|
* @param string $txt
|
|
|
|
*/
|
|
|
|
public function planPeriod($txt)
|
|
|
|
{
|
2016-11-24 16:02:49 +01:00
|
|
|
if (preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $txt, $matches)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
$this->PlanPeriod = $matches[1] * 12; // 10 ans = 120 mois
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calcul de la date de fin du plan
|
|
|
|
*/
|
|
|
|
public function planEnd()
|
|
|
|
{
|
|
|
|
$calc = \DateTime::createFromFormat('Ymd', $this->PlanDateStart);
|
|
|
|
$interval = new \DateInterval('P'.$this->PlanPeriod.'M');
|
|
|
|
$calc->add($interval);
|
|
|
|
$this->PlanDateEnd = $calc->format('Ymd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function situationEnd()
|
|
|
|
{
|
|
|
|
$calc = \DateTime::createFromFormat('Ymd', $this->SituationDateStart);
|
|
|
|
$interval = new \DateInterval('P'.$this->ProcolMaxYear.'Y');
|
|
|
|
$calc->add($interval);
|
|
|
|
$this->SituationDateEnd = $calc->format('Ymd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function nbMonthPast($date)
|
|
|
|
{
|
|
|
|
$date1 = new \DateTime();
|
|
|
|
$date1->createFromFormat('Ymd', $date);
|
|
|
|
$date2 = new \DateTime();
|
|
|
|
$diff = $date2->diff($date1)->m;
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traite l'annonce dans le flux en executant les règles
|
|
|
|
* @param stdClass $ann
|
|
|
|
* date, code, txt
|
|
|
|
*/
|
|
|
|
public function parse($ann)
|
|
|
|
{
|
|
|
|
$this->Even = $ann->code;
|
|
|
|
$this->EvenDateJugement = $ann->date;
|
|
|
|
$this->EvenTxt = $ann->txt;
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "Annonce : ".$ann->date . '-' . $ann->code."\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marqueur d'effacement de la procol
|
|
|
|
if (array_key_exists($this->Even, $this->ListEvenProcolDelete)) {
|
|
|
|
$this->EvenDelete = $this->ListEvenProcolDelete[$this->Even];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evenement procol précédent
|
|
|
|
if (count($this->Timeline) > 0) {
|
|
|
|
$last = end($this->Timeline);
|
|
|
|
$this->SituationLastEven = $last['even'];
|
|
|
|
$this->SituationNbMonthPast = $this->nbMonthPast($last['DateStart']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- Variable pour le plan
|
|
|
|
$this->PlanDateStart = $this->EvenDateJugement;
|
|
|
|
$this->planPeriod($this->EvenTxt);
|
|
|
|
$this->planEnd();
|
|
|
|
|
|
|
|
// Lancement des règles
|
|
|
|
$this->rules();
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execution des règles
|
|
|
|
*/
|
|
|
|
protected function rules()
|
|
|
|
{
|
|
|
|
$rules = include __DIR__ . '/DetectTable.php';
|
|
|
|
$setSituation = false;
|
|
|
|
// Parcours des règles
|
|
|
|
foreach ($rules as $rule) {
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', $rule['name']."\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
$result = $this->params($rule['params']);
|
|
|
|
if ($result === true) {
|
|
|
|
// Defintion paramètres situation
|
|
|
|
$this->SituationDateStart = $this->EvenDateJugement;
|
|
|
|
$this->situationEnd();
|
|
|
|
|
|
|
|
// Enregistrement dans la timeline
|
|
|
|
$this->Timeline[] = array(
|
|
|
|
'Situation' => $this->Situation,
|
|
|
|
'Even' => $this->Even,
|
|
|
|
'DateStart' => $this->SituationDateStart,
|
|
|
|
'DateEnd' => $this->SituationDateEnd,
|
|
|
|
);
|
2016-11-24 16:02:49 +01:00
|
|
|
file_put_contents('procol.log', print_r($this->Timeline, 1)."\n", FILE_APPEND);
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
if ($result === true) {
|
|
|
|
file_put_contents('procol.log', "=> OK\n", FILE_APPEND);
|
|
|
|
} else {
|
|
|
|
file_put_contents('procol.log', "=> PASS\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execution des conditions
|
|
|
|
* @param array $conditions
|
|
|
|
*/
|
|
|
|
protected function params($conditions)
|
|
|
|
{
|
|
|
|
$cNb = count($conditions);
|
|
|
|
$cIncr = 1;
|
2016-11-24 16:02:49 +01:00
|
|
|
foreach ($conditions as $cond) {
|
2016-08-30 10:24:06 +02:00
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t".$cond['var']." ".$cond['op']." ".$cond['value']."\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
$result = $this->paramEval($cond['var'], $cond['op'], $cond['value']);
|
|
|
|
if ($result === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($cNb == $cIncr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$cIncr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transformation des variables
|
|
|
|
* @param string $val
|
|
|
|
* @return number|mixed|NULL
|
|
|
|
*/
|
|
|
|
protected function paramValue($val)
|
|
|
|
{
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_numeric($val)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return (float) $val;
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_array($val)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_string($val) && property_exists($this, $val)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return $this->{$val};
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_string($val) && defined('self::'.$val)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return constant('self::'.$val);
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_string($val)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluation de la condition
|
|
|
|
* @param string $var
|
|
|
|
* @param string $op
|
|
|
|
* @param string $value
|
|
|
|
* @return boolean|NULL
|
|
|
|
*/
|
|
|
|
protected function paramEval($var, $op, $value)
|
|
|
|
{
|
|
|
|
// Operation
|
|
|
|
switch ($op) {
|
|
|
|
case 'SET':
|
|
|
|
$this->{$var} = $value;
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t\tSET ".$var." = ".$value."\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'MIN':
|
|
|
|
$valueReal = $this->paramValue($value);
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t".$this->{$var}." > ".$valueReal."\n", FILE_APPEND);
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($this->{$var} !== null && $this->{$var} > $valueReal) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'MAX':
|
|
|
|
$valueReal = $this->paramValue($value);
|
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t".$this->{$var}." < ".$valueReal."\n", FILE_APPEND);
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($this->{$var} !== null && $this->{$var} < $valueReal) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'EGAL':
|
|
|
|
$valueReal = $this->paramValue($value);
|
2016-11-24 16:02:49 +01:00
|
|
|
if (is_array($valueReal)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t".$this->{$var}." = ".$value."\n", FILE_APPEND);
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
if (in_array($this->{$var}, $valueReal)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
} elseif ($this->{$var} == $valueReal) {
|
2016-08-30 10:24:06 +02:00
|
|
|
if ($this->debug) {
|
|
|
|
file_put_contents('procol.log', "\t".$this->{$var}." = ".$valueReal."\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'LIST':
|
|
|
|
$valueReal = $this->paramValue($value);
|
|
|
|
if ($this->debug) {
|
2016-11-24 16:02:49 +01:00
|
|
|
file_put_contents('procol.log', "\t".$this->{$var}." = ".print_r($valueReal, 1)."\n", FILE_APPEND);
|
2016-08-30 10:24:06 +02:00
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
if ($valueReal !== null && in_array($this->{$var}, $valueReal)) {
|
2016-08-30 10:24:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2016-11-24 16:02:49 +01:00
|
|
|
}
|