Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim btnDiscount As Button
Dim btnDonation As Button
Dim lblDtTm As Label
Dim lblSalesId As Label
Dim lbl1 As Label
Dim lbl2 As Label
Dim lblTotal As Label
Dim lblcount as Label
Dim SpnUpc As Spinner
Dim lbldesc As Label
Dim lblprice As Label
Dim lblReduce As Label
Dim lblsnum As Label
Dim btnFindSale As Button
Dim Label1 As Label
Dim Label2 As Label
Dim pnlItemDet As Panel
Dim v_reduced As String
Dim v_price As Float
Dim v_total As Float
Dim v_count As Int
Dim ListView1 As ListView
End Sub
'**********New Sale is created, waiting on items to be added ******
Sub New()
Dim dttm As String
Dim now As Long
Dim rowid As String
Dim sqlcmd As String
DateTime.TimeFormat = "HH:mm"
now = DateTime.now
dttm = DateTime.Date(now) & " " & DateTime.Time(now)
lblDtTm.Text = dttm
sqlcmd = "INSERT INTO sales VALUES(Null, 'mobile','teresa','" & dttm & "','" & dttm & "','','',0);"
Main.SQL.ExecNonQuery(sqlcmd)
rowid = Main.SQL.ExecQuerySingleResult("SELECT ROWID from sales order by ROWID DESC limit 1")
Log("Last Sale ID inserted=" & rowid)
lblSalesId.Text = rowid
End Sub
'*********************Activity Create ***************
Sub Activity_Create(FirstTime As Boolean)
v_total = 0
Activity.LoadLayout("Sales")
New ' creates a new master record
If FirstTime Then
ListView1.Initialize("ListView1")
' Fill my spinner. When a value is chosen on the spinner, trigger the on click event
DBUtils.ExecuteSpinner(Main.SQL, "select upc from items_checkin order by upc",Null,0 , SpnUpc)
End If
End Sub
'*******************PopulateList of items added *****************
Sub ShopCartLoad()
Dim cur As Cursor
Dim sqlcmd As String
Dim linetext As String
sqlcmd = "SELECT items_sold.upc as isupc, description, items_sold.price as isprice FROM items_sold, items_checkin WHERE items_checkin.upc = items_sold.upc and items_sold.sales_id=" & lblSalesId.Text
'DBUtils.ExecuteListView(Main.SQL, sqlcmd, Null, 200, lv1, False)
cur = Main.SQL.ExecQuery(sqlcmd)
For i = 0 To cur.RowCount - 1
cur.Position = i
linetext = cur.GetString("isupc") & " : " & cur.GetString("description")& " " &cur.GetString("isprice")
ListView1.AddSingleLine(linetext)
Next
End Sub
'*********************UPC Spinner onclick ***************
Sub SpnUpc_ItemClick (Position As Int, Value As Object)
Dim Send As Spinner
Dim upc As String
Dim cur As Cursor
Dim sqlcmd As String
Dim results As Map
Send = Sender
upc = Send.GetItem(Position)
sqlcmd = "select description,price,seller_number,reduce from items_checkin where upc = '" & upc & "'"
results = DBUtils.ExecuteMap(Main.SQL,sqlcmd,Null)
'Build the labels on the screen as formatted for viewing. the v_ variables will be used for database insertion
lblprice.Text = "$" & NumberFormat2(results.Get("price"), 0,2,2,True)
v_price = results.Get("price")
lbldesc.text = results.Get("description")
lblsnum.text = results.Get("seller_number")
If (results.Get("reduce")= 1) Then
lblReduce.Text = "Y"
v_reduced = "reduced"
Else
lblReduce.Text = "N"
v_reduced = ""
End If
v_total = Main.SQL.ExecQuerySingleResult("select sum(price) from items_sold where sales_id = " & lblSalesId.Text)
lblTotal.Text = "$" & NumberFormat2(v_total, 0,2,2,True)
v_count = Main.SQL.ExecQuerySingleResult("select count(*) from items_sold where sales_id = " & lblSalesId.Text)
lblcount.Text = v_count
BuildItemsSoldMap(Position)
ShopCartLoad
End Sub