Compare commits
No commits in common. "19e3573fe8381ec240892929e7c3392127273193" and "992d0b42b7de0e65ca20f09f329646adae54ed58" have entirely different histories.
19e3573fe8
...
992d0b42b7
|
|
@ -3,7 +3,7 @@
|
||||||
(url "https://git.savannah.gnu.org/git/guix.git")
|
(url "https://git.savannah.gnu.org/git/guix.git")
|
||||||
(branch "master")
|
(branch "master")
|
||||||
(commit
|
(commit
|
||||||
"54202c6b356df4942468ca5c3ff751ba00b182b7")
|
"ee0cf3b9ff4cd5a9d3637d09677195ea9ee1a8c0")
|
||||||
(introduction
|
(introduction
|
||||||
(make-channel-introduction
|
(make-channel-introduction
|
||||||
"9edb3f66fd807b096b48283debdcddccfea34bad"
|
"9edb3f66fd807b096b48283debdcddccfea34bad"
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ executable laskutin
|
||||||
Laskutin,
|
Laskutin,
|
||||||
Laskutin.CSV,
|
Laskutin.CSV,
|
||||||
Laskutin.Email,
|
Laskutin.Email,
|
||||||
Laskutin.InvoiceList,
|
|
||||||
Laskutin.Options,
|
Laskutin.Options,
|
||||||
Laskutin.Status,
|
Laskutin.Status,
|
||||||
Laskutin.Types
|
Laskutin.Types
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,12 @@ import Laskutin.Email
|
||||||
import Laskutin.Options
|
import Laskutin.Options
|
||||||
import Laskutin.Types
|
import Laskutin.Types
|
||||||
import Laskutin.Status
|
import Laskutin.Status
|
||||||
import Laskutin.InvoiceList
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
Options {csv, command} <- parseOptions
|
Options {csv, command} <- parseOptions
|
||||||
case command of
|
case command of
|
||||||
Status -> statusMain csv
|
Status -> statusMain csv
|
||||||
List listOptions -> listMain csv listOptions
|
|
||||||
Send sendOptions -> sendInvoicesMain csv sendOptions
|
Send sendOptions -> sendInvoicesMain csv sendOptions
|
||||||
UpdateTable bankCsv -> updateTableMain csv bankCsv
|
UpdateTable bankCsv -> updateTableMain csv bankCsv
|
||||||
|
|
||||||
|
|
@ -65,11 +63,6 @@ statusMain invoiceCsv = do
|
||||||
(_, invoices) <- parseCsvFile invoiceCsv
|
(_, invoices) <- parseCsvFile invoiceCsv
|
||||||
T.putStr $ showStatus $ invoiceStatus invoices
|
T.putStr $ showStatus $ invoiceStatus invoices
|
||||||
|
|
||||||
listMain :: FilePath -> ListOptions -> IO ()
|
|
||||||
listMain invoiceCsv options = do
|
|
||||||
(_, invoices) <- parseCsvFile invoiceCsv
|
|
||||||
T.putStr $ showInvoiceList options invoices
|
|
||||||
|
|
||||||
updateInvoices :: [CsvTransaction] -> CsvInvoice -> CsvInvoice
|
updateInvoices :: [CsvTransaction] -> CsvInvoice -> CsvInvoice
|
||||||
updateInvoices transactions invoice@CsvInvoice {reference, ..}
|
updateInvoices transactions invoice@CsvInvoice {reference, ..}
|
||||||
| csvIsPaid invoice = invoice
|
| csvIsPaid invoice = invoice
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
|
||||||
|
|
||||||
module Laskutin.InvoiceList (showInvoiceList) where
|
|
||||||
|
|
||||||
import qualified Data.Text as T
|
|
||||||
import qualified Data.Text.Encoding as T
|
|
||||||
|
|
||||||
import Data.MIME (renderAddress)
|
|
||||||
import Data.Maybe (mapMaybe, fromMaybe)
|
|
||||||
|
|
||||||
import Laskutin.Email (renderInvoiceRow)
|
|
||||||
import Laskutin.Types (renderEuro, renderReference)
|
|
||||||
import Laskutin.CSV (CsvInvoice(..), csvInvoiceSum, invoiceRowFromCsv)
|
|
||||||
import Laskutin.Options (ListOptions(..))
|
|
||||||
|
|
||||||
showInvoiceList :: ListOptions -> [CsvInvoice] -> T.Text
|
|
||||||
showInvoiceList ListOptions {verbose, overpaid} =
|
|
||||||
T.intercalate separator
|
|
||||||
. map render
|
|
||||||
. filter selectors
|
|
||||||
where render invoice@CsvInvoice {..}
|
|
||||||
| verbose = "Viite: " <> renderReference reference <> "\n" <>
|
|
||||||
"Sposti: " <> T.decodeUtf8 (renderAddress invoiceRecipient) <> "\n" <>
|
|
||||||
"Summa: " <> renderEuro (csvInvoiceSum invoice) <> "\n" <>
|
|
||||||
"Maksettu: " <> maybe "-" renderEuro paid <> "\n\n" <>
|
|
||||||
T.intercalate "\n" (renderInvoiceRow <$> mapMaybe invoiceRowFromCsv rows)
|
|
||||||
| otherwise = renderReference reference <> "\t" <>
|
|
||||||
T.decodeUtf8 (renderAddress invoiceRecipient) <> "\t" <>
|
|
||||||
maybe "-" renderEuro paid <> " / " <> renderEuro (csvInvoiceSum invoice)
|
|
||||||
separator = if verbose then "\n\n---\n\n" else "\n"
|
|
||||||
selectors = if overpaid then (>) <$> fromMaybe 0 . paid <*> csvInvoiceSum else const True
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE NoFieldSelectors #-}
|
{-# LANGUAGE NoFieldSelectors #-}
|
||||||
|
|
||||||
module Laskutin.Options (Options(..), SendOptions(..), Command(..), ListOptions(..), parseOptions) where
|
module Laskutin.Options (Options(..), SendOptions(..), Command(..), parseOptions) where
|
||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Time (Day)
|
import Data.Time (Day)
|
||||||
|
|
@ -22,7 +22,6 @@ data Options = Options
|
||||||
data Command = Send SendOptions
|
data Command = Send SendOptions
|
||||||
| UpdateTable FilePath
|
| UpdateTable FilePath
|
||||||
| Status
|
| Status
|
||||||
| List ListOptions
|
|
||||||
|
|
||||||
data SendOptions = SendOptions
|
data SendOptions = SendOptions
|
||||||
{ account :: IBAN
|
{ account :: IBAN
|
||||||
|
|
@ -36,8 +35,6 @@ data SendOptions = SendOptions
|
||||||
, dryRun :: Bool
|
, dryRun :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
data ListOptions = ListOptions { verbose :: Bool, overpaid :: Bool}
|
|
||||||
|
|
||||||
parseOptions :: IO Options
|
parseOptions :: IO Options
|
||||||
parseOptions = execParser $ info (options <**> helper)
|
parseOptions = execParser $ info (options <**> helper)
|
||||||
(fullDesc <> progDesc "Send email invoices from CSV" <> header "laskutin - email invoice sender")
|
(fullDesc <> progDesc "Send email invoices from CSV" <> header "laskutin - email invoice sender")
|
||||||
|
|
@ -48,8 +45,7 @@ options = Options
|
||||||
<*> subparser
|
<*> subparser
|
||||||
(command "send" (info (sendOptions <**> helper) (progDesc "Send email invoices from CSV"))
|
(command "send" (info (sendOptions <**> helper) (progDesc "Send email invoices from CSV"))
|
||||||
<> command "update" (info (updateTableOptions <**> helper) (progDesc "Update invoice CSV from a bank CSV"))
|
<> command "update" (info (updateTableOptions <**> helper) (progDesc "Update invoice CSV from a bank CSV"))
|
||||||
<> command "status" (info (pure Status) (progDesc "Print the status of the invoices"))
|
<> command "status" (info (pure Status) (progDesc "Print the status of the invoices")))
|
||||||
<> command "list" (info ((List <$> listOptions) <**> helper) (progDesc "List the invoices")))
|
|
||||||
|
|
||||||
updateTableOptions :: Parser Command
|
updateTableOptions :: Parser Command
|
||||||
updateTableOptions = UpdateTable <$> strOption (long "bank-csv" <> metavar "FILE")
|
updateTableOptions = UpdateTable <$> strOption (long "bank-csv" <> metavar "FILE")
|
||||||
|
|
@ -66,8 +62,3 @@ sendOptions = fmap Send $ SendOptions
|
||||||
<*> strOption (long "sendmail" <> short 'm' <> metavar "FILE" <> help "The sendmail program to use")
|
<*> strOption (long "sendmail" <> short 'm' <> metavar "FILE" <> help "The sendmail program to use")
|
||||||
<*> switch (long "reminders" <> short 'r' <> help "Send reminder emails")
|
<*> switch (long "reminders" <> short 'r' <> help "Send reminder emails")
|
||||||
<*> switch (long "dry-run" <> short 'd' <> help "Only print what invoices would be sent. Do not send anything")
|
<*> switch (long "dry-run" <> short 'd' <> help "Only print what invoices would be sent. Do not send anything")
|
||||||
|
|
||||||
listOptions :: Parser ListOptions
|
|
||||||
listOptions = ListOptions
|
|
||||||
<$> switch (long "verbose" <> short 'v' <> help "Print entire invoices")
|
|
||||||
<*> switch (long "overpaid" <> short 'o' <> help "Only print overpaid invoices")
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue