GnuCash 7574033+
Loading...
Searching...
No Matches
StockTransactionFeesEntry Class Reference

Specialized Entry for fees, taxes, commissions, and so on. More...

Inheritance diagram for StockTransactionFeesEntry:
StockTransactionEntry

Public Member Functions

 StockTransactionFeesEntry (const char *action, const char *tag)
void set_fieldmask (FieldMask mask) override
 Set up the state variables from the FieldMask.
void set_capitalize (bool capitalize) override
bool do_capitalize () const override
void validate_amount (Logger &logger) const override
void create_split (Transaction *trans, AccountVec &commits) const override
Public Member Functions inherited from StockTransactionEntry
 StockTransactionEntry (const char *action, const char *kvp_tag)
 StockTransactionEntry (const StockTransactionEntry &)=default
virtual bool enabled () const
virtual bool debit_side () const
virtual bool input_new_balance () const
virtual void set_account (Account *account)
virtual Account * account () const
virtual const char * print_account () const
virtual void set_memo (const char *memo)
virtual const char * get_kvp_tag ()
virtual const char * memo () const
virtual void set_value (gnc_numeric amount)
virtual GncNumeric value ()
virtual void set_amount (gnc_numeric)
virtual gnc_numeric amount () const
virtual bool has_amount () const
virtual bool marker_split () const
virtual void set_balance (gnc_numeric balance)
virtual gnc_numeric get_balance () const
virtual const char * print_value () const
virtual const char * print_amount (gnc_numeric amt) const
virtual std::string amount_str_for_display () const
 Generate a string representation of the value.
virtual gnc_numeric calculate_price () const
 Calculate the price (amount/value) for non-currency accounts.
virtual const char * print_price () const

Additional Inherited Members

Protected Attributes inherited from StockTransactionEntry
bool m_enabled
bool m_debit_side
bool m_fieldmask_debit_side = false
bool m_allow_zero
bool m_allow_negative = false
bool m_input_new_balance = false
Account * m_account
gnc_numeric m_value
const char * m_memo
const char * m_action
gnc_numeric m_balance = gnc_numeric_zero()
const char * m_kvp_tag
int m_qof_event_handler

Detailed Description

Specialized Entry for fees, taxes, commissions, and so on.

It can optionally create its balancing split in a user-provided account or as a 0-amount split on the stock account.

Definition at line 1009 of file assistant-stock-transaction.cpp.

Constructor & Destructor Documentation

◆ StockTransactionFeesEntry() [1/2]

StockTransactionFeesEntry::StockTransactionFeesEntry ( )
inline

Definition at line 1013 of file assistant-stock-transaction.cpp.

1013: StockTransactionEntry{}, m_capitalize{false} {}

◆ StockTransactionFeesEntry() [2/2]

StockTransactionFeesEntry::StockTransactionFeesEntry ( const char * action,
const char * tag )
inline

Definition at line 1014 of file assistant-stock-transaction.cpp.

1014: StockTransactionEntry{action, tag}, m_capitalize{false} {}

Member Function Documentation

◆ create_split()

void StockTransactionFeesEntry::create_split ( Transaction * trans,
AccountVec & commits ) const
overridevirtual

Reimplemented from StockTransactionEntry.

Definition at line 1059 of file assistant-stock-transaction.cpp.

1060{
1061 g_return_if_fail(trans);
1062 if ((!m_account && !m_capitalize) || gnc_numeric_check(m_value))
1063 return;
1064 auto split = xaccMallocSplit(qof_instance_get_book(trans));
1065 xaccSplitSetParent(split, trans);
1066 if (m_capitalize)
1067 {
1068 xaccSplitSetAccount(split, commits[0]); // Should be the stock account
1069 }
1070 else
1071 {
1072 xaccAccountBeginEdit(m_account);
1073 commits.push_back(m_account);
1074 xaccSplitSetAccount(split, m_account);
1075 xaccSplitSetAmount(split, amount());
1076 }
1077 xaccSplitSetMemo(split, m_memo);
1078 xaccSplitSetValue(split, m_debit_side ? m_value : gnc_numeric_neg(m_value));
1079 PINFO("creating %s split in Acct(%s): Val(%s), Amt(%s) => Val(%s), Amt(%s)",
1080 m_action, m_account ? xaccAccountGetName (m_account) : "Empty!",
1081 gnc_num_dbg_to_string(m_value),
1082 gnc_num_dbg_to_string(amount()),
1085 gnc_set_num_action(nullptr, split, nullptr,
1086 g_dpgettext2(nullptr, "Stock Assistant: Action field",
1087 m_action));
1088}
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3270
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition Account.cpp:1464
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Split * xaccMallocSplit(QofBook *book)
Constructor.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.

◆ do_capitalize()

bool StockTransactionFeesEntry::do_capitalize ( ) const
inlineoverridevirtual

Reimplemented from StockTransactionEntry.

Definition at line 1017 of file assistant-stock-transaction.cpp.

1017{ return m_capitalize; }

◆ set_capitalize()

void StockTransactionFeesEntry::set_capitalize ( bool capitalize)
inlineoverridevirtual

Reimplemented from StockTransactionEntry.

Definition at line 1016 of file assistant-stock-transaction.cpp.

1016{ m_capitalize = capitalize; }

◆ set_fieldmask()

void StockTransactionFeesEntry::set_fieldmask ( FieldMask mask)
overridevirtual

Set up the state variables from the FieldMask.

Parameters
AFieldmast to configure the StockTransactionEntry.

Reimplemented from StockTransactionEntry.

Definition at line 1023 of file assistant-stock-transaction.cpp.

1024{
1026 m_capitalize = mask & FieldMask::CAPITALIZE_DEFAULT;
1027}
virtual void set_fieldmask(FieldMask mask)
Set up the state variables from the FieldMask.

◆ validate_amount()

void StockTransactionFeesEntry::validate_amount ( Logger & logger) const
overridevirtual

Reimplemented from StockTransactionEntry.

Definition at line 1030 of file assistant-stock-transaction.cpp.

1031{
1032 auto add_error = [&logger](const char* format_str, const char* arg)
1033 {
1034 char *buf = g_strdup_printf (_(format_str),
1035 g_dpgettext2 (nullptr, "Stock Assistant: Page name", arg));
1036 logger.error(buf);
1037 g_free (buf);
1038 };
1039
1040
1041 if (gnc_numeric_check (m_value))
1042 {
1043 if (!m_allow_zero)
1044 add_error (N_("Amount for %s is missing."), m_action);
1045 return;
1046 }
1047
1048 if (gnc_numeric_negative_p (m_value) && !m_allow_negative && m_allow_zero)
1049 add_error (N_("Amount for %s must not be negative."), m_action);
1050
1051 if (!m_allow_zero && !gnc_numeric_positive_p (m_value))
1052 add_error (N_("Amount for %s must be positive."), m_action);
1053
1054 if (!gnc_numeric_zero_p(m_value) && !m_account && !m_capitalize)
1055 add_error(N_("The %s amount has no associated account."), m_action);
1056}
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.

The documentation for this class was generated from the following file: