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.Quantity
22 import Hcompta.LCC.Account
23 import Hcompta.LCC.Tag
28 { chart_accounts :: !(TreeMap NameAccount Account_Tags)
29 , chart_tags :: !(Map Tag_Path (Map Account ()))
30 } deriving (Data, Eq, Show, Typeable)
31 instance NFData Chart where
33 rnf chart_accounts `seq`
35 instance Semigroup Chart where
38 { chart_accounts = TreeMap.union (<>) (chart_accounts x) (chart_accounts y)
39 , chart_tags = Map.unionWith (<>) (chart_tags x) (chart_tags y)
41 instance Monoid Chart where
43 { chart_accounts = mempty
47 instance Zeroable Chart where
49 instance Nullable Chart where
50 null = null . chart_accounts
54 type Zipper_Chart = TreeMap.Zipper NameAccount Account_Tags
55 type Zipper_Account_Tags = TreeMap.Zipper Tag_Path_Section [Tag_Data]
56 type Chart_Select = Zipper_Chart -> [Zipper_Chart]
57 type Zipper_Select k a = TreeMap.Zipper k a -> [TreeMap.Zipper k a]
58 type Zipper_SelectF f k a = TreeMap.Zipper k a -> f (TreeMap.Zipper k a)
60 zipper_chart :: Chart -> Zipper_Chart
61 zipper_chart = TreeMap.zipper . chart_accounts
63 zipper_accounts_tags :: Zipper_Chart -> Zipper_Account_Tags
64 zipper_accounts_tags z =
65 case TreeMap.node_value $ TreeMap.axis_self z of
66 Strict.Just (Account_Tags (Tags tags)) -> TreeMap.zipper tags
67 _ -> TreeMap.zipper TreeMap.empty
75 } deriving (Data, Eq, Foldable, Functor, Show, Traversable, Typeable)
77 instance Ord a => Ord (Charted a) where
78 compare = compare `on` charted
81 instance H.Account (Charted Account)
83 account_step account_child (\a -> "A" == a_name a)
85 account_step account_child (\a -> "A" == a_name a) >=>
86 account_step account_child (\a -> "B" == a_name a)