This commit is contained in:
Gwenhael Le Moine 2017-11-24 16:09:55 +01:00
parent a95134c201
commit 106cae75fb
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -1,11 +1,11 @@
# encoding: utf-8 # encoding: utf-8
require "csv" require "csv"
require "xml"
# Crystal wrapper module for calling ledger # Crystal wrapper module for calling ledger
class Ledger class Ledger
def initialize( binary : String = "ledger", ledger_file : String = ENV[ "LEDGER_FILE" ] ||= "/home/cycojesus/org/comptes.ledger" ) def initialize( binary : String = "ledger",
ledger_file : String = ENV[ "LEDGER_FILE" ] ||= "/home/cycojesus/org/comptes.ledger" )
@binary = binary @binary = binary
@file = ledger_file @file = ledger_file
end end
@ -39,7 +39,10 @@ class Ledger
.sort_by { |a| a.size } .sort_by { |a| a.size }
end end
def balance( cleared : Bool = false, depth : Int32 = 9999, period : String = nil, categories : String = "" ) : Array( NamedTuple( account: String, amount: Float64 ) ) def balance( cleared : Bool = false,
depth : Int32 = 9999,
period : String = nil,
categories : String = "" ) : Array( NamedTuple( account: String, amount: Float64 ) )
period = period.nil? ? "" : "-p '#{period}'" period = period.nil? ? "" : "-p '#{period}'"
depth = depth.nil? ? "" : "--depth #{depth}" depth = depth.nil? ? "" : "--depth #{depth}"
operation = cleared ? "cleared" : "balance" operation = cleared ? "cleared" : "balance"
@ -55,7 +58,8 @@ class Ledger
end end
end end
def graph_values( period : String = "", categories : Array(String) = ["Expenses"] ) : Hash( String, Array( NamedTuple( date: String, amount: String, currency: String ) ) ) def graph_values( period : String = "",
categories : Array(String) = ["Expenses"] ) : Hash( String, Array( NamedTuple( date: String, amount: String, currency: String ) ) )
period = period == "" ? "" : "-p '#{period}'" period = period == "" ? "" : "-p '#{period}'"
result = {} of String => Array(NamedTuple(date: String, amount: String, currency: String)) result = {} of String => Array(NamedTuple(date: String, amount: String, currency: String))
@ -72,7 +76,8 @@ class Ledger
result result
end end
def register( period : String = "", categories : Array(String) = ["Expenses"] ) : Array( NamedTuple( date: String, payee: String, account: String, amount: String, currency: String ) ) def register( period : String = "",
categories : Array(String) = ["Expenses"] ) : Array( NamedTuple( date: String, payee: String, account: String, amount: String, currency: String ) )
period = period == "" ? "" : "-p '#{period}'" period = period == "" ? "" : "-p '#{period}'"
CSV CSV