VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Ticker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Const m_modName As String = "FMStocks_Bus.Ticker"

'VerifySymbol
'
Public Function VerifySymbol(ByVal Ticker As String) As Boolean
    On Error GoTo errorHandler
    Dim obj As FMStocks_DB.Ticker
    Set obj = New FMStocks_DB.Ticker
    
    VerifySymbol = obj.VerifySymbol(Ticker)
    Set obj = Nothing
    
    
    Exit Function
    
errorHandler:
    Set obj = Nothing
    
    RaiseError m_modName, "VerifySymbol(" & Ticker & ")"

End Function

' ListByTicker
'
Public Function ListByTicker(ByVal Ticker As String) As ADODB.Recordset
    On Error GoTo errorHandler
    Dim obj As FMStocks_DB.Ticker
    Set obj = New FMStocks_DB.Ticker
    
    Set ListByTicker = obj.ListByTicker(Ticker)
    Set obj = Nothing
    
    
    Exit Function
    
errorHandler:
    Set obj = Nothing
    
    RaiseError m_modName, "ListByTicker(" & Ticker & ")"
End Function


' ListByCompany
'
Public Function ListByCompany(ByVal company As String) As ADODB.Recordset
    On Error GoTo errorHandler
    Dim obj As FMStocks_DB.Ticker
    Set obj = New FMStocks_DB.Ticker
    
    Set ListByCompany = obj.ListByCompany(company)
    Set obj = Nothing
    
    
    Exit Function
        
errorHandler:
    Set obj = Nothing
    
    RaiseError m_modName, "ListByCompany(" & company & ")"
End Function


' GetFundamentals
'
' Takes a ticker symbol and returns an array of fundamental metric values,
' the company name and the trading exchange.
Public Function GetFundamentals(ByVal Ticker As String, ByRef company As Variant, ByRef Exchange As Variant) As ADODB.Recordset
    On Error GoTo errorHandler
    Dim obj As FMStocks_DB.Ticker
    Set obj = New FMStocks_DB.Ticker
    
    Dim rs As ADODB.Recordset
    Set rs = obj.GetFundamentals(Ticker)
    
    ' Construct a new recordset based on the results from the fundamental queries
    
    Dim rsnew As ADODB.Recordset
    Set rsnew = New ADODB.Recordset
    
    rsnew.CursorLocation = adUseClient
    
    'Add Some Fields
    rsnew.Fields.Append "ShortDesc", adVarChar, 50
    rsnew.Fields.Append "LongDesc", adVarChar, 100
    rsnew.Fields.Append "Criteria", adVarChar, 50
    rsnew.Fields.Append "Value", adVarChar, 50
    rsnew.Fields.Append "Status", adInteger, 4
       
    rsnew.Open , , adOpenStatic, adLockBatchOptimistic
    
    Do While Not (rs.EOF)
        company = rs("Company")
        Exchange = rs("Exchange")
        
        FormatItem rsnew, NullsToZero(rs("MarketCap")) < 1000, "MarketCap", "$" & NullsToZero(rs("MarketCap")) & "M", "< $1B", "Total market capitalization less than $1 Billion."
        FormatItem rsnew, NullsToZero(rs("Sales")) < 100, "Sales", "$" & NullsToZero(rs("Sales")) & "M", "< $100M", "Gross revenue (total sales) less than $100 Million."
        FormatItem rsnew, NullsToZero(rs("Price")) > 7, "Price", "$" & NullsToZero(rs("Price")), "> $7/share", "Stock price greater than $7 per share."
        FormatItem rsnew, NullsToZero(rs("DailyDollarVol")) > 1, "Daily dollar volume", "$" & NullsToZero(rs("DailyDollarVol")) & "M", "> $1M per day", "At least $100M in shares move on an average day."
        FormatItem rsnew, NullsToZero(rs("SalesGrowth")) > 25, "Sales growth", NullsToZero(rs("SalesGrowth")) & "%", "> 25%", "Gross revenue growth of 25% trailing-twelve months (TTM)."
        FormatItem rsnew, NullsToZero(rs("EPSGrowth")) > 25, "Earnings growth", NullsToZero(rs("EPSGrowth")) & "%", "> 25%", "Earnings-per-share growth over TTM."
        FormatItem rsnew, NullsToZero(rs("NetProfitMargin")) > 7, "Profit margin", NullsToZero(rs("NetProfitMargin")) & "%", "> 7%", "Net profit margin at least 7%."
        FormatItem rsnew, NullsToZero(rs("InsiderShares")) > 10, "Insider holdings", NullsToZero(rs("InsiderShares")) & "%", "> 10%", "At least 10% of the shares should be held by insiders."
            
        rs.MoveNext
    Loop
    rsnew.UpdateBatch adAffectAll
    rsnew.MoveFirst
    
    Set obj = Nothing
    Set rs = Nothing
    Set GetFundamentals = rsnew
    
    Exit Function
        
errorHandler:
    Set obj = Nothing
    Set rs = Nothing
    
    
    RaiseError m_modName, "GetFundamentals(" & Ticker & ")"
End Function

'Helper sub to add the new records
Private Sub FormatItem(ByRef rs As ADODB.Recordset, Status As Integer, ShortDesc As String, Value As String, Criteria As String, LongDesc As String)
    rs.AddNew Array("ShortDesc", "LongDesc", "Criteria", "Value", "Status"), _
        Array(ShortDesc, LongDesc, Criteria, Value, Status)
End Sub

