1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE RecordWildCards #-}
3 module Hcompta.LCC.Chart where
5 import Control.DeepSeq (NFData(..))
8 import Data.Function (($), (.))
9 import Data.Map.Strict (Map)
10 import Data.Monoid (Monoid(..))
11 import Data.Semigroup (Semigroup(..))
12 import Data.Strict.Maybe as Strict
13 import Data.TreeMap.Strict (TreeMap)
14 import Data.Typeable ()
16 import Text.Show (Show)
17 import qualified Data.Map.Strict as Map
18 import qualified Data.TreeMap.Strict as TreeMap
19 import qualified Data.TreeMap.Strict.Zipper as TreeMap
21 import Hcompta.LCC.Account
22 import Hcompta.LCC.Tag
27 { chart_accounts :: !(TreeMap Account_Section Account_Tags)
28 , chart_tags :: !(Map Tag_Path (Map Account ()))
29 } deriving (Data, Eq, Show, Typeable)
30 instance NFData Chart where
32 rnf chart_accounts `seq`
34 instance Semigroup Chart where
37 { chart_accounts = TreeMap.union (<>) (chart_accounts x) (chart_accounts y)
38 , chart_tags = Map.unionWith (<>) (chart_tags x) (chart_tags y)
40 instance Monoid Chart where
42 { chart_accounts = mempty
49 type Zipper_Chart = TreeMap.Zipper Account_Section Account_Tags
50 type Zipper_Account_Tags = TreeMap.Zipper Tag_Path_Section [Tag_Data]
51 type Chart_Select = Zipper_Chart -> [Zipper_Chart]
52 type Zipper_Select k a = TreeMap.Zipper k a -> [TreeMap.Zipper k a]
53 type Zipper_SelectF f k a = TreeMap.Zipper k a -> f (TreeMap.Zipper k a)
55 zipper_chart :: Chart -> Zipper_Chart
56 zipper_chart = TreeMap.zipper . chart_accounts
58 zipper_accounts_tags :: Zipper_Chart -> Zipper_Account_Tags
59 zipper_accounts_tags z =
60 case TreeMap.node_value $ TreeMap.zipper_self z of
61 Strict.Just (Account_Tags (Tags tags)) -> TreeMap.zipper tags
62 _ -> TreeMap.zipper TreeMap.empty
70 } deriving (Data, Eq, Foldable, Functor, Show, Traversable, Typeable)
72 instance Ord a => Ord (Charted a) where
73 compare = compare `on` charted
76 instance H.Account (Charted Account)
78 account_step account_child (\a -> "A" == a_name a)
80 account_step account_child (\a -> "A" == a_name a) >=>
81 account_step account_child (\a -> "B" == a_name a)