]> git.stg.codes - stg.git/commitdiff
Ticket 37. The switch case construction for changePolicy checking
authorElena Mamontova <helenh463@gmail.com>
Tue, 26 Jul 2016 13:29:20 +0000 (16:29 +0300)
committerElena Mamontova <helenh463@gmail.com>
Tue, 26 Jul 2016 13:29:20 +0000 (16:29 +0300)
added in the ProcessNewMonth() function.

projects/stargazer/user_impl.cpp

index 5d505307a72302bbddccbe92be280aefdea592a7..afd70b607c93f1e90ad4ba98240f09db74cec8d9 100644 (file)
@@ -1181,7 +1181,47 @@ if (nextTariff.ConstData() != "")
         WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.",
                      login.c_str(), property.tariffName.Get().c_str());
     else
         WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.",
                      login.c_str(), property.tariffName.Get().c_str());
     else
-        property.tariffName.Set(nextTariff, sysAdmin, login, store);
+        {
+        switch (tariff->GetChangePolicy())
+            {
+            case TARIFF::ALLOW:
+                {
+                property.tariffName.Set(nextTariff, sysAdmin, login, store);
+                break;
+                }
+            case TARIFF::TO_CHEAP:
+                {
+                if (nt->GetFee() < tariff->GetFee())
+                    property.tariffName.Set(nextTariff, sysAdmin, login, store);
+                else
+                    WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more cheap than new tariff %s.",
+                                 login.c_str(),
+                                 TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(),
+                                 property.tariffName.Get().c_str(),
+                                 property.nextTariff.Get().c_str());
+                break;
+                }
+            case TARIFF::TO_EXPENSIVE:
+                {
+                if (nt->GetFee() > tariff->GetFee())
+                    property.tariffName.Set(nextTariff, sysAdmin, login, store);
+                else
+                    WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more expensive than new tariff %s.",
+                                 login.c_str(),
+                                 TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(),
+                                 property.tariffName.Get().c_str(),
+                                 property.nextTariff.Get().c_str());
+                break;
+                }
+            case TARIFF::DENY:
+                {
+                WriteServLog("Tariff change is prohibited for user %s. Tariff %s.",
+                             login.c_str(),
+                             property.tariffName.Get().c_str());
+                break;
+                }
+            }
+        }
     ResetNextTariff();
     WriteConf();
     }
     ResetNextTariff();
     WriteConf();
     }