Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions drinkomatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ local function main_menu()
print " 2 | Update or create new product."
print " /<p>| Check price for the product <p>."
print " . | Print this menu."
print " 3 | Show account numbers for last year"
print " 4 | Show account numbers for current year"
print "-------------------------------------------"

local r = assert(db:fetchone(
Expand Down Expand Up @@ -152,6 +154,12 @@ MAIN = {
print(" Scan barcode (or /<barcode>, or press enter to abort):")
return 'PROD_CODE'
end,
['3'] = function()
return 'LAST_YEAR'
end,
['4'] = function()
return 'CURRENT_YEAR'
end,
['.'] = function()
main_menu()
return 'MAIN'
Expand Down Expand Up @@ -635,6 +643,36 @@ TRANSFER_LIST = {
},
}

LAST_YEAR = {
keyboard = {
[''] = function()
print " Aborted."
return 'MAIN'
end,
function() --default
local r = assert(db:fetchone(
'select sum(amount*count) from full_log where dt<("'..math.floor(os.date("%Y")-1)..'-12-31 23:59:59") and dt > ("'..math.floor(os.date("%Y")-1)..'-01-01 00:00:00")'))
print(" Last year: %16.2f DKK", r[1])
return 'MAIN'
end,
},
}

CURRENT_YEAR = {
keyboard = {
[''] = function()
print " Aborted."
return 'MAIN'
end,
function() --default
local r = assert(db:fetchone(
'select sum(amount*count) from full_log where dt>("'..math.floor(os.date("%Y")-1)..'-12-31 23:59:59")'))
print(" Current year: %16.2f DKK", r[1])
return 'MAIN'
end,
},
}

TRANSFER_AMOUNT = {
wait = timeout,
timeout = function(_, id)
Expand Down