sumTurnovers mbDate rgroup calcTotals calcSaldo ag list = do
  let c = agCurrency ag
  list' <- forM list $ \tr -> do
                cr' :# _  <- convert mbDate rgroup c (trCredit tr)
                dt' :# _  <- convert mbDate rgroup c (trDebit tr)
                inc' <- convertBalanceInfo mbDate rgroup c (trIncSaldo tr)
                out' <- convertBalanceInfo mbDate rgroup c (trOutSaldo tr)
                t'  <- case trTotals tr of
                         Nothing -> return Nothing
                         Just t -> do
                                   x :# _ <- convert mbDate rgroup c t
                                   return (Just x)
                s <- case trSaldo tr of
                       Nothing -> return Nothing
                       Just s -> do
                                 x :# _ <- convert mbDate rgroup c s
                                 return (Just x)
                return $ TRecord {
                           trCredit = cr',
                           trDebit  = dt',
                           trIncSaldo = inc',
                           trOutSaldo = out',
                           trTotals = t',
                           trSaldo  = s }
  let credits = sum $ map trCredit list'
      debits  = sum $ map trDebit  list'
      inc     = sumBalanceInfo c $ map trIncSaldo list'
      out     = sumBalanceInfo c $ map trOutSaldo list'
      totals  = if calcTotals
                  then Just $ (sum $ map (fromJust . trTotals) list') :# c
                  else Nothing
      saldo   = if calcSaldo
                  then Just $ (sum $ map (fromJust . trSaldo) list') :# c
                  else Nothing
  return $ TRecord {
             trCredit = credits :# c,
             trDebit  = debits  :# c,
             trIncSaldo = inc,
             trOutSaldo = out,
             trTotals = totals,
             trSaldo  = saldo }
sumTurnovers mbDate rgroup calcTotals calcSaldo ag list = do
  let c = agCurrency ag
  list' <- forM list $ \tr -> do
                cr' :# _  <- convert mbDate rgroup c (trCredit tr)
                dt' :# _  <- convert mbDate rgroup c (trDebit tr)
                inc' <- convertBalanceInfo mbDate rgroup c (trIncSaldo tr)
                out' <- convertBalanceInfo mbDate rgroup c (trOutSaldo tr)
                t'  <- case trTotals tr of
                         Nothing -> return Nothing
                         Just t -> do
                                   x :# _ <- convert mbDate rgroup c t
                                   return (Just x)
                s <- case trSaldo tr of
                       Nothing -> return Nothing
                       Just s -> do
                                 x :# _ <- convert mbDate rgroup c s
                                 return (Just x)
                return $ TRecord {
                           trCredit = cr',
                           trDebit  = dt',
                           trIncSaldo = inc',
                           trOutSaldo = out',
                           trTotals = t',
                           trSaldo  = s }
  let credits = sum $ map trCredit list'
      debits  = sum $ map trDebit  list'
      inc     = sumBalanceInfo c $ map trIncSaldo list'
      out     = sumBalanceInfo c $ map trOutSaldo list'
      totals  = if calcTotals
                  then Just $ (sum $ map (fromJust . trTotals) list') :# c
                  else Nothing
      saldo   = if calcSaldo
                  then Just $ (sum $ map (fromJust . trSaldo) list') :# c
                  else Nothing
  return $ TRecord {
             trCredit = credits :# c,
             trDebit  = debits  :# c,
             trIncSaldo = inc,
             trOutSaldo = out,
             trTotals = totals,
             trSaldo  = saldo }
sumTurnovers mbDate rgroup calcTotals calcSaldo ag list = do
  let c = agCurrency ag
  list' <- forM list $ \tr -> do
                cr' :# _  <- convert mbDate rgroup c (trCredit tr)
                dt' :# _  <- convert mbDate rgroup c (trDebit tr)
                inc' <- convertBalanceInfo mbDate rgroup c (trIncSaldo tr)
                out' <- convertBalanceInfo mbDate rgroup c (trOutSaldo tr)
                t'  <- case trTotals tr of
                         Nothing -> return Nothing
                         Just t -> do
                                   x :# _ <- convert mbDate rgroup c t
                                   return (Just x)
                s <- case trSaldo tr of
                       Nothing -> return Nothing
                       Just s -> do
                                 x :# _ <- convert mbDate rgroup c s
                                 return (Just x)
                return $ TRecord {
                           trCredit = cr',
                           trDebit  = dt',
                           trIncSaldo = inc',
                           trOutSaldo = out',
                           trTotals = t',
                           trSaldo  = s }
  let credits = sum $ map trCredit list'
      debits  = sum $ map trDebit  list'
      inc     = sumBalanceInfo c $ map trIncSaldo list'
      out     = sumBalanceInfo c $ map trOutSaldo list'
      totals  = if calcTotals
                  then Just $ (sum $ map (fromJust . trTotals) list') :# c
                  else Nothing
      saldo   = if calcSaldo
                  then Just $ (sum $ map (fromJust . trSaldo) list') :# c
                  else Nothing
  return $ TRecord {
             trCredit = credits :# c,
             trDebit  = debits  :# c,
             trIncSaldo = inc,
             trOutSaldo = out,
             trTotals = totals,
             trSaldo  = saldo }