394 lines
11 KiB
PHP
Executable File
394 lines
11 KiB
PHP
Executable File
<?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;
|
|
|
|
protected $ListEvenProcol = array(50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1100,1101,1102,1110,1111,1115,1116,1118,1119,1120,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1214,1215,1216,1217,1218,1219,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,1311,1312,1313,1314,1346,1400,1401,1402,1403,1404,1405,1406,1407,1408,1409,1410,1411,1412,1413,1414,1415,1416,1417,1418,1419,1420,1421,1423,1425,1430,1431,1435,1436,1440,1445,1450,1455,1460,1463,1465,1470,1472,1474,1475,1480,1490,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,1511,1512,1513,1514,1515,1517,1518,1519,1520,1521,1522,1525,1530,1535,1540,1541,1542,1543,1544,1545,1546,1580,1600,1601,1602,1603,1604,1605,1610,1611,1620,1640,1645,1650,1700,1800,1801,1900,1901,1999);
|
|
protected $ListEvenProcolDelete = array();
|
|
protected $ListEvenAbsorption = array(2720, 2721);
|
|
protected $ListEvenRadiation = array(40, 41, 42, 2202, 2203, 2204, 2210, 2211, 2212, 6000, 6001, 6002, 6003, 6004, 6005, 6100, 6200, 6300, 6400, 6500, 6600, 6700, 8090);
|
|
protected $ListEvenDissolution = array(2202, 2203, 2204, 2210, 2211, 2212);
|
|
|
|
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()
|
|
{
|
|
if ($this->debug) file_put_contents('procol.log', "=== Situation Juridique ===\n");
|
|
|
|
// Définir la date du jour
|
|
$this->DateToday = date('Ymd');
|
|
|
|
// 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)
|
|
{
|
|
if ( preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $txt, $matches) ) {
|
|
$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,
|
|
);
|
|
file_put_contents('procol.log', print_r($this->Timeline,1)."\n", FILE_APPEND);
|
|
}
|
|
|
|
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;
|
|
foreach ($conditions as $cond)
|
|
{
|
|
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)
|
|
{
|
|
if ( is_numeric($val) ) {
|
|
return (float) $val;
|
|
}
|
|
|
|
if ( is_array($val) ) {
|
|
return $val;
|
|
}
|
|
|
|
if ( is_string($val) && property_exists($this, $val)) {
|
|
return $this->{$val};
|
|
}
|
|
|
|
if ( is_string($val) && defined('self::'.$val) ) {
|
|
return constant('self::'.$val);
|
|
}
|
|
|
|
if ( is_string($val) ) {
|
|
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);
|
|
}
|
|
if ( $this->{$var} !== null && $this->{$var} > $valueReal ) {
|
|
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);
|
|
}
|
|
if ( $this->{$var} !== null && $this->{$var} < $valueReal ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
break;
|
|
|
|
case 'EGAL':
|
|
$valueReal = $this->paramValue($value);
|
|
if ( is_array($valueReal) ) {
|
|
if ($this->debug) {
|
|
file_put_contents('procol.log', "\t".$this->{$var}." = ".$value."\n", FILE_APPEND);
|
|
}
|
|
if ( in_array($this->{$var}, $valueReal) ) {
|
|
return true;
|
|
}
|
|
}
|
|
elseif ( $this->{$var} == $valueReal ) {
|
|
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) {
|
|
file_put_contents('procol.log', "\t".$this->{$var}." = ".print_r($valueReal,1)."\n", FILE_APPEND);
|
|
}
|
|
if ( $valueReal !== null && in_array($this->{$var}, $valueReal) ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
break;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
} |