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 537 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 616 of file assistant-stock-transaction.cpp.

616 { 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 623 of file assistant-stock-transaction.cpp.

623 { 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 733 of file assistant-stock-transaction.cpp.

734 {
735  if (!m_account || gnc_numeric_check(amt))
736  return nullptr;
737  auto commodity{xaccAccountGetCommodity(m_account)};
738  auto pinfo{gnc_commodity_print_info(commodity, TRUE)};
739  return xaccPrintAmount(amt, pinfo);
740 }
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:3408
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
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 769 of file assistant-stock-transaction.cpp.

770 {
771  auto price{calculate_price()};
772  if (gnc_numeric_check(price))
773 //Translators: "N/A" here means that a commodity doesn't have a valid price.
774  return _("N/A");
775  auto currency{gnc_account_get_currency_or_parent(m_account)};
776  auto pinfo{gnc_price_print_info(currency, TRUE)};
777  return xaccPrintAmount(price, pinfo);
778 }
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:3415
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
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 712 of file assistant-stock-transaction.cpp.

713 {
714  if (!m_enabled || (gnc_numeric_check(m_value) && m_allow_zero))
715  return nullptr;
716 
717  if ((gnc_numeric_check(m_value) || gnc_numeric_zero_p(m_value))
718  && !m_allow_zero)
719  return _("missing");
720 
721  /* Don't combine this with the first if, it would prevent showing
722  * "missing" when the value is required.
723  */
724  if (!m_account)
725  return nullptr;
726 
727  auto currency{gnc_account_get_currency_or_parent(m_account)};
728  auto pinfo{gnc_commodity_print_info(currency, TRUE)};
729  return xaccPrintAmount(m_value, pinfo);
730 }
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:3415
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
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 643 of file assistant-stock-transaction.cpp.

644 {
645  m_enabled = mask != FieldMask::DISABLED;
646  m_debit_side = mask & FieldMask::ENABLED_DEBIT;
647  m_allow_zero = mask & FieldMask::ALLOW_ZERO;
648  m_allow_negative = mask & FieldMask::ALLOW_NEGATIVE;
649 }

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