Commit 20aff4d4cbad70bceefa571e10f299e1a6b16812
1 parent
ea4aad25
add round for koef margin grup before writing to bd
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
backend/controllers/RgGrupController.php
@@ -168,7 +168,8 @@ class RgGrupController extends BaseController | @@ -168,7 +168,8 @@ class RgGrupController extends BaseController | ||
168 | 168 | ||
169 | $row['importer_id'] = trim($importer_id); | 169 | $row['importer_id'] = trim($importer_id); |
170 | $row['margin_id'] = ltrim($key, '!'); | 170 | $row['margin_id'] = ltrim($key, '!'); |
171 | - $row['koef'] = \Yii::$app->converter->convertTo('float', $value); | 171 | + $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); |
172 | + | ||
172 | 173 | ||
173 | $arr_values[] = $row; | 174 | $arr_values[] = $row; |
174 | 175 |
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 |