Re: Budget Builder file: register.e part 3, edit 1
- Posted by Senator
Oct 05, 2020
-- register.e part 3, edit 1
public constant SELECT=13 -- flag to select search_year and/or search_month
public procedure search(integer search_year = 0, integer search_month = 0)
integer caption_flag = 1, cash_flag = 1, start = 1, cont = 1
sequence caption, table_text, search
object note, key = 0, data = {}
atom amt = 0, subtotal = 0, reg
search = upper(prompt_string("\n\tEnter search keyword: "))
caption = text:format("<keyword: []>",{search})
if search_year = SELECT then search_year = select_year() end if
if search_year then caption &= text:format(" Year: []", search_year) end if
if search_month = SELECT then search_month = select_month() end if
if search_month then caption &= text:format(" Month: []", search_month)
else caption &= text:format(" YEAR To DATE")
end if
db_select_table(REGISTER)
while cont do
if find(current_table, {REGISTER, CASH}) then
table_text = text:format("*****[]*****",{db_current_table()})
else return
end if
for rec = start to db_table_size() do
key = db_record_key(rec)
data = db_record_data(rec)
note = upper(data[1])
amt = data[2]/100
if match("AUTOLOG",note) then continue end if
if match(search, note) then
-- display keyword and initial table caption once
if caption_flag then
center_display(caption, rightMargin)
draw_line()
center_display(table_text,rightMargin+5)
if equal(db_current_table(),CASH) then
cash_flag = 0
end if
caption_flag = 0
end if
-- display new table caption once
if cont = 2 then
if cash_flag then center_display(table_text,rightMargin+5) end if
cash_flag = 0
end if
if search_year and search_month then
-- update subtotal for search month
if key[MONTH] = search_month then
subtotal += amt
display_full_note(rec, 1) -- 0 = do not truncate
end if
else
-- update subtotal for all years/months
subtotal += amt
display_full_note(rec, 1) -- 1 = truncate
end if
end if
end for
-- display subtotal for current table
if subtotal then
display_total(subtotal)
puts(1,"\n")
draw_line()
end if
-- after display of search subtotal for registry table
-- assign subtotal to reg variable and reset subtotal = 0
if cont = 1 then
reg = subtotal
subtotal = 0
end if
-- after display of search subtotal for cash table
-- display total of search for both tables
if cont = 2 then
if subtotal then
display_total(reg+subtotal)
end if
end if
cont += 1
if cont = 2 then
db_select_table(CASH)
else
db_select_table(REGISTER)
cont = 0
end if
end while
-- return to register
db_select_table(REGISTER)
any_key("\n\nPress Any Key to continue...")
list()
end procedure
procedure draw_line(integer dash = 1)
sequence FILL
if dash then set_foreground_color(HLC) FILL = "-"
else set_foreground_color(FGC) FILL = " "
end if
for i = 1 to rightMargin-5 do puts(1,FILL) end for
set_foreground_color(FGC)
end procedure
function get_highlight_record_number(datetime dt = now())
integer rec_num-- returns rec #
rec_num = db_find_key(dt)
if rec_num > 0 then return rec_num
elsif rec_num < 0 then return -rec_num-2
else return 0
end if
end function
-- end register.e part 3, edit 1
Not Categorized, Please Help
|
|