Re: Budget Builder file: register.e part 1, edit 1
- Posted by Senator Oct 05, 2020
- 1586 views
-- -- register.e part 1, edit 1 -- include std/console.e include std/datetime.e include std/filesys.e include std/io.e include std/text.e include std/eds.e include std/get.e include std/convert.e include std/utils.e include std/io.e include std/filesys.e include std/math.e --------------------- include xbackup.e include formtext.e include db_tools.e global sequence pos global integer line public integer autolog = 0 public integer rec_col, key_col, budget_note_col, note_col, full_note_col, amt_col,bal_col, bal_amt_col, bal_bal_col, table_size public procedure reset_columns() rec_col=1 key_col=7 full_note_col=30 budget_note_col=11 note_col=13 amt_col=50 bal_col=67 bal_amt_col=40 bal_bal_col=57 end procedure public function is_error(integer rec_num) if rec_num = 0 then any_key("\n\tERROR! aborting transaction... ") return 1 else return 0 end if end function global function bankers_rounding(atom pence, integer precision=1) integer pennies, -- (or nearest 100, etc, but never nearest < 1 ) s = sign(pence), whole pence = abs(pence)/precision whole = floor(pence) atom fract = pence-whole if fract=0.5 then pennies = whole+and_bits(whole,1) else pennies = floor(0.5+pence) end if pennies *= s*precision return pennies end function public procedure truncate_note(object note, integer truncate_at) if atom(note) then note = to_string(note) display("ERROR! note is []",note,0) end if if length(note)>=truncate_at then note = note[1..truncate_at] display("[]",{note},0) hilite("~",HLC,0) else display("[]",{note},0) end if end procedure public procedure toggle_tables() current_table = db_current_table() if equal(current_table,REGISTER) then db_select_table(BUDGET) else db_select_table(REGISTER) end if update_tables() end procedure public enum D,H,M,S public function set_budget_key() integer DD, last_day, rec -- D=1,H=2,M=3,S=4, sequence text, key, -- {DD,HH,MM,SS} dt = now() last_day = days_in_month(dt) text="\n\tEnter day of budget transaction: " DD = prompt_number(text, {0,last_day}) if DD = 0 then DD = last_day end if dt[DAY]=DD key = dt[DAY..$] -- {D,H,1,1} rec = db_find_key(key) -- if rec with key already exists -- within database subtract 1 second from -- key and try again if rec then loop do dt = datetime:subtract(dt,1,SECONDS) key = dt[DAY..$] rec = db_find_key(key) until rec < 0 end loop end if return key end function public function balance(integer rec) sequence data atom bal = 0 for i = 1 to rec do data = db_record_data(i) bal += data[$] end for return bal end function -- end register.e part 1, edit 1
Regards, Ken