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->ListEvenProcol = array(); } 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; } /** * 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 = new \DateTime(); $calc->createFromFormat('Ymd', $this->PlanDateStart); $interval = new \DateInterval('P'.$this->PlanPeriod.'M'); $calc->add($interval); $this->PlanDateEnd = $calc->format('Ymd'); } public function situationEnd() { $calc = new \DateTime(); $calc->createFromFormat('Ymd', $this->SituationDateStart); $interval = new \DateInterval('P'.$this->ProcolMaxYear.'M'); $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->EvenDateJugement = $ann->date; $this->EvenCode = $ann->code; $this->EvenTxt = $ann->txt; // Marqueur d'effacement de la procol if (in_array($this->EvenCode, $this->ListEvenProcolDelete)) { $this->EvenDelete = $this->ListEvenProcolDelete[$this->EvenCode]; } // 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(); } /** * Execution des règles */ protected function rules() { $rules = include __DIR__ . '/DetectTable.php'; $setSituation = false; // Parcours des règles foreach ($rules as $rule) { $result = $this->params($rule['params']); if ($result === true) { // Defintion paramètres situation $this->SituationDateStart = $ann->date; $this->situationEnd(); // Enregistrement dans la timeline $this->Timeline[] = array( 'Situation' => $this->Situation, 'Even' => $this->EvenCode, 'DateStart' => $this->SituationDateStart, 'DateEnd' => $this->SituationDateEnd, ); } } } /** * Execution des conditions * @param array $conditions */ protected function params($conditions) { $cNb = count($conditions); $cIncr = 0; foreach ($conditions as $cond) { $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_string($val) && defined('self::'.$val) ) { return constant('self::'.$val); } if ( is_string($val) ) { return $this->{$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) { // Valeur réelle $valueReal = $this->paramValue($value); // Operation switch ($op) { case 'SET': break; case 'MIN': if ( $this->{$var} !== null && $this->{$var} > $valueReal ) { return true; } return false; break; case 'MAX': if ( $this->{$var} !== null && $this->{$var} < $valueReal ) { return true; } return false; break; case 'EGAL': if ( $this->{$var} == $valueReal ) { return true; } return false; break; case 'LIST': if ( $valueReal !== null && in_array($this->{$var}, $valueReal) ) { return true; } return false; break; } return null; } }