Commit afed0f43 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Conservation des fractions pour les types d'intervention

parent 375f37aa
# OSE 16 (à venir) # OSE 16 (à venir)
Objectif : Connecteur Export OSE => Logiciel RH Objectif : Connecteur Export OSE => Logiciel RH + import Actul+
# OSE 15.2 (à venir) # OSE 15.2 (à venir)
## Nouveautés
* Au niveau des types d'intervention, il est désormais possible de saisir des fractions (2/3 TP par exemple)
## Corrections de bugs ## Corrections de bugs
* Vérification que le champs 'numéro de rue' contient uniquement des chiffres lors de l'enregistrement des données personnelles (#37492) * Vérification que le champs 'numéro de rue' contient uniquement des chiffres lors de l'enregistrement des données personnelles (#37492)
......
...@@ -9,12 +9,26 @@ class FloatFromString extends AbstractFilter ...@@ -9,12 +9,26 @@ class FloatFromString extends AbstractFilter
private static $instance; private static $instance;
public function filter($value) public function filter($value)
{ {
if ($value === '') return null; if ($value === '') return null;
$value = preg_replace("/[^0-9,\.-]/","",$value); if (false !== strpos($value, '/')) {
$value = str_replace(',','.',$value); [$f1, $f2] = explode('/', $value);
return $this->convert($f1) / $this->convert($f2);
} else {
return $this->convert($value);
}
}
protected function convert($value): float
{
$value = preg_replace("/[^0-9,\.-]/", "", $value);
$value = str_replace(',', '.', $value);
$value = floatval($value); $value = floatval($value);
return $value; return $value;
...@@ -22,12 +36,12 @@ class FloatFromString extends AbstractFilter ...@@ -22,12 +36,12 @@ class FloatFromString extends AbstractFilter
public static function run( $value ) public static function run($value)
{ {
if (!self::$instance){ if (!self::$instance) {
self::$instance = new self; self::$instance = new self;
} }
return self::$instance->filter($value ); return self::$instance->filter($value);
} }
} }
\ No newline at end of file
...@@ -9,22 +9,56 @@ class StringFromFloat extends AbstractFilter ...@@ -9,22 +9,56 @@ class StringFromFloat extends AbstractFilter
{ {
private static $instance; private static $instance;
private $fractions = [
['f' => 0.333333, 's' => '1/3'],
['f' => 0.166667, 's' => '1/6'],
['f' => 0.142857, 's' => '1/7'],
['f' => 0.111111, 's' => '1/9'],
['f' => 0.666667, 's' => '2/3'],
['f' => 0.285714, 's' => '2/7'],
['f' => 0.222222, 's' => '2/9'],
['f' => 0.428571, 's' => '3/7'],
['f' => 1.333333, 's' => '4/3'],
['f' => 0.571429, 's' => '4/7'],
['f' => 0.444444, 's' => '4/9'],
['f' => 1.666667, 's' => '5/3'],
['f' => 0.833333, 's' => '5/6'],
['f' => 0.714286, 's' => '5/7'],
['f' => 0.555556, 's' => '5/9'],
['f' => 0.857143, 's' => '6/7'],
['f' => 2.333333, 's' => '7/3'],
['f' => 1.166667, 's' => '7/6'],
['f' => 0.777778, 's' => '7/9'],
['f' => 2.666667, 's' => '8/3'],
['f' => 1.142857, 's' => '8/7'],
['f' => 0.888889, 's' => '8/9'],
['f' => 1.285714, 's' => '9/7'],
];
public function filter($value, $show0Digits=true)
public function filter($value, $show0Digits = true)
{ {
$valfrac = round($value, 6);
foreach ($this->fractions as $fs) {
if ($fs['f'] === $valfrac) {
return $fs['s'];
}
}
$res = Util::formattedFloat($value); $res = Util::formattedFloat($value);
if (! $show0Digits){ if (!$show0Digits) {
$res = str_replace( ',00', '', $res ); $res = str_replace(',00', '', $res);
} }
return $res; return $res;
} }
public static function run( $value, $show0Digits=true ) public static function run($value, $show0Digits = true)
{ {
if (!self::$instance){ if (!self::$instance) {
self::$instance = new self; self::$instance = new self;
} }
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
namespace Application\View\Helper; namespace Application\View\Helper;
use Application\Entity\Db\TypeInterventionStatut;
use Application\Entity\Db\TypeIntervention; use Application\Entity\Db\TypeIntervention;
use Application\Filter\StringFromFloat;
use Application\Service\Traits\TypeInterventionServiceAwareTrait; use Application\Service\Traits\TypeInterventionServiceAwareTrait;
use UnicaenApp\Util;
/** /**
* Aide de vue permettant d'afficher une liste de statuts * Aide de vue permettant d'afficher une liste de statuts
...@@ -88,7 +87,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper ...@@ -88,7 +87,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper
*/ */
public function render($details = false) public function render($details = false)
{ {
$ti = $this->getTypeIntervention(); $ti = $this->getTypeIntervention();
$title = ''; $title = '';
$statuts = $ti->getTypeInterventionStatut(); $statuts = $ti->getTypeInterventionStatut();
...@@ -96,7 +95,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper ...@@ -96,7 +95,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper
if ($title) $title .= ' - '; if ($title) $title .= ' - ';
$title .= $tis->getStatutIntervenant()->getLibelle(); $title .= $tis->getStatutIntervenant()->getLibelle();
} }
$etoile= (strlen($title)? '★':''); $etoile = (strlen($title) ? '★' : '');
$url = $this->getView()->url('type-intervention/statut', ['typeIntervention' => $ti->getId()]); $url = $this->getView()->url('type-intervention/statut', ['typeIntervention' => $ti->getId()]);
...@@ -108,7 +107,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper ...@@ -108,7 +107,7 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper
'title' => $title, 'title' => $title,
'href' => $url, 'href' => $url,
'data-submit-reload' => 'true', 'data-submit-reload' => 'true',
])->text(Util::formattedNumber($ti->getTauxHetdService()).$etoile); ])->text(StringFromFloat::run($ti->getTauxHetdService()) . $etoile);
$html .= '</td><td>'; $html .= '</td><td>';
$html .= $this->getView()->tag('a', [ $html .= $this->getView()->tag('a', [
...@@ -118,9 +117,9 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper ...@@ -118,9 +117,9 @@ class TypeInterventionAdminViewHelper extends AbstractViewHelper
'title' => $title, 'title' => $title,
'href' => $url, 'href' => $url,
'data-submit-reload' => 'true', 'data-submit-reload' => 'true',
])->text(Util::formattedNumber($ti->getTauxHetdComplementaire()).$etoile); ])->text(StringFromFloat::run($ti->getTauxHetdComplementaire()) . $etoile);
$html.='</td>'; $html .= '</td>';
return $html; return $html;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment