-- | The multi-commodity Balance report. This is the simpler balance-- report because it does not allow for commodities to be converted.modulePenny.Cabin.Balance.MultiCommodity(Opts(..),defaultOpts,defaultParseOpts,defaultFormat,parseReport,defaultReport,report)whereimportControl.Applicative(Applicative,pure)importqualifiedPenny.Cabin.Balance.UtilasUimportqualifiedPenny.Cabin.SchemeasEimportqualifiedPenny.LincolnasLimportqualifiedPenny.LibertyasLyimportqualifiedData.EitherasEiimportqualifiedData.MapasMimportqualifiedPenny.Cabin.OptionsasCOimportData.Monoid(mappend,mempty)importqualifiedData.TextasXimportqualifiedData.TreeasEimportqualifiedPenny.Cabin.Balance.MultiCommodity.ChunkerasKimportqualifiedPenny.Cabin.Balance.MultiCommodity.ParserasPimportqualifiedPenny.Cabin.InterfaceasIimportqualifiedPenny.Cabin.ParsersasCPimportqualifiedSystem.Console.MultiArgasMA-- | Options for making the balance report. These are the only options-- needed to make the report if the options are not being parsed in-- from the command line.dataOpts=Opts{balanceFormat::L.Commodity->L.Qty->X.Text,showZeroBalances::CO.ShowZeroBalances,order::L.SubAccount->L.SubAccount->Ordering}defaultOpts::OptsdefaultOpts=Opts{balanceFormat=defaultFormat,showZeroBalances=CO.ShowZeroBalancesTrue,order=compare}defaultParseOpts::P.ParseOptsdefaultParseOpts=P.ParseOpts{P.showZeroBalances=CO.ShowZeroBalancesFalse,P.order=CP.Ascending,P.needsHelp=False}fromParseOpts::(L.Commodity->L.Qty->X.Text)->P.ParseOpts->OptsfromParseOptsfmt(P.ParseOptsszbo_)=Optsfmtszbo'whereo'=caseoofCP.Ascending->compareCP.Descending->CO.descendingcomparedefaultFormat::a->L.Qty->X.TextdefaultFormat_=X.pack.showsummedSortedBalTree::CO.ShowZeroBalances->(L.SubAccount->L.SubAccount->Ordering)->[L.Boxa]->(E.Forest(L.SubAccount,L.Balance),L.Balance)summedSortedBalTreeszbo=U.sumForestmemptymappend.U.sortForesto'.U.balancesszbwhereo'xy=o(fstx)(fsty)rows::(E.Forest(L.SubAccount,L.Balance),L.Balance)->[K.Row]rows(o,b)=first:restwherefirst=K.Row0(X.pack"Total")(M.assocs.L.unBalance$b)rest=maprow.concatMapE.flatten.mapU.labelLevels$orow(l,(s,ib))=K.Rowl(L.texts)(M.assocs.L.unBalance$ib)-- | This report is what to use if you already have your options (that-- is, you are not parsing them in from the command line.)report::Opts->[L.Boxa]->[E.PreChunk]report(Optsbfszbo)=K.rowsToChunksbf.rows.summedSortedBalTreeszbo-- | The MultiCommodity report with configurable options that have-- been parsed from the command line.parseReport::(L.Commodity->L.Qty->X.Text)-- ^ How to format balances. For instance you can use this to-- perform commodity-sensitive digit grouping.->P.ParseOpts-- ^ Default options for the report. These can be overriden on the-- command line.->I.ReportparseReportfmtort=(helpo,makeMode)wheremakeMode__fsf=MA.Mode{MA.mName="balance",MA.mIntersperse=MA.Intersperse,MA.mOpts=map(fmapRight)P.allSpecs,MA.mPosArgs=Left,MA.mProcess=processfmtortfsf}process::Applicativef=>(L.Commodity->L.Qty->X.Text)->P.ParseOpts->a->([L.Transaction]->[L.BoxLy.LibertyMeta])->[EitherString(P.ParseOpts->P.ParseOpts)]->f(EitherI.HelpStrI.ArgsAndReport)processfmto_fsfls=let(posArgs,fns)=Ei.partitionEitherslsmkParsedOpts=foldl(flip(.))idfnsos'=mkParsedOptsomcOpts=fromParseOptsfmtos'prtxns_=return$reportmcOpts(fsftxns)inpure$ifP.needsHelpos'thenLeft$helpoelseRight(posArgs,pr)-- | The MultiCommodity report, with default options.defaultReport::I.ReportdefaultReport=parseReportdefaultFormatdefaultParseOpts-------------------------------------------------------------- ## Help------------------------------------------------------------ifDefault::Bool->StringifDefaultb=ifbthen" (default)"else""help::P.ParseOpts->Stringhelpo=unlines["balance"," Show account balances. Accepts ONLY the following options:","","--show-zero-balances"," Show balances that are zero"++ifDefault(CO.unShowZeroBalances.P.showZeroBalances$o),"--hide-zero-balances"," Hide balances that are zero"++ifDefault(not.CO.unShowZeroBalances.P.showZeroBalances$o),"","--ascending"," Sort in ascending order by account name"++ifDefault(P.ordero==CP.Ascending),"--descending"," Sort in descending order by account name"++ifDefault(P.ordero==CP.Descending),"","--help, -h"," Show this help and exit"]