Lisää komento laskujen listaamiseen
This commit is contained in:
parent
e538c4c69f
commit
19e3573fe8
|
|
@ -26,6 +26,7 @@ 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,12 +23,14 @@ 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
|
||||||
|
|
||||||
|
|
@ -63,6 +65,11 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
{-# 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(..), parseOptions) where
|
module Laskutin.Options (Options(..), SendOptions(..), Command(..), ListOptions(..), parseOptions) where
|
||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Time (Day)
|
import Data.Time (Day)
|
||||||
|
|
@ -22,6 +22,7 @@ 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
|
||||||
|
|
@ -35,6 +36,8 @@ 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")
|
||||||
|
|
@ -45,7 +48,8 @@ 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")
|
||||||
|
|
@ -62,3 +66,8 @@ 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