byOneAccount queries options account = do
  let calcTotals = TShowTotals `elem` options
      calcSaldo  = TShowSaldo  `elem` options
      bqry = if TBothBalances `elem` options
                then BothBalances
                else if TLedgerBalances `elem` options
                      then Only LedgerBalance
                      else Only AvailableBalance
  turns <- forM queries $ \qry ->
               allTurnovers bqry calcTotals calcSaldo qry account
  let check
        | TNoZeros `elem` options = noZeroTurns
        | otherwise               = const True
      xs = [(tr,qry) | (tr,qry) <- zip turns queries, check tr]
      turns'   = map fst xs
      queries' = map snd xs 
  let credits = map trCredit turns'
      debits  = map trDebit  turns'
      inc     = map trIncSaldo turns'
      out     = map trOutSaldo turns'
      totals  = map trTotals   turns'
      saldo   = map trSaldo    turns'
      starts  = map qStart queries'
      ends    = map qEnd   queries'
  oformat <- getOutputFormat
  let format = case oformat of
                 OASCII ASCII -> tableColumns ASCII
                 OCSV csv   -> tableColumns csv
                 OHTML html -> tableColumns html
  outputText $ unlinesText $ format $
      [([output "FROM"], ALeft, map showMaybeDate starts),
       ([output "TO"],   ALeft, map showMaybeDate ends),
       ([output "BALANCE C/F"], ARight, map prettyPrint inc),
       ([output "DEBIT"],       ARight, map prettyPrint debits),
       ([output "CREDIT"],      ARight, map prettyPrint credits),
       ([output "BALANCE B/D"], ARight, map prettyPrint out)] ++
      (if calcTotals
         then [([output "TOTALS"], ARight, map (prettyPrint . fromJust) totals)]
         else []) ++
      (if calcSaldo
         then [([output "SALDO"],  ARight, map (prettyPrint . fromJust) saldo)]
         else [])
byOneAccount queries options account = do
  let calcTotals = TShowTotals `elem` options
      calcSaldo  = TShowSaldo  `elem` options
      bqry = if TBothBalances `elem` options
                then BothBalances
                else if TLedgerBalances `elem` options
                      then Only LedgerBalance
                      else Only AvailableBalance
  turns <- forM queries $ \qry ->
               allTurnovers bqry calcTotals calcSaldo qry account
  let check
        | TNoZeros `elem` options = noZeroTurns
        | otherwise               = const True
      xs = [(tr,qry) | (tr,qry) <- zip turns queries, check tr]
      turns'   = map fst xs
      queries' = map snd xs 
  let credits = map trCredit turns'
      debits  = map trDebit  turns'
      inc     = map trIncSaldo turns'
      out     = map trOutSaldo turns'
      totals  = map trTotals   turns'
      saldo   = map trSaldo    turns'
      starts  = map qStart queries'
      ends    = map qEnd   queries'
  oformat <- getOutputFormat
  let format = case oformat of
                 OASCII ASCII -> tableColumns ASCII
                 OCSV csv   -> tableColumns csv
                 OHTML html -> tableColumns html
  outputText $ unlinesText $ format $
      [([output "FROM"], ALeft, map showMaybeDate starts),
       ([output "TO"],   ALeft, map showMaybeDate ends),
       ([output "BALANCE C/F"], ARight, map prettyPrint inc),
       ([output "DEBIT"],       ARight, map prettyPrint debits),
       ([output "CREDIT"],      ARight, map prettyPrint credits),
       ([output "BALANCE B/D"], ARight, map prettyPrint out)] ++
      (if calcTotals
         then [([output "TOTALS"], ARight, map (prettyPrint . fromJust) totals)]
         else []) ++
      (if calcSaldo
         then [([output "SALDO"],  ARight, map (prettyPrint . fromJust) saldo)]
         else [])
byOneAccount queries options account = do
  let calcTotals = TShowTotals `elem` options
      calcSaldo  = TShowSaldo  `elem` options
      bqry = if TBothBalances `elem` options
                then BothBalances
                else if TLedgerBalances `elem` options
                      then Only LedgerBalance
                      else Only AvailableBalance
  turns <- forM queries $ \qry ->
               allTurnovers bqry calcTotals calcSaldo qry account
  let check
        | TNoZeros `elem` options = noZeroTurns
        | otherwise               = const True
      xs = [(tr,qry) | (tr,qry) <- zip turns queries, check tr]
      turns'   = map fst xs
      queries' = map snd xs 
  let credits = map trCredit turns'
      debits  = map trDebit  turns'
      inc     = map trIncSaldo turns'
      out     = map trOutSaldo turns'
      totals  = map trTotals   turns'
      saldo   = map trSaldo    turns'
      starts  = map qStart queries'
      ends    = map qEnd   queries'
  oformat <- getOutputFormat
  let format = case oformat of
                 OASCII ASCII -> tableColumns ASCII
                 OCSV csv   -> tableColumns csv
                 OHTML html -> tableColumns html
  outputText $ unlinesText $ format $
      [([output "FROM"], ALeft, map showMaybeDate starts),
       ([output "TO"],   ALeft, map showMaybeDate ends),
       ([output "BALANCE C/F"], ARight, map prettyPrint inc),
       ([output "DEBIT"],       ARight, map prettyPrint debits),
       ([output "CREDIT"],      ARight, map prettyPrint credits),
       ([output "BALANCE B/D"], ARight, map prettyPrint out)] ++
      (if calcTotals
         then [([output "TOTALS"], ARight, map (prettyPrint . fromJust) totals)]
         else []) ++
      (if calcSaldo
         then [([output "SALDO"],  ARight, map (prettyPrint . fromJust) saldo)]
         else [])