supplant the old interface, which relied on the Num typeclass. MixedAmount did not have a very good Num instance. The only functions which were defined were fromInteger, (+), and negate. Furthermore, it was not law-abiding, as 0 + a /= a in general. Replacements for used functions are: 0 -> nullmixedamt / mempty (+) -> maPlus / (<>) (-) -> maMinus negate -> maNegate sum -> maSum sumStrict -> maSum Also creates some new constructors for MixedAmount: mixedAmount :: Amount -> MixedAmount maAddAmount :: MixedAmount -> Amount -> MixedAmount maAddAmounts :: MixedAmount -> [Amount] -> MixedAmount Add Semigroup and Monoid instances for MixedAmount. Ideally we would remove the Num instance entirely. The only change needed have nullmixedamt/mempty substitute for 0 without problems was to not squash prices in mixedAmount(Looks|Is)Zero. This is correct behaviour in any case.
46 lines
1.3 KiB
Haskell
46 lines
1.3 KiB
Haskell
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
|
{-|
|
|
|
|
The @incomestatement@ command prints a simple income statement (profit & loss report).
|
|
|
|
-}
|
|
|
|
module Hledger.Cli.Commands.Incomestatement (
|
|
incomestatementmode
|
|
,incomestatement
|
|
) where
|
|
|
|
import System.Console.CmdArgs.Explicit
|
|
|
|
import Hledger
|
|
import Hledger.Cli.CliOptions
|
|
import Hledger.Cli.CompoundBalanceCommand
|
|
|
|
incomestatementSpec = CompoundBalanceCommandSpec {
|
|
cbcdoc = $(embedFileRelative "Hledger/Cli/Commands/Incomestatement.txt"),
|
|
cbctitle = "Income Statement",
|
|
cbcqueries = [
|
|
CBCSubreportSpec{
|
|
cbcsubreporttitle="Revenues"
|
|
,cbcsubreportquery=journalRevenueAccountQuery
|
|
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyNegative})
|
|
,cbcsubreporttransform=fmap maNegate
|
|
,cbcsubreportincreasestotal=True
|
|
}
|
|
,CBCSubreportSpec{
|
|
cbcsubreporttitle="Expenses"
|
|
,cbcsubreportquery=journalExpenseAccountQuery
|
|
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyPositive})
|
|
,cbcsubreporttransform=id
|
|
,cbcsubreportincreasestotal=False
|
|
}
|
|
],
|
|
cbctype = PeriodChange
|
|
}
|
|
|
|
incomestatementmode :: Mode RawOpts
|
|
incomestatementmode = compoundBalanceCommandMode incomestatementSpec
|
|
|
|
incomestatement :: CliOpts -> Journal -> IO ()
|
|
incomestatement = compoundBalanceCommand incomestatementSpec
|