{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.CLI.Format.JCC where -- import Control.DeepSeq (NFData) -- import Control.Monad.Trans.Except (ExceptT(..)) import Data.Foldable (Foldable(..)) import Data.Function ((.)) import qualified Data.List as List import qualified Data.Text as Text import qualified Data.Text.Lazy as TL import Prelude (($)) -- import System.IO (IO) import Text.Show (Show(..)) import Hcompta.Date (Date) import qualified Hcompta.Balance as Balance -- import qualified Hcompta.CLI.Format as CLI.Format -- import Hcompta.CLI.Format (Format(..)) import qualified Hcompta.CLI.Lang as Lang import qualified Hcompta.Format.JCC as JCC import qualified Hcompta.Format.JCC.Amount as JCC.Amount import qualified Hcompta.Format.JCC.Amount.Write as JCC.Amount.Write import qualified Hcompta.Format.JCC.Read as JCC.Read import qualified Hcompta.Format.JCC.Write as JCC.Write -- import Hcompta.Lib.Consable (Consable) import Hcompta.Lib.Leijen (ToDoc(..)) import qualified Hcompta.Lib.Leijen as W -- import qualified Hcompta.Lib.Parsec as Parsec import qualified Hcompta.Polarize as Polarize import qualified Hcompta.CLI.Lib.Leijen.Table as Leijen.Table instance Lang.Translate JCC.Read.Error W.Doc where translate lang err = case err of JCC.Read.Error_date date -> toDoc lang date JCC.Read.Error_transaction_not_equilibrated styles tr unit_sums -> i18n_transaction_not_equilibrated styles tr unit_sums Lang.Error_Transaction_The_following_transaction_is_not_equilibrated_because JCC.Read.Error_reading_file file_path exn -> W.vsep $ [ Lang.translate lang $ Lang.Error_Failed_to_read_file file_path , W.text $ TL.pack $ show exn ] JCC.Read.Error_including_file file_path errs -> W.vsep $ [ Lang.translate lang $ Lang.Error_Failed_to_include_file file_path , Lang.translate lang errs ] JCC.Read.Error_account_anchor_unknown pos anchor -> Lang.translate lang $ Lang.Error_Account_Anchor_unknown pos anchor JCC.Read.Error_account_anchor_not_unique pos anchor -> Lang.translate lang $ Lang.Error_Account_Anchor_is_not_unique pos anchor where i18n_transaction_not_equilibrated styles tr unit_sums msg = W.vsep $ [ Lang.translate lang msg , W.vsep $ List.map (\(unit, Balance.Unit_Sum{Balance.unit_sum_quantity}) -> Lang.translate lang $ Lang.Error_Transaction_JCC_Unit_sums_up_to_the_non_null_amount unit $ JCC.Amount.style styles $ JCC.Amount unit $ Polarize.depolarize unit_sum_quantity ) unit_sums , W.space , JCC.Write.transaction styles tr ] instance Leijen.Table.Cell_of_forall_param JCC.Journal Date where cell_of_forall_param _ctx date = Leijen.Table.cell { Leijen.Table.cell_content = JCC.Write.date date , Leijen.Table.cell_width = JCC.Write.date_length date } instance Leijen.Table.Cell_of_forall_param JCC.Journal JCC.Account where cell_of_forall_param _ctx account = Leijen.Table.cell { Leijen.Table.cell_content = JCC.Write.account account , Leijen.Table.cell_width = JCC.Write.account_length account } instance Leijen.Table.Cell_of_forall_param JCC.Journal (JCC.Unit, JCC.Quantity) where cell_of_forall_param j (unit, qty) = let sty = JCC.journal_amount_styles j in let amt = JCC.Amount.Amount unit qty in let sa = JCC.Amount.style sty amt in Leijen.Table.cell { Leijen.Table.cell_content = JCC.Amount.Write.amount sa , Leijen.Table.cell_width = JCC.Amount.Write.amount_length sa } instance Leijen.Table.Cell_of_forall_param JCC.Journal JCC.Wording where cell_of_forall_param _j w = Leijen.Table.cell { Leijen.Table.cell_content = toDoc () w , Leijen.Table.cell_width = Text.length w } instance Foldable f => W.Leijen_of_forall_param JCC.Journal (f JCC.Transaction) where leijen_of_forall_param = JCC.Write.transactions . JCC.journal_amount_styles