GnuCash  5.6-150-g038405b370+
Public Member Functions | Protected Attributes
StockTransactionEntry Class Reference

Holds the configuration information from the fieldmask and the data to create a single split. More...

Inheritance diagram for StockTransactionEntry:
StockTransactionFeesEntry StockTransactionStockCapGainsEntry StockTransactionStockEntry

Public Member Functions

 StockTransactionEntry (const char *action, const char *kvp_tag)
 
 StockTransactionEntry (const StockTransactionEntry &)=default
 
virtual void set_fieldmask (FieldMask mask)
 Set up the state variables from the FieldMask. More...
 
virtual bool enabled () const
 
virtual bool debit_side () const
 
virtual void set_capitalize (bool capitalize)
 
virtual bool input_new_balance () const
 
virtual bool do_capitalize () const
 
virtual void set_account (Account *account)
 
virtual Accountaccount () 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 validate_amount (Logger &) const
 
virtual void set_balance (gnc_numeric balance)
 
virtual gnc_numeric get_balance () const
 
virtual void create_split (Transaction *trans, AccountVec &commits) 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. More...
 
virtual gnc_numeric calculate_price () const
 Calculate the price (amount/value) for non-currency accounts. More...
 
virtual const char * print_price () const
 

Protected Attributes

bool m_enabled
 
bool m_debit_side
 
bool m_allow_zero
 
bool m_allow_negative
 
bool m_input_new_balance = false
 
Accountm_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

Holds the configuration information from the fieldmask and the data to create a single split.

The base class is used for cash splits to currency accounts. Except as noted the functions are simple accessors and setters that don't need much documentation.

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

Member Function Documentation

◆ amount_str_for_display()

virtual std::string StockTransactionEntry::amount_str_for_display ( ) const
inlinevirtual

Generate a string representation of the value.

Internally uses xaccPrintAmount, which writes to a static string, so the result is copied to a std::string to prevent it being replaced by subsequent calls.

Returns
a std:sstring containing a representation of the value.

Reimplemented in StockTransactionStockEntry.

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

613 { return ""; }

◆ calculate_price()

virtual gnc_numeric StockTransactionEntry::calculate_price ( ) const
inlinevirtual

Calculate the price (amount/value) for non-currency accounts.

Note that multiple currencies in stock transaction s are not supported.

Returns
The calculated price for the Stock entry, GNC_ERROR_ARG otherwise.

Reimplemented in StockTransactionStockEntry.

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

620 { return gnc_numeric_error(GNC_ERROR_ARG); }
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Create a gnc_numeric object that signals the error condition noted by error_code, rather than a numbe...
Argument is not a valid number.
Definition: gnc-numeric.h:224

◆ print_amount()

const char * StockTransactionEntry::print_amount ( gnc_numeric  amt) const
virtual
Returns
a string representation of the amount.

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

731 {
732  if (!m_account || gnc_numeric_check(amt))
733  return nullptr;
734  auto commodity{xaccAccountGetCommodity(m_account)};
735  auto pinfo{gnc_commodity_print_info(commodity, TRUE)};
736  return xaccPrintAmount(amt, pinfo);
737 }
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
Definition: Account.cpp:3351
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ print_price()

const char * StockTransactionEntry::print_price ( ) const
virtual
Returns
a string representation of the price if valid.

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

767 {
768  auto price{calculate_price()};
769  if (gnc_numeric_check(price))
770 //Translators: "N/A" here means that a commodity doesn't have a valid price.
771  return _("N/A");
772  auto currency{gnc_account_get_currency_or_parent(m_account)};
773  auto pinfo{gnc_price_print_info(currency, TRUE)};
774  return xaccPrintAmount(price, pinfo);
775 }
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
virtual gnc_numeric calculate_price() const
Calculate the price (amount/value) for non-currency accounts.
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Definition: Account.cpp:3358
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ print_value()

const char * StockTransactionEntry::print_value ( ) const
virtual
Returns
a string representation of the value.

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

710 {
711  if (!m_enabled || (gnc_numeric_check(m_value) && m_allow_zero))
712  return nullptr;
713 
714  if ((gnc_numeric_check(m_value) || gnc_numeric_zero_p(m_value))
715  && !m_allow_zero)
716  return _("missing");
717 
718  /* Don't combine this with the first if, it would prevent showing
719  * "missing" when the value is required.
720  */
721  if (!m_account)
722  return nullptr;
723 
724  auto currency{gnc_account_get_currency_or_parent(m_account)};
725  auto pinfo{gnc_commodity_print_info(currency, TRUE)};
726  return xaccPrintAmount(m_value, pinfo);
727 }
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Definition: Account.cpp:3358
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ set_fieldmask()

void StockTransactionEntry::set_fieldmask ( FieldMask  mask)
virtual

Set up the state variables from the FieldMask.

Parameters
AFieldmast to configure the StockTransactionEntry.

Reimplemented in StockTransactionFeesEntry, and StockTransactionStockEntry.

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

641 {
642  m_enabled = mask != FieldMask::DISABLED;
643  m_debit_side = mask & FieldMask::ENABLED_DEBIT;
644  m_allow_zero = mask & FieldMask::ALLOW_ZERO;
645  m_allow_negative = mask & FieldMask::ALLOW_NEGATIVE;
646 }

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