Ledger Calculations
This script is used in a Money Manager application.
var &accountPath = GetPath(#input/Account) var &accountLedger = &accountPath/Ledger var #ledgerRec = new record for &accountLedger set #ledgerRec/Date = #input/Date set #ledgerRec/Payee = #input/Payee if (#input/Amount>0) then set #ledgerRec/Credit = #input/Amount else set #ledgerRec/Debit = - #input/Amount end if set #ledgerRec/SalesTax = #input/SalesTax set #ledgerRec/Notes = #input/Notes set #ledgerRec/RelatedTransaction = MakeLink("Link", &path) insert #ledgerRec at &accountLedger // then add it to the category, if any is specified if (Exists(#input/Category)) then var &accountPath = GetPath(#input/Category) var &accountLedger = &accountPath/Ledger var #ledgerRec = new record for &accountLedger set #ledgerRec/Date = #input/Date set #ledgerRec/Payee = #input/Payee if (#input/Amount>0) then set #ledgerRec/Credit = #input/Amount else // both are credit for category set #ledgerRec/Credit = - #input/Amount end if set #ledgerRec/SalesTax = #input/SalesTax set #ledgerRec/Notes = #input/Notes set #ledgerRec/RelatedTransaction = MakeLink("Link", &path) insert #ledgerRec at &accountLedger end if // update the last entries in the file var &txnFilePath = Parent(&path) var #txnFile = load(&txnFilePath) set #txnFile/LastEntryDate = Now() set #txnFile/LastEntryTitle = #input/Payee set #txnFile/LastEntryBy = ForeignLinkDisplay(UserRef()) save #txnFile