Commit 94c7f4e1 authored by Martin Straka's avatar Martin Straka
Browse files

Made pdz info task async and include credit info in this.

parent dedc8e0e
......@@ -1060,7 +1060,10 @@ Item {
return
}
var dbID = accounts.dbId(actionAcntId);
databoxInfo.text = databoxInfo.text + isds.pdzInfo(actionAcntId, dbID);
isds.getPdzInfo(actionAcntId, dbID);
}
function onGetPdzInfoSig(pdzInfo) {
databoxInfo.text = databoxInfo.text + pdzInfo;
}
} // Connections
} // Item
......@@ -629,7 +629,7 @@ void Isds::Tasks::syncSingleAccount(const AcntId &acntId,
}
}
QList<Isds::PDZInfoRec> Isds::Tasks::downloadPdzInfo(const AcntId &acntId,
void Isds::Tasks::downloadPdzInfo(const AcntId &acntId,
const QString &dbID)
{
debugFuncCall();
......@@ -637,21 +637,17 @@ QList<Isds::PDZInfoRec> Isds::Tasks::downloadPdzInfo(const AcntId &acntId,
if (Q_UNLIKELY((GlobInstcs::workPoolPtr == Q_NULLPTR) ||
dbID.isEmpty())) {
Q_ASSERT(0);
return QList<PDZInfoRec>();
return;
}
TaskPDZInfo *task =
new (::std::nothrow) TaskPDZInfo(acntId, dbID);
if (Q_UNLIKELY(task == Q_NULLPTR)) {
Q_ASSERT(0);
return QList<PDZInfoRec>();
return;
}
task->setAutoDelete(false);
GlobInstcs::workPoolPtr->runSingle(task);
QList<PDZInfoRec> pdzInfo(task->m_pdzInfoRecs);
delete task; task = Q_NULLPTR;
return pdzInfo;
task->setAutoDelete(true);
GlobInstcs::workPoolPtr->assignHi(task);
}
void Isds::Tasks::downloadPdzSendInfo(const AcntId &acntId, const QString &dbID,
......
......@@ -244,11 +244,9 @@ namespace Isds {
*
* @param[in] acntId Account identifier.
* @param[in] dbID Data box id.
* @return Pdz info list.
*/
static
QList<Isds::PDZInfoRec> downloadPdzInfo(const AcntId &acntId,
const QString &dbID);
void downloadPdzInfo(const AcntId &acntId, const QString &dbID);
/*!
* @brief Download pdz send info.
......
......@@ -55,6 +55,9 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
logErrorNL("%s", "Cannot connect to status message emitter.");
return;
}
qRegisterMetaType<QList<Isds::PDZInfoRec>>("QList<Isds::PDZInfoRec");
/* Worker-related processing signals. */
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(downloadAccountInfoFinishedSignal(AcntId, bool, QString)),
......@@ -62,7 +65,8 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
SLOT(downloadAccountInfoFinished(AcntId, bool, QString)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(downloadDeliveryInfoFinishedSignal(AcntId, qint64, bool, QString)),
SIGNAL(downloadDeliveryInfoFinishedSignal(AcntId, qint64,
bool, QString)),
this,
SLOT(downloadDeliveryInfoFinished(AcntId, qint64, bool, QString)));
......@@ -72,18 +76,29 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
SLOT(downloadMessageFinished(AcntId, qint64, bool, QString)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(downloadMessageListFinishedSignal(AcntId, bool, QString, QString, bool)),
SIGNAL(downloadMessageListFinishedSignal(AcntId, bool, QString,
QString, bool)),
this,
SLOT(downloadMessageListFinished(AcntId, bool, QString, QString, bool)));
SLOT(downloadMessageListFinished(AcntId, bool, QString,
QString, bool)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(importZFOFinishedSignal(int, int, QString)),
this, SLOT(importZFOFinished(int, int, QString)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(sendMessageFinishedSignal(AcntId, QString, QString, QString, qint64, bool, QString)),
SIGNAL(sendMessageFinishedSignal(AcntId, QString, QString, QString,
qint64, bool, QString)),
this,
SLOT(sendMessageFinished(AcntId, QString, QString, QString,
qint64, bool, QString)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(pdzInfoFinishedSignal(AcntId, qint64,
QList<Isds::PDZInfoRec>, bool, QString)),
this,
SLOT(sendMessageFinished(AcntId, QString, QString, QString, qint64, bool, QString)));
SLOT(pdzInfoFinished(AcntId, qint64,
QList<Isds::PDZInfoRec>, bool, QString)));
}
void IsdsWrapper::closeAllOtpConnections(void)
......@@ -506,55 +521,17 @@ QString getPDZCreditFromISDS(const AcntId &acntId, const QString &dbId)
Isds::Tasks::downloadCreditInfo(acntId, dbId, QDate(), QDate(),
currentCredit, notifEmail);
if (currentCredit <= 0) {
return QString();
}
return QString::number((float)currentCredit / 100, 'f', 2);
}
/*!
* @brief Insert separator prepend text.
*
* @param[in] str Text.
* @return Text with separator.
*/
static
QString insertSeparator(const QString &str)
{
return QStringLiteral("; ") + str;
}
QString IsdsWrapper::pdzInfo(const QmlAcntId *qAcntId, const QString &dbID)
void IsdsWrapper::getPdzInfo(const QmlAcntId *qAcntId, const QString &dbID)
{
if (Q_UNLIKELY(qAcntId == Q_NULLPTR) || dbID.isEmpty()) {
Q_ASSERT(0);
return insertSeparator(tr("PDZ sending: N/A"));
}
m_pdzInfos = Isds::Tasks::downloadPdzInfo(*qAcntId, dbID);
if (m_pdzInfos.count() == 0) {
return insertSeparator(tr("PDZ sending: No"));
}
QString pdzSending(insertSeparator(tr("PDZ sending: Active")));
/* Payment priority: O->G->K->E */
foreach (const Isds::PDZInfoRec &info, m_pdzInfos) {
/* Isds::Type::PPT_O not used now. */
if (info.pdzType() == Isds::Type::PPT_G) {
pdzSending += insertSeparator(tr("Sponsored by data box %1.").arg(info.pdzPayer()));
break;
} else if (info.pdzType() == Isds::Type::PPT_K) {
pdzSending += insertSeparator(tr("Contract"));
} else if (info.pdzType() == Isds::Type::PPT_E) {
m_pdzCredit = getPDZCreditFromISDS(*qAcntId, dbID);
pdzSending += insertSeparator(tr("Remaining credit: %1 Kč").arg(m_pdzCredit));
}
return;
}
return pdzSending;
Isds::Tasks::downloadPdzInfo(*qAcntId, dbID);
}
/*!
......@@ -1225,3 +1202,52 @@ void IsdsWrapper::sendMessageFinished(const AcntId &acntId,
emit sentMessageFinished(false);
}
}
/*!
* @brief Insert separator prepend text.
*
* @param[in] str Text.
* @return Text with separator.
*/
static
QString insertSeparator(const QString &str)
{
return QStringLiteral("; ") + str;
}
void IsdsWrapper::pdzInfoFinished(const AcntId &acntId, qint64 currentCredit,
const QList<Isds::PDZInfoRec> &infos, bool success, const QString &errTxt)
{
QString pdzSending(insertSeparator(tr("PDZ sending: N/A")));
if (!success) {
logErrorNL("Cannot download pdz info for username %s; Error: %s",
acntId.username().toUtf8().constData(),
errTxt.toUtf8().constData());
goto finish;
}
m_pdzInfos = infos;
if (m_pdzInfos.count() == 0) {
pdzSending = insertSeparator(tr("PDZ sending: No"));
goto finish;
}
pdzSending = insertSeparator(tr("PDZ sending: Active"));
foreach (const Isds::PDZInfoRec &info, m_pdzInfos) {
if (info.pdzType() == Isds::Type::PPT_G) {
pdzSending += insertSeparator(tr("Sponsored by data box %1.").arg(info.pdzPayer()));
break;
} else if (info.pdzType() == Isds::Type::PPT_K) {
pdzSending += insertSeparator(tr("Contract"));
} else if (info.pdzType() == Isds::Type::PPT_E) {
m_pdzCredit = QString::number((float)currentCredit / 100, 'f', 2);
pdzSending += insertSeparator(tr("Remaining credit: %1 Kč").arg(m_pdzCredit));
}
}
finish:
emit getPdzInfoSig(pdzSending);
}
......@@ -300,10 +300,9 @@ public:
*
* @param[in] qAcntId Account identifier.
* @param[in] dbID Data box ID.
* @return Pdz info string.
*/
Q_INVOKABLE
QString pdzInfo(const QmlAcntId *qAcntId, const QString &dbID);
void getPdzInfo(const QmlAcntId *qAcntId, const QString &dbID);
/*!
* @brief Add recipient into recipient model and set pdz payment methods.
......@@ -482,6 +481,19 @@ public slots:
const QString &dmRecipient, qint64 msgId, bool success,
const QString &errTxt);
/*!
* @brief Do some actions when pdz info finished.
*
* @param[in] acntId Account identifier.
* @param[in] currentCredit Current credit in CZK.
* @param[in] infos Pdz info list.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void pdzInfoFinished(const AcntId &acntId, qint64 currentCredit,
const QList<Isds::PDZInfoRec> &infos, bool success,
const QString &errTxt);
signals:
/*!
* @brief Update message model in QML.
......@@ -637,6 +649,13 @@ signals:
*/
void initSendMsgDlgSig(QString userName, bool testing);
/*!
* @brief Send ommercial message sending info to QML.
*
* @param[in] pdzInfo Commercial message sending info.
*/
void getPdzInfoSig(QString pdzInfo);
/*!
* @brief Do some post QML action after message sending.
*
......
......@@ -26,6 +26,7 @@
#include <QObject>
#include "src/datovka_shared/identifiers/account_id.h"
#include "src/datovka_shared/isds/box_interface.h"
/*!
* @brief Message processing status emitter.
......@@ -114,4 +115,19 @@ signals:
*/
void rmSyncFinishedSignal(const AcntId &acntId, int accNumber,
int accTotal);
/*!
* @brief Do some actions when pdz info finished.
*
* @param[in] acntId Account identifier.
* @param[in] currentCredit Current credit in CZK.
* @param[in] infos Pdz info list.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void pdzInfoFinishedSignal(const AcntId &acntId, qint64 currentCredit,
const QList<Isds::PDZInfoRec> &infos, bool success,
const QString &errTxt);
};
Q_DECLARE_METATYPE(QList<Isds::PDZInfoRec>)
......@@ -37,6 +37,7 @@ TaskPDZInfo::TaskPDZInfo(const AcntId &acntId,
: m_result(DL_ERR),
m_lastError(),
m_pdzInfoRecs(),
m_currentCredit(0),
m_acntId(acntId),
m_dbId(dbId)
{
......@@ -51,7 +52,14 @@ void TaskPDZInfo::run(void)
/* ### Worker task begin. ### */
m_result = pdzInfo(m_acntId, m_dbId, m_pdzInfoRecs, m_lastError);
m_result = pdzInfo(m_acntId, m_dbId, m_pdzInfoRecs, m_currentCredit,
m_lastError);
if (GlobInstcs::msgProcEmitterPtr != Q_NULLPTR) {
emit GlobInstcs::msgProcEmitterPtr->pdzInfoFinishedSignal(
m_acntId, m_currentCredit, m_pdzInfoRecs,
TaskPDZInfo::DL_SUCCESS == m_result, m_lastError);
}
logDebugLv0NL("Finished in thread '%p'", QThread::currentThreadId());
logDebugLv0NL("%s", "-----------------------------------------------");
......@@ -84,7 +92,7 @@ enum TaskPDZInfo::Result error2result(enum Isds::Type::Error error)
enum TaskPDZInfo::Result TaskPDZInfo::pdzInfo(const AcntId &acntId,
const QString &dbId, QList<Isds::PDZInfoRec> &pdzInfoRecs,
QString &lastError)
qint64 &currentCredit, QString &lastError)
{
if (Q_UNLIKELY((!acntId.isValid()) ||
(GlobInstcs::isdsSessionsPtr == Q_NULLPTR) ||
......@@ -108,5 +116,29 @@ enum TaskPDZInfo::Result TaskPDZInfo::pdzInfo(const AcntId &acntId,
return error2result(error);
}
bool credit = false;
foreach (const Isds::PDZInfoRec &info, pdzInfoRecs) {
if (info.pdzType() == Isds::Type::PPT_E) {
credit = true;
break;
}
}
if (!credit) {
return DL_SUCCESS;
}
/* Ask to credit info. */
QString notifEmail;
QList<Isds::CreditEvent> creditEvents;
QString errTxt;
error = Isds::dataBoxCreditInfo(*session, dbId, QDate(), QDate(),
currentCredit, notifEmail, creditEvents, Q_NULLPTR, &errTxt);
if (Q_UNLIKELY(error != Isds::Type::ERR_SUCCESS)) {
logErrorNL("Cannot download credit info for username %s; Error: %s",
acntId.username().toUtf8().constData(),
errTxt.toUtf8().constData());
}
return DL_SUCCESS;
}
......@@ -63,6 +63,7 @@ public:
enum Result m_result; /*!< Return state. */
QString m_lastError; /*!< Last ISDS error message. */
QList<Isds::PDZInfoRec> m_pdzInfoRecs; /*!< PDZ info record list. */
qint64 m_currentCredit; /*!< Current credit in CZK. */
private:
/*!
......@@ -77,12 +78,14 @@ private:
* @param[in] acntId Account identifier.
* @param[in] dbId Data box identifier.
* @param[out] pdzInfoRecs List of PDZ info.
* @param[out] currentCredit Current credit in CZK.
* @param[out] lastError Last ISDS error message.
* @return Error state.
*/
static
enum Result pdzInfo(const AcntId &acntId, const QString &dbId,
QList<Isds::PDZInfoRec> &pdzInfoRecs, QString &lastError);
QList<Isds::PDZInfoRec> &pdzInfoRecs, qint64 &currentCredit,
QString &lastError);
const AcntId m_acntId; /*!< Account identifier. */
const QString m_dbId; /*!< Data box identifier. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment