Commit 40c9728a38dae8e44d07de0fa2b66126b5093c43
Merge remote-tracking branch 'origin/master'
Showing
2 changed files
with
19 additions
and
1 deletions
 
Show diff stats
backend/controllers/RgGrupController.php
| @@ -174,7 +174,8 @@ class RgGrupController extends BaseController | @@ -174,7 +174,8 @@ class RgGrupController extends BaseController | ||
| 174 | 174 | ||
| 175 | $row['importer_id'] = trim($importer_id); | 175 | $row['importer_id'] = trim($importer_id); | 
| 176 | $row['margin_id'] = ltrim($key, '!'); | 176 | $row['margin_id'] = ltrim($key, '!'); | 
| 177 | - $row['koef'] = \Yii::$app->converter->convertTo('float', $value); | 177 | + $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); | 
| 178 | + | ||
| 178 | 179 | ||
| 179 | $arr_values[] = $row; | 180 | $arr_values[] = $row; | 
| 180 | 181 | 
common/components/parsers/CustomConverter.php
| @@ -15,6 +15,8 @@ class CustomConverter extends Converter | @@ -15,6 +15,8 @@ class CustomConverter extends Converter | ||
| 15 | public static $importer_id; | 15 | public static $importer_id; | 
| 16 | public static $brand; | 16 | public static $brand; | 
| 17 | public static $begin_of_the_day = true; | 17 | public static $begin_of_the_day = true; | 
| 18 | + // точность для округления десятичных чисел | ||
| 19 | + public static $precision = 2; | ||
| 18 | 20 | ||
| 19 | public static function convertToDetails(array $row) | 21 | public static function convertToDetails(array $row) | 
| 20 | { | 22 | { | 
| @@ -145,5 +147,20 @@ class CustomConverter extends Converter | @@ -145,5 +147,20 @@ class CustomConverter extends Converter | ||
| 145 | return $res; | 147 | return $res; | 
| 146 | } | 148 | } | 
| 147 | 149 | ||
| 150 | + public static function convertToFloat( $value ) | ||
| 151 | + { | ||
| 152 | + if ($value == '') { | ||
| 153 | + $value = 0; | ||
| 154 | + } | ||
| 155 | + $value = trim(str_replace(",", ".", $value)); | ||
| 156 | + $value = preg_replace("/[^0-9.]+/", "", strtoupper($value)); | ||
| 157 | + | ||
| 158 | + if ($value == '') { | ||
| 159 | + return ''; | ||
| 160 | + } | ||
| 161 | + $value = round( (float)$value, self::$precision ); | ||
| 162 | + | ||
| 163 | + return $value; | ||
| 164 | + } | ||
| 148 | 165 | ||
| 149 | } | 166 | } | 
| 150 | \ No newline at end of file | 167 | \ No newline at end of file | 
