internal IncomeStatement PopulateFinancialStatement(IncomeStatementFilterItem item, IncomeStatement inc)
        {
            inc.Revenue = GetMaxValue(item.RevenueItems);
            inc.Cogs = GetMaxValue(item.CogsItems);
            inc.OperatingExpenses = GetMaxValue(item.OperatingItems);
            inc.Depreciation = GetMaxValue(item.DepreciationItems);
            inc.NetIncome = GetMaxValue(item.NetIncomeItems);

            return inc;
        }
 public void UpdateIncomeStatement(IncomeStatement inc)
 {
     if (IncomeStatementExists(inc.Symbol, inc.Year))
     {
         _dao.UpdateIncomeStatement(inc);
     }
     else
     {
         _dao.InsertIncomeStatement(inc);
     }
 }
        public IncomeStatement Populate(XbrlNodeBL nodeMngr, XbrlDocument xbrlDoc, string symbol, int year, Dictionary<string, List<string>> xbrlTaxonomyTree)
        {    
            IncomeStatement inc = new IncomeStatement();
            inc.Symbol = symbol;
            inc.Year = year;

            IncomeStatementFilterItem item = new IncomeStatementFilterItem();

            foreach (XbrlFragment frag in xbrlDoc.XbrlFragments)
            {
                foreach (Item xbrlItem in frag.Facts)
                {
                    if (nodeMngr.IsAnnualItem(xbrlItem) && xbrlItem.Type.Name.Equals("monetaryItemType"))
                    {
                        if (xbrlItem.ContextRef.PeriodEndDate.Year == inc.Year)
                        {
                            item = CheckItem(xbrlItem, item, xbrlTaxonomyTree);
                        }
                    } 
                }
            }
            return PopulateFinancialStatement(item, inc);
        }
        public void ProcessXbrlInstanceDocument(string xmlUrl, Dictionary<string, List<string>> xbrlTaxonomyTree)
        {
            JeffFerguson.Gepsio.XbrlDocument xbrlDoc = new XbrlDocument();
            xbrlDoc.Load(xmlUrl);

            //AddXbrlNodes(xbrlDoc);

            int yearsToLoad = 3;

            string fileName = System.IO.Path.GetFileNameWithoutExtension(xmlUrl);
            string tickerSymbol = fileName.Split(new[] { '-' })[0];
            int year = GetFiscalYear(tickerSymbol, xbrlDoc.XbrlFragments[0]);

            IncomeStatement incToAdd = new IncomeStatement();
            BalanceSheet balToAdd = new BalanceSheet();
            CompanyAnnualData compAnnToAdd = new CompanyAnnualData();

            Dictionary<string, Object> yahooStats = GetYahooStatistics(tickerSymbol);

            CreateCompanyObject(tickerSymbol, xbrlDoc, yahooStats);

            for (int y = year; y > year - yearsToLoad; y--)
            {
                XbrlIncomeStatementFilter incFilter = new XbrlIncomeStatementFilter();
                XbrlBalanceSheetFilter bsFilter = new XbrlBalanceSheetFilter();
                XbrlCompanyAnnualFilter compAnFilter = new XbrlCompanyAnnualFilter();
                
                incToAdd = incFilter.Populate(this, xbrlDoc, tickerSymbol, y, xbrlTaxonomyTree);
                balToAdd = bsFilter.Populate(xbrlDoc, tickerSymbol, y, xbrlTaxonomyTree);
                compAnnToAdd = compAnFilter.Populate(xbrlDoc, tickerSymbol, y);

                compAnnToAdd.LeveredBeta = Convert.ToDecimal(yahooStats["Beta"]);
                compAnnToAdd.DividendYield = Convert.ToDecimal(yahooStats["DividendYield"]);

                IncomeStatementBL.Instance.UpdateIncomeStatement(incToAdd);
                BalanceSheetBL.Instance.UpdateBalanceSheet(balToAdd);
                CompanyAnnualDataBL.Instance.UpdateCompanyAnnual(compAnnToAdd);
            }
        }
 private static void SetIncomeStatementParameters(IncomeStatement inc, MySqlParameter[] parms)
 {
     parms[0].Value = inc.Symbol;
     parms[1].Value = inc.Year;
     parms[2].Value = inc.Revenue;
     parms[3].Value = inc.Cogs;
     parms[4].Value = inc.OperatingExpenses;
     parms[5].Value = inc.Depreciation;
     parms[6].Value = inc.NetIncome;
     parms[7].Value = inc.CapitalExpenditures;
 }
        private IncomeStatement ConvertReaderToIncomeStatementObject(MySqlDataReader rdr)
        {
            IncomeStatement incstm = new IncomeStatement();
            incstm.Symbol = MySqlHelper.ConvertReaderToString(rdr, "SYMBOL");
            incstm.Year = MySqlHelper.ConvertReaderToInt(rdr, "YEAR");
            incstm.Revenue = MySqlHelper.ConvertReaderToDecimal(rdr, "REVENUE");
            incstm.Cogs = MySqlHelper.ConvertReaderToDecimal(rdr, "COGS");
            incstm.OperatingExpenses = MySqlHelper.ConvertReaderToDecimal(rdr, "OPERATING_EXPENSES");
            incstm.Depreciation = MySqlHelper.ConvertReaderToDecimal(rdr, "DEPRECIATION");
            incstm.NetIncome = MySqlHelper.ConvertReaderToDecimal(rdr, "NET_INCOME");
            incstm.CapitalExpenditures = MySqlHelper.ConvertReaderToDecimal(rdr, "CAPITAL_EXPENDITURES");

            return incstm;
        }
        public void UpdateIncomeStatement(IncomeStatement inc)
        {
            MySqlParameter[] parms = GetIncomeStatementParameters();
            SetIncomeStatementParameters(inc, parms);

            using (MySqlConnection conn = new MySqlConnection(MySqlHelper.SV_CONN_STRING))
            {
                conn.Open();
                MySqlHelper.ExecuteNonQuery(conn, SQL_UPDATE_INCOMESTATEMENT, parms);
            }
        }
        public void PopulateCompanyFinancialStatisticsFromStatements(CompanyFinancialStatistics finStats, IncomeStatement inc, BalanceSheet bs, CompanyAnnualData cad)
        {
            finStats.BookValuePerShare = bs.ShareholdersEquity / cad.SharesOutstanding;
            finStats.DebtToEquity = bs.Debt / bs.ShareholdersEquity;
            finStats.ProfitMargin = inc.NetIncome / inc.Revenue;
            finStats.ReturnOnAssets = inc.NetIncome / bs.TotalAssets;

            if (bs.ShareholdersEquity == 0)
            {
                finStats.ReturnOnEquity = 0;
            }
            else
            {
                finStats.ReturnOnEquity = inc.NetIncome / bs.ShareholdersEquity;
            }
            
            finStats.RevenuePerShare = inc.Revenue / cad.SharesOutstanding;
            finStats.TotalDebt = bs.Debt;
        }