From: Maxim Mamontov <faust.madf@gmail.com>
Date: Sun, 20 Dec 2015 17:25:55 +0000 (+0200)
Subject: Fixed editing tariffs.
X-Git-Tag: 2.409~174^2~6
X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/bd6a9a4e59fa38929491c7114abef914d4002ee5

Fixed editing tariffs.
---

diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp
index cc32b6fc..0607db6f 100644
--- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp
+++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp
@@ -56,6 +56,16 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi
     return res;
 }
 
+template <typename T>
+bool str2res(const std::string& source, RESETABLE<T>& dest, T divisor)
+{
+    T value = 0;
+    if (str2x(source, value))
+        return false;
+    dest = value / divisor;
+    return true;
+}
+
 template <typename A, typename C, typename F>
 bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE<F> C::* field, F divisor)
 {
@@ -64,15 +74,13 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE<F>
     std::string::size_type pos = 0;
     while (index < size && (pos = source.find('/', from)) != std::string::npos)
     {
-        if (str2x(source.substr(from, pos - from), (array[index].*field).data()))
+        if (!str2res(source.substr(from, pos - from), array[index].*field, divisor))
             return false;
-        (array[index].*field).data() /= divisor;
         from = pos + 1;
         ++index;
     }
-    if (str2x(source.substr(from), (array[index].*field).data()))
+    if (str2res(source.substr(from), array[index].*field, divisor))
         return false;
-    (array[index].*field).data() /= divisor;
     return true;
 }
 
diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
index f7aef966..a7b719ed 100644
--- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
+++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
@@ -31,6 +31,13 @@
 #include "firebird_store.h"
 #include "stg/ibpp.h"
 
+namespace
+{
+
+const int pt_mega = 1024 * 1024;
+
+}
+
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
@@ -305,8 +312,8 @@ try
     st->Get(7, td->dirPrice[dir].priceNightB);
     td->dirPrice[dir].priceNightB /= 1024*1024;
     st->Get(8, td->dirPrice[dir].threshold);
-    if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 &&
-        std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3)
+    if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega &&
+        std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega)
         {
         td->dirPrice[dir].singlePrice = true;
         }
diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp
index dabc06db..045411b1 100644
--- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp
+++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp
@@ -36,6 +36,13 @@
 #include "postgresql_store.h"
 #include "stg/locker.h"
 
+namespace
+{
+
+const int pt_mega = 1024 * 1024;
+
+}
+
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
@@ -568,8 +575,8 @@ for (int i = 0; i < std::min(tuples, DIR_NUM); ++i)
         tuple >> td->dirPrice[dir].mNight;
         }
 
-    if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) > 1.0e-3 &&
-        std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) > 1.0e-3)
+    if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega &&
+        std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega)
         {
         td->dirPrice[dir].singlePrice = true;
         }