コード例 #1
0
ファイル: payee.cpp プロジェクト: Zorg2409/moneymanagerex
void mmReportPayeeExpenses::getPayeeStats(std::map<int, std::pair<double, double> > &payeeStats
                                          , mmDateRange* date_range, bool ignoreFuture) const
{
    //Get base currency rates for all accounts
    std::map<int, double> acc_conv_rates;
    for (const auto& account: Model_Account::instance().all())
    {
        Model_Currency::Data* currency = Model_Account::currency(account);
        acc_conv_rates[account.ACCOUNTID] = currency->BASECONVRATE;
    }

    const auto &transactions = Model_Checking::instance().find(
        Model_Checking::STATUS(Model_Checking::VOID_, NOT_EQUAL)
        , Model_Checking::TRANSDATE(m_date_range->start_date(), GREATER_OR_EQUAL)
        , Model_Checking::TRANSDATE(m_date_range->end_date(), LESS_OR_EQUAL));
    const wxDateTime today = m_date_range->today();
    const auto all_splits = Model_Splittransaction::instance().get_all();
    for (const auto& trx: transactions)
    {
        if (Model_Checking::type(trx) == Model_Checking::TRANSFER) continue;

        // Do not include asset or stock transfers in income expense calculations.
        if (Model_Checking::foreignTransactionAsTransfer(trx))
            continue;

        double convRate = acc_conv_rates[trx.ACCOUNTID];

        Model_Splittransaction::Data_Set splits;
        if (all_splits.count(trx.id())) splits = all_splits.at(trx.id());
        if (splits.empty())
        {
            if (Model_Checking::type(trx) == Model_Checking::DEPOSIT)
                payeeStats[trx.PAYEEID].first += trx.TRANSAMOUNT * convRate;
            else
                payeeStats[trx.PAYEEID].second -= trx.TRANSAMOUNT * convRate;
        }
        else
        {
            for (const auto& entry : splits)
            {
                if (Model_Checking::type(trx) == Model_Checking::DEPOSIT)
                {
                    if (entry.SPLITTRANSAMOUNT >= 0)
                        payeeStats[trx.PAYEEID].first += entry.SPLITTRANSAMOUNT * convRate;
                    else
                        payeeStats[trx.PAYEEID].second += entry.SPLITTRANSAMOUNT * convRate;
                }
                else
                {
                    if (entry.SPLITTRANSAMOUNT < 0)
                        payeeStats[trx.PAYEEID].first -= entry.SPLITTRANSAMOUNT * convRate;
                    else
                        payeeStats[trx.PAYEEID].second -= entry.SPLITTRANSAMOUNT * convRate;
                }
            }
        }
    }
}
コード例 #2
0
ファイル: transdialog.cpp プロジェクト: dqf88/moneymanagerex
void mmTransDialog::OnOk(wxCommandEvent& event)
{
    m_trx_data.STATUS = "";
    m_trx_data.NOTES = textNotes_->GetValue();
    m_trx_data.TRANSACTIONNUMBER = textNumber_->GetValue();
    m_trx_data.TRANSDATE = dpc_->GetValue().FormatISODate();
    wxStringClientData* status_obj = (wxStringClientData*) choiceStatus_->GetClientObject(choiceStatus_->GetSelection());
    if (status_obj) m_trx_data.STATUS = Model_Checking::toShortStatus(status_obj->GetData());

    if (!validateData()) return;

    Model_Checking::Data *r = Model_Checking::instance().get(m_trx_data.TRANSID);
    if (m_new_trx || m_duplicate)
        r = Model_Checking::instance().create();

    Model_Checking::putDataToTransaction(r, m_trx_data);

    m_trx_data.TRANSID = Model_Checking::instance().save(r);

    Model_Splittransaction::Data_Set splt;
    for (const auto& entry : local_splits) 
    {
        Model_Splittransaction::Data *s = Model_Splittransaction::instance().create();
        s->CATEGID = entry.CATEGID;
        s->SUBCATEGID = entry.SUBCATEGID;
        s->SPLITTRANSAMOUNT = entry.SPLITTRANSAMOUNT;
        splt.push_back(*s);
    }
    Model_Splittransaction::instance().update(splt, m_trx_data.TRANSID);

    if (CustomFieldDialog_)
        CustomFieldDialog_->OnSave(true);

    if (m_new_trx || m_duplicate)
    {
        const wxString& RefType = Model_Attachment::reftype_desc(Model_Attachment::TRANSACTION);
        mmAttachmentManage::RelocateAllAttachments(RefType, -1, m_trx_data.TRANSID);
        Model_CustomFieldData::instance().RelocateAllData(RefType, -1, m_trx_data.TRANSID);
    }

    const Model_Checking::Data& tran(*r);
    Model_Checking::Full_Data trx(tran);
    wxLogDebug("%s", trx.to_json());
    EndModal(wxID_OK);
}
コード例 #3
0
ファイル: payee.cpp プロジェクト: edgiru/moneymanagerex
void mmReportPayeeExpenses::getPayeeStats(std::map<int, std::pair<double, double> > &payeeStats
                                          , mmDateRange* date_range, bool ignoreFuture) const
{
    //Get base currency rates for all accounts
    std::map<int, double> acc_conv_rates;
    for (const auto& account: Model_Account::instance().all())
    {
        Model_Currency::Data* currency = Model_Account::currency(account);
        acc_conv_rates[account.ACCOUNTID] = currency->BASECONVRATE;
    }

    const auto &transactions = Model_Checking::instance().all();
    const auto all_splits = Model_Splittransaction::instance().get_all();
    for (const auto & trx: transactions)
    {
        if (Model_Checking::status(trx) == Model_Checking::VOID_) continue;
        if (Model_Checking::type(trx) == Model_Checking::TRANSFER) continue;

        wxDateTime trx_date = Model_Checking::TRANSDATE(trx);
        if (ignoreFuture)
        {
            if (trx_date.IsLaterThan(wxDateTime::Today()))
                continue; //skip future dated transactions
        }

        if (!trx_date.IsBetween(date_range->start_date(), date_range->end_date()))
            continue; //skip

        double convRate = acc_conv_rates[trx.ACCOUNTID];

        Model_Splittransaction::Data_Set splits;
        if (all_splits.count(trx.id())) splits = all_splits.at(trx.id());
        if (splits.empty())
        {
            if (Model_Checking::type(trx) == Model_Checking::DEPOSIT)
                payeeStats[trx.PAYEEID].first += trx.TRANSAMOUNT * convRate;
            else
                payeeStats[trx.PAYEEID].second -= trx.TRANSAMOUNT * convRate;
        }
        else
        {
            for (const auto& entry : splits)
            {
                if (Model_Checking::type(trx) == Model_Checking::DEPOSIT)
                {
                    if (entry.SPLITTRANSAMOUNT >= 0)
                        payeeStats[trx.PAYEEID].first += entry.SPLITTRANSAMOUNT * convRate;
                    else
                        payeeStats[trx.PAYEEID].second += entry.SPLITTRANSAMOUNT * convRate;
                }
                else
                {
                    if (entry.SPLITTRANSAMOUNT < 0)
                        payeeStats[trx.PAYEEID].first -= entry.SPLITTRANSAMOUNT * convRate;
                    else
                        payeeStats[trx.PAYEEID].second -= entry.SPLITTRANSAMOUNT * convRate;
                }
            }
        }
    }
}