Enhanced `TransactionInfo` with new fields such as type, status, fee, and timestamps. Updated DAO functionality to handle these changes, including insertion, updates, and retrieval methods. Additionally, implemented utility functions for type/status conversion.
114 lines
3.1 KiB
C
114 lines
3.1 KiB
C
#pragma once
|
|
|
|
#include <QString>
|
|
#include <QDateTime>
|
|
|
|
enum class TransactionType {
|
|
Card,
|
|
Phone,
|
|
Unknown
|
|
};
|
|
|
|
enum class TransactionStatus {
|
|
Wait,
|
|
Complete,
|
|
Unknown
|
|
};
|
|
|
|
|
|
inline QString transactionTypeToString(const TransactionType type) {
|
|
switch (type) {
|
|
case TransactionType::Card: return "card";
|
|
case TransactionType::Phone: return "phone";
|
|
default: return "unknown";
|
|
}
|
|
}
|
|
|
|
inline TransactionType transactionTypeFromString(const QString &str) {
|
|
if (str == "card") return TransactionType::Card;
|
|
if (str == "phone") return TransactionType::Phone;
|
|
return TransactionType::Unknown;
|
|
}
|
|
|
|
inline QString transactionStatusToString(const TransactionStatus type) {
|
|
switch (type) {
|
|
case TransactionStatus::Wait: return "wait";
|
|
case TransactionStatus::Complete: return "complete";
|
|
default: return "unknown";
|
|
}
|
|
}
|
|
|
|
inline TransactionStatus transactionStatusFromString(const QString &str) {
|
|
if (str == "wait") return TransactionStatus::Wait;
|
|
if (str == "complete") return TransactionStatus::Complete;
|
|
return TransactionStatus::Unknown;
|
|
}
|
|
|
|
struct TransactionInfo {
|
|
int id = -1;
|
|
int accountId = -1;
|
|
|
|
double amount = 0;
|
|
double fee = 0;
|
|
TransactionStatus status = TransactionStatus::Unknown;
|
|
TransactionType type = TransactionType::Unknown;
|
|
QString phone;
|
|
QString name;
|
|
|
|
QString shortDescription;
|
|
QString updatedShortDescription;
|
|
QString description;
|
|
QString updatedDescription;
|
|
|
|
QString bankName;
|
|
QString bankTime;
|
|
|
|
QString trExternalId;
|
|
|
|
QDateTime updateTime;
|
|
QDateTime completeTime;
|
|
QDateTime timestamp;
|
|
};
|
|
|
|
inline QString convertTransactionToString(const TransactionInfo &tx) {
|
|
return QString(
|
|
"TransactionInfo {\n"
|
|
" id: %1\n"
|
|
" accountId: %2\n"
|
|
" amount: %3\n"
|
|
" fee: %4\n"
|
|
" status: %5\n"
|
|
" type: %6\n"
|
|
" phone: %7\n"
|
|
" shortDescription: %8\n"
|
|
" updatedShortDescription: %9\n"
|
|
" description: %10\n"
|
|
" updatedDescription: %11\n"
|
|
" bankName: %12\n"
|
|
" bankTime: %13\n"
|
|
" name: %14\n"
|
|
" trExternalId: %15\n"
|
|
" updateTime: %16\n"
|
|
" completeTime: %17\n"
|
|
" timestamp: %18\n"
|
|
"}"
|
|
).arg(tx.id)
|
|
.arg(tx.accountId)
|
|
.arg(tx.amount)
|
|
.arg(tx.fee)
|
|
.arg(transactionStatusToString(tx.status))
|
|
.arg(transactionTypeToString(tx.type))
|
|
.arg(tx.phone)
|
|
.arg(tx.shortDescription)
|
|
.arg(tx.updatedShortDescription)
|
|
.arg(tx.description)
|
|
.arg(tx.updatedDescription)
|
|
.arg(tx.bankName)
|
|
.arg(tx.bankTime)
|
|
.arg(tx.name)
|
|
.arg(tx.trExternalId)
|
|
.arg(tx.updateTime.toString(Qt::ISODate))
|
|
.arg(tx.completeTime.toString(Qt::ISODate))
|
|
.arg(tx.timestamp.toString(Qt::ISODate));
|
|
}
|