wxString StocksListCtrl::OnGetItemText(long item, long column) const { if (column == COL_ID) return wxString::Format("%i", m_stocks[item].STOCKID).Trim(); if (column == COL_DATE) return mmGetDateForDisplay(mmGetStorageStringAsDate(m_stocks[item].PURCHASEDATE)); if (column == COL_NAME) return m_stocks[item].STOCKNAME; if (column == COL_SYMBOL) return m_stocks[item].SYMBOL; if (column == COL_NUMBER) { int precision = m_stocks[item].NUMSHARES == floor(m_stocks[item].NUMSHARES) ? 0 : 4; return Model_Currency::toString(m_stocks[item].NUMSHARES, stock_panel_->m_currency, precision); } if (column == COL_PRICE) return Model_Currency::toString(m_stocks[item].PURCHASEPRICE, stock_panel_->m_currency); if (column == COL_VALUE) return Model_Currency::toString(m_stocks[item].VALUE, stock_panel_->m_currency, 4); if (column == COL_GAIN_LOSS) return Model_Currency::toString(getGainLoss(item), stock_panel_->m_currency); if (column == COL_CURRENT) return Model_Currency::toString(m_stocks[item].CURRENTPRICE, stock_panel_->m_currency, 4); if (column == COL_CURRVALUE) return Model_Currency::toString(m_stocks[item].CURRENTPRICE*m_stocks[item].NUMSHARES, stock_panel_->m_currency); if (column == COL_PRICEDATE) return mmGetDateForDisplay(mmGetStorageStringAsDate(Model_Stock::instance().lastPriceDate(&m_stocks[item]))); if (column == COL_COMMISSION) return Model_Currency::toString(m_stocks[item].COMMISSION, stock_panel_->m_currency); if (column == COL_NOTES) { wxString full_notes = m_stocks[item].NOTES; if (Model_Attachment::NrAttachments(Model_Attachment::reftype_desc(Model_Attachment::STOCK), m_stocks[item].STOCKID)) full_notes = full_notes.Prepend(mmAttachmentManage::GetAttachmentNoteSign()); return full_notes; } return wxEmptyString; }
wxString StocksListCtrl::OnGetItemText(long item, long column) const { if (column == COL_DATE) return mmGetDateForDisplay(mmGetStorageStringAsDate(m_stocks[item].PURCHASEDATE)); if (column == COL_NAME) return m_stocks[item].STOCKNAME; if (column == COL_NUMBER) { int precision = m_stocks[item].NUMSHARES == floor(m_stocks[item].NUMSHARES) ? 0 : 4; return Model_Currency::toString(m_stocks[item].NUMSHARES, stock_panel_->m_currency, precision); } if (column == COL_GAIN_LOSS) return Model_Currency::toString(getGainLoss(item), stock_panel_->m_currency /*, 4*/); if (column == COL_VALUE) return Model_Currency::toString(m_stocks[item].VALUE, stock_panel_->m_currency); if (column == COL_CURRENT) return Model_Currency::toString(m_stocks[item].CURRENTPRICE, stock_panel_->m_currency); if (column == COL_NOTES) { wxString full_notes = m_stocks[item].NOTES; if (Model_Attachment::NrAttachments(Model_Attachment::reftype_desc(Model_Attachment::STOCK), m_stocks[item].STOCKID)) full_notes = full_notes.Prepend(mmAttachmentManage::GetAttachmentNoteSign()); return full_notes; } return ""; }
wxString StocksListCtrl::getStockInfo(int selectedIndex) const { int purchasedTime = 0; double stocktotalnumShares = 0; double stockavgPurchasePrice = 0; for (const auto& s: Model_Stock::instance().find(Model_Stock::SYMBOL(m_stocks[selectedIndex].SYMBOL))) { purchasedTime++; stocktotalnumShares += s.NUMSHARES; stockavgPurchasePrice += s.PURCHASEPRICE * s.NUMSHARES; } stockavgPurchasePrice /= stocktotalnumShares; double sNumShares = m_stocks[selectedIndex].NUMSHARES; wxString sTotalNumShares; if ((stocktotalnumShares - static_cast<long>(stocktotalnumShares)) != 0.0) sTotalNumShares = wxString::Format("%.4f", stocktotalnumShares); else sTotalNumShares << static_cast<long>(stocktotalnumShares); wxString sGainLoss = Model_Currency::toCurrency(getGainLoss(selectedIndex)); double stockPurchasePrice = m_stocks[selectedIndex].PURCHASEPRICE; double stockCurrentPrice = m_stocks[selectedIndex].CURRENTPRICE; double stockDifference = stockCurrentPrice - stockPurchasePrice; double stocktotalDifference = stockCurrentPrice - stockavgPurchasePrice; //Commision don't calculates here double stockPercentage = (stockCurrentPrice / stockPurchasePrice - 1.0)*100.0; double stocktotalPercentage = (stockCurrentPrice / stockavgPurchasePrice - 1.0)*100.0; double stocktotalgainloss = stocktotalDifference * stocktotalnumShares; wxString sPurchasePrice = Model_Currency::toCurrency(stockPurchasePrice); wxString sAvgPurchasePrice = Model_Currency::toCurrency(stockavgPurchasePrice); wxString sCurrentPrice = Model_Currency::toCurrency(stockCurrentPrice); wxString sDifference = Model_Currency::toCurrency(stockDifference); wxString sTotalDifference = Model_Currency::toCurrency(stocktotalDifference); wxString sPercentage = wxNumberFormatter::ToString(stockPercentage, 2); wxString sTotalPercentage = wxNumberFormatter::ToString(stocktotalPercentage, 2); wxString sTotalGainLoss = Model_Currency::toCurrency(stocktotalgainloss); wxString miniInfo = ""; if (m_stocks[selectedIndex].SYMBOL != "") miniInfo << "\t" << _("Symbol: ") << m_stocks[selectedIndex].SYMBOL << "\t\t"; miniInfo << _ ("Total:") << " (" << stocktotalnumShares << ") "; stock_panel_->stock_details_short_->SetLabelText(miniInfo); wxString additionInfo = ""; //Selected share info additionInfo << "|" << sCurrentPrice << " - " << sPurchasePrice << "|" << " = " << sDifference << " * " << sNumShares << " = " << sGainLoss << " ( " << sPercentage << "%" << " )" << "\n"; //Summary for account for selected symbol if (purchasedTime > 1) { additionInfo << "|" << sCurrentPrice << " - " << sAvgPurchasePrice << "|" << " = " << sTotalDifference << " * " << sTotalNumShares << " = " << sTotalGainLoss << " ( " << sTotalPercentage << "%" << " )" << "\n" << OnGetItemText(selectedIndex, (long)COL_NOTES); } return additionInfo; }
int StocksListCtrl::OnGetItemImage(long item) const { /* Returns the icon to be shown for each entry */ if (getGainLoss(item) > 0) return 0; return 1; }
wxString StocksListCtrl::getStockInfo(int selectedIndex) const { int purchasedTime = 0; double stocktotalnumShares = 0; double stockavgPurchasePrice = 0; for (const auto& s: Model_Stock::instance().find(Model_Stock::SYMBOL(m_stocks[selectedIndex].SYMBOL))) { purchasedTime++; stocktotalnumShares += s.NUMSHARES; stockavgPurchasePrice += s.PURCHASEPRICE * s.NUMSHARES; } stockavgPurchasePrice /= stocktotalnumShares; double numShares = m_stocks[selectedIndex].NUMSHARES; wxString sNumShares = wxString::Format("%i", (int)numShares); if (numShares - static_cast<long>(numShares) != 0.0) sNumShares = wxString::Format("%.4f", numShares); wxString sTotalNumShares = wxString::Format("%i", (int)stocktotalnumShares); if ((stocktotalnumShares - static_cast<long>(stocktotalnumShares)) != 0.0) sTotalNumShares = wxString::Format("%.4f", stocktotalnumShares); double stockPurchasePrice = m_stocks[selectedIndex].PURCHASEPRICE; double stockCurrentPrice = m_stocks[selectedIndex].CURRENTPRICE; double stockDifference = stockCurrentPrice - stockPurchasePrice; double stocktotalDifference = stockCurrentPrice - stockavgPurchasePrice; //Commision don't calculates here double stockPercentage = (stockCurrentPrice / stockPurchasePrice - 1.0)*100.0; double stocktotalPercentage = (stockCurrentPrice / stockavgPurchasePrice - 1.0)*100.0; double stocktotalgainloss = stocktotalDifference * stocktotalnumShares; const wxString& sPurchasePrice = Model_Currency::toCurrency(stockPurchasePrice, stock_panel_->m_currency, 4); const wxString& sAvgPurchasePrice = Model_Currency::toCurrency(stockavgPurchasePrice, stock_panel_->m_currency, 4); const wxString& sCurrentPrice = Model_Currency::toCurrency(stockCurrentPrice, stock_panel_->m_currency, 4); const wxString& sDifference = Model_Currency::toCurrency(stockDifference, stock_panel_->m_currency, 4); const wxString& sTotalDifference = Model_Currency::toCurrency(stocktotalDifference); wxString miniInfo = ""; if (m_stocks[selectedIndex].SYMBOL != "") miniInfo << "\t" << wxString::Format(_("Symbol: %s"), m_stocks[selectedIndex].SYMBOL) << "\t\t"; miniInfo << wxString::Format(_("Total: %s"), " (" + sTotalNumShares + ") "); stock_panel_->stock_details_short_->SetLabelText(miniInfo); //Selected share info wxString additionInfo = wxString::Format("|%s - %s| = %s, %s * %s = %s ( %s %% )\n" , sCurrentPrice, sPurchasePrice, sDifference , sDifference, sNumShares , Model_Currency::toCurrency(getGainLoss(selectedIndex)) , wxNumberFormatter::ToString(stockPercentage, 2)); //Summary for account for selected symbol if (purchasedTime > 1) { additionInfo += wxString::Format( "|%s - %s| = %s, %s * %s = %s ( %s %% )\n%s" , sCurrentPrice, sAvgPurchasePrice, sTotalDifference , sTotalDifference, sTotalNumShares , Model_Currency::toCurrency(stocktotalgainloss) , wxNumberFormatter::ToString(stocktotalPercentage, 2) , OnGetItemText(selectedIndex, (long)COL_NOTES)); } return additionInfo; }