2019-07-16 07:19:52 +03:00
|
|
|
#!/usr/bin/env stack
|
|
|
|
{- stack runghc --verbosity info
|
|
|
|
--package hledger-lib
|
|
|
|
--package hledger
|
|
|
|
--package here
|
|
|
|
--package text
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-}
|
2019-07-17 01:31:18 +03:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
2019-07-16 07:19:52 +03:00
|
|
|
|
|
|
|
import Data.String.Here
|
|
|
|
import Hledger
|
|
|
|
import Hledger.Cli
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
cmdmode = hledgerCommandMode
|
|
|
|
[here| swap-dates
|
2019-07-17 01:31:18 +03:00
|
|
|
Swap date and date2, on transactions which have date2 defined.
|
|
|
|
(Does not yet swap posting dates.)
|
2019-07-16 07:19:52 +03:00
|
|
|
FLAGS
|
|
|
|
|]
|
|
|
|
[]
|
|
|
|
[generalflagsgroup1]
|
|
|
|
[]
|
|
|
|
([], Nothing) -- Just $ argsFlag "[QUERY]")
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2019-07-17 01:31:18 +03:00
|
|
|
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts cmdmode
|
2019-07-16 07:19:52 +03:00
|
|
|
withJournalDo opts $
|
2019-07-17 01:31:18 +03:00
|
|
|
\j -> do
|
2019-07-16 07:19:52 +03:00
|
|
|
d <- getCurrentDay
|
|
|
|
let
|
|
|
|
q = queryFromOpts d ropts
|
|
|
|
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
|
2019-07-17 01:31:18 +03:00
|
|
|
ts' = map transactionSwapDates ts
|
|
|
|
mapM_ (putStrLn . showTransactionUnelided) ts'
|
|
|
|
|
|
|
|
transactionSwapDates :: Transaction -> Transaction
|
|
|
|
transactionSwapDates t@Transaction{tdate2=Nothing} = t
|
|
|
|
transactionSwapDates t@Transaction{tdate2=Just d} = t{tdate=d, tdate2=Just $ tdate t}
|