From: Maxim Mamontov Date: Thu, 26 May 2011 11:53:50 +0000 (+0300) Subject: Fee charge rule selector added with 3 different charge rules X-Git-Tag: 2.408-alpha~145 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/cc7685dc764b43b8a9a061f4a38549f1c04fe047 Fee charge rule selector added with 3 different charge rules --- diff --git a/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf b/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf index 004ced0e..55efa6ac 100644 --- a/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf +++ b/projects/stargazer/inst/freebsd/etc/stargazer/stargazer.conf @@ -156,6 +156,15 @@ ModulesPath = /usr/lib/stg # Default: 0 (day) # MessagesTimeout = 0 +# Defines fee charging rules. +# 0 - classic rules, allow fee charge even cash is negative; +# 1 - disallow fee charge if cash value is negative; +# 2 - disallow fee charge if there is not enought cash (cash < fee). +# Parameter: optional +# Value: 0 - 2 +# Default: 0 (classic) +# FeeChargeType = 0 + ################################################################################ # Store module # Configure the module that works with the database server diff --git a/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf b/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf index 004ced0e..55efa6ac 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/stargazer.conf @@ -156,6 +156,15 @@ ModulesPath = /usr/lib/stg # Default: 0 (day) # MessagesTimeout = 0 +# Defines fee charging rules. +# 0 - classic rules, allow fee charge even cash is negative; +# 1 - disallow fee charge if cash value is negative; +# 2 - disallow fee charge if there is not enought cash (cash < fee). +# Parameter: optional +# Value: 0 - 2 +# Default: 0 (classic) +# FeeChargeType = 0 + ################################################################################ # Store module # Configure the module that works with the database server diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index d5fb2dad..33b3e840 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -63,6 +63,7 @@ SETTINGS_IMPL::SETTINGS_IMPL() writeFreeMbTraffCost(false), showFeeInCash(true), messageTimeout(0), + feeChargeType(0), modulesSettings(), storeModuleSettings(), logger(GetStgLogger()) @@ -93,6 +94,7 @@ SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) writeFreeMbTraffCost(false), showFeeInCash(true), messageTimeout(0), + feeChargeType(0), modulesSettings(), storeModuleSettings(), logger(GetStgLogger()) @@ -123,6 +125,7 @@ SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) writeFreeMbTraffCost(rval.writeFreeMbTraffCost), showFeeInCash(rval.showFeeInCash), messageTimeout(rval.messageTimeout), + feeChargeType(rval.feeChargeType), modulesSettings(rval.modulesSettings), storeModuleSettings(rval.storeModuleSettings), logger(GetStgLogger()) @@ -429,6 +432,15 @@ while (node) } } + if (strcasecmp(node->getName(), "FeeChargeType") == 0) + { + if (ParseUnsignedInRange(node->getValue(0), 0, 2, &feeChargeType) != 0) + { + strError = "Incorrect FeeChargeType value: \'" + string(node->getValue(0)) + "\'"; + return -1; + } + } + if (strcasecmp(node->getName(), "DirNames") == 0) { const DOTCONFDocumentNode * child = node->getChildNode(); diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index c7829b27..97990d32 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -90,6 +90,7 @@ public: const std::string & GetMonitorDir() const { return monitorDir; } bool GetMonitoring() const { return monitoring; } unsigned GetMessageTimeout() const { return messageTimeout * 3600 * 24; } + unsigned GetFeeChargeType() const { return feeChargeType; } const std::string & GetModulesPath() const { return modulesPath; } const MODULE_SETTINGS & GetStoreModuleSettings() const @@ -135,6 +136,7 @@ private: bool writeFreeMbTraffCost; bool showFeeInCash; unsigned messageTimeout; + unsigned feeChargeType; std::vector modulesSettings; MODULE_SETTINGS storeModuleSettings; diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 34c922b2..5abbeef7 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -1120,13 +1120,26 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (passive.ConstData()) return; -double f = tariff->GetFee() / DaysInCurrentMonth(); +double fee = tariff->GetFee() / DaysInCurrentMonth(); -if (f == 0.0) +if (fee == 0.0) return; double c = cash; -property.cash.Set(c - f, sysAdmin, login, store, "Subscriber fee charge"); +switch (settings->GetFeeChargeType()) + { + case 0: + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 1: + if (c > 0) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 2: + if (c > fee) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + } ResetPassiveTime(); } //----------------------------------------------------------------------------- @@ -1147,11 +1160,11 @@ else return; } } -double f = tariff->GetFee() * passiveTimePart; +double fee = tariff->GetFee() * passiveTimePart; ResetPassiveTime(); -if (f == 0.0) +if (fee == 0.0) return; double c = cash; @@ -1159,8 +1172,21 @@ printfd(__FILE__, "login: %8s Fee=%f PassiveTimePart=%f fee=%f\n", login.c_str(), tariff->GetFee(), passiveTimePart, - f); -property.cash.Set(c - f, sysAdmin, login, store, "Subscriber fee charge"); + fee); +switch (settings->GetFeeChargeType()) + { + case 0: + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 1: + if (c > 0) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + case 2: + if (c > fee) + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + break; + } } //----------------------------------------------------------------------------- void USER_IMPL::SetPrepaidTraff()