Macro Library acct
A collection of accounting macros
June 2013
makestatement(statement array, start number, options, $anstypes, $questions, $answer, $showanswer, $displayformat, $answerformat, $answerboxsize)
statement array form:
$statement[0]['bigtitle'] = "Title for whole table"
$statement[#]['header'] = "title", or array ("title", value) if fixed value is associated
$statement[#]['headerops'] = array of options for header. If not set, header is fixed. Can't use with header with value.
$statement[#]['elements'] = array("Title",amount,"title",amount)
$statement[#]['explanation'] = array(explanation for each line of elements)
$statement[#]['indent'] = number of indent for elements group. If >0, then header and tottitle will be indented one less
$statement[#]['fixed'] = array(index into elements to have fixed - first col only)
$statement[#]['totrows'] = total number of entry rows to show. optional, defaults to number of elements
$statement[#]['tottitle'] = title for total row
$statement[#]['tottitleops'] = array of options for tottitle. If not set, tottitle is fixed
$statement[#]['tottitleline'] = -1 for on last line of elements, not set or 0 for own line. Only works if indent>0
$statement[#]['totneg'] = set to make total negative
$statement[#]['totsigns'] = array of 1,-1,etc to indicate signs for totaling
$statement[#]['totaltotal'] = array("title", statement #, statement #) Totals across multiple statement groups. Neg to subtract
$statement[#]['totaltotalops'] = array of options for totaltotal. If not set, totaltotal title is fixed
$statement[#]['totalindent'] = number of indent for totaltotal entry. 0 if not set
$statement[#]['dblunder'] = true if double-underline under the totaltotal entry
scorestatement($stuanswers[$thisq], $answer, $statement array, start number)
Call with $stuanswers, and $answer array
and statement array and the multipart starting number for this statement
returns a new $answer array
makejournal(journal array, start number, options, $anstypes, $questions, $answer, $showanswer, $displayformat, $answerboxsize)
journal array should be an array in the form
$journal[0]['date'] = '5/13/14'
$journal[0]['debits'] = array("Bonds payable",357.14,"Expense payable",345.13)
$journal[0]['credits'] = array("Expense due",15.34)
$journal[0]['note'] = 'to accrue interest'
Optional: $journal[0]['extrarows'] = 2, to add 2 extra rows to entry
start number is the starting multipart value for this journal set.
options is an array of type-ahead values for the descriptions
for $anstypes through $displayformat, just pass the variable through.
Set $journal[0]['haspostrefs'] to enable post ref. column, and add post ref
values to debits and credits arrays between description and value.
scorejournal($stuanswers[$thisq], $answer, $journal, start number)
Call with $stuanswers, and $answer array
and journal array and the multipart starting number for this journal
returns a new $answer array
makeaccttable(headers, $rows, $anshead, $ansarray, start number, &$anstypes, &$answer, &$showanswer, &$displayformat, &$answerboxsize)
rowhead: array of column headers
rows: an array of column arrays. These are the fixed-value columns
ansarray: an array of column arrays. These are the answers to the to-be-filled-in columns
start number: starting value for multipart
makeaccttable2(headers, $coltypes, $fixedrows, $cols, $sn, $anstypes, $answer, $showanswer, $displayformat, $answerformat, $answerboxsize, [$opts, $questions])
headers: array(title, colspan, title, colspan,...) or array(title,title,title) or array of these for multiple headers
coltypes: array(true if scores, false if fixed), one for each column
fixedrows: array of array(title, colspan, title, colspan,...), ignores coltypes
cols: an array for each column of fixed values or answer values
sn: The starting part number for the table
anstypes, answer, showanswer, displayformat, answerformat, answerboxsize: pass these
variables directly to the function; it will extend them will values determined
by the other inputs.
opts: optionsal array of options:
$opts['totrow']: row to treat as totals row (decorates above and below with lines) - optional
$opts['class']: class to use for table
$opts['ops']: a list of typeahead options for string entries
$questions: you only need to pass this if you're using $opts['ops']
makeaccttable3(headers, $coltypes, $fixedrows, $cols, $sn, $anstypes, $answer, $showanswer, $displayformat, $questions, $answerformat, $answerboxsize, $opts)
headers: array(title, colspan, title, colspan,...) or array(title,title,title) or array of these for multiple headers
coltypes: array(true if scores, false if fixed), one for each column (use 2 to add dollar signs when not already in column values, -1 for non-numeric)
fixedrows: array(title, colspan, title, colspan,...), ignores coltypes
columsn: an array for each column of fixed values or answer values
opts: optional array of options:
$opts['totrow']: row to treat as totals row (decorates above and below with lines) - optional
$opts['class']: class to use for table
$opts['underline']: array of row=>underline style: 1 single, 2 double
can also do row=>[style, column] or row=>[style, [column, column]]
$opts['questions'][n] = array of pull-down options for column n
makeTchartsfromjournal($j, $order, $sn, $anstypes, $answer, $showanswer, $displayformat, $answerboxsize)
scoreTchartsfromjournal($stua,$answer,$j,$order,$sn)
makeTchart(title,numrows,leftentries,rightentries, start number, $anstypes, $answer, $showanswer, $displayformat, $answerboxsize, [dofloat, showtotal])
num rows, leftentries, and rightentries should not include the total - that will be automatically added
float (def false) set true to add display:float to table.
showtotal (def true) to show total rows. Defaults to 0 total on right; set to 'zeroleft' to show 0 total on left.
function scoreTchart($stua,$answer,$numrows,$leftentries,$rightentries, $sn)
returns a new answer array
types: 1 if debits add to balance, -1 if debits subtract from balance
start: starting balance
makeledgerfromjournal($j, $start, $order, $types, $sn, $anstypes, $answer, $questions, $showanswer, $displayformat, $answerboxsize)
scoreinventory($stua, $answer, $invs, $rowper, $sn)
makeinventory($invs, $type, $rowper, $sn, &$anstypes, $questions, &$answer, &$showanswer, &$displayformat, &$answerformat, &$answerboxsize, $get) {
invs has form array(array('type','date',quantity, value)), where type is 'init','purch',or 'sale'
get can be set to 'journal' or 'totals', but defaults to 'rec', which generates a perpetual inventory record
'journal' returns array(journal record, journal display)
'totals' returns array(total cogs, total inventory, total inventory value, total sales)
type is FIFO, LIFO, or WA, or SPEC
if SPEC, then the form of $invs changes for sales, and should be 'sale','date',array(quantity, purchase#, quantity, purchase #, ...)) where
init is purchase #0.
rowsper sets the number of rows for each date. Will get extended for a particular date if needed
maketrialbalancefromjournal($j, $groups, $sn, $numrows, $ops, $bigtitle, &$anstypes, &$answer, &$questions, &$showanswer, &$displayformat, &$answerboxsize)
j is journal
groups is array(array of assets, liab, equity, revenue, expenses)
maketrialbalance($data, $sn, $numrows, $ops, $bigtitle, &$anstypes, &$answer, &$questions, &$showanswer, &$displayformat, &$answerboxsize) {
$data['assets'] = array(account, value, account, value)
['liabilities'], [equity],[revenue],[expenses]
scoretrialbalance($stua, $answer, $data, $numrows, $sn)
$data['assets'] = array(account, value, account, value)
['liabilities'], [equity],[revenue],[expenses]