X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6f7160dd027c8ce7e2760aa369768ba39ab80181..5d4c15726d59897e9b6b52aaf986a4c4ea2fb553:/projects/stargazer/tariff_impl.cpp?ds=inline diff --git a/projects/stargazer/tariff_impl.cpp b/projects/stargazer/tariff_impl.cpp index bfae5215..d619b32d 100644 --- a/projects/stargazer/tariff_impl.cpp +++ b/projects/stargazer/tariff_impl.cpp @@ -31,20 +31,20 @@ #include #include // std::max +#include "stg/common.h" #include "tariff_impl.h" #include "stg_timer.h" -#include "common.h" //----------------------------------------------------------------------------- -TARIFF & TARIFF_IMPL::operator=(const TARIFF_DATA & td) +TARIFF_IMPL & TARIFF_IMPL::operator=(const TARIFF_DATA & td) { tariffData = td; return *this; } //----------------------------------------------------------------------------- -TARIFF & TARIFF_IMPL::operator=(const TARIFF & t) +TARIFF_IMPL & TARIFF_IMPL::operator=(const TARIFF_IMPL & t) { -tariffData = t.GetTariffData(); +tariffData = t.tariffData; return *this; } //----------------------------------------------------------------------------- @@ -119,7 +119,7 @@ else } } //----------------------------------------------------------------------------- -double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int mb, time_t t) const +double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int64_t mb, time_t t) const { int interval = Interval(dir, t); @@ -143,45 +143,34 @@ else if (!sp && th) return tariffData.dirPrice[dir].priceNightA; else return tariffData.dirPrice[dir].priceDayA; - -/*if (tariffData.dirPrice[dir].noDiscount && tariffData.dirPrice[dir].singlePrice) - { - return tariffData.dirPrice[dir].priceDayA; - } -else +} +//----------------------------------------------------------------------------- +std::string TARIFF_IMPL::TariffChangeIsAllowed(const TARIFF & to) const +{ +switch (GetChangePolicy()) { - if (tariffData.dirPrice[dir].noDiscount) + case TARIFF::ALLOW: { - // Without threshold - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceNightA; + return ""; } - - if (tariffData.dirPrice[dir].singlePrice) + case TARIFF::TO_CHEAP: { - // Without day/night - if (mb < tariffData.dirPrice[dir].threshold) - return tariffData.dirPrice[dir].priceDayA; + if (to.GetFee() < GetFee()) + return ""; else - return tariffData.dirPrice[dir].priceDayB; + return "Current tariff " + GetName() + " is more cheap than new tariff " + to.GetName() + ". The policy is " + TARIFF::ChangePolicyToString(GetChangePolicy()).c_str() + "."; } - - if (mb < tariffData.dirPrice[dir].threshold) + case TARIFF::TO_EXPENSIVE: { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; + if (to.GetFee() > GetFee()) + return ""; else - return tariffData.dirPrice[dir].priceNightA; + return "Current tariff " + GetName() + " is more expensive than new tariff " + to.GetName() + ". The policy is " + TARIFF::ChangePolicyToString(GetChangePolicy()).c_str() + "."; } - else + case TARIFF::DENY: { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayB; - else - return tariffData.dirPrice[dir].priceNightB; + return "Current tariff " + GetName() + ", new tariff " + to.GetName() + "."; } - }*/ + } } //-----------------------------------------------------------------------------