Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Dec 7, 2024
1 parent e33a3eb commit 7d19167
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 66 deletions.
4 changes: 2 additions & 2 deletions plugins/LCLBroker/src/Headers/LCLBrokerBuild.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define LCLBroker_Prefix "LCLBroker"
#define LCLBroker_BuildNumber 295
#define LCLBroker_BuildNumber 302
#define LCLBroker_MinorNumber 0
#define LCLBroker_MajorNumber 0
#define LCLBroker_BuildId "0.0.295"
#define LCLBroker_BuildId "0.0.302"
22 changes: 4 additions & 18 deletions src/Frontend/Dialogs/IncomeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void IncomeDialog::m_drawContentCreation(const ImVec2& vPos) {
ImGui::DisplayAlignedWidget(width, "Min day", align, [this]() { ImGui::InputInt("##MinDay", &m_IncomeMinDayInputInt32); });
ImGui::DisplayAlignedWidget(width, "Max day", align, [this]() { ImGui::InputInt("##MaxDay", &m_IncomeMaxDayInputInt32); });
m_IncomeDescriptionInputText.DisplayInputText(width, "Description", "", false, align);
m_IncomeCommentInputText.DisplayInputText(width, "Comment", "", false, align);
}

void IncomeDialog::m_drawContentUpdate(const ImVec2& vPos) {
Expand Down Expand Up @@ -167,13 +166,10 @@ void IncomeDialog::m_prepare() {
m_IncomeToUpdate.entity = trans.entity;
m_IncomeToUpdate.operation = trans.operation;
m_IncomeToUpdate.description = trans.description;
m_IncomeToUpdate.comment = trans.comment;
m_IncomeToUpdate.maxAmount = trans.amount;
m_IncomeToUpdate.minAmount = trans.amount;
m_IncomeToUpdate.startDate = trans.date;
m_IncomeToUpdate.startDateEpoch = trans.epoch;
m_IncomeToUpdate.endDate = trans.date;
m_IncomeToUpdate.endDateEpoch = trans.epoch;
m_IncomeToUpdate.minDay = ez::time::decomposeEpoch(trans.epoch).tm_mday;
m_IncomeToUpdate.maxDay = m_IncomeToUpdate.minDay;
for (const auto& t : m_TransactionToAddAsIncomes) {
Expand All @@ -189,26 +185,16 @@ void IncomeDialog::m_prepare() {
if (m_IncomeToUpdate.description != t.description) {
m_IncomeToUpdate.description = "Many values";
}
if (m_IncomeToUpdate.comment != t.comment) {
m_IncomeToUpdate.comment = "Many values";
}
if (t.amount < m_IncomeToUpdate.minAmount) {
m_IncomeToUpdate.minAmount = t.amount;
}
if (t.amount > m_IncomeToUpdate.maxAmount) {
m_IncomeToUpdate.maxAmount = t.amount;
}
// cette simple conversion n'est pas viable
// il va falloir convertir en epoch
if (t.epoch < m_IncomeToUpdate.startDateEpoch) {
m_IncomeToUpdate.startDateEpoch = t.epoch;
m_IncomeToUpdate.startDate = t.date;
}
if (t.epoch > m_IncomeToUpdate.endDateEpoch) {
m_IncomeToUpdate.endDateEpoch = t.epoch;
m_IncomeToUpdate.endDate = t.date;
}
// et aussi extraire le numero du jour dans le mois
auto day = ez::time::decomposeEpoch(t.epoch).tm_mday;
if (day < m_IncomeToUpdate.minDay) {
m_IncomeToUpdate.minDay = day;
Expand All @@ -230,7 +216,6 @@ void IncomeDialog::m_prepare() {
m_IncomeMinAmountInputDouble = m_IncomeToUpdate.minAmount;
m_IncomeMaxAmountInputDouble = m_IncomeToUpdate.maxAmount;
m_IncomeDescriptionInputText.SetText(m_IncomeToUpdate.description);
m_IncomeCommentInputText.SetText(m_IncomeToUpdate.comment);
}

const char* IncomeDialog::m_getTitle() const {
Expand Down Expand Up @@ -301,7 +286,7 @@ void IncomeDialog::m_confirmDialogCreation() {
RowID account_id = 0U;
if (DataBase::Instance()->GetAccount(m_AccountsCombo.getText(), account_id)) {
if (DataBase::Instance()->OpenDBFile()) {
DataBase::Instance()->AddIncome(
DataBase::Instance()->AddIncome( //
account_id,
m_IncomeNameInputText.GetText(),
m_EntitiesCombo.getText(),
Expand All @@ -312,7 +297,8 @@ void IncomeDialog::m_confirmDialogCreation() {
m_IncomeMinAmountInputDouble,
m_IncomeMaxAmountInputDouble,
m_IncomeMinDayInputInt32,
m_IncomeMaxDayInputInt32);
m_IncomeMaxDayInputInt32,
m_IncomeDescriptionInputText.GetText());
DataBase::Instance()->CloseDBFile();
}
}
Expand Down Expand Up @@ -429,7 +415,7 @@ void IncomeDialog::m_UpdateAccounts() {

void IncomeDialog::m_UpdateEntities() {
m_EntitiesCombo.clear();
DataBase::Instance()->GetEntities( //
DataBase::Instance()->GetEntities( //
[this](const EntityName& vEntityName) { //
m_EntitiesCombo.getArrayRef().push_back(vEntityName);
});
Expand Down
5 changes: 2 additions & 3 deletions src/Frontend/Dialogs/IncomeDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class IncomeDialog : public ADataDialog {
ImWidgets::InputText m_IncomeNameInputText;
ImWidgets::InputText m_IncomeStartDateInputText;
ImWidgets::InputText m_IncomeEndDateInputText;
IncomeDelayDays m_IncomeMinDayInputInt32 = 0;
IncomeDelayDays m_IncomeMaxDayInputInt32 = 0;
IncomeDay m_IncomeMinDayInputInt32 = 0;
IncomeDay m_IncomeMaxDayInputInt32 = 0;
ImWidgets::InputText m_IncomeDescriptionInputText;
ImWidgets::InputText m_IncomeCommentInputText;

// transactions to add as incomes
std::vector<Transaction> m_TransactionToAddAsIncomes;
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/Dialogs/TransactionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ void TransactionDialog::m_confirmDialogUpdateAll() {
DataBase::Instance()->UpdateTransaction( //
t.id, //
t.entity, //
t.operation, //
t.category, //
t.operation, //
t.source, //
t.date, //
t.description, //
Expand Down
163 changes: 147 additions & 16 deletions src/Frontend/Tables/IncomesTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ IncomeDialog& IncomesTable::getIncomeDialogRef() {
}

size_t IncomesTable::m_getItemsCount() const {
return m_Incomes.size();
return m_Datas.incomes.size();
}

RowID IncomesTable::m_getItemRowID(const size_t& vIdx) const {
if (vIdx < m_Incomes.size()) {
return m_Incomes.at(vIdx).id;
if (vIdx < m_Datas.incomes.size()) {
return m_Datas.incomes.at(vIdx).id;
}
return 0; // the db row id cant be 0
}

void IncomesTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) {
auto& t = m_Incomes.at(vIdx);
auto& t = m_Datas.incomes.at(vIdx);
m_drawColumnSelectable(vIdx, t.id, t.name);
m_drawColumnText(t.startDate);
m_drawColumnText(t.endDate);
Expand All @@ -64,23 +64,23 @@ void IncomesTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmou
void IncomesTable::m_setupColumns() {
ImGui::TableSetupScrollFreeze(0, 2);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("StartDate", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("EndDate", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Start Date", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("End Date", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Entity", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Category", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Operation", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Min", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Max", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("MinDays", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("MaxDays", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Min Day", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Max Day", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableHeadersRow();
}

void IncomesTable::m_drawContextMenuContent() {
if (!m_getSelectedRows().empty()) {
if (ImGui::MenuItem("Update")) {
std::vector<Income> incomes_to_update;
for (const auto& trans : m_Incomes) {
for (const auto& trans : m_Datas.incomes) {
if (m_IsRowSelected(trans.id)) {
incomes_to_update.push_back(trans);
}
Expand All @@ -96,7 +96,7 @@ void IncomesTable::m_drawContextMenuContent() {
if (m_getSelectedRows().size() > 1U) {
if (ImGui::MenuItem("Merge")) {
std::vector<Income> incomes_to_update;
for (const auto& trans : m_Incomes) {
for (const auto& trans : m_Datas.incomes) {
if (m_IsRowSelected(trans.id)) {
incomes_to_update.push_back(trans);
}
Expand All @@ -107,7 +107,7 @@ void IncomesTable::m_drawContextMenuContent() {
}
if (ImGui::MenuItem("Delete")) {
std::vector<Income> incomes_to_delete;
for (const auto& trans : m_Incomes) {
for (const auto& trans : m_Datas.incomes) {
if (m_IsRowSelected(trans.id)) {
incomes_to_delete.push_back(trans);
}
Expand All @@ -119,12 +119,12 @@ void IncomesTable::m_drawContextMenuContent() {
}

void IncomesTable::m_doActionOnDblClick(const size_t& vIdx, const RowID& vRowID) {
m_IncomeDialog.setIncome(m_Incomes.at(vIdx));
m_IncomeDialog.setIncome(m_Datas.incomes.at(vIdx));
m_IncomeDialog.show(DataDialogMode::MODE_UPDATE_ONCE);
}

void IncomesTable::refreshDatas() {

m_UpdateAccounts();
}

void IncomesTable::drawDebugMenu(FrameActionSystem& vFrameActionSystem) {
Expand Down Expand Up @@ -156,8 +156,7 @@ void IncomesTable::drawDebugMenu(FrameActionSystem& vFrameActionSystem) {
refreshDatas();
}
if (ImGui::MenuItem("Incomes")) {
EZ_TOOLS_DEBUG_BREAK;
//DataBase::Instance()->DeleteIncomes();
DataBase::Instance()->DeleteIncomes();
refreshDatas();
}
ImGui::EndMenu();
Expand All @@ -167,6 +166,138 @@ void IncomesTable::drawDebugMenu(FrameActionSystem& vFrameActionSystem) {
#endif
}

void IncomesTable::drawAccountsMenu(FrameActionSystem& vFrameActionSystem) {
if (ImGui::BeginMenu("Accounts")) {
for (const auto& bank : m_Accounts) {
if (ImGui::BeginMenu(bank.first.c_str())) { // bank name
for (const auto& agency : bank.second) {
if (ImGui::BeginMenu(agency.first.c_str())) { // bank agency
static auto flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg;
if (ImGui::BeginTable("##MenuAccounts", 4, flags)) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Number", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Count", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableHeadersRow();
size_t idx = 0U;
for (const auto& number : agency.second) {
const auto& a = number.second;
ImGui::TableNextRow();

ImGui::PushID(a.id);
{
ImGui::TableNextColumn();
ImGui::PushID(&a);
{
if (ImGui::Selectable(a.number.c_str(), m_getAccountComboRef().getIndex() == idx, ImGuiSelectableFlags_SpanAllColumns)) {
m_ResetSelection();
m_UpdateIncomes(a.id);
m_getAccountComboRef().getIndexRef() = idx;
}
}
ImGui::PopID();

ImGui::TableNextColumn();
ImGui::Text("%s", a.name.c_str());

ImGui::TableNextColumn();
ImGui::Text("%s", a.type.c_str());

ImGui::TableNextColumn();
ImGui::Text("%u", a.count);
}
ImGui::PopID();

++idx;
}
ImGui::EndTable();
}
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
}

void IncomesTable::clear() {
m_Incomes.clear();
m_Datas.clear();
}

void IncomesTable::m_UpdateAccounts() {
m_Accounts.clear();
m_Datas.accounts.clear();
m_Datas.accountNumbers.clear();
DataBase::Instance()->GetAccounts( //
[this](
const RowID& vRowID,
const BankName& vBankName,
const BankAgency& vBankAgency,
const AccountType& vAccountType,
const AccountName& vAccountName,
const AccountNumber& vAccountNumber,
const AccounBaseSolde& vBaseSolde,
const TransactionsCount& vCount) { //
Account a;
a.id = vRowID;
a.bank = vBankName;
a.agency = vBankAgency;
a.type = vAccountType;
a.name = vAccountName;
a.number = vAccountNumber;
a.base_solde = vBaseSolde;
a.count = vCount;
m_Datas.accounts.push_back(a);
m_Datas.accountNumbers.push_back(vAccountNumber);
m_Accounts[vBankName + "##BankName"][vBankAgency + "##BankAgency"][vAccountNumber] = a;
});
if (m_getAccountComboRef().getIndex() < m_Datas.accounts.size()) {
m_UpdateIncomes(m_Datas.accounts.at(m_getAccountComboRef().getIndex()).id);
}
}

void IncomesTable::m_UpdateIncomes(const RowID& vAccountID) {
m_Datas.incomes.clear();
const auto& zero_based_account_id = vAccountID - 1;
if (zero_based_account_id < m_Datas.accounts.size()) {
const auto& account_number = m_Datas.accounts.at(zero_based_account_id).number;
DataBase::Instance()->GetIncomes(
vAccountID,
[this, account_number](
const RowID& vIncomeID,
const IncomeName& vIncomeName,
const EntityName& vEntityName,
const CategoryName& vCategoryName,
const OperationName& vOperationName,
const IncomeDate& vStartDate,
const IncomeDateEpoch& vStartDateEpoch,
const IncomeDate& vEndDate,
const IncomeDateEpoch& vEndDateEpoch,
const IncomeAmount& vMinAmount,
const IncomeAmount& vMaxAmount,
const IncomeDay& vMinDays,
const IncomeDay& vMaxDays,
const IncomeDescription& vDescription) {
Income in;
in.id = vIncomeID;
in.account = account_number;
in.entity = vEntityName;
in.category = vCategoryName;
in.operation = vOperationName;
in.name = vIncomeName;
in.startDate = vStartDate;
in.startDateEpoch = vStartDateEpoch;
in.endDate = vEndDate;
in.endDateEpoch = vEndDateEpoch;
in.minAmount = vMinAmount;
in.maxAmount = vMaxAmount;
in.minDay = vMinDays;
in.maxDay = vMaxDays;
in.description;
m_Datas.incomes.push_back(in);
});
}
}
20 changes: 17 additions & 3 deletions src/Frontend/Tables/IncomesTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@

class IncomesTable : public ADataTable {
private:
std::vector<Income> m_Incomes;

struct Datas {
std::vector<Account> accounts;
std::vector<AccountNumber> accountNumbers;
std::vector<Income> incomes;
void clear() {
accounts.clear();
accountNumbers.clear();
incomes.clear();
}
} m_Datas;
IncomeDialog m_IncomeDialog;
// accounts display
std::map<BankName, std::map<BankAgency, std::map<AccountNumber, Account>>> m_Accounts;

public:
IncomesTable();
Expand All @@ -27,9 +37,10 @@ class IncomesTable : public ADataTable {

IncomeDialog& getIncomeDialogRef();

void clear();
void clear();
void refreshDatas();
void drawDebugMenu(FrameActionSystem& vFrameActionSystem);
void drawAccountsMenu(FrameActionSystem& vFrameActionSystem);

protected:
size_t m_getItemsCount() const final;
Expand All @@ -38,4 +49,7 @@ class IncomesTable : public ADataTable {
void m_setupColumns() final;
void m_drawContextMenuContent() final;
void m_doActionOnDblClick(const size_t& vIdx, const RowID& vRowID) final;

void m_UpdateAccounts();
void m_UpdateIncomes(const RowID& vAccountID);
};
Loading

0 comments on commit 7d19167

Please sign in to comment.