ofxToTxn
  :: OfxIn
  -- ^
  -> OfxOut
  -- ^
  -> Transaction ()
ofxToTxn ofxIn ofxOut = Transaction tl bal
  where
    tl = topLineTranche ofxIn ofxOut
    bal = twoPostingBalanced (rar, metaForeign) cy (_arrangement ofxOut)
      metaOffset
      where
        (metaForeign, (Amount.Amount cy q)) = foreignPair ofxIn ofxOut
        rar = repDecimal (Right Nothing) q
        metaOffset = offsettingMeta ofxOut

-- * Parsing Copper data and importing OFX data

-- | Importing OFX transactions is a three-step process:
--
-- 1. Parse Copper files.  These files contain existing transactions and
-- are used to detect duplicate OFX transactions.  Also, optionally
-- the new OFX transactions are appended to the last Copper file, so
-- the parse step returns the last Copper file.
--
-- 2. Import OFX transactions.  Uses the duplicate detector from step 1.
--
-- 3. Copperize and format new transactions.  Append new transactions
-- to Copper file, if requested.  Return new, formatted transactions,
-- and new Copper file (if requested).
ofxToTxn
  :: OfxIn
  -- ^
  -> OfxOut
  -- ^
  -> Transaction ()
ofxToTxn ofxIn ofxOut = Transaction tl bal
  where
    tl = topLineTranche ofxIn ofxOut
    bal = twoPostingBalanced (rar, metaForeign) cy (_arrangement ofxOut)
      metaOffset
      where
        (metaForeign, (Amount.Amount cy q)) = foreignPair ofxIn ofxOut
        rar = repDecimal (Right Nothing) q
        metaOffset = offsettingMeta ofxOut

-- * Parsing Copper data and importing OFX data

-- | Importing OFX transactions is a three-step process:
--
-- 1. Parse Copper files.  These files contain existing transactions and
-- are used to detect duplicate OFX transactions.  Also, optionally
-- the new OFX transactions are appended to the last Copper file, so
-- the parse step returns the last Copper file.
--
-- 2. Import OFX transactions.  Uses the duplicate detector from step 1.
--
-- 3. Copperize and format new transactions.  Append new transactions
-- to Copper file, if requested.  Return new, formatted transactions,
-- and new Copper file (if requested).
ofxToTxn ofxIn ofxOut = Transaction tl bal
  where
    tl = topLineTranche ofxIn ofxOut
    bal = twoPostingBalanced (rar, metaForeign) cy (_arrangement ofxOut)
      metaOffset
      where
        (metaForeign, (Amount.Amount cy q)) = foreignPair ofxIn ofxOut
        rar = repDecimal (Right Nothing) q
        metaOffset = offsettingMeta ofxOut

-- * Parsing Copper data and importing OFX data

-- | Importing OFX transactions is a three-step process:
--
-- 1. Parse Copper files.  These files contain existing transactions and
-- are used to detect duplicate OFX transactions.  Also, optionally
-- the new OFX transactions are appended to the last Copper file, so
-- the parse step returns the last Copper file.
--
-- 2. Import OFX transactions.  Uses the duplicate detector from step 1.
--
-- 3. Copperize and format new transactions.  Append new transactions
-- to Copper file, if requested.  Return new, formatted transactions,
-- and new Copper file (if requested).