st->Prepare("insert into tb_users_services (fk_user, fk_service) \
values (?, (select pk_service from tb_services \
where name = ?))");
- for(std::vector<std::string>::const_iterator it = conf.service.begin(); it != conf.service.end(); ++it)
+ for(std::vector<std::string>::const_iterator it = conf.services.begin(); it != conf.services.end(); ++it)
{
st->Set(1, uid);
st->Set(2, *it);
{
std::string name;
st->Get(1, name);
- conf->service.push_back(name);
+ conf->services.push_back(name);
}
// User data
where fk_user = ?");
st->Set(1, uid);
st->Execute();
- conf->ips.Erase();
+ USER_IPS ips;
while (st->Fetch())
{
IP_MASK im;
st->Get(1, (int32_t &)im.ip);
st->Get(2, (int32_t &)im.mask);
- conf->ips.Add(im);
+ ips.Add(im);
}
+ conf->ips = ips;
tr->Commit();
}
PQclear(result);
-if (SaveUserServices(uid, conf.service))
+if (SaveUserServices(uid, conf.services))
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveUserConf(): 'Failed to save user's services'\n");
if (RollbackTransaction())
for (int i = 0; i < tuples; ++i)
{
- conf->service.push_back(PQgetvalue(result, i, 0));
+ conf->services.push_back(PQgetvalue(result, i, 0));
}
PQclear(result);
tuples = PQntuples(result);
- conf->ips.Erase();
+ USER_IPS ips;
for (int i = 0; i < tuples; ++i)
{
- IP_MASK ipm;
+ IP_MASK im;
- int ip, mask;
+ im.ip = inet_strington(PQgetvalue(result, i, 0));
- ip = inet_strington(PQgetvalue(result, i, 0));
-
- if (str2x(PQgetvalue(result, i, 1), mask))
+ if (str2x(PQgetvalue(result, i, 1), im.mask))
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreUserConf(): 'Failed to fetch mask'\n");
continue;
}
- ipm.ip = ip;
- ipm.mask = mask;
-
- conf->ips.Add(ipm);
+ ips.Add(im);
}
+ conf->ips = ips;
PQclear(result);
{
password = "*_EMPTY_PASSWORD_*";
tariffName = NO_TARIFF_NAME;
+ tariff = tariffs->FindByName(tariffName);
ips = StrToIPS("*");
lastWriteStat = stgTime + random() % settings->GetStatWritePeriod();
lastWriteDetailedStat = stgTime;
ResetPassiveTime();
}
//-----------------------------------------------------------------------------
+void USER_IMPL::ProcessServices()
+{
+struct tm tms;
+time_t t = stgTime;
+localtime_r(&t, &tms);
+
+double passiveTimePart = 1.0;
+if (!settings->GetFullFee())
+ {
+ passiveTimePart = GetPassiveTimePart();
+ }
+else
+ {
+ if (passive.ConstData())
+ {
+ printfd(__FILE__, "Don't charge fee `cause we are passive\n");
+ return;
+ }
+ }
+
+for (size_t i = 0; i < property.Conf().services.size(); ++i)
+ {
+ SERVICE_CONF conf;
+ if (m_services.Find(property.Conf().services[i], &conf))
+ continue;
+ if (conf.payDay == tms.tm_mday ||
+ (conf.payDay == 0 && tms.tm_mday == DaysInCurrentMonth()))
+ {
+ double c = cash;
+ double fee = conf.cost * passiveTimePart;
+ printfd(__FILE__, "Service fee. login: %8s Cash=%f Credit=%f Fee=%f PassiveTimePart=%f fee=%f\n",
+ login.c_str(),
+ cash.ConstData(),
+ credit.ConstData(),
+ tariff->GetFee(),
+ passiveTimePart,
+ fee);
+ switch (settings->GetFeeChargeType())
+ {
+ case 0:
+ property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+ SetPrepaidTraff();
+ break;
+ case 1:
+ if (c + credit >= 0)
+ {
+ property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+ SetPrepaidTraff();
+ }
+ break;
+ case 2:
+ if (c + credit >= fee)
+ {
+ property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+ SetPrepaidTraff();
+ }
+ break;
+ case 3:
+ if (c >= 0)
+ {
+ property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+ SetPrepaidTraff();
+ }
+ break;
+ }
+ }
+ }
+}
+//-----------------------------------------------------------------------------
void USER_IMPL::SetPrepaidTraff()
{
if (tariff != NULL)